I have a code that I want to optimise that should run in a variaty of threads ammount. After running some tests using different scheduling techniques in a for loop that I have, I came to the conclusion that what suits best is to perform a dynamic scheduling when I have only one thread and guided otherwise. Is that even possible in openMP?
To be more precise I want to be able to do something like the following:
if(omp_get_max_threads()>1)
#pragma omp parallel for .... scheduling(guided)
else
#pragma omp parallel for .... scheduling(dynamic)
for(.....){
...
}
If anyone can help me I would appreciate it. The other solution would be to write two times the for loop and use an if condition. But I want to avoid that if it is possible.
Possible solution is to copy the loop into an if statement and to "extract" loop body into function to avoid breaking DRY principle. Then there will be only one place where you have to change this code if you need to change it in the future:
void foo(....)
{
...
}
if(omp_get_max_threads()>1)
{
#pragma omp parallel for .... scheduling(guided)
for (.....)
foo(....);
}
else
{
#pragma omp parallel for .... scheduling(dynamic)
for (.....)
foo(....);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With