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