Note that there are some explanatory texts on larger screens.

plurals
  1. POopenMP conditional pragma "if else"
    primarykey
    data
    text
    <p>I have a for loop that can be executed using <code>schedule(static)</code> or <code>schedule(dynamic, 10)</code> 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:</p> <pre><code>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 } } </code></pre> <p>After reading these threads, I noticed that openMP has an <code>#if(expression)</code> pragma:</p> <ul> <li><a href="https://stackoverflow.com/questions/7413331/openmp-conditional-use-of-pragma">OpenMP: conditional use of #pragma</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/5187hzke.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/5187hzke.aspx</a></li> <li><a href="https://stackoverflow.com/questions/9366466/choose-openmp-pragma-according-to-condition">Choose OpenMP pragma according to condition</a></li> <li><a href="https://stackoverflow.com/questions/4085595/conditional-pragma-omp">Conditional &quot;pragma omp&quot;</a></li> <li><a href="http://openmp.org/mp-documents/ntu-vanderpas.pdf" rel="nofollow noreferrer">http://openmp.org/mp-documents/ntu-vanderpas.pdf</a></li> </ul> <p>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. </p> <p>So I wonder, does OpenMP have an <code>#if(expression) else</code> sort of pragma? Something like:</p> <pre><code>#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) </code></pre> <p>Or am I forced to place my for loop body into a separate function and call it that way?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload