Are variables supported in parallel?

I read this article: Parallel programming in Fortran 95 using OpenMP Where it reads on pages 11 and 12, which:

real(8) :: A(1000), B(1000) 
! $OMP PARALLEL DO
do i = 1, 1000 
   B(i) = 10 * i 
   A(i) = A(i) + B(i) 
enddo
! $OMP END PARALLEL DO

It cannot work because matrix values ​​are Bnot guaranteed to ! $OMP END (PARALLEL) DO. For me, this is crucial. I have several loops with many statements that depend on previous statements in the do loop, and I thought it would be natural. I get that B(j)cannot be provided at the iteration i, given that i/=j, but at the same iteration I thought it was a given. Am I right or wrong? If so, is there a command to ensure that, at least during the iteration, the values ​​of the variables are updated for each statement to the next?

I tried a few simple loops that seem to work as if it were serial code, but I have another code where it seems a bit more random: it works with / O 3 but not / O 0, the code is pretty big and a bit hard to read, so I won’t post it here ...)

+4
source share
2 answers

It looks very strange. If it was like most of the code you see that uses OpenMP would be a mismatch. You will see such things throughout your code base, and I believe the lawsuit is fictitious. Unfortunately, there is no direct reference to the corresponding piece of specification there, and it is difficult to find what was meant.

, , atomic critical, , , .

, , , , .

+4

.

"" OpenMP", OpenMP.

" " , "" "" ( flush ..). . , . , .

+2

All Articles