Fortran + Openmp比顺序运行更慢 [英] Fortran + Openmp more slow that sequential
问题描述
我在Fortran中有此顺序代码.我的问题是,当我放置Openmp指令时,并行代码比顺序代码慢,而且我看不到错误.
I have this sequential code in Fortran. My problem is, when I put Openmp directives, the paralleled code is more slow than the sequential, and I don't see the error.
REAL, DIMENSION(:), ALLOCATABLE :: current, next
ALLOCATE ( current(TOTAL_Z), next(TOTAL_Z))
CALL CPU_TIME(t1)
!$OMP PARALLEL SHARED (current, next) PRIVATE (z)
DO t = 1, TOTAL_TIME
!$OMP DO SCHEDULE(STATIC, 2)
DO z = 2, (TOTAL_Z - 1)
next(z) = current (z) + KAPPA*DELTA_T*((current(z - 1) - 2.0*current(z) + current(z + 1)) / DELTA_Z**2)
END DO
!$OMP END DO
current = next
END DO
CALL CPU_TIME(t2)
!$OMP END PARALLEL
TOTAL_Z,TOTAL_TIME,KAPPA,DELTA_T和DELTA_Z是常量.
当我运行并行代码时,我在htop中看到了我的2个内核都以100%的速度工作
在顺序代码中,CPU_TIME为79 seg,在并行情况下为132 seg
谢谢
TOTAL_Z, TOTAL_TIME, KAPPA, DELTA_T, DELTA_Z are constants.
When I run the paralleled code, I see in htop and my 2 cores are working at 100%
In sequential code, CPU_TIME is 79 seg and in paralleled is 132 seg
Thank
推荐答案
我刚刚遇到了同样的问题.
I've just been experiencing the same problem.
似乎不适合使用cpu_time()来衡量多线程代码的性能.cpu_time()将添加所有线程的总时间,这可能会随着线程数量的增加而增加.
It seems that using cpu_time() is not suitable to measure the performance of multi-threaded code. cpu_time() will add the total time of all the threads which is likely to increase with increasing number of threads.
我在另一个论坛中找到了这个, http://software.intel.com/en-us/forums/topic/281897
I've found this in another forum, http://software.intel.com/en-us/forums/topic/281897
您应该使用system_clock()或omp_get_wtime()函数来获取例程的更准确计时.
You should use system_clock() or omp_get_wtime() functions to get a more accurate timing of your routine.
这篇关于Fortran + Openmp比顺序运行更慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!