Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

do -if -exit whith openmp

gefei
Beginner
913 Views

hello

I want to use openmp to parallelize the code, but I dont konw how to do it with the if-exit code.

My environmrnt is VS2010, and the code is as follows:

!------------------------------------------------------------------------------------------

do 

!$omp do reduction(+:diffall) private(i,j,hs_w,serr,hs_e)   
do j=1,nz
do i=1,nx
       hs_w = (hs(i-1)+hs(i))*0.5d0
       hs_e = (hs(i)+hs(i+1))*0.5d0
       serr =  1.d0/hs(i)*( (-hs_w*wu(i-1,j)+hs_e*wu(i,j))*dxx+(-v1(i,j-1)+v1(i,j))*dyy )  
        diffall =  diffall +dabs(serr)            
end do
end do       
!$omp end do
        
if( diffall<1e-5 ) exit
 
end do
!------------------------------------------------------------------------------------------
 
Thanks in advance
Labels (2)
0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
878 Views

Your code doesn't seem to make sense. Is something missing?

First, diffall is the accumulation of the absolute values of serr, meaning, with the exception of serr=0.0, diffall will be ever increasing. Hence, should the first test of (diffall < 1e-5) fail, all subsequent iterations of your outer loop will fail, and the code will lock in the loops.

 

Now then (supposition on my part), IIF (if and only if) you intend to perform an array search for a combinational instance on indices i and j that produce an (serr < 1.0e-5), and you desire to early exit the parallel region, then please say so.

 

Jim Dempsey

0 Kudos
gefei
Beginner
858 Views

Very Thanks to you

The following serial code is hoped to transformed into a parallel version with the openmp:

 

!------------------------------------------------------------------------------------------

other code 

 

do 

!update hs, wu v1 at a given rule

call update( hs wu v1)

 

!calculat the abs sum of divergence of dudx and dvdy

serr = 0.0d0

do j=1,nz
do i=1,nx
       hs_w = (hs(i-1)+hs(i))*0.5d0
       hs_e = (hs(i)+hs(i+1))*0.5d0
       serr =  1.d0/hs(i)*( (-hs_w*wu(i-1,j)+hs_e*wu(i,j))*dxx+(-v1(i,j-1)+v1(i,j))*dyy )  
        diffall =  diffall +dabs(serr)            
end do
end do       

!if divergency is small enough, exit the do loop and do the following code , if not,continue to do loop   
if( diffall<1e-5 ) exit

end do

other code

!------------------------------------------------------------------------------------------

diffall is defined in a function, which is carried out before the !$OMP paraller
but have no idea how to parallel the if-exit in the openmp

In your kindness reply " Now then (supposition on my part), IIF (if and only if) you intend to perform an array search for a combinational instance on indices i and j that produce an (serr < 1.0e-5), and you desire to early exit the parallel region, then please say so. " I think that is what I want to deal with.

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
840 Views

In your initial coding (post 1 of thread), the convergence test was made outside of the parallel region.

Due to the call to update(...) is within the outer most loop .AND. precedes the parallel region containing the inner two loops, placing the convergence test following the parallel region is the correct place for the test.

Placing the convergence test inside the inner two loops would be incorrect because the value of diffall would be incomplete until the last iteration of both of the inner two loops (and which the exit of the parallel region is imminent.

 

My only comment is that you evaluate the expected extremes of the input arrays to assure that the convergence test is constructed properly. iow scaling the serr by hs(i) may or may not be sufficient. The appropriate value may depend upon the values within wu and v1 as well.

 

** Is it correct for us to presume the arrays will have indices of 0 and nx+1/nz+1?

 

Jim Dempsey

 

JohnNichols
Valued Contributor III
820 Views

Jim:

serr =  1.d0/hs(i)*( (-hs_w*wu(i-1,j)+hs_e*wu(i,j))*dxx+(-v1(i,j-1)+v1(i,j))*dyy )  

Setting aside the main discussion points, this type of equation is subject to error with the assumed order of calculation, the first division and multiplication would be easy to confuse and give completely different results, as well as the *dyy inside brackets and the *dxx not.  

RPN with Lisp is so much better.  Bring back the HP Calculator. 

John

 

0 Kudos
Reply