gfortran 程序运行速度比 ifort

问题描述

我有一些 fortran 代码,用 gfortran 编译时比用 ifort 编译时要快。我通常在互联网上找到相反的情况...

我尝试运行 intel vtune 来识别可执行文件间的不同热点,但我无法解决这些问题。

我不确定是什么导致了这种差异。这是性能输出

gfortran:

Performance counter stats for 'build/gnuRelease/NBODY inputFile temp' (10 runs):

      2,489.36 msec task-clock:u              #    0.986 cpus utilized            ( +-  0.21% )
             0      context-switches:u        #    0.000 K/sec                  
             0      cpu-migrations:u          #    0.000 K/sec                  
           589      page-faults:u             #    0.237 K/sec                    ( +-  0.05% )
10,678,130,527      cycles:u                  #    4.290 GHz                      ( +-  0.20% )
31,102,858,644      instructions:u            #    2.91  insn per cycle           ( +-  0.00% )
 3,537,572,458      branches:u                # 1421.078 M/sec                    ( +-  0.00% )
       566,054      branch-misses:u           #    0.02% of all branches          ( +-  5.14% )

        2.5235 +- 0.0150 seconds time elapsed  ( +-  0.59% )

重点:

 Performance counter stats for 'build/ifortRelease/NBODY inputFile temp' (10 runs):

      2,834.44 msec task-clock:u              #    0.978 cpus utilized            ( +-  0.14% )
             0      context-switches:u        #    0.000 K/sec                  
             0      cpu-migrations:u          #    0.000 K/sec                  
         2,600      page-faults:u             #    0.917 K/sec                    ( +-  0.01% )
12,146,500,211      cycles:u                  #    4.285 GHz                      ( +-  0.14% )
36,441,911,065      instructions:u            #    3.00  insn per cycle           ( +-  0.00% )
 2,936,917,079      branches:u                # 1036.154 M/sec                    ( +-  0.00% )
       339,226      branch-misses:u           #    0.01% of all branches          ( +-  3.74% )

        2.8991 +- 0.0165 seconds time elapsed  ( +-  0.57% )

页面错误指标引起了我的注意,但我不确定它是什么意思......

更新:

gfortran 版本:10.2.0

ifort 版本:19.1.3.304

英特尔至强(R)

更新:

类似例子:Puzzling performance difference between ifort and gfortran

来自这个例子:

去掉复杂的 IF 语句后,gfortran 花费的时间大约是原来的 4 倍(10-11 秒)。这是可以预料的,因为该语句大约抛出了大约 75% 的数字,避免对它们进行 SQRT。另一方面,ifort 只使用稍微多一点的时间。我的猜测是当 ifort 尝试优化 IF 语句时出现问题。

似乎也与本案有关

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)