#include #include #include #include #include //Uncomment if these need to be undefined //#undef SEEK_SET //#undef SEEK_CUR //#undef SEEK_END #include "mpi.h" void PrintSurfaceMatrix(double** M, int LD, int D); int main(int argc, char* argv[]){ MPI_Init(&argc,&argv); int NCPUS, MY_PE; MPI_Comm_size(MPI_COMM_WORLD, &NCPUS); MPI_Comm_rank(MPI_COMM_WORLD, &MY_PE); // Read Input Parameters if(argc < 4) { cerr << "\nToo many input paramters.. should be four\n"; exit(2); } int Dimension = atoi(argv[1]); int Iterations = atoi(argv[2]); int RowPeek = atoi(argv[3]); int ColPeek = atoi(argv[4]); // cout <<"\nInputs = " << Dimension << " "< Dimension) || (ColPeek > Dimension)){ cerr << "Cannot Peek a matrix element outside of the surface"; cerr << "Arguments 3 and 4 must be smaller than " << Dimension; exit(3); } // Initialize Matrix // So on each processor, we need only enough memory to hold our rows // and the two other rows double **SurfaceMatrix; int *Offsets = (int*)malloc(sizeof(int)*NCPUS); int *LocalDims = (int*)malloc(sizeof(int)*NCPUS); int LocalDim = Dimension/NCPUS; for(int ip = 0; ip < NCPUS; ip++){ LocalDims[ip] = LocalDim; if(ip < (Dimension % NCPUS)) LocalDims[ip]++; } Offsets[0] = 0; for(int ip =1; ip < NCPUS; ip++) Offsets[ip] = Offsets[ip-1] + LocalDims[ip-1]; SurfaceMatrix = (double**)malloc(sizeof(double*)*(LocalDims[MY_PE]+2)); for(int i=0;i Offsets[ip]){ IPRowPeek = ip; LocalRowPeek = RowPeek - Offsets[ip]; } } if(MY_PE == IPRowPeek){ cout << "\n Result SurfaceMatrix["<