I am adding omp command to run my program in a i-j nested loop. However, the result was very different from the original/serial job which I have no idea why that happened. I suspect if this issue has somethg to do with my global variable (it shouldn't be...). It will be great if I can get some help here. The following is part of my code.
(n_tot, xn, yn, zn, chk_radius, pow, G, m, de, rn and PEj are declared as global variable in the global module)
- Code: Select all
subroutine selfg()
use global
implicit none
integer :: i, j
real :: delx, dely, delz, rr, r, netaccterm
real, dimension(n_tot,n_tot) :: gxj, gyj, gzj, PEj
!$omp parallel do private(j,delx,dely,delz,rr,r,netaccterm) &
!$omp num_threads(4)
do i=1, n_tot
do j=i+1, n_tot
delx = xn(step,i)-xn(step,j)
dely = yn(step,i)-yn(step,j)
delz = zn(step,i)-zn(step,j)
rr = delx**2+dely**2+delz**2
r = sqrt(rr)
rn(i,j) = r
if (r < chk_radius) then
!models of self-gravitation
netaccterm = G*m*(-1/rr + de**(pow-2)/r**pow)/r !inverse law
gxj(i,j) = delx*netaccterm
gyj(i,j) = dely*netaccterm
gzj(i,j) = delz*netaccterm
PEj(i,j) = G*m*(-1/r + de**(pow-2)*r**(1-pow)/(pow-1))
endif
enddo
enddo
!$omp end parallel do
.
.
.
end subroutine selfg
I appreciate for your help...
-yt
