collapse and control variables

collapse and control variables

After updating into C++ 14.0.2.176 I found a different treatment for variables in collapsed control loops.For version 13.x, the following code was correct

#pragma omp parallel for collapse(3)

    for (k=0; k< h->nz;  k++)
    for (j=0; j< h->ny ; j++)
    for (i=0; i< h->nx ; i++)
    {
       Point3DType p3d;

       XYZ(h, i, j, k, &p3d);
       d2pc[(h->nx * h->ny)*k + h->nx * j + i] = kdNNS(&p3d);
    }

For version 14.0.2.176 it needs to be modified into:

#pragma omp parallel for collapse(3) private (k,j,i)
    for (k=0; k< h->nz;  k++)
    for (j=0; j< h->ny ; j++)
    for (i=0; i< h->nx ; i++)
    {
       Point3DType p3d;

       XYZ(h, i, j, k, &p3d);
       d2pc[(h->nx * h->ny)*k + h->nx * j + i] = kdNNS(&p3d);
    }

I had to declare as private at less j and i. I do not know if it is mandatory to declare i and j as private according to OpenMP definition. But I found important to share my case with others because it was not easy to locate the source of the problem and there are lot of examples of use of "collapse" omitting private declaration for the control variables affected.

3 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

 

yes, in c or c++ only the outer loop induction variable defaults to private, so your observation is expected.  in simple cases, with optimization on (so you may not be able to observe the counter), the inner counters may not materialize in a shared manner, so failing to make them local isn't guaranteed to fail (or not).  easy solution is to make them local like for(int j=0;.... so as not to require omp private

Tim, thanks for your clarifications

Sorry for posting several times, it took 7 hours to be published and I keep trying...

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi