cpp: #include <stdio.h>\n#include <math.h>\n\n#define MSIZE 200\nint n=MSIZE, m=MSIZE, mits=1000;\ndouble tol=0.0000000001, relax = 1.0, alpha = 0.0543;\ndouble u[MSIZE][MSIZE], f[MSIZE][MSIZE], uold[MSIZE][MSIZE];\ndouble dx, dy;\n\nvoid\ninitialize ()\n{\n  int i, j, xx, yy;\n\n  dx = 2.0 / (n - 1);\n  dy = 2.0 / (m - 1);\n\n/* Initialize initial condition and RHS */\n//#pragma omp parallel for private(i,j,xx,yy)\n  for (i = 0; i < n; i++)\n    for (j = 0; j < m; j++)\n    {\n      xx = (int) (-1.0 + dx * (i - 1));       /* -1 < x < 1 */\n      yy = (int) (-1.0 + dy * (j - 1));       /* -1 < y < 1 */\n      u[i][j] = 0.0;\n      f[i][j] = -1.0 * alpha * (1.0 - xx * xx) * (1.0 - yy * yy)\n        - 2.0 * (1.0 - xx * xx) - 2.0 * (1.0 - yy * yy);\n\n    }\n}\n\nvoid\njacobi ()\n{\n  double omega;\n  int i, j, k;\n  double error, resid,  ax, ay, b;\n\n  omega = relax;\n/* Initialize coefficients */\n\n  dx = 2.0 / (n - 1); \n  dy = 2.0 / (m - 1);\n\n  ax = 1.0 / (dx * dx);         /* X-direction coef */\n  ay = 1.0 / (dy * dy);         /* Y-direction coef */\n  b = -2.0 / (dx * dx) - 2.0 / (dy * dy) - alpha;       /* Central coeff */\n\n  error = 10.0 * tol;\n  k = 1;\n\n  while (k <= mits)\n    {\n      error = 0.0;\n\n/* Copy new solution into old */\n#pragma omp parallel\n      {\n#pragma omp for private(i,j)\n        for (i = 0; i < n; i++)\n          for (j = 0; j < m; j++)\n            uold[i][j] = u[i][j];\n#pragma omp for private(i,j,resid) reduction(+:error) nowait\n        for (i = 1; i < (n - 1); i++)\n          for (j = 1; j < (m - 1); j++)\n            {\n              resid = (ax * (uold[i - 1][j] + uold[i + 1][j])\n                       + ay * (uold[i][j - 1] + uold[i][j + 1]) +\n                       b * uold[i][j] - f[i][j]) / b;\n\n              u[i][j] = uold[i][j] - omega * resid;\n              error = error + resid * resid;\n            }\n      }\n/*  omp end parallel */\n\n/* Error check */\n\n     k = k + 1;\n      error = sqrt (error) / (n * m);\n    }                           /*  End iteration loop */\n\n  printf ("Total Number of Iterations:%d\n", k);\n  printf ("Residual:%E\n", error);\n}\n\nint main()\n{\n  initialize();\n  jacobi();\n  return 0;\n}\n
fortran: module DRB058\nuse omp_lib\nimplicit none\n\ninteger :: MSIZE\ninteger :: n,m,mits\ninteger, parameter :: dp = kind(1.0d0)\nreal(dp), dimension(:,:), pointer :: u,f,uold\nreal(dp) :: dx,dy,tol,relax,alpha\n\ncontains\nsubroutine initialize()\ninteger :: i,j,xx,yy\n\nMSIZE = 200\nmits = 1000\ntol=0.0000000001\nrelax = 1.0\nalpha = 0.0543\nn = MSIZE\nm = MSIZE\nallocate(u(MSIZE,MSIZE))\nallocate(f(MSIZE,MSIZE))\nallocate(uold(MSIZE,MSIZE))\n\ndx = 2.0D0 / DBLE(n-1)\ndy = 2.0D0 / DBLE(m-1)\n\ndo i = 1, n\ndo j = 1, m\nxx = int(-1.0 + dx * (i-1))\nyy = int(-1.0 + dy * (i-1))\nu(i,j) = 0.0\nf(i,j) = -1.0 * alpha * (1.0-xx*xx) * (1.0-yy*yy) - 2.0* (1.0-xx*xx) -2.0 * (1.0-yy*yy)\nend do\nend do\n\nend subroutine\n\nsubroutine jacobi()\ninteger, parameter :: dp = kind(1.0d0)\nreal(dp) :: omega\ninteger :: i, j, k\nreal(dp) :: error, resid,  ax, ay, b\n\nMSIZE = 200\nmits = 1000\ntol=0.0000000001\nrelax = 1.0\nalpha = 0.0543\nn = MSIZE\nm = MSIZE\n\nomega = relax\ndx = 2.0D0 / DBLE(n-1)\ndy = 2.0D0 / DBLE(m-1)\n\nax = 1.0D0 / (dx * dx);         !/* X-direction coef */\nay = 1.0D0 / (dy * dy);         !/* Y-direction coef */\nb = -2.0D0 / (dx * dx) - 2.0D0 / (dy * dy) - alpha;\n\nerror = 10.0 * tol\nk = 1\n\ndo k = 1, mits\nerror = 0.0\n\n!Copy new solution into old\n!$omp parallel\n!$omp do private(i,j)\ndo i = 1, n\ndo j = 1, m\nuold(i,j) = u(i,j)\nend do\nend do\n!$omp end do\n!$omp do private(i,j,resid) reduction(+:error)\ndo i = 2, (n-1)\ndo j = 2, (m-1)\nresid = (ax * (uold(i - 1,j) + uold(i + 1,j)) + ay * (uold(i,j - 1) + uold(i,j + 1)) + b * uold(i,j) - f(i,j)) / b\nu(i,j) = uold(i,j) - omega * resid\nerror = error + resid * resid\nend do\nend do\n!$omp end do nowait\n!$omp end parallel\n\n!Error check\nerror = sqrt(error)/(n*m)\nend do\n\nprint*,"Total number of iterations: ",k\nprint*,"Residual: ",error\n\nend subroutine\nend module program DRB058_jacobikernel_orig_no\n    use omp_lib\n    use DRB058\n    implicit none\n\n    call initialize()\n    call jacobi()\nend program