Search code examples
cparallel-processingpgcc

pgcc, C - Loop not parallelized: may not be beneficial


I want help to figure out automatic parallelization with error - Loop not parallelized: may not be beneficial. I want to test this code for parallelization, but I don't know, how to make the code effective for compiler to parallelizie it.

Here is the code:

   for (i = 0; i < piece_length; i++) {
       x=(i/(double)piece_length)+piece/(float)2;
      // if(x<=1.0){
           integral=4/(1+x*x);
           sum=sum+integral;
      // }  

    }

Loop not parallelized: may not be beneficial

Do you know how to make this loop more time demanding to be able to accept automatic parallelization?

Thx


Solution

  • The result that your are accumulating in sum is dependent on the order of computation. I imagine that pgcc must have a way that you can tell that you don't care about the implications that reordering might have. But as such it can't know and it can't parallelize anything.

    In OpenMp you would put something like

    #pragma omp parallel for reduction(+: sum)
    

    in front of the loop.