I have a for loop that can be executed using schedule(static)
or schedule(dynamic, 10)
depending on a condition. Currently, My code is not DRY (Don't repeat yourself) enough and to accommodate the previous functionality it has the following repetition:
boolean isDynamic; //can be true or false
if(isDynamic){
#pragma omp parallel for num_threads(thread_count) default(shared) private(...) schedule(dynamic, 10)
for(...){
//for code inside
}
}else{
#pragma omp parallel for num_threads(thread_count) default(shared) private(...) schedule(static)
for(...){
//SAME for code inside, in fact, this is the EXACT same for as before
}
}
After reading these threads, I noticed that openMP has an #if(expression)
pragma:
- OpenMP: conditional use of #pragma
- http://msdn.microsoft.com/en-us/library/5187hzke.aspx
- Choose OpenMP pragma according to condition
- Conditional "pragma omp"
- http://openmp.org/mp-documents/ntu-vanderpas.pdf
But although I've seen many people with my problem, there seems to be lacking a general solution. The best solution is to transform the body of the for loop into a function, and then have the function called, but this solution is not good enough for me.
So I wonder, does OpenMP have an #if(expression) else
sort of pragma?
Something like:
#if(isDynamic )pragma omp parallel for num_threads(thread_count) default(shared)
private(...) schedule(dynamic, 10)
else
pragma omp parallel for num_threads(thread_count) default(shared)
private(...) schedule(static)
Or am I forced to place my for loop body into a separate function and call it that way?