[Omp] Array update inside a parallel loop

Francisco Jesús Martínez Serrano franjesus at gmail.com
Wed Dec 7 08:59:56 PST 2005


Thanks for the prompt answer.

That statement has mislead us a bit, but from my understanding of the
underlying pthreads mechanism it had to be wrong.

Many thanks for your tutorial it's very clear and has proven very useful.

Saludos! ;-)

2005/12/7, Miguel Hermanns <hermanns at tupi.dmt.upm.es>:
> Dear Francisco,
>
> Thanks for including me in the discussion. The example you mention of my
> tutorial is wrong and you are right. Somebody already pointed me to it,
> but I had no time yet to change it. I will correct it in the next
> version of the tutorial, which I hope I will be able to do in 2006.
>
> Best regards,
>
> Miguel Hermanns
>
> Francisco Jesús Martínez Serrano wrote:
> > Is it safe to access parts of an array previously updated inside the
> > same parallel loop if you are only accessing the parts "belonging" to
> > the current thread?
> >
> > According to Miguel Hermanns
> > (http://www.openmp.org/presentations/miguel/F95_OpenMPv1_v2.pdf), it's
> > not, since:
> >
> > "Since each thread is executing part of the iterations of the do-loop
> > and the updates of
> > the modifications made to the variables are not ensured until the end
> > of the work-sharing
> > construct, the following example will not work correctly using the
> > !$OMP DO/!$OMP END
> > DO directive-pair for its parallelization:
> >
> > real(8) :: A(1000), B(1000)
> > do i = 1, 1000
> >   B(i) = 10 * i
> >   A(i) = A(i) + B(i)
> > end do
> >    because the correct value of the matrix B is not ensured until the
> > end of the work-
> > sharing construct !$OMP END DO.
> > "
> >
> > However, i'm doing precisely that to make a parallel 3D convolution
> > routine using fftw and multiple calls to fftw 1D (the 3D version of
> > fftw does not work for us because of special boundary conditions).
> >
> > In fact, trying this same example with the latest public version of
> > Intel's Fortran compiler (9.0.028):
> >
> >       program test4
> >       implicit none
> >       integer,parameter :: N=10000000
> >       real(4) :: A(N), B(N)
> >       integer(4) :: i
> > !$OMP PARALLEL DEFAULT(PRIVATE) SHARED(A,B)
> > !$OMP DO
> >       do i = 1,N
> >         A(i)=0.
> >       end do
> > !$OMP END DO
> >
> > !$OMP DO
> >       do i = 1,N
> >         B(i) = float(i)
> >         A(i) = A(i) + B(i)
> >       end do
> > !$OMP END DO
> > !$OMP END PARALLEL
> >
> >       do i = 1,N
> >         if(A(i) .ne. float(i)) then
> >           print*, 'OOOOOOOOooooooooops!!'
> >           exit
> >         end if
> >       end do
> >
> >       end program
> >
> > works fine and does not yield any error. What am i missing? Is the
> > fortran compiler implementing some sort of data-consistency that I am
> > unaware of?
> >
> > Thanks.
> >
>


More information about the Omp mailing list