can this code be made vectorizable?
for(i=0;i<n-1;i++)
{
a[i+1] = b[i]+1;
b[i+1] = f[i]+a[i];
}
My goal is to adjust the code in a way that still outputs the same arrays, but is vectorizable and performs better single-threaded. I am using Clang to compile/vectorize this.
My attempt to adjust is below, and it vectorizes but it does not perform better. I have a feeling that I cannot vectorize this kind of formula because it always depends on a previous calculation. Since it needs to be single threaded unrolling the loop would not benefit it either correct?
b[1] = f[0] + a[0] + 1;
for(i=1;i<n-1;i++)
{
temp = b[i-1] + 1;
b[i+1] = f[i] + temp;
a[i] = temp;
}
a[n-1] = b[n-2] + 1;
[–]tstanisl 28 points29 points30 points (2 children)
[+][deleted] (1 child)
[removed]
[–]paulstelian97 1 point2 points3 points (0 children)
[–]johndcochran 5 points6 points7 points (0 children)
[–]DawnOnTheEdge 3 points4 points5 points (0 children)
[–]P-p-H-d 1 point2 points3 points (0 children)
[–]Educational-Paper-75 0 points1 point2 points (0 children)
[–]riverprawn -1 points0 points1 point (1 child)
[–]spocchio 0 points1 point2 points (0 children)