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>

void test_function(float **p0)
    int ix,iz,ib,ibx,ibz;
    float w;
    #ifdef _OPENMP
    #pragma omp parallel for 
    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