/**************************************************************** C-DAC Tech Workshop : hyPACK-2013 October 15-18, 2013 Example 5.7 : mv_mult_mult_checkerboard.c Objective : Matrix_Vector Multiplication (Using Block CheckerBoard 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 processors should be perfect square and less than or equal to 8 Created : August-2013 E-mail : hpcfte@cdac.in ***************************************************************/ #include #include #include #include main(int argc, char** argv) { /* .......Variables Initialisation ......*/ MPI_Status status; MPI_Comm row_comm, col_comm; MPI_Group MPI_GROUP_WORLD; int Numprocs, MyRank, root_p, Root = 0; int irow, icol, iproc, jproc, index, Proc_Id; int NoofRows, NoofCols, NoofRows_Bloc, NoofCols_Bloc; int Bloc_MatrixSize, Bloc_VectorSize, VectorSize; int Local_Index, Global_Row_Index, Global_Col_Index; float **Matrix, *Matrix_Array, *Bloc_Matrix, *Vector, *Bloc_Vector; float *FinalResult, *MyResult, *FinalVector; int *ranks, colsize, colrank, rowsize, rowrank, myrow; int MatrixFileStatus = 1, VectorFileStatus = 1; FILE *fp; /* MPI Initialisation */ MPI_Init(&argc, &argv); MPI_Comm_group(MPI_COMM_WORLD,&MPI_GROUP_WORLD); MPI_Comm_rank(MPI_COMM_WORLD, &MyRank); MPI_Comm_size(MPI_COMM_WORLD, &Numprocs); root_p = sqrt((double)Numprocs); if(Numprocs != (root_p * root_p)) { if( MyRank == 0) printf("Error : Number of processors should be perfect square \n"); MPI_Finalize(); exit(-1); } 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); NoofRows_Bloc = NoofRows/root_p; NoofCols_Bloc = NoofCols/root_p; /* ...Allocate memory and read Matrix from file .......*/ Matrix = (float **)malloc(NoofRows*sizeof(float *)); for(irow=0 ;irow