循环矢量化及其避免方法 [英] Loop vectorization and how to avoid it

查看:140
本文介绍了循环矢量化及其避免方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

循环矢量化是指在开始时计算所有右侧表达式的情况.我只是发现我的循环被矢量化了(在FORTRAN 77中...不要问).我需要在每次迭代中更新循环条件变量,但是如何重写才能解决此矢量化问题?

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?

相关文章中,我正在寻找一种方法来专门禁用FORTRAN中的此优化功能",但是在这里,我正在寻找一种针对一般情况的更算法的解决方案.

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.

推荐答案

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

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.

您如何看待所有RHS表达式都是一开始就计算"的?我不知道那是什么意思.您能发布一些代码来解释吗?如果您的意思是通过循环的行程数是在第一次迭代进入时计算的,那是正确的.当涉及到优化代码时,这是一项非常有用的功能,避免使用大多数Fortran程序都不会受益.

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.

如果您要在Fortran中编写DO循环,则标准会禁止迭代变量,并且据我所知一直如此.您的编译器可能会让您无法使用它,但是我不相信发生这种情况的Fortran程序.

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.

这篇关于循环矢量化及其避免方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆