问题
I have a code written mostly in f77 however there are also routines written with the f90 syntax.
I've been reading how to use openMP for each case, but now I have the doubt how should I do it if I have both syntax in the same code?
More specifically should I use
use omp_lib
or
include 'omp_lib.h'
but in the same .f file I have both sintaxys. what if I use both?
I am compiling with gfortran 4.8.4.
If I use let's say
use omp_lib (meaning f90 syntax)
Then I have to use the correspondent syntax
!$omp parallel shared ( var1, var2 ) private ( i, j )
!$omp do
do j = 1, n
do i = 1, m
var1(i,j) = var2
end do
end do
!$omp end do
However a few lines down I'll have a do loop written in f77
c$omp parallel shared ( w ) private ( i, j )
c$omp do
do 20 i = 10, 1, -2
write(*,*) 'i =', i
20 continue
c$omp end do
but this way to call the parallel loop would be recognised by using use omp_lib?
The same question when is the opposite.
回答1:
First, you need the use
or include
only if you call OpenMP procedures. If you just have a couple of !$omp
directives it is not needed.
You only need this, when you call a procedure like:
call omp_set_num_threads(1)
or
tid = omp_get_thread_num()
but not for the directives.
For Fortran 90 and later code (even in fixed form which looks like Fortran 77) use
use omp_lib
because the compiler is then better able to check if you call the functions properly (it has an explicit interface to them).
If the code is true Fortran 77 (and not just looking like it), you have to use the include
although technically Fortran 77 doesn't even know that. It is a common non-standard extension to Fortran 77.
来源:https://stackoverflow.com/questions/35203586/paralelize-mixed-f77-f90-fortran-code