openmp two consecutive loops, problem with reduction clause

  c++, openmp

There is two consecutive loops and there is a reduction clause in the second loop.

#pragma opm parallel
{
#pragma omp for
    for (size_t i = 0; i < N; ++i)
    {
      
    }
#pragma omp barrier
#pragma omp for reduction(+ 
                    : sumj)
    for (size_t i = 0; i < N; ++i)
    {
        sumj = 0.0;
        for (size_t j = 0; j < adjList[i].size(); ++j)
        {
            sumj += 0;
        }
        Jac[i, i] = sumj;
    }
}

to reduce the creating threads overhead I wand to keep the threads and use them in the second loop, but I get the following error

lib.cpp:131:17: error: reduction variable ‘sumj’ is private in outer context
         #pragma omp for reduction(+ 
                 ^~~

how to fix that?

Source: Windows Questions C++

LEAVE A COMMENT