为什么Visual C自动矢量化器不能矢量化这个简单的循环?

为什么Visual C自动矢量化器不能矢量化这个简单的循环?,第1张

概述我无法弄清楚为什么Visual C无法自动矢量化这个循环…任何想法? 我明白了: testvec.cpp:12: info C5002: loop not vectorized due to reason '1200' 原因代码1200是: Loop contains loop-carried data dependences that prevent vectorization. Differe 我无法弄清楚为什么Visual C无法自动矢量化这个循环…任何想法?

我明白了:

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自动矢量化器不能矢量化这个简单的循环?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1238659.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存