/* ******************************************************************** C-DAC Tech Workshop : hyPACK-2013 October 15-18, 2013 Example 5.5 : mv_mult_master_sschd.c Objective : Matrix_Vector Multiplication (Self_scheduling algorithm master program) Input : Process 0 (master) 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 greater than 2 and less than or equal to 8 Created : August-2013 E-mail : hpcfte@cdac.in ****************************************************************/ #include #include #include main(int argc, char** argv) { int Numprocs, MyRank; int NoofCols, NoofRows, VectorSize; int index, irow, icol, iproc, ValidInput=1; int Root=0, Source, Destination; int Source_tag, Destination_tag; int RowtoSend = 0; float **Matrix, *Buffer, Sum; float *Vector, *FinalVector; float *CheckResultVector; FILE *fp; int MatrixFileStatus = 1, VectorFileStatus = 1; MPI_Status status; /* ........MPI Initialisation .......*/ MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &MyRank); MPI_Comm_size(MPI_COMM_WORLD, &Numprocs); if(Numprocs < 2) { printf("Invalid Number of Processors ..... \n"); printf("Numprocs must be greater than 1 ......\n"); MPI_Finalize(); exit(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