I'm trying to define my own reduction for vectors of complex<float>, following this answer to the question Reducing on array in OpenMP.
But the size of my vectors aren't fixed at compile time, so I'm not sure how to define the initializer for the vector in the declare reduction
pragma. That is, I can't just have
initializer( omp_priv=TComplexVector(10,0) )
But the initializer is needed for vectors.
How can I pass the initializer clause the size of the vector I need at run time? What I have so far is below:
typedef std::vector<complex<float>> TCmplxVec;
void ComplexAdd(TCmplxVec & x,TCmplxVec & y){
for (int i=0;i<x.size();i++)
{
x.real()+= y.real();
//... same for imaginary part and other operations
}
}
#pragma omp declare reduction(AddCmplx: TCmplxVec: \
ComplexAdd(&omp_out, &omp_in)) initializer( \
omp_priv={TCmplxVec(**here I want a variable length**,0} )
void DoSomeOperation ()
{
//TCmplxVec vec is empty and anotherVec not
//so each thread runs the inner loop serially
#pragma omp parallel for reduction(AddCmplx: vec)
for ( n=0 ; n<10 ; ++n )
{
for (m=0; m<=someLength; ++m){
vec[m] += anotherVec[m+someOffset dependend on n and else];
}
}
}