#include #include #define NRA 12 // number of rows in matrix A #define NCA 15 // number of columns in matrix A #define NCB 7 // 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 a[NRA][NCA], // matrix A to be multiplied b[NCA][NCB], // matrix B to be multiplied c[NRA][NCB]; // result matrix C MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); MPI_Comm_rank(MPI_COMM_WORLD, &taskid); if(taskid == MASTER) { printf("Number of worker tasks = %d\n", numtasks-1); // initialize matrix a and matrix b for(i=0; i