#include #include #include #define EPSILON 0.00001 #define N 100 #define time_steps 100 int main (int argc, char *argv[]) { int i,j; int myid, numprocs; int from,to; int step; double time; double eps, enew, global_eps; double time_max = 3.0; double alpha = 0.06; double dx = 1.0/N; double dy = 1.0/time_steps; double dt = time_max/time_steps; double dxinv = 1.0/dx; double dyinv = 1.0/dy; double dtinv = 1.0/dt; double divinv = 1.0/(dtinv + 2 * alpha * (dxinv * dxinv + dyinv * dyinv)); double **t,*tS; double **told,*toldS; double **tstep,*tstepS; double *sendR1,*sendR2; double *recvR1,*recvR2; double minval, maxval; long clock(),cputime; char fname[40]; FILE *out; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); if (((N % numprocs) == 0) && (numprocs > 1)) { if (myid == 0) { clock(); tstepS = (double *) malloc(N * N * sizeof(double)); tstep = (double **) malloc(N * sizeof(double *)); for (i=0; i 0) && (myid < (numprocs-1))) { //allocate memory for message arrays sendR1 = (double *) malloc(N * sizeof(double)); recvR1 = (double *) malloc(N * sizeof(double)); sendR2 = (double *) malloc(N * sizeof(double)); recvR2 = (double *) malloc(N * sizeof(double)); //send my first computed row to myid-1 for(j=0; j eps) { eps = enew; } } } for (i=0; i<((N/numprocs)+2); i++) for (j=0; j EPSILON); // gather all the subsets of the grid MPI_Gather(told[1],N*(N/numprocs),MPI_DOUBLE,tstepS,N*(N/numprocs),MPI_DOUBLE,0,MPI_COMM_WORLD); // Produce a raster image for this time step if (myid == 0) { minval = 0.0; maxval = 0.0; for (i=0; i maxval) { maxval = tstep[i][j]; } } } sprintf(fname,"Output\\heat%03d.raw",step); out = fopen(fname,"w+b"); for (i=0; i