|
下面这段程序,通过改变nscanpts=1,10,40分别得到串行,并行1路,4路的时间,1路有10核。发现时间分别为 600s,5608s,15275s。不知道为什么并行效率这么低。用的是ivf编译器,且设置了并行计算的功能。
[Fortran] 纯文本查看 复制代码 program test1
implicit none
integer,parameter::nscanpts = 8
integer:: n=150000,m=1000000
integer i,j,k
real time1,time2,timescan(nscanpts),time3,time4
integer rel(nscanpts)
rel = 0
call cputime(time3)
!$OMP PARALLEL SHARED(n,rel,timescan,m), PRIVATE(i,time1,time2)
!$OMP DO
do i = 1, nscanpts
write(*,*) "iscan=",i
call cputime(time1)
do j = 1,n
do k = 1,m
rel(i) = rel(i) + k * j
end do
end do
call cputime(time2)
timescan(i) = time2-time1
end do
!$OMP END DO
!$OMP END PARALLEL
call writeTime(nscanpts,timescan)
call writeResult(nscanpts,rel)
call cputime(time4)
write(*,*) "Time=",time4-time3
end program
subroutine cputime(t)
implicit none
real, intent(out) :: t
integer date_time(8)
character (len=10) big_ben(3)
call date_and_time(big_ben(1),big_ben(2),big_ben(3),date_time)
t = date_time(5)*3600 + date_time(6)*60 + date_time(7)+ &
date_time(8)*1.0d-3
return
end subroutine cputime
!****************************************************************
!
subroutine writeTime(n,time)
implicit none
integer, intent(in) :: n
real, intent(in) :: time(n)
integer:: fid=40, i
open (fid, file = 'timescan.dat', status = 'unknown')
write(fid,'(e16.8)') (time(i), i=1,n)
close(fid)
return
end subroutine writeTime
subroutine writeResult(n,r)
implicit none
integer, intent(in) :: n
integer, intent(in) :: r(n)
integer:: fid=41, i
open (fid, file = 'results.dat', status = 'unknown')
write(fid,'(i16)') (r(i), i=1,n)
close(fid)
return
end subroutine writeResult
|
|