Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9171811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:12:50+00:00 2026-06-17T16:12:50+00:00

I want to parallelize the following function with OpenMP: void calculateAll() { int k;

  • 0

I want to parallelize the following function with OpenMP:

void calculateAll() {
int k;
int nodeId1, minCost1, lowerLimit1, upperLimit8;
for (k = mostUpperLevel; k > 0; k--) {
    int myStart = borderNodesArrayStartGlobal[k - 1];
    int size = myStart + borderNodesArraySizeGlobal[k - 1];
/* this loop may be parallel */    
for (nodeId1 = myStart; nodeId1 < size; nodeId1++) {
        if (getNodeScanned(nodeId1)) {
            setNodeScannedFalse(nodeId1);
        } else {
            minCost1 = myMax;
            lowerLimit1 = getNode3LevelsDownAll(nodeId1);
            upperLimit8 = getUpperLimit3LevelsDownAll(nodeId1);
            changeNodeValue(nodeId1, lowerLimit1, upperLimit8, minCost1, minCost1);
        }
    }
}

int myStart = restNodesArrayStartGlobal;
int size = myStart + restNodesArraySizeGlobal;
/* this loop may also be parallel */  
for (nodeId1 = myStart; nodeId1 < size; nodeId1++) {
    if (getNodeScanned(nodeId1)) {
        setNodeScannedFalse(nodeId1);
    } else {
        minCost1 = myMax;
        lowerLimit1 = getNode3LevelsDownAll(nodeId1);
        upperLimit8 = getUpperLimit3LevelsDownAll(nodeId1);
        changeNodeValue(nodeId1, lowerLimit1, upperLimit8, minCost1, minCost1);
    }
}
}

Although I can use “omp pragma parallel for” on the 2 inside loops, code is too slow due to the constant overhead of creating new threads. Is there a way to separate “omp pragma parallel” so that at the beginning of function I take the necessary threads and then with “omp pragma for” to get the best possible results? I am using gcc 4.6.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:12:51+00:00Added an answer on June 17, 2026 at 4:12 pm

    The creation of the threads is normally not the bottleneck in openmp programs. It is the distribution of the tasks to the threads. The threads are actually generated at the first #pragma omp for (You can verify that with a profiler like VTune. At each loop the work is assigned to the threads. This assignment is often the problem as this is a costly operation.

    However you should try to play around with the schedulers. As this might have a big impact on the performance. E.g play with schedule(dynamic,chunksize) vs schedule(static,chunksize) and also try different chunksizes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following nested for loops. I want to parallelize the first loop
Following to this post , I want parallelize this method : public IEnumerable<string> GetAllLogs(IEnumerable<IComputer>
As the title states, I want to parallelize a sum using OpenMP. I searched
I want to parallelize a function using IPython.parallel, and when I define it in
I want to use MPI to parallelize a function that is being called multiple
I want to write a function which employs openMP parallelism but should work whether
I want to parallelize a loop in a class member function. However there are
I have a function that I eventually want to parallelize. Currently, I call things
I want to parallelize an numerical integration function. I want to use this function
I create a QFuture that I want to use to parallelize calls to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.