- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much your comments.
I will try it according to your suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
to: Tim, jimdempseyatthecove
Thank you very much.
Because of your precious suggestions, it finally works.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page