对数组的操作会创建数组临时性吗?

发布于 2025-01-25 00:51:53 字数 2475 浏览 1 评论 0原文

考虑以下子例程,该子例程计算泊松方程求解器中的稀疏基质产物。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文