【问题标题】:Eliminating hidden copies in Fortran消除 Fortran 中的隐藏副本
【发布时间】:2016-05-03 16:39:06
【问题描述】:

我想请教一些 Fortran 专家关于我在使用最新版本的 Cray 编译器时遇到的问题。我有几个警告,尽管它们不会影响正确性,但它们可能会影响性能。警告是:

此参数生成一个临时变量的副本。

这是我收到此警告的一种情况。在同一个文件 (fem.f90) 和模块中:

  call fem( array_local( i, : ), pcor, arcol, inder,    & 
                              ^ 
  ftn-1438 crayftn: CAUTION FFEM, File = fem.f90, Line = 676, Column = 31 
  This argument produces a copy in to a temporary variable. 

调用array_local的例程FFEM如下所示:

-------------------------- 
subroutine ffem( alow, pcor, arcol, inder,  iflag ) 

  integer , intent( in ) :: alow(3), pcor(3) 
  real, intent( in ) :: inder,arcol 
  integer, intent( out ) :: iflag 

  integer::  array_local(5,3) 

 ! within in a loop 
  call fem( array_local( i, : ),  pcor, arcol, inder,    & 
   .......... 
-------------------------- 

这里是fem 子程序:

-------------------------- 
subroutine fem (ac,  pc, rc, id, flag ) 
 integer, intent( in ) :: ac(3) 
       ....... 
-------------------------- 

我找不到摆脱那种copy in的方法,这肯定会减慢我的代码速度。我想知道,有谁知道为什么会发生这种情况,我该如何解决?

【问题讨论】:

  • @francescalus 我想更多的是对代码的更改。也许这也可以通过不同的编译选项来解决,但我在更改代码后才能理解它。
  • 更改fem() 子例程也会有所帮助。这是一个选择吗?我看不到如何使用编译器选项解决此问题。如果(小)数组临时在堆栈上,也许它只会稍微减慢代码。
  • integer, intent( in ) :: ac(:) 显式接口(最好使用模块)是必要的。
  • array_local 还有什么用途?可能只是使用array_local(3,5) 并传递array_local(:,i) 就足够了。
  • 有关更多信息,您可以访问 OP 的交叉帖子groups.google.com/forum/#!topic/comp.lang.fortran/eiVhBf8p_fo

标签: fortran


【解决方案1】:

如果 array_local 必须按原样定义,并且您不能将其定义为 (5,3),如 brady 所示,您可以考虑假设形状虚拟参数

subroutine fem (ac,  pc, rc, id, flag ) 
 integer, intent( in ) :: ac(:) 

在那里传递的数组可以是不连续的,但仍然没有副本,ac 也将是不连续的(跨步)。

为此,您需要显式接口。这最好通过将子例程放在一个模块中来实现。

【讨论】:

    【解决方案2】:

    此更改的可行性取决于您在其他地方使用array_local,但您可以交换顺序:

    integer:: array_local(3,5)

    然后拨打fem:

    call fem( array_local( :, i ), pcor, arcol, inder, &

    这将允许编译器简单地发送对array_local 数组适当部分的引用,因为列在内存中是连续排序的。

    【讨论】:

      猜你喜欢
      • 2011-09-24
      • 2022-06-30
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      相关资源
      最近更新 更多