17

Is there a way to set number of threads in OpenMP parallel for region based on the value of a variable? Initially for the whole application number of threads = nofCores. On my AMD FX 8350, nofCores =8. For this area if the variable is 3 then I only need 3 threads. If variable>cores then number of threads should remain equal to nofCores.

I do not want to set the number of threads globally for all the application. Just for this specific parallel loop.

Sorry if this is a naive question, but I am a newbie in OpenMP.

1
  • 5
    make sure to look into the documentation; it's not that massive. Commented Oct 8, 2013 at 14:23

1 Answer 1

33

Add this to your omp parallel for directive:

#pragma omp parallel for num_threads(variable)
for( ... )
Sign up to request clarification or add additional context in comments.

Comments

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.