【发布时间】:2020-11-01 10:17:52
【问题描述】:
我有一个结构如下所示的 Fortran 90 程序。 subroutinne A 中的步骤 compute the 2D array myMatrix(1:N,1:N) 很昂贵。它只依赖于全局变量N,只需要计算一次;子程序中的“其他步骤”不会改变 myMatrix 的值。目前,每当调用子例程时都会计算myMatrix。
有没有办法让二维数组myMatrix只计算一次?
module constants
integer :: N
end module constans
module A_module
use constants
contains
subroutine A
! compute the 2D real array myMatrix(1:N,1:N)
! other steps that use myMatrix
end subroutine A
end module A_module
program main
use constants
use A_module
integer :: k
do k = 1,10000
call A
end do
end program main
【问题讨论】: