使用C和OpenMP对一组数据使用并行处理时,我的for循环一直出现以下错误。
Parallel reduction calculation is invalid!
Parallel atomic calculation is invalid!
代码是:
#pragma omp parallel for num_threads(numberOfThreads \
reduction(+:number_in_circle) shared(count)
for(count = 0; count < iterations; count++)
//calculate number in circle
# pragma omp parallel for num_threads(numberOfThreads) private(x, y,\
dist_sqrd) shared(count, number_in_circle, iterations)
for(count = 0; count < iterations; count++)
//calculate number_in_circle using atomic instruction to add to it.
我的语法有问题还是循环本身有问题?
答案 0 :(得分:2)
我不确定您的OpenMP指令的副本是否100%正确,但这里肯定存在问题:
#pragma omp parallel for num_threads(numberOfThreads \
reduction(+:number_in_circle) shared(count)
for(count = 0; count < iterations; count++)
num_threads(numberOfThreads
错过了右括号shared(count)
无效,因为count
是您要并行化的for
循环的索引。试图定义这样的私有索引既愚蠢又explicitly forbidden by the OpenMP standard
对于您引用的第二个指令,同样的说法也是如此。关于atomic
和reduction
子句错误,您的代码段中没有足够的建议。