Close

Not a member yet?Register now and get started.

lock and key

Sign in to your account.

Account Login

OpenACC Accelerating a Jacobi Iteration

#pragma acc data copy(A) create(Anew)
while ( error > tol  &&  iter  <  iter_max )  {
  error = 0.0;
  #pragma acc kernels
  {
  #pragma acc loop
  for (  int  j = 1; j < n-1;  j++ )  {
    for (  int  i = 1; i < m-1; i++ )  {
       Anew [j] [i] = 0.25 * ( A [j] [i+1] + A [j] [i-1] +
                                      A [j-1] [i] + A [j+1] [i];
       error = fmax ( error, fabs (Anew [j] [i] - A [j] [i];
    }
  }
 
  #pragma acc loop
  for (  int j = 1; j < n-1; j++) {
     for (int = i; i < m-1; i++ )  {
       A [j] [i] = Anew [j] [i];
     }
    }
  }
 
   if (iter % 100 == 0) printf ("%5d, %0.6f\n", iter, error);
   iter++;
}