/* heateqn.c Chris Nevison modified by Wal Maxey and Xiannong Meng as MPI lab in Parallel Computing Workshop, Colgate U. July 14, 1997 June 27, 1997 This program solves the heat equation for a rectangle with fixed boundary values. The values are converted into color pixels, ranging from blue for coldest, through green for medium, to red for hottest. */ #include #include #include "graphics.h" #include "heat.h" #include "mpi.h" int main(int argc, char* argv[]) { char filename[30]; FILE * infile; FILE * outfile; int numrows, numcols, maxiter; double * row0; double * rowmax; double * col0; double * colmax; double * * mat; double tol; double minval; double maxval; double startTime, endTime; Pixel * * pmap; MPI_Init(&argc, &argv); /* start MPI */ printf("Enter input file name: "); scanf("%s", filename); if((infile = fopen(filename, "r+b")) == NULL){ printf("unable to open input file %s, exiting program.\n\n", filename); exit(1); } printf("Enter output file name: "); scanf("%s", filename); if((outfile = fopen(filename, "w+b")) == NULL){ printf("unable to open output file %s, exiting program.\n\n", filename); exit(2); } printf("Enter tolerance for heat computation: "); scanf("%lf", &tol); printf("\nEnter maximum number of iterations: "); scanf("%d", &maxiter); startTime = MPI_Wtime(); ReadHeatBndry(infile, &numrows, &numcols, &row0, &rowmax, &col0, &colmax); SolveHeat(row0, rowmax, col0, colmax, numrows, numcols, tol, maxiter, &mat); FindMinMax(numrows, numcols, mat, &minval, &maxval); CreatePixelMap(numrows, numcols, &pmap); DMatToPMap(mat, minval, maxval, numrows, numcols, pmap); StoreTGAHeader(outfile, numrows, numcols); StorePixelBlock(outfile, numrows, numcols, pmap); endTime = MPI_Wtime(); printf(" TOTAL TIME : %10.4f seconds\n",endTime - startTime); MPI_Finalize(); /* shut down MPI */ return 0; }