/* RHS initializes the right hand side "vector". */ void rhs(int matrix_size, int matrix_size2, double *f_, int block_size) { double (*f)[matrix_size][matrix_size] = (double (*)[matrix_size][matrix_size])f_; int i,ii; int j,jj; double x; double y; // The "boundary" entries of F store the boundary values of the solution. // The "interior" entries of F store the right hand sides of the Poisson equation. #pragma omp parallel #pragma omp master //for collapse(2) for (j = 0; j < matrix_size; j+=block_size) for (i = 0; i < matrix_size; i+=block_size) #pragma omp task firstprivate(block_size,i,j,matrix_size) private(ii,jj,x,y) for (jj=j; jj<j+block_size; ++jj) { y = (double) (jj) / (double) (matrix_size - 1); for (ii=i; ii<i+block_size; ++ii) { x = (double) (ii) / (double) (matrix_size - 1); if (ii == 0 || ii == matrix_size - 1 || jj == 0 || jj == matrix_size - 1) (*f)[ii][jj] = u_exact(x, y); else (*f)[ii][jj] = - uxxyy_exact(x, y); } } }
/* RHS initializes the right hand side "vector". */ void rhs(int nx, int ny, double *f, int block_size) { int i,ii; int j,jj; double x; double y; // The "boundary" entries of F store the boundary values of the solution. // The "interior" entries of F store the right hand sides of the Poisson equation. #pragma omp parallel { #pragma omp single for (j = 0; j < ny; j+=block_size) { for (i = 0; i < nx; i+=block_size) { #pragma omp task firstprivate(block_size,i,j,nx,ny) private(ii,jj,x,y) for (jj=j; jj<j+block_size; ++jj) { y = (double) (jj) / (double) (ny - 1); for (ii=i; ii<i+block_size; ++ii) { x = (double) (ii) / (double) (nx - 1); if (ii == 0 || ii == nx - 1 || jj == 0 || jj == ny - 1) (f)[ii * ny + jj] = u_exact(x, y); else (f)[ii * ny + jj] = - uxxyy_exact(x, y); } } } } } }
void rhs ( int nx, int ny, double f[NX][NY] ) /******************************************************************************/ /* * Purpose: * RHS initializes the right hand side "vector". * Discussion: * It is convenient for us to set up RHS as a 2D array. However, each * entry of RHS is really the right hand side of a linear system of the * form * A * U = F * In cases where U(I,J) is a boundary value, then the equation is simply * U(I,J) = F(i,j) * and F(I,J) holds the boundary data. * Otherwise, the equation has the form * (1/DX^2) * ( U(I+1,J)+U(I-1,J)+U(I,J-1)+U(I,J+1)-4*U(I,J) ) = F(I,J) * where DX is the spacing and F(I,J) is the value at X(I), Y(J) of * pi^2 * ( x^2 + y^2 ) * sin ( pi * x * y ) * Licensing: * This code is distributed under the GNU LGPL license. * Modified: * 28 October 2011 * Author: * John Burkardt * Parameters: * Input, int NX, NY, the X and Y grid dimensions. * Output, double F[NX][NY], the initialized right hand side data. * */ { double fnorm; int i; int j; double x; double y; /* * The "boundary" entries of F store the boundary values of the solution. * The "interior" entries of F store the right hand sides of the Poisson equation. * */ for ( j = 0; j < ny; j++ ) { y = ( double ) ( j ) / ( double ) ( ny - 1 ); for ( i = 0; i < nx; i++ ) { x = ( double ) ( i ) / ( double ) ( nx - 1 ); if ( i == 0 || i == nx - 1 || j == 0 || j == ny - 1 ) { f[i][j] = u_exact ( x, y ); } else { f[i][j] = - uxxyy_exact ( x, y ); } } } fnorm = r8mat_rms ( nx, ny, f ); printf ( " RMS of F = %g\n", fnorm ); return; }