我无法弄清楚为什么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; } } }