title: Gauss Seidel using OpenMP | Linear Equations solving
body: <p><strong>I am doing a code on Gauss Seidel using OpenMP to solve a system of linear equations.
  But I am not getting the correct output.
  The output comes correct if n is set to 1.
  The algorithm seems right to me though.
  Can anyone help?</strong></p>
  <p>Code:</p>
  <blockquote>
  </blockquote>
  <pre><code>    int seidel_p(double *A, double *b, double *x, int n)
  {
      double *dx;
      dx = (double*) calloc(n,sizeof(double));
      int epsilon = 1.0e-4;
      int i,j,k,id;
      double dxi;
      double sum;
      for(int i =0; i&lt;n ; i++)
      {
          x[i] = 0;
      }
  
      int maxit = 2*n*n;
  
      for(k=0; k&lt;maxit; k++)
     {
        for(i=0; i&lt;n; i++)
        {
           dx[i] = b[i];
           #pragma omp parallel shared(A,x)
           {
              for(j=0; j&lt;n; j++)
              {
                  if(i!=j)
                  {
                      dxi += A[i*n+j]*x[j];
                  }
              }
  
              #pragma omp critical
                 dx[i] -= dxi;
           }
           dx[i] /= A[i*n +i];
           x[i] = dx[i];
           sum += ( (dx[i] &gt;= 0.0) ? dx[i] : -dx[i]);
           if(sum&lt;= epsilon) break;
  
        }
     }
  
     for( int i = 0 ; i&lt;n ; i++ )
     {
          printf(&quot;\t\t%f\n&quot;, dx[i]);
     }
  
      free(dx);
  }
  </code></pre>