OPENMP nested loop in C

I am very new to parallel computation. I have tried to build up a code with OPENMP for nested loops. But my results are different than that by doing sequentially. May I get any help to fix it ? Thank you.

#include <stdio.h>
#include <math.h>
#ifdef _OPENMP
#include <omp.h>
#endif

void test_function(float **p0)
{
    int ix,iz,ib,ibx,ibz;
    float w;
    #ifdef _OPENMP
    #pragma omp parallel for 
    private(ib,iz,ix,ibz,ibx,w)  
    shared(bndr,nzpad,nxpad,nb,p0)
    #endif
    for(ib=0; ib<nb; ib++) {
            w = bndr[nb-ib-1];
            ibz = nzpad-ib-1;
            for(ix=0; ix<nxpad; ix++) {
                p0[ix][ib ] *= w; /*    top */
                p0[ix][ibz] *= w; /* bottom */
            }
            ibx = nxpad-ib-1;
            for(iz=0; iz<nzpad; iz++) {
                p0[ib ][iz] *= w; /*   left  */
                p0[ibx][iz] *= w; /*  right */
            }
    }
}


Source: c#

Leave a Reply