I have a fortran code in which I have a parallel part. It is compiled by gfortran successfully, but I get a segmentation fault by running it. The serial compiled run file does not show any fault. Also I have examined the parallel program with very small input matrix (rho1 & rho2) and tested the step by step parameters. There were no fault. If I understand correctly, when I determine the variables as PRIVATE, there is no need to use
$OMP ATOMIC. Here the matrices rho1 and rho2, have a dimension of about 15,000,000. Here is the parallel part of code:
!$OMP PARALLEL DO ORDERED DEFAULT(PRIVATE)
do ix = 1 , nx
do iy = 1 , ny
do iz = 1 , nz
k = iz + (iy-1) * nz + (ix-1) * ny * nz
if (rho1(k) .GT. 0.d0) then
x1 = x0 + ((ix-1) * dx)
y1 = y0 + ((iy-1) * dy)
z1 = z0 + ((iz-1) * dz)
rr = (x1-xa)**2 + (y1-ya)**2 + (z1-za)**2
r1a = dsqrt (rr)
rr = (x1-xb)**2 + (y1-yb)**2 + (z1-zb)**2
r1b = dsqrt (rr)
if (r1a == 0.d0) Vnuc = (rho1(k) * Znb)/r1b
if (r1b == 0.d0) Vnuc = (rho1(K) * Zna)/r1a
if (r1a .GT. 0.d0 .AND. r1b .GT. 0.d0) then
Vnuc = (rho1(k) * Zna)/r1a + (rho1(K) * Znb)/r1b
endif
Ve = 0
!$OMP ORDERED
j = 1
do jx = 1 , nx
do jy = 1 , ny
do jz = 1 , nz
if (rho2(j) .GT. 0.d0) then
x2 = x0 + ((jx-1) * dx)
y2 = y0 + ((jy-1) * dy)
z2 = z0 + ((jz-1) * dz)
rr= (x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2
r12 = dsqrt (rr)
if (r12 .GT. 0.d0) then
Ve = Ve + (rho1(k)*rho2(j))/r12
endif
endif
j = j + 1
enddo
enddo
enddo
!$OMP END ORDERED
V1 = (Ve * dx * dy * dz * 0.529177d0) - Vnuc
rr = (x1-xmid)**2 + (y1-ymid)**2 + (z1-zmid)**2
r = dsqrt (rr)
zef1(k) = V1 * r
endif
enddo
enddo
enddo
!$OMP END PARALLEL DO
gfortran -fbounds-check -O0 -g -ggdbor something and then run?nyandnzbefirstprivate?