Search code examples
c++loopsfor-loopopenmpmulticore

OpenMP - index variable in OpenMP 'for' statement must have signed integral type


I'm new to OpenMP. I'm trying to use multiple cores for a for loop but I get this compiling error:

"error C3016: 'x' : index variable in OpenMP 'for' statement must have signed integral type".

I know OpenMP 2.0, which is standard with Microsoft Visual Studio 2010 ( what I'm using ), does not support unsigned data types for some reason but I don't believe I have any unsigned data types being used in this loop.

Here is how my code looks like:

Variable Declerations:

struct Vertex
{
    float x, y;
};

FractalGenerator::Vertex FractalGenerator::_fracStart;
FractalGenerator::Vertex FractalGenerator::_fracEnd;
float FractalGenerator::_pointPrecision = 0.008f;
float FractalGenerator::_scaleFactor = 1;

For Loop:

float _fracStep =  _pointPrecision / _scaleFactor;

#pragma omp parallel for
for (float x = _fracStart.x; x < _fracEnd.x; x += _fracStep)
{
    for (float y = _fracStart.y; y < _fracEnd.y; y += _fracStep)
    {

Solution

  • Looks like OpenMP doesn't support non-integral types as the index in a for loop. You have float x, and while float is an arithmetic type, it's not an integral type.

    An integral type is one of: bool, char, char16_t, char32_t, wchar_t, and any of the signed and unsigned integer types (char, short, int, long, and long long).

    You'll need to convert your algorithm to use one of these for the index of your for loop. This might work:

    int iEnd = (_fracEnd.x - _fracStart.x) / _fracStep;
    int jEnd = (_fracEnd.y - _fracStart.y) / _fracStep;
    for (int i = 0; i < iEnd; i++)
    {
      float x = _fracStart.x + i * _fracStep;
      for (int j = 0; j < jEnd; j++)
      {
        float y = _fracStart.y + j * _fracStep;
        // ...
      }
    }