/* ********************************************************************* C-DAC Tech Workshop : hyPACK-2013 October 15-18, 2013 Objective : Matrix_Vector multiplication (Using block striped partitioning) Input : Process 0 reads files (mdata.inp) for Matrix and (vdata.inp) for Vector Output : Process 0 prints the result of Matrix_Vector Multiplication Necessary Condition : Number of rows of matrix should be less than number of processors and perfectly divisible by number of processors.Number of processors should be less than or equal to 8 Created : August-2013 E-mail : hpcfte@cdac.in ********************************************************************* */ #include #include #include #include main(int argc, char** argv) { int Numprocs, MyRank; int NoofCols, NoofRows, VectorSize, ScatterSize; int index, irow, icol, iproc; int Root = 0, ValidOutput = 1; float **Matrix, *Buffer, *Mybuffer, *Vector, *MyFinalVector, *FinalVector; float *CheckResultVector; FILE *fp; int MatrixFileStatus = 1, VectorFileStatus = 1; /* ........MPI Initialisation .......*/ MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &MyRank); MPI_Comm_size(MPI_COMM_WORLD, &Numprocs); if(MyRank == 0) { /* .......Read the Input file ......*/ if ((fp = fopen ("./data/mdata.inp", "r")) == NULL){ MatrixFileStatus = 0; } if(MatrixFileStatus != 0) { fscanf(fp, "%d %d\n", &NoofRows,&NoofCols); /* ...Allocate memory and read Matrix from file .......*/ Matrix = (float **)malloc(NoofRows*sizeof(float *)); for(irow=0 ;irow 1.0E-10){ printf("Error %d\n",irow); ValidOutput = 0; } } free(CheckResultVector); if(ValidOutput) printf("\n-------Correct Result------\n"); } MPI_Finalize(); }