2

I use this for loop, which I want to have parallelizide automaticaly, it is used for count of PI number:

piece=1.0/100000;
for (t=0.0; t<1.0; t=t+piece){
    x=t+piece/(float)2;
    if(x<=1.0){
        integral=4/(1+x*x);
        sum=sum+integral;
        }
}

This is doint partial sum for all values in interval 0-1. Then I made from it PI value. But this is not the problem, problem is, when I use automatic parallelization with pgcc, I set up number of processes but I am told that "Loop not vectorized/parallelized: not countable" when I am compiling my program. I have tried everything, but still no change. Any ideas? Thanks

Waypoint
  • 17,283
  • 39
  • 116
  • 170

2 Answers2

3

Your loop variable is a double, try changing the code so it uses an integer:

for (int t = 0; t < 100000; t++) {
    x=(t/100000.0)+piece/(float)2;
    if(x<=1.0){
        integral=4/(1+x*x);
        sum=sum+integral;
        }
}
schnaader
  • 49,103
  • 10
  • 104
  • 136
2

I'm guessing this is because your loop counter is a float or double. Try using an integral counter.

int step;
for (step = 0; step < 100000; step++) {
   // determine x from step
   ...
}
Mat
  • 202,337
  • 40
  • 393
  • 406
  • Thanks, but now I am getting this one: Loop not parallelized: may not be beneficial :-( – – Waypoint Mar 19 '11 at 16:30
  • I don't know enough about pgcc, but it looks like it thinks the loop is too "simple" to merit a parallel rework. Could you try splitting it in two nested loops like (pseudo-code) `for (step 1..100) { for (substep 1..10000) { ... } }` ? That would make each `step` of the outer loop more "expensive" / maybe worthy of running parallel. (This is a pure guess) – Mat Mar 19 '11 at 16:35
  • Thank you for your comment. I tried it, but pgcc doesn't like when something contains call, so thanks anyway for help – Waypoint Mar 19 '11 at 16:44
  • there are no calls in what I suggested, just nested for loops – Mat Mar 19 '11 at 16:48