1 | Correct reduction: |
2 | c$omp parallel private(suml,i) |
3 | c$omp& shared(sum,a,n) |
4 | suml = 0.0 |
5 | c$omp do |
6 | do 10 i=1,n |
7 | 10 suml = suml + a(i) |
8 | c$omp critical |
9 | sum = sum + suml |
10 | c$omp end critical |
11 | c$omp end parallel |
12 | Using Reduction does the same: |
13 | c$omp parallel private(i) |
14 | c$omp& shared(a,n) |
15 | c$omp& reduction(+:sum) |
16 | c$omp do |
17 | do 10 i=1,n |
18 | 10 sum = sum + a(i) |
19 | c$omp end parallel |