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;
}
我可以使用MSVC和gcc编译并运行上面的代码。是的,这非常棒!使用模板类型的OpenMP缩减
但我的问题是在代码评论; “因为结果类型(T)在预处理'#pragma'时未确定,所以编译器如何验证结果类型是否适合于OpenMP压缩?”。
我敢肯定,如果T = double和NG,如果T = std :: string,那么确定没问题,但是预处理器如何知道T的类型?
我记得很久以前我无法用一些小的C++编译器编译上面的代码。
让我问在C++/OpenMP规范的上下文中哪些行为(可编译或不可编译)是正确的。
'#pragma omp'是编译器支持OpenMP的方向,不是预处理器。 – yohjp 2014-12-06 04:13:28