I need to vectorize a C ++ function that gives a lot (say 4) of results. The caller uses these results in local computing. Assuming that I use simdlen(4), I need a small constant space for numbers 16 doubleor 4 of the vector, each of which contains 4 elements. I do not want to store these numbers in a large global array. Let's say an example function looks like this:
#pragma omp declare simd simdlen(4) linear(out:4)
void multifun(double v1, double v2, double *out)
{
out[0] = (v1+v2)/2;
out[1] = (v1-v2)/2;
out[2] = (v1+v2)/3;
out[3] = (v1-v2)/3;
}
Question . Can this vectorized function be called with outsome small local / static variable? The following does not work, i.e. The call is multifunnot vectorized
#pragma omp declare simd simdlen(4)
double test1(double v1, double v2)
{
double out[4];
multifun(v1, v2, out);
return out[0] + out[1] + out[2] + out[3];
}
- out , . ?
, , ,
#pragma omp declare simd simdlen(4) linear(out:4)
double test2(double v1, double v2, *out)
{
multifun(v1, v2, out);
return out[0] + out[1] + out[2] + out[3];
}
, : () .
test1 simd, :
void test_multifun(int n, const double *v1, const double *v2, double * result)
{
#pragma omp for simd
for(int i=0; i<n; i++){
result[i] = test1(v1[i], v2[i]);
}
}
#pragma omp for simd
for(int i=0; i<n; i++){
result[i] = test2(v1[i], v2[i], out+i*4);
}
}
OpenMP?