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]);
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:
<
, <=
, >
or >=
; andI simply rewrote your loop to abide to these simple rules. It was easy enough, as it is in most cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With