循环向量化以及如何避免它

发布于 2024-10-07 05:36:23 字数 237 浏览 6 评论 0原文

循环向量化是指从一开始就计算所有右侧表达式。我刚刚发现我的循环正在被矢量化(在 FORTRAN 77 中......不要问)。我需要在每次迭代中更新循环条件变量,但如何重写以解决此矢量化问题?

相关帖子中,我正在寻找一种方法来专门禁用 FORTRAN 中的此优化“功能”,但在这里我我正在寻找针对一般情况的更具算法性的解决方案。

Loop vectorization is when all right-hand-side expressions are computed at the onset. I just discovered my loops are being vectorized (in FORTRAN 77... don't ask). I need my loop condition variable to be updated in each iteration, but how can I rewrite to work around this vectorization?

In a related post, I'm looking for a way to disable this optimization "feature" in FORTRAN specifically, but here I am looking for a more algorithmic solution to the general case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧笙踏歌 2024-10-14 05:36:23

这不是循环矢量化对我的意义。对我来说,这个短语意味着编译器将生成可以利用硬件的任何向量计算功能的代码。在简单的 Intel Xeon 上,这可能意味着生成 SSE4 指令来同时操作几个相邻的数组元素,在 Cray 上,在向量寄存器上同时执行相同操作方面可能有更多可用的功能。

您如何认为所有 RHS 表达式都是“一开始就计算出来的”?我不确定你的意思是什么。您可以发布一些代码来解释吗?如果您的意思是在进入第一次迭代时计算循环的次数,那么这是正确的。在优化代码时,这是一个非常有用的功能,大多数 Fortran 程序都不会从避免这一功能中受益。

如果您在 Fortran 中编写 DO 循环,则标准会禁止更新迭代变量,而且据我记得一直如此。你的编译器可能会让你侥幸逃脱,但我不相信发生这种情况的 Fortran 程序。

That's not what loop vectorisation means to me. To me the phrase means that the compiler will generate code which can take advantage of any vector computation capabilities of the hardware. On a simple Intel Xeon this might mean generating SSE4 instructions to simultaneously manipulate a few adjacent array elements together, on a Cray there may be much more available in terms of simultaneous execution of the same operation on vector registers.

How do you think that all the RHS expressions are 'computed at the onset' ? I'm not sure what you mean by that. Could you post some code to explain ? If you mean that the number of trips through the loop is computed on entry to the first iteration, then that is correct. That is a very useful feature when it comes to optimising code and not one most Fortran programs would benefit from avoiding.

If you are writing DO loops in Fortran updating the iteration variable is forbidden by the standard, and always has been so far as I recall. Your compiler might let you get away with it but I wouldn't trust a Fortran program in which this happened.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文