undu
undu

Reputation: 2519

openmp syntax error under VS10

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.

Upvotes: 0

Views: 1182

Answers (1)

Hristo Iliev
Hristo Iliev

Reputation: 74385

I don't think object style initialisers are supported inside the for loop control block when OpenMP is active. You should rewrite your code as:

for (int i = 0; i < size; ++i)

In the second case the error is due to the fact that omp for requires an immediately following for loop and not a code block.

Upvotes: 1

Related Questions