6

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]);
Ishant Mrinal
  • 4,898
  • 3
  • 29
  • 47
  • 1
    Check out http://stackoverflow.com/questions/13312679/why-is-the-operator-not-allowed-with-openmp – gokul_uf Nov 03 '15 at 07:12

1 Answers1

14

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.

Gilles
  • 9,269
  • 4
  • 34
  • 53