I am trying to get my code for automatic vectorization, but it does not work.
int _tmain(int argc, _TCHAR* argv[]) { const int N = 4096; float x[N]; float y[N]; float sum = 0; //create random values for x and y for (int i = 0; i < N; i++) { x[i] = rand() >> 1; y[i] = rand() >> 1; } for (int i = 0; i < N; i++){ sum += x[i] * y[i]; } }
No cycle is drawn here, but I am only interested in the second cycle.
I am using visual studio express 2013 and compiling with /O2 and /Qvec-report:2 (in order to tell if the loop has been vectorized). When I compile, I get the following message:
--- Analyzing function: main c:\users\...\documents\visual studio 2013\projects\intrin3\intrin3\intrin3.cpp(28) : info C5002: loop not vectorized due to reason '1200' c:\users\...\documents\visual studio 2013\projects\intrin3\intrin3\intrin3.cpp(41) : info C5002: loop not vectorized due to reason '1305'
Reason '1305', as can be seen HERE , says that "the compiler cannot recognize the correct vectorization information for this loop." I'm not quite sure what that means. Any ideas?
After dividing the second cycle into two loops:
for (int i = 0; i < N; i++){ sumarray[i] = x[i] * y[i]; } for (int i = 0; i < N; i++){ sum += sumarray[i]; }
Now the first of the above loops vectorizes, and the second does not, again with error code 1305.
c ++ optimization vectorization sse simd
Jon B. jones
source share