Page 1 of 1

Countable loops for openMP

Posted: Sun Nov 18, 2018 3:32 am
by david.livshin
Some OpenMP related documents state that in order for loop to be treated by OpenMP is must be “countable” providing different definitions for loop being “countable”:
• the number of iterations in the loop must be countable with an integer and loop use a fixed increment.
• the loop count can be “determined” ( what does it mean “determined”? )
Is it indeed the requirement of OpenMP? Or is it requirement of a specific compiler implementation of OpenMP?
Can the following code ( doesn't seems to be countable ) be parallelized by OpenMP ( note that the question is if the code can be pararallelized and not if there is a way to create a parallel equivalent of the code )
for ( i = 0; i < cnt; )
x1 = 2.0 * x - 1.;
if ( x1 < 1.0 )
i = i + 3;
x = x*2.;
else // if ( x1 >= 1. )
i = i + 2;
x = x/2.;

Thank you,


Re: Countable loops for openMP

Posted: Mon Nov 19, 2018 3:03 am
by MarkB
It's a requirement of OpenMP - the standard lays out some (somewhat verbose) restrictions on the form of for loops that are allowable with the OpenMP loop directive (Section 2.9.1 starting on Page 95 in Version 5.0). The rationale for these restrictions is indeed that the runtime needs to be able to compute the number of loop iterations before the loop starts executing. Your example is not allowed because the loop iterator is modified in the body of the loop.