Countable loops for openMP

General OpenMP discussion

Countable loops for openMP

Postby david.livshin » Sun Nov 18, 2018 3:32 am

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,


David
http://www.dalsoft.com
david.livshin
 
Posts: 2
Joined: Mon Jul 09, 2018 10:11 pm

Re: Countable loops for openMP

Postby MarkB » Mon Nov 19, 2018 3:03 am

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.
MarkB
 
Posts: 779
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 3 guests

cron