/*
 *******************************************************************
 * Laplace Eqn 
 * T is initially 0.0 everywhere except at boundaries where T=100.
 *                                                        
 *             T = 100                                      Y
 *     |-------------------|        |-------------------|   |
 *     |                   |        |                   |   |
 *  T  |                   |  T     |-------------------|   |
 *  =  |                   |  =     |                   |   |
 * 100 |                   | 100    |-------------------|   |_______X
 *     |                   |        |                   | 
 *     |                   |        |-------------------| 
 *     |                   |        |                   | 
 *     |-------------------|        |-------------------| 
 *            T = 100
 *
 * Use Central Differencing Method
 * Each process only has subgrid.
 * Each Processor works on a sub grid and then sends its
 * Boundaries to neighbours
 *
 *    /mpp/bin/cc -T cray-t3d -o laplace.par laplace.serial.c -lpvm3
 *
 * Raghu Reddy,  PSC.... Apr 1995;
 * From the original Fortran version by Sushell Chitre, PSC 1994
 *
 ******************************************************************   */

#define NPROC    1
#define NROWS    1000
#define NCOLS    1000
#define NROWSL   NROWS/NPROC
#define NITER    1000

main(int argc, char **argv) {

  float T[NROWSL+2][NCOLS+2], Told[NROWSL+2][NCOLS+2];
  int   i, ii, j, jj, itop, ibot, iter;

/*    Initial and Boundary Values     */

  for( i=0; i<=NROWSL+1; i++ )
    for ( j=0; j<=NCOLS+1; j++ )
      T[i][j] = 0.0;

/*     Left and Right Boundaries      */

  for( i=0; i<=NROWSL+1; i++ ) {
    T[i][0]       = 100.0;
    T[i][NCOLS+1] = 100.0;            /* The last col, right bound */
  }

/*     Top and Bottom Boundaries      */

  for( j=0; j<=NCOLS+1; j++ ) {
    T[0][j]        = 100.0;
    T[NROWSL+1][j] = 100.0;
  }

  for( i=0; i<=NROWSL+1; i++ )
    for( j=0; j<=NCOLS+1; j++ )
      Told[i][j] = T[i][j];


/*    Do Computation on Sub-grid for Niter iterations     */

  for( iter=0; iter<NITER; iter++ ) {

    for( i=1; i<=NROWSL; i++ )
      for( j=1; j<=NCOLS; j++ )
	T[i][j] = 0.25 * ( Told[i+1][j] + Told[i-1][j] +
			   Told[i][j+1] + Told[i][j-1] );

/*   Copy for next iteration  */

    for( i=1; i<=NROWSL; i++ )
      for( j=1; j<=NCOLS; j++ )
	Told[i][j] = T[i][j];


/*   Print some test Values   */

    if( (iter%100) == 0 )
      printf("Iter = %10d; T[10][10] = %20.8f; T[NROWSL-9][10] = %20.8f\n",
	      iter, T[10][10],T[NROWSL-9][10]);
  }  /* End of iteration */

}    /* End of Program */

