我的理解:
1. 并行结构最好不要包含输入输出语句,因为它们并不具有可并行性能。
2. CPU_TIME在并行结构中会重复计算,并不是真实的物理挂钟时间。你占用4个线程,每个·1秒,则cpu_time就是4秒,即使真实物理时间只过了1秒。
所以,如下是一个更好的测试程序。
[Fortran] 纯文本查看 复制代码 program main
implicit none
include 'omp_lib.h'
integer i
integer,parameter :: s=3200000
integer :: t1 , t2
real :: epf , nobs
open(1,file='./epf.dat')
call system_clock(t1)
call omp_set_num_threads(4)
!$OMP PARALLEL DO PRIVATE(epf,nobs)
do i=1,s
epf=2.0*i
nobs=epf**2
end do
!$OMP END PARALLEL DO
call system_clock(t2)
write(*,*) t2-t1
end
|