Reputation: 9
I want to parallelize a loop that have a sequence of random numbers generated by the function erand48. The order of the sequence is important so I can't change it. I tried this:
#pragma omp parallel for
for(int i=0; i<5; i++){
printf("%f \n",erand48(vector));
}
But the order of the sequence changed. Any suggestion??
Upvotes: 0
Views: 161
Reputation: 32717
If the order of execution is important, you can't parallelize the loop. When it is parallelized, the 2nd iteration could run before the 1st one.
You could generate all of your random numbers, store those in an array, then run the parallel loop accessing the array.
Upvotes: 1