Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenMP error invalid controlling predicate [duplicate]

Tags:

c++

c

openmp

I have written the following code and trying to parallelize it using openmp. but i am unbale to compile the program and end up with error invalid controlling predicate error

#pragma omp parallel for schedule(dynamic, 1)
for( ; i+o<N*C && i < C*n; i++ )
       buf[i] = (a[i]-b[i])*(a[i]-b[i]);
like image 629
Ishant Mrinal Avatar asked Nov 03 '15 07:11

Ishant Mrinal


1 Answers

Rewrite the loop like this and it should work:

int maxII = min( N*C-o, C*n);
#pragma omp parallel for schedule(dynamic, 1)
for ( int ii=i; ii<maxII; ii++ )
   buf[ii] = (a[ii]-b[ii])*(a[ii]-b[ii]);

OpenMP for loops have to follow a "Canonical Loop Form" as described in the standard chapter 2.6


EDIT: "Could you please explain me what was wrong with my code?"

Well, the loop form you used isn't compliant with OpenMP's "Canonical Loop Form" which basically (I over-simply here, sorry) asks that:

  • the loop index is clearly defined;
  • the lower bound of the loop is given in the initialisation part;
  • the test is one of the following operators: <, <=, > or >=; and
  • the increment is clear.

I simply rewrote your loop to abide to these simple rules. It was easy enough, as it is in most cases.

like image 170
Gilles Avatar answered Oct 11 '22 13:10

Gilles