2016-05-31 5 views
0

다음 코드는 for 루프 내에서 무언가를 업데이트하고, for 루프 이후에는 다른 for 루프를 업데이트합니다. 그러나 두 번째 루프가 시작될 때 "예상 선언"오류가 발생했습니다. 문제가 "비판적인"부분 인 것 같습니다. 삭제하면 오류가 사라지기 때문입니다. OpenMP에 대해 처음 접했을 때 여기에 예제를 따라했습니다 : http://www.viva64.com/en/a/0054/#ID0EBUEM ("5. 중요한 섹션에 항목이 너무 많음"참조). 아무도 내가 여기서 뭘 잘못하고 있는지 알지 못해?루프 내에서 openmp 임계 섹션

게다가 "비교가 중요한 섹션보다 먼저 수행되면 중요한 섹션은 루프의 모든 반복 중에 입력되지 않습니다"라는 사실입니까?

또 다른 것은 실제로 동시에 두 개의 루프를 병렬 처리하려고하지만, 루프 내부의 연산이 다르기 때문에 두 개의 스레드 팀을 여기에서 사용합니다. 필요하지 않은 스레드가 있으면 첫 번째 루프에서 두 번째 루프를 즉시 시작할 수 있습니다. 이게 효과가 있니?

double maxValue = 0.0; 
#pragma omp parallel for schedule (dynamic) //first loop 
    for (int i = 0; i < n; i++){ 
     if (some condition satisfied) 
     { 
      #pragma omp atomic 
      count++; 
      continue; 
     } 

     double tmp = getValue(i); 

     #pragma omp flush(maxValue) 
     if (tmp > maxValue){ 
      #pragma omp critical(updateMaxValue){ 
      if (tmp > maxValue){ 
       maxValue = tmp; 
       //update some other variables 
        ... 
      } 
      } 
     } 
    } 
#pragma omp parallel for schedule (dynamic) //second loop 
    for (int i = 0; i < m; i++){ 
     //some operations... 
    } 
#pragma omp barrier 

미안하지만 너무 많은 질문과 감사의 말을 전합니다.

#pragma omp critical(updateMaxValue) 
{ 

(당신 돈 :

#pragma omp critical(updateMaxValue){ 
//         ~^~ 

로 변경해야합니다 여는 중괄호 존재하는 경우, 새로운 라인으로 이동해야합니다 -

+0

넣어 {'새로운 라인 ('그 'critical (updateMaxValue)'다음에 오는 것), 또는 중괄호를 모두 제거하십시오 –

+1

고마워, 작동 해! 나는 openmp가 이런 식으로 작동한다는 것을 몰랐다 ... – pumpkinjuice

답변

0

However, I got the error: "expected a declaration" at the beginning of the second loop.

당신은 구문 오류가 뒤에 오는 if 문은 구조화 된 블록이므로 실제로 필요하지 않습니다.


Another thing is that I actually want to parallelize the two loops at the same time, but since the operations inside the loops are different, I use two thread teams here, hoping that if there are threads that are not needed in the first loop, they can start executing the second loop immediately.

를 사용하여 하나의 병렬 영역 및 대한 루프 처음에 다음 nowait 절 : 당신은 구문 오류가

#pragma omp parallel 
{ 
    #pragma omp for schedule(dynamic) nowait 
    //        ~~~~~^ 
    for (int i = 0; i < n; i++) 
    { 
     // ... 
    } 

    #pragma omp for schedule(dynamic) 
    for (int i = 0; i < m; i++) 
    { 
     // ... 
    } 
}