arrays - Parallelizing pairwise gravitational force calculation with OpenMP in Fortran 90 -
i trying parallelize calculation of gravitational forces in program using openmp. calculation of distances (r , r2) no problem forces/accelerations (a) come out wrong. know has race conditions in summation. have experimented bit atomic , critical constructs not find solution. also, i'm not sure variables should private , why.
does more experience in using openmp have suggestion on how correct in following code example?
a = 0.0 !$omp parallel do = 1, nobj j = + 1, nobj r2(i,j) = (x(j,1) - x(i,1))**2 & + (x(j,2) - x(i,2))**2 & + (x(j,3) - x(i,3))**2 r(i,j) = sqrt(r2(i,j)) k = 1, 3 a(i,k) = a(i,k) + ((mass_2_acc(i,j) / r2(i,j)) * ((x(j,k) - x(i,k)) / r(i,j))) a(j,k) = a(j,k) + ((mass_2_acc(i,j) / r2(i,j)) * ((x(i,k) - x(j,k)) / r(i,j))) enddo enddo a(i,:) = a(i,:) * g / mass_acc(i) enddo !$omp end parallel
you modifying a(j,k)
- neither j
nor k
"local" thread thread-parallel index i
. mean neither of index ranges restricted particular thread, threads update a(j,k)
hence race condition.
things can - split r
, a
calculations or not use symmetry update a
.
also, fortran column major , traversing outer index first bad performance.
Comments
Post a Comment