template <typename T, std::size_t N>
static T sum(const std::array<T, N>& a)
{
T result;
// type of result (T) is not determined when pre-process?
#pragma omp parallel for reduction(+: result)
for(int i = 0; i < static_cast<int>(N); i++)
{
result += a[i];
}
return result;
}
I can compile and run above code with MSVC and gcc. Yes, it's excellent!
But my question is in the code comment; "Because the type of result (T) is not determined while pre-processing '#pragma', how does the compiler validate that the type of result is suited to OpenMP reduction?".
I'm sure it's OK if T=double and NG if T=std::string, but how does the pre-processor know the type of T?
I remember I couldn't compile the above code with some minor c++ compiler a long time ago.
Let me ask which behavior (compilable or uncompilable) is correct in the context of C++/OpenMP specifications.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…