Search code examples
c++openmpreduction

Unrecognized pragma: Reduction clause | openMP


For the code below I get an error: unrecognized #pragma: #pragma omp reduction (+: sum). Note that the for-loop inside the function is not a parallel-for-loop because the function itself is parallelized already. Could you say where is the problem?

Main cpp file:

#include <omp.h>

int main ()
{
    #pragma omp parallel
    {
        function ();
    }
}

Another cpp file wherein function defined

#include <omp.h>

void function ()
{
    T priv_var;

    // some calculations

    #pragma omp reduction (+: sum)  // sum is a shared variable
    {
        for (;;)
        {
            sum = sum + priv_var;
        }
    }
}

Solution

  • I tried #pragma omp parallel reduction (+: sum) and it worked. Several usages of reduction is here: http://msdn.microsoft.com/en-us/library/88b1k8y5(v=vs.80).aspx