Why is the != operator not allowed with OpenMP

General OpenMP discussion

Why is the != operator not allowed with OpenMP

Postby Vortex16 » Mon Nov 12, 2012 9:23 am

Hello, i had come across, a couple of days, on this question on stackoverflow http://stackoverflow.com/questions/1331 ... ith-openmp. It make me also wonder why, does someone know the reason why? thanks.
Vortex16
 
Posts: 3
Joined: Sun Nov 11, 2012 1:02 pm

Re: Why is the != operator not allowed with OpenMP

Postby ftinetti » Mon Nov 12, 2012 11:55 am

Well, using != implies there is no way to know in advance the number of actual iterations... from the Spec.
The canonical form allows the iteration count of all associated loops to be computed before executing the outermost loop.


Fernando.
ftinetti
 
Posts: 558
Joined: Wed Feb 10, 2010 2:44 pm

Re: Why is the != operator not allowed with OpenMP

Postby Vortex16 » Mon Nov 12, 2012 12:00 pm

So should it allow for(int i = 0; i != 10; i++) for example? we know before hand that will be 10 iterations.
Vortex16
 
Posts: 3
Joined: Sun Nov 11, 2012 1:02 pm

Re: Why is the != operator not allowed with OpenMP

Postby ftinetti » Mon Nov 12, 2012 2:25 pm

So should it allow for(int i = 0; i != 10; i++) for example? we know before hand that will be 10 iterations.


No, perhaps you should take a look at the OpenMP Spec. (original text formatting not maintained in this copy):

The for directive places restrictions on the structure of all associated for-loops.
Specifically, all associated for-loops must have the following canonical form:
for (init-expr; test-expr; incr-expr) structured-block
init-expr One of the following:
var = lb
integer-type var = lb
random-access-iterator-type var = lb
pointer-type var = lb
test-expr One of the following:
var relational-op b
b relational-op var
incr-expr One of the following:
++var
var++
--var
var--
var += incr
var -= incr
var = var + incr
var = incr + var
var = var - incr
var One of the following:
A variable of a signed or unsigned integer type.
For C++, a variable of a random access iterator type.
For C, a variable of a pointer type.
If this variable would otherwise be shared, it is implicitly made
private in the loop construct. This variable must not be
modified during the execution of the for-loop other than in
incr-expr. Unless the variable is specified lastprivate on
the loop construct, its value after the loop is unspecified.
relational-op One of the following:
<
<=
>
>=
lb and b Loop invariant expressions of a type compatible with the type
of var.
incr A loop invariant integer expression.


HTH,

Fernando.
ftinetti
 
Posts: 558
Joined: Wed Feb 10, 2010 2:44 pm

Re: Why is the != operator not allowed with OpenMP

Postby Vortex16 » Sat Dec 01, 2012 3:07 pm

Thanks, for all the help. Apparently the original poster, send it a email for the develop team about the subject and they had answer about the reason for that constrain. If you are wonder it here http://stackoverflow.com/questions/1331 ... ith-openmp .
Vortex16
 
Posts: 3
Joined: Sun Nov 11, 2012 1:02 pm


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 11 guests