/************************************************************ * File: mm_speedup.c * Purpose: Parallel matrix multiplication with measurement * of the average time taken by each worker process * to complete its computation. ************************************************************/ #include #include #include #include "mxm.h" #define NRA 2880 // number of rows in matrix A #define NCA 2000 // number of columns in matrix A #define NCB 450 // number of columns in matrix B #define MASTER 0 // taskid of first task #define FROM_MASTER 1 // setting a message type #define FROM_WORKER 2 // setting a message type int main(int argc, char *argv[]) { int numtasks, // number of tasks taskid, // task identifier source, // task id of message source dest, // task id of message destination mtype, // message type rows, // rows of matrix A sent to each worker averow, extra, offset, // used to determine rows sent to each worker i, j, k; // misc double stime, etime, my_compute_time, compute_time; FILE *stream; char *file = "output_c.dat"; MPI_Status status; double **a, // matrix A to be multiplied **b, // matrix B to be multiplied **c; // result matrix C MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); MPI_Comm_rank(MPI_COMM_WORLD, &taskid); if(taskid == MASTER) { rows = NRA; } else { averow = NRA/(numtasks-1); extra = NRA%(numtasks-1); rows = (taskid <= extra) ? averow+1 : averow; } a = (double **)malloc(rows*sizeof(double *)); a[0] = (double *)malloc(rows*NCA*sizeof(double)); for(i=1; i