我明白了:
testvec.cpp:12: info C5002: loop not vectorized due to reason '1200'
原因代码1200是:
Loop contains loop-carrIEd data dependences that prevent vectorization. Different iterations of the loop interfere with each other such that vectorizing the loop would produce wrong answers,and the auto-vectorizer cannot prove to itself that there are no such data dependences.
但为什么?
#include <stdlib.h>int main(int argc,char *argv[]){ int const n = argc; double *const p1 = (double *)malloc(n * n * sizeof(*p1)),*const p2 = (double *)malloc(n * n * sizeof(*p2)); for (int j = 0; j < n; ++j) { double const sj = p1[n * j]; for (int i = 0; i < n; ++i) { double const sum = p1[i] + sj,old = p1[i + n * j]; p2[i + n * j] = sum < old ? sum : old; } }}解决方法 我终于找到了如何解决它…似乎n * j中的乘法是罪魁祸首.
将其作为int nj = n * j挂在外面;并在内循环中使用nj来修复问题.
我仍然不知道为什么会这样.
如果有人知道,请发布!
总结以上是内存溢出为你收集整理的为什么Visual C自动矢量化器不能矢量化这个简单的循环?全部内容,希望文章能够帮你解决为什么Visual C自动矢量化器不能矢量化这个简单的循环?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)