The reduction variable is private in the external context

I have the following code:

void simulation (MD *md){

    double sum;
    #pragma omp parallel private (move)
    {

        for(move = 0; move < maxIterations; ++move)
        {
                cicleDoMove(md);
                cicleForces(md);
                cicleMkekin(md,sum);
                // ...
        }
    }
}

Where:

void cicleMkekin(Md *md, double sum){

    #pragma omp for reduction(+ : sum)
    for (i = 0; i < md->mdsize; i++)
    {
        sum += mkekin(..);
    }
    // .. 
}

I got the following error:

"reduction variable 'sum' is private in outer context"

The variable amount is general, not private, in fact, if I changed the simulation code to:

 void simulation (MD *md){

        double sum;
        #pragma omp parallel private (move)
        {

            for(move = 0; move < maxIterations; ++move)
            {
                    cicleDoMove(md);
                    cicleForces(md);

                    #pragma omp for reduction(+ : sum)
                    for (i = 0; i < md->mdsize; i++)
                    {
                         sum += mkekin(..);
                    }
                    // ...
            }
        }
    }

It works great.

Anyway, can I use my first version of code without getting this error? or am i doing something wrong?

+4
source share
1 answer

OpenMP can be a bit confusing in this particular case. The specification prescribes (§2.14.3.6) that:

, , , .

, (§2.14.1.1), C ++,

, .

sum cicleMkekin , , . , cicleMkekin (, , , ), sum . , , , , , .

, cicleMkekin, sum . , default , (§2.14.1), reduction .

+7

All Articles