multithreading - Is it legal that the index for !$omp atomic different from its host's loop index variable? -
i came across question when learning how avoid data conflict multiple threads potential reading , writing using openmp directive !$atomic.
shown in text below code snippet made question. wondering if legal in fortran use different index (here j) !$atomic loop index variable i, 1 following directive !$omp parallel private(a,b) ? thanks.
program main ... integer :: i,j integer, dimension(10000) :: vx,vy,va,vb ... va=0 !$omp parallel private(j) i=1,10000 j=merge(vx(i),vy(i),mod(i,2)==1) !$omp atomic update va(j)=va(j)+vb(j) end !$omp end parallel ... end program
furthermore, ok loop on atomic directive?
program main ... integer :: i,j integer, dimension(10000) :: vx,vy integer, dimension(12,10000) :: va,vb ... va=0 !$omp parallel private(j,k) i=1,10000 j=merge(vx(i),vy(i),mod(i,2)==1) k=1,12 !$omp atomic update va(k,j)=va(k,j)+vb(k,j) enddo end !$omp end parallel ... end program
yes, why not? update of memory address, there no difference. there wouldn't sense in using atomic in case, different threads have different values of i
.
but, aware of race condition j
writing more thread, should private
.
your second example adds nothing new, same situation, still legal.
Comments
Post a Comment