0
votes

I am trying to parallelize a subroutine using Openmp. The subroutine contains a successive over relaxation loop which runs on the total error which is a shared variable. Now, when I parralelize the part where I call the subroutine in the main program, it makes the error a private variable and then I can't make it explicitly a shared variable in the main program.

I am pasting the code for reference.

program test
!$omp parallel
call sub()
!$omp end parallel
end program test

subroutine sub()
do  while(totalerror.ge.0.0001.and.sor.lt.10000)
totalerror=0.0
sor=sor+1
error=0.0
!$OMP DO REDUCTION(+:toterror) REDUCTION(MAX:error) 
! shared (vorticity,strmfn,toterror,error,guess) PRIVATE (i,j,t1,t2)
do i=1,nx
do j=1,ny
guess(i,j)=0.25*((h**2.)*vorticity(i,j)+strmfn(i+1,j)+strmfn(i-    1,j)+strmfn(i,j+1)+strmfn(i,j-1))
totalerror = totalerror + error
error      = max(abs(strmfn(`enter code here`i,j) - guess(i,j)),error)
strmfn(i,j)= strmfn(i,j) + omega*(guess(i,j)-strmfn(i,j))
enddo
enddo
!$OMP END DO
enddo

Any help would be appreciated.

1
This is just an example and so the variables are not defined. - user2329134

1 Answers

0
votes

toterror and error shouldn't be in the shared clause since they are in the reduction. If you need shared versions, copy them to different variables.