[Omp] Declaring private and shared variables
Hakan Lane
Hakan.Lane at epfl.ch
Thu Aug 17 14:07:14 PDT 2006
Hello all,
I have problems with making a parallel a loop do the same things as the
corresponding serial routine. I
have noticed that I have to state the names of all variables in the shared
and private lists. The problem for this part is that there are so many of
them that the compiler won´t allow so long lines. As a consequence, I think
that I will have to split it up. I have tried by doing:
!$OMP parallel
!$OMP shared(....)
!$OMP private(.....)
However, the shared variables do not have the right values after the loop. I
have tried both !$OMP do and finding the upper and lower iteration limits
for each processor manually, as indicated below. Can you see how I should do
it instead?
Regards,
Håkan Lane
Email: Hakan.Lane at epfl.ch
!$OMP parallel
!$OMP
shared(gridet,elements,materials,sections,normals0,orientations,ellist,A,B,n
odf,elemf,normf,delta_nodf,num,delta_elemf,delta_time,time,mfac,nrhs,flagMat
,flagProb,flagFint,nlgeom,L2Fieldnr,flaghht,energy,flux,nflux)
!$OMP
private(Me,Ke,Fe,Ce,ene,info,accv,nee,eqindx,tnr,lvarde,varde,hvarde,kel,eqi
nd,eqindxp,work,col,i)
anttrad=omp_get_num_threads()
tnr=omp_get_thread_num()
bas=num/anttrad
varde=tnr*bas
lvarde=nint(varde)+1
print *,tnr,lvarde
if (tnr.LT.(anttrad-1)) then
varde=(tnr+1)*bas
hvarde=nint(varde)
else
hvarde=num
end if
do i = lvarde,hvarde
kel = ellist(i)
!$OMP critical
call get_elmat(gridet,elements,materials,sections, &
normals0,orientations,nodf,elemf,normf, &
delta_nodf,delta_elemf,delta_time,time,mfac,&
flagProb,flagFint,nlgeom,L2Fieldnr,kel, &
nrhs,nee,eqindx,Me,Ke,Fe,Ce,ene,info,accv)
!$OMP end critical
if (flagProb.GT.0) then
do eqind=1,nee
do col=1,nee
Fe(eqind,1)=Fe(eqind,1)+Me(eqind,col)*accv(col)
end do
end do
Ke(1:nee,1:nee) = Ke(1:nee,1:nee)*mfac(2) +
Ce(1:nee,1:nee)*mfac(1)+Me(1:nee,1:nee)
deallocate(accv)
end if
!$OMP critical
call add_elmat2crs(Ke,Fe,eqindx,nee,ene,flagMat, &
nrhs,work,A,B,energy,flux,nflux)
!$OMP end critical
end do
!$OMP barrier
!$OMP end parallel
More information about the Omp
mailing list