Error "incorrect predicate control" when compiling with -fopenmp

void random(int M,int a,int c,int *seq,int start,int size) { int i = start; seq[0] = 1; seq[i] = (a * seq[i - size] + c) % M; i += size; } for(int iter = 0;iter < ceil((double)(n/size));iter++) { random(M,a,c,seq,1,1); } 

A loop compiled with -fopenmp and gcc gives the error "incorrect predicate control". How to solve it?

+6
source share
2 answers

There are no OpenMP constructs in the code shown, so compiling with or without -fopenmp should not affect it. But if there was a [parallel] for construct, then it fails, because the ceil() type is double , and OpenMP allows only integer types in loops.

You must force the result from ceil() to an integer:

 #pragma omp parallel for for(int iter = 0; iter < (int)ceil((double)n/size); iter++) { random(M,a,c,seq,1,1); } 
+4
source

I gave an example from your code that I can compile correctly (I did not try to execute it).

I can compile it with the following command (note the -lm linker option):

 gcc -fopenmp <<example_name>>.c -lm 

The code:

 #include <math.h> int n = 1; int size = 2; int M, a, c; int *seq; void random(int M,int a,int c,int *seq,int start,int size) { int i = start; seq[0] = 1; seq[i] = (a * seq[i - size] + c) % M; i += size; } int main() { double iter = 0; for(;iter < ceil((double)(n/size));iter++) { random(M,a,c,seq,1,1); } return 0; } 
+2
source

All Articles