forrtl:warning(402):堡垒:(1)

why*_*n0t 5 arrays fortran intel-fortran

我在运行时收到以下警告:

...
forrtl: warning (402): fort: (1): In call to I/O Write routine, an array temporary was created for argument #2

forrtl: warning (402): fort: (1): In call to I/O Write routine, an array temporary was created for argument #3

forrtl: warning (402): fort: (1): In call to GERADHEIT_LINIAL, an array temporary was created for argument #2

forrtl: warning (402): fort: (1): In call to GERADHEIT_LINIAL, an array temporary was created for argument #3
...   
Run Code Online (Sandbox Code Playgroud)

对于子例程/写入语句的每次调用.

子程序的调用:

integer :: l,kreise
character(*)::setname
real(8),diemnsion(:,:,:),allocatable::stripe
integer,dimension(:)s(j)

...code and allocation of arrays...
 do j=n(1)
   call geradheit_linial (s(j),stripe(j,1:s(j),1),
&                       stripe(j,1:s(j),2),setname)
 end do

...

subroutine geradheit_linial (ndaten,x,r,setname)
  implicit none
  integer,intent(in) :: ndaten
  real(8),dimension(ndaten),intent(in)  :: x,r
  character(*),intent(in) :: setname   
Run Code Online (Sandbox Code Playgroud)

和写声明:

    write(91,*)'Gerade: ',gerade(maxloc(reslt(1:i)),minsumloc,1),
&               gerade(maxloc(reslt(1:i)),minsumloc,2)
Run Code Online (Sandbox Code Playgroud)

数组stripe分配有每个维度预期的最大值,因此大多数时间只通过调用传递一个子集.

据我所知,它在准确性方面并不是一个真正的问题,但可能会减慢程序的速度,因此大量写入RAM就完成了.那么它减慢了多少我的计算速度(stripe可能有一个维度,stripe(100,300,3)可能会在以后的某个时间变大)?我怎样才能避免这种额外的阵列?

Hig*_*ark 7

我认为您收到此警告是因为子例程正在传递非连续的数组部分,并且编译器已决定子例程应该获得包含必要值的连续临时数组.我希望子程序代码是用数组编写的,并且隐含地假设,就像我们在Fortran中编程时一样,它是连续的.

如果我正确读取您的代码,编译器就会理解这个语句

stripe(j,1:s(j),1)
Run Code Online (Sandbox Code Playgroud)

意思是(原样)

stripe(j,1,1)
stripe(j,2,1)
stripe(j,3,1)
...
Run Code Online (Sandbox Code Playgroud)

因为,正如我所期望的那样,Fortran数组存储的第一个索引值变化最快,您的数组部分跨越内存.

您可以使用编译器选项来禁止警告noarg_temp_created.请注意,这只会抑制警告(这可能会节省程序运行时间的微笑),它不会影响编译器的作用,仍会创建临时数组.

您可以编写代码来创建包含要传递给子例程的节的临时数组.我没有看到这样做的好处; 我希望编译器发出的代码优于你为这种简单的操作编写的代码.

或者,您可以在开始调用子例程之前对原始数组进行一次整形/置换,并为其提供正确的形状和排列,以便切割成连续的块.然后在所有通话结束时取消/取消.

回答关于当前代码和任何替代配方的相对性能的问题的唯一结论性方法是对它们进行编码并拿出秒表.