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

Pergunta

 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)

Foi útil?

Solução

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)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top