I’m trying to use a simple #pragma omp parallel for under Visual Studio 10 and I get an error I don’t understand
Here’s what I do :
#pragma omp parallel for
for (int i(0); i < size; ++i)
{
// do some stuff
}
And I get these errors when compiling :
error C2059: syntax error : 'constant' // on the for() line
error C2059: syntax error : ';' // on the for() line
error C2143: syntax error : missing ';' before '{'
// repeat previous error for every { or } in file
fatal error C1004: unexpected end-of-file found // on last line of file
openmp support is activated in the compiler options. This code compiles and runs perfectly fine without openmp instructions.
I tried to nest the for loop in braces like this :
#pragma omp parallel for
{
for (int i(0); i < size; ++i)
{
// do some stuff
}
}
but then compiler tells me he expects a for loop right after the #pragma instruction.
Does anyone see what I can be doing wrong here ? It drives me crazy since I have already successfully used OpenMP within the same conditions in other programs.
I don’t think object style initialisers are supported inside the
forloop control block when OpenMP is active. You should rewrite your code as:In the second case the error is due to the fact that
omp forrequires an immediately followingforloop and not a code block.