OMP Single for 输出子程序
OMP Single for output subroutine
我有一个代码可以在一段时间内计算一个动态过程,即 it = 1, itlast
,并且在这段时间内,我想在每个 itsprint
间隔中打印特定结果。下面是代码:
!$OMP PARALLEL DEFAULT (none) SHARED(w) &
!$OMP& SHARED(itlast) &
!$OMP& SHARED(itprint, itsprint) &
!$OMP& PRIVATE(i, j, it) &
!$OMP& PRIVATE(ntprint, mtprint)
do it = 1, itlast
!..... ALL COMPUTATIONS .....!
!$OMP SINGLE
mtprint = it/itsprint
if (itsprint*mtprint .ne. it) goto 20
call timser(it)
20 continue
!$OMP END SINGLE
end do
!$OMP PARALLEL END
而subroutine timser
显示如下。
subroutine timser(it)
use tuna_params
implicit none
integer :: it, k
real :: time_s, hour
time_s = it*delt
hour = time_s/3600.0
write(16,89) hour, (w(nxwtser(k),nywtser(k),2), k = 1, ntser, 1)
89 format(f10.4, 999f10.4)
end subroutine timser
这样做,我允许所有线程进行计算。对于每个 it
,在计算结束时,只有一个线程会检查 if
语句并进入 subroutine timser
进行输出打印。此代码在使用
时工作正常
gfortran (GNU Fortran (Ubuntu 4.8.4.-2ubuntu1~14.04) 4.8.4)
: gfortran mycode.f90 -fopenmp -fbounds-check -o mycode.out
ifort (Intel Compiler 16.0 Update 1)
: ifort mycode.f90 -openmp -CB -o mycode.exe
但是,如果我使用 gfortran (GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50))
在集群中编译和 运行 此代码:gfortran mycode.f90 -fopenmp -fbounds-check -o mycode.out
,所有线程都可以进入 subroutine timser
并写入输出文件。我不知道调试这个问题,请指导我解决这个问题。谢谢。
根据 http://openmp.org/wp/openmp-compilers,从 4.2 版开始,gcc/gfortran 支持 OpenMP 2.5。也许 gcc/gfortan 4.1.x.
中的 OpenMP 支持不是很好
gomp历史并不清楚4.2之前的OpenMP状态(https://gcc.gnu.org/projects/gomp)。
我有一个代码可以在一段时间内计算一个动态过程,即 it = 1, itlast
,并且在这段时间内,我想在每个 itsprint
间隔中打印特定结果。下面是代码:
!$OMP PARALLEL DEFAULT (none) SHARED(w) &
!$OMP& SHARED(itlast) &
!$OMP& SHARED(itprint, itsprint) &
!$OMP& PRIVATE(i, j, it) &
!$OMP& PRIVATE(ntprint, mtprint)
do it = 1, itlast
!..... ALL COMPUTATIONS .....!
!$OMP SINGLE
mtprint = it/itsprint
if (itsprint*mtprint .ne. it) goto 20
call timser(it)
20 continue
!$OMP END SINGLE
end do
!$OMP PARALLEL END
而subroutine timser
显示如下。
subroutine timser(it)
use tuna_params
implicit none
integer :: it, k
real :: time_s, hour
time_s = it*delt
hour = time_s/3600.0
write(16,89) hour, (w(nxwtser(k),nywtser(k),2), k = 1, ntser, 1)
89 format(f10.4, 999f10.4)
end subroutine timser
这样做,我允许所有线程进行计算。对于每个 it
,在计算结束时,只有一个线程会检查 if
语句并进入 subroutine timser
进行输出打印。此代码在使用
gfortran (GNU Fortran (Ubuntu 4.8.4.-2ubuntu1~14.04) 4.8.4)
:gfortran mycode.f90 -fopenmp -fbounds-check -o mycode.out
ifort (Intel Compiler 16.0 Update 1)
:ifort mycode.f90 -openmp -CB -o mycode.exe
但是,如果我使用 gfortran (GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50))
在集群中编译和 运行 此代码:gfortran mycode.f90 -fopenmp -fbounds-check -o mycode.out
,所有线程都可以进入 subroutine timser
并写入输出文件。我不知道调试这个问题,请指导我解决这个问题。谢谢。
根据 http://openmp.org/wp/openmp-compilers,从 4.2 版开始,gcc/gfortran 支持 OpenMP 2.5。也许 gcc/gfortan 4.1.x.
中的 OpenMP 支持不是很好gomp历史并不清楚4.2之前的OpenMP状态(https://gcc.gnu.org/projects/gomp)。