2015-10-13 35 views
0

在使用C和OpenMP對一組數據使用並行處理時,我一直在使用for循環獲取以下錯誤。使用OpenMP時出錯:並行減少計算無效

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. 

是不是有什麼毛病我的語法還是有點毛病循環本身?

回答

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 這同樣的評論適用於你引用的第二個指令。

關於atomicreduction子句錯誤,您的代碼段中沒有足夠的任何建議。