Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Help for the problem with OPENMP

qlsn5
Beginner
1,042 Views

I am a beginner of using OPENMP in intel fortran 90 program.

I have programmed the following but it does not work and gives errors.

I could not find the problem and really need a help.

My main program calls the subroutine "CAL_PHIN" and a parallel procedure is to be conducted in the subroutine.

The subroutine "CAL_PHIN" is:

-------------------------------------------------------------------------------------------

SUBROUTINE CAL_PHIN()
    integer(i4b) :: i
    integer(i4b) :: n, nev, ncv, maxn, maxnev, maxncv, ldv

    !$omp parallel
    !$omp do private(i, nev, ncv, maxnev, maxncv, n, maxn, ldv)
    do i = 1, tn_subst
        nev = PHI(i).nev
        ncv = 2*nev + 1
        maxnev = nev + 1
        maxncv = ncv + 1
        
        n = MKS(i).nn
        maxn = n + 1
        ldv  = maxn

        allocate( PHI(i).lambda(nev), PHI(i).aa(n, nev) )
        call DSDRV1_ALLT(n, nev, ncv, maxn, maxnev, maxncv, ldv, 'LA', &
                         MKS(i).am, MKS(i).dmk, MKS(i).ak, MKS(i).dmk, &
                         PHI(i).lambda, PHI(i).aa)
    end do
    !$omp end do
    !$omp end parallel
END SUBROUTINE CAL_PHIN

-------------------------------------------------------------------------------------------

In  the above routine, the subroutine "DSDRV1_ALLT" is called and in the subroutine "DSDRV1_ALLT", the bolded variables are intended output and the others are intended input.

The variables "MKS" and "PHI" are derived data type and global variables. In the derived data type "MKS", MKS(:).am, MKS(:).ak, and MKS(:).dmk are stated allocatable.

I look forward to getting your precious comments.

Thank you.

0 Kudos
7 Replies
jimdempseyatthecove
Honored Contributor III
1,042 Views
What are the errors? Compiler errors out? Runtime crash? Results wrong? other? DSDRV1_ALLT must be either compiled with -openmp or be recursive and/or .not. contain static workspace variables (explicitly SAVE or implicitly saved). I assume the PHI and MKS arrays are properly allocated and initialized (and that prior to call lambda and aa were not allocated). Jim Dempsey
0 Kudos
qlsn5
Beginner
1,042 Views

to : jimdempseyatthecove

Thank you very much for your comments.

The error varies when execute the resultant exe file. (Compile is o.k.)

When execute the exe file, sometimes it gives wrong result, sometimes it gives stack error.

I have a question. All the subroutines that will be called in the parallel region should be compiled with "Qopenmp" option?

 

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,042 Views

You should compile the entire application with openmp.

subroutine FOO(in, out)
real :: in(:),out(:), temp(3), x

When compiling without OpenMP, and default options, in and out are dummies, temp(3) is SAVE, x is on stack.

When compiling with OpenMP, and default options, in and out are dummies, temp(3) is on stack, x is on stack.

If your parallel regions call FOO (without FOO being compiled with -openmp) then they are sharing temp(3), which is most likely to introduce errors in results.

In lieu of compiling foo with openmp you could also attribute subroutine FOO with RECURSIVE, or use a command line option (/auto) that specifies local vectors are automatic, or compile all routines with /recursive.

Note, Fortran does not have an attribute REENTRANT, which is technically what you want. RECURSIVE is sufficient for reentrant programs

You also want to assure you link with OpenMP compatible libraries and DLLs. Otherwise known as thread-safe.

Jim Dempsey

0 Kudos
qlsn5
Beginner
1,042 Views

to: jimdempseyatthecove

Thank you very much your comments.

I will try it according to your suggestions.

0 Kudos
qlsn5
Beginner
1,042 Views

to: jimdempseyatthecove

O.K. I found the problem.

In many called subroutines, there are many local variables with SAVE attribute.

Is it possible that local variables are declared as PRIVATE?

Thank you.

0 Kudos
TimP
Honored Contributor III
1,042 Views

With the options Jim mentioned, local variables are compiled in a thread-safe manner.  If you need thread local storage which persists when procedures go out of scope, threadprivate is a possibility.

0 Kudos
qlsn5
Beginner
1,042 Views

to: Tim, jimdempseyatthecove

Thank you very much.

Because of your precious suggestions, it finally works.

0 Kudos
Reply