Noob C++/OpenMP: Why do I get this compile time error? variable in 'reduction' clause must be shared in enclosing context

StackOverflow https://stackoverflow.com/questions/15455765

문제

 1 int result = 0;
 2 int b = 0;
 3 #pragma  omp for reduction(+:result) private(b)
 4 for(int i = 0; i < size; i++) {
 5    ifile >> b;
 6    if(b== 100)
 7      result++;
 8 }

Why do I get this error?

(3) error C3037: 'result' : variable in 'reduction' clause must be shared in enclosing context

I tried googling btw... all the examples look like this. I am also coding this in visual studios 2012 if that matters. I hate asking a question like this, but it is blocking me from continuing.

Fixed: add parallel

#pragma omp parallel for private(buffer) reduction(+:result)

도움이 되었습니까?

해결책

You're missing the "parallel" tag from the reduction clause:

#pragma  omp for reduction(+:result) private(b)

should be

#pragma omp parallel for reduction(+:result) private(b)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top