views:

50

answers:

1

I am attempting to use OpenMP to create a parallel for loop in Visual Studio 2005 Professional. I have included omp.h and specified the /openmp compiler flag. However, I cannot get even the simplest parallel for loop to compile.

#pragma omp parallel for
for ( int i = 0; i < 10; ++i )
{
    int a = i + i;
}

The above produces Compiler Error C3005 at the #pragma line.

Google hasn't been much help. I only found one obscure Japanese website with a user having similar issues. No mention of a resolution.

A standard parallel block compiles fine.

#prgram omp parallel
{
    // Do some stuff
}

That is until you try to add a for loop.

#pragma omp parallel
{
    #pragma omp for
    for ( int i = 0; i < 10; ++i )
    {
        int a = i + i;
    }
}

The above causes Compiler Error C3001. It seems 'for' is confusing to the compiler, but it shouldn't be. Any ideas?

A: 

I found the problem. Some genius defined the following macro deep within the headers:

#define for   if ( false ) ; else for

My only guess is this was used to get variables declared in for loops to scope properly in Visual C++ 6. Undefining or commenting out the macro resolved the issue.

Joe Waller