Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'invalid controlling predicate' error when compiled with-fopenmp

Tags:

c

openmp

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);    
}

The loop compiled with -fopenmp and gcc gives "invalid controlling predicate" error. How to solve it?

like image 680
Anirudh Avatar asked Sep 10 '16 07:09

Anirudh


2 Answers

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

You have to coerce 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);
}
like image 116
Hristo Iliev Avatar answered Nov 15 '22 10:11

Hristo Iliev


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

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

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

The code is;

#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;
}
like image 20
acornagl Avatar answered Nov 15 '22 09:11

acornagl