## Gauss Siedel OpenMP Problem

General OpenMP discussion

### Gauss Siedel OpenMP Problem

Hello,

I've got an implementation of the Gauss-Siedel algorithm in C/C++ that I'm currently attempting to parallelize with OpenMP. Having done a bit of research, I have the following (simplified for readability) code, which is being compiled with gcc-4.4 and run on a 32-bit dual-core Linux system:

Code: Select all
`static double red_parallel_for_step(unsigned int NX, unsigned int NY, unsigned int NZ, double stepSize, double* red, double* black){   double tmp = 0.0;      double avg = 0.0;   double old = 0.0;   double max = -HUGE_VAL;   int x1, x2, y1, y2, z1, z2;   #pragma omp parallel \   shared(NX, NY, NZ, stepSize, black, red, max) \   private(x1, x2, y1, y2, z1, z2) \   firstprivate(old, avg, tmp)    {      double priv_max = -HUGE_VAL;      #pragma omp for       for(unsigned int j = 0; j < NY+2; j++){         for(unsigned int i = 0; i < NX/2+1; i++){            for(unsigned int k = 1; k < NZ; k++){               if(red[IX3] == HUGE_VAL) continue;               old = red[IX3];               avg = 0.0;               x1 = ( black[IX3+IX3_XR1STEP] != HUGE_VAL );                x2 = ( black[IX3+IX3_XR2STEP] != HUGE_VAL );                y1 = ( black[IX3+IX3_YSTEP]     != HUGE_VAL );                y2 = ( black[IX3-IX3_YSTEP]     != HUGE_VAL );                z1 = ( black[IX3+IX3_ZSTEP]     != HUGE_VAL );               z2 = ( black[IX3-IX3_ZSTEP]     != HUGE_VAL );               if (x1) avg += black[IX3+IX3_XR1STEP];               if (x2) avg += black[IX3+IX3_XR2STEP];               if (y1) avg += black[IX3+IX3_YSTEP];               if (y2) avg += black[IX3-IX3_YSTEP];               if (z1) avg += black[IX3+IX3_ZSTEP];               if (z2) avg += black[IX3-IX3_ZSTEP];               avg /= (double) (x1+x2+y1+y2+z1+z2);               red[IX3] = old + stepSize * (avg - old);               tmp = fabs(old - red[IX3]) / fabs(old);               if( tmp > priv_max ) priv_max = tmp;            }         }      }      #pragma omp flush (max)      if ( priv_max > max ) {         #pragma omp critical         {            if ( priv_max > max ) max = priv_max;         }      }   }}`

I use the -fopenmp switch when compiling and include <omp.h> and can clearly see the usage on both processors spike when the code is run, so I know that the problem is not as trivial as not fully utilizing the hardware. As it stands, 7 iterations of this function takes about 2.5 times as long to complete as the serial version. I've been working through similar OpenMP examples but I can't seem to find the problem. Any help would be much appreciated.

Thanks
FiberOptix

Posts: 1
Joined: Tue Aug 06, 2013 5:18 pm

### Re: Gauss Siedel OpenMP Problem

Hi there,

Couple of questions for you: what values of NX, NY, NZ are you using? What are the actual times you observe? What are you using to do the timing?

Thanks,
Mark.
MarkB

Posts: 746
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh