0

I have a function myFunc() which utilizes OMP loops internally, but does not consume all the cores I have available. At a higher level, I call this function several times within a loop. Is there a simple way to use OMP on this outer loop, but not restrict each loop pass to a single thread?

e.g:

// I have 24 cores
// Would like to allow each for loop pass to have 12 cores
for (int outIter=0; outIter<2; outIter++) {
    x[outIter] = myFunc(...)  // This function has OMP inside
}

1 Answer 1

1

You should first find out, why myFunc cannot exhaust all 24 cores. Often you are limited by memory bandwidth. Having said that, the above loop is obviously not parallel. You would have to try something like this:

#pragma omp parallel num_threads(2)
{
   myFunc(...);
}

where myFunc's input would be a function of omp_get_thread_num(). But again, do not be to hopeful of being able to achieve more parallelism. If your problem is limited by memory bandwidth there is little hope for speedup. What happens roughly in you myFunc?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, yeah, I know it's not parallel as is. If I put the pragma statement right above the for loop, my understanding is that this provides only a single thread to each loop iteration (normal use case being loop_iterations >> number_of_cores). Any additional OMP calls inside the loop would be negated because there is only one thread available. Inside the function, the for loops are over small numbers of iterations which is why I'm trying to do this.
No go on with your omp calls inside. This just breaks down the outer loop in two. It does not limit the inside operation to 2 cores. You might have to look, if you gain anything from specifying KMP_AFFINITY additionally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.