对数组的操作会创建数组临时性吗?
考虑以下子例程,该子例程计算泊松方程求解器中的稀疏基质产物。
SUBROUTINE mut_A_sparse(n, w, v)
INTEGER, INTENT(IN) :: n
REAL, INTENT(IN) :: w(n*n)
REAL, INTENT(OUT) :: v(n*n)
v = -EOSHIFT(w, -n) - EOSHIFT(w, -1) + 4*w - EOSHIFT(w, 1) - EOSHIFT(w, n)
v((n + 1):n*n:n) = v((n + 1):n*n:n) + w(n:(n*n - 1):n)
v(n:(n*n - 1):n) = v(n:(n*n - 1):n) + w((n + 1):n*n:n)
END SUBROUTINE mut_A_sparse
我不确定这是什么编译。编译器会将-eoshift(W,-n)的中间结果存储到某些临时数组中,或者为
v
的每个索引即时计算它? ta告诉我这是后一种情况,但据我所知,eoshift
不是elemental
,因此编译器知道如何即时计算它不会导致意外的二次复杂性?
此外,阵列切片呢?我想知道以下是否会产生临时数组。我之所以问,是因为将切片数组传递给函数/过程将在参数绑定期间诱导副本,但是像+ - */
这样的原始操作员呢?
z(::2) = a(::2) + b(::2) + c(::2)
我想我应该阅读组件,但是汇编输出为一个完整的混乱超出了我的理解。
Consider the following subroutine, which calculates a sparse matrix product in a Poisson equation solver.
SUBROUTINE mut_A_sparse(n, w, v)
INTEGER, INTENT(IN) :: n
REAL, INTENT(IN) :: w(n*n)
REAL, INTENT(OUT) :: v(n*n)
v = -EOSHIFT(w, -n) - EOSHIFT(w, -1) + 4*w - EOSHIFT(w, 1) - EOSHIFT(w, n)
v((n + 1):n*n:n) = v((n + 1):n*n:n) + w(n:(n*n - 1):n)
v(n:(n*n - 1):n) = v(n:(n*n - 1):n) + w((n + 1):n*n:n)
END SUBROUTINE mut_A_sparse
I'm not sure what this compiles to. Will the compiler store the intermediate result of -EOSHIFT(w, -n)
to some temporary array, or calculate it on the fly for each index of v
? The TA told me it is the latter case, but as far as I know, EOSHIFT
is not ELEMENTAL
, so how does the compiler know calculating it on the fly will not cause accidentally quadratic complexity?
Additionally, what about array slices? I wonder if the following creates an array temporary. I am asking because passing sliced arrays to functions/procedures will induce a copy during argument binding, but what about primitive operators like + - * /
?
z(::2) = a(::2) + b(::2) + c(::2)
I guess I should read the assembly, but the assembly output is a complete mess beyond my comprehension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论