Home > Mobile >  After the openmp parallel Fortran inconsistent results every time
After the openmp parallel Fortran inconsistent results every time

Time:09-17

Inconsistent results every time, after parallel to atomic assignment code is protected, have a big help to look at what's going on,
Code is very long, also do not know to have bosses have the patience to read...
 implicit none 
An integer n, m, node, node1, 2, ni, mj, p, q, k
The integer I, j

Real RCM (3) (4), RCN (3), dist
R2f real r1f (3), (3), r3f (3), nSm (3), RJF (3, SNum_samp), r1s (3), r2s (3), r3s (3), ris (3, SNum_samp)
Real Am, the An, lj, li, RMJ (3), rni (3), RTMPV (3)
Real Jrm (3, maxRWG), Irn (3, maxRWG), Jlengthm (maxRWG), Ilengthn (maxRWG)

Complex coef1, coef2
Complex Amn_E Zji, I1ss, I2ss (3), I3ss (3), I4ss
Complex CTMP, ctmp1

Real, external: : re_Norm
The integer * 4 time1, time2, time

Call SYSTEM_CLOCK (time1)
Write (*, *) "Start to compute the SS part of the impedance matrix, on the way... "

The allocate (SparseValue (Num_side Num_side))
SparseValue=https://bbs.csdn.net/topics/0

Coef1=CMPLX (0.0, omega * MU0/* PI (16.0))
Coef2=CMPLX (0.0, 1.0/(4.0 * PI * * EPS0 omega))

! $OMP parallel do default (none) Shared (Num_Triangle triangle_centroid, triangle_area, point_cor, triangle_point, triangle_rwgs, side_index, side_length, SparseValue, threshold_R, coef1, coef2) private (n, m, node, node1, 2, ni, mj, I, j, RCM, RCN, dist, r1f, r2f, r3f, RJF, r1s, r2s, r3s, ris, Am, the An, lj, li, RMJ, rni, Jrm, Irn, Jlengthm, Ilengthn, Amn_E, CTMP, I1ss, I2ss, I3ss, I4ss)
Do m=1, Num_Triangle
RCM=triangle_centroid (:, m)
Am=triangle_area (m)

R1f=point_cor (:, triangle_point (1, m))
R2f=point_cor (:, triangle_point (2 m))
R3f=point_cor (:, triangle_point (3 m))

Do k=1, SNum_samp
RJF (:, k)=epsilS * r1f + etaS (k) (k) * r2f + xiS (k) * r3f
Enddo

Do mj=1, triangle_rwgs (m) % N_rwg
J=triangle_rwgs RWG (m) % (mj)

If (side_index (3, j)==m) then
! Flagm=1.0
Jlengthm (mj)=side_length (j)
The else! If (side_index (4, j)==m) then
! Flagm=1.0
Jlengthm (mj)=- side_length (j)
Endif

Node1=side_index (1, j); 2=side_index (2, j)
Do p=1, 3
The node=triangle_point (p, m)
If ((node/=node1). And. (the node/=2)) exit
Enddo
Jrm (:, mj)=point_cor (:, node)
Enddo

Do n=1, Num_Triangle
RCN=triangle_centroid (:, n)
The An=triangle_area (n)

R1s=point_cor (:, triangle_point (1, n))! The source triangle coordinates
R2s=point_cor (:, triangle_point (2, n))
R3s=point_cor (:, triangle_point (3, n))

Do k=1, SNum_samp
Ris (:, k)=epsilS * r1s + etaS (k) (k) * r2s + xiS (k) * r3s
Enddo

Dist=re_Norm (RCM - RCN)

Call Comp_eltsI (I1ss, I2ss I3ss, I4ss, dist>=threshold_R, the An, RJF, ris, r1s, r2s, r3s, SNum_samp, SNum_samp, weightS, weightS)

Do ni=1, triangle_rwgs (n) % N_rwg
I=triangle_rwgs (n) % RWG (ni)
If (side_index (3, I)==n) then
! Flagn=1.0
Ilengthn (ni)=side_length (I)
The else! If (side_index (4, I)==n) then
! Flagn=1.0
Ilengthn (ni)=- side_length (I)
Endif

Node1=side_index (1, I); 2=side_index (2, I)
Do q=1, 3
The node=triangle_point (q, n)
If ((node/=node1). And. (the node/=2)) exit
Enddo
Irn (:, ni)=point_cor (:, node)
Enddo

Do mj=1, triangle_rwgs (m) % N_rwg
J=triangle_rwgs RWG (m) % (mj)
RMJ=Jrm (:, mj)
Lj=Jlengthm (mj)

CTMP=coef1 * (I4ss - dot_product (RMJ, I3ss)) - coef2 * I1ss

Do ni=1, triangle_rwgs (n) % N_rwg
I=triangle_rwgs (n) % RWG (ni)

Rni=Irn (:, ni)
Li=Ilengthn (ni)

Li Amn_E=lj * * (coef1 * (dot_product (RMJ, rni) * I1ss - dot_product (rni, I2ss)) + CTMP)

! $OMP atomic
SparseValue (I, j)=SparseValue (I, j) + Amn_E

Enddo
Enddo
Enddo

Enddo
! $OMP end parallel do
  • Related