CSE4001 Parallel and Distributed Computing: Lab Assignment 6
CSE4001 Parallel and Distributed Computing: Lab Assignment 6
ANUKRITI JAIN
17BCE0519
LAB ASSIGNMENT 6
Using MPI, Design, develop and run matrix multiplication
using MPI_Send and MPI_Recv. In this code, the master task
distributes a matrix multiply operation to numtasks-1 worker
tasks.
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&taskid);
MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
if (numtasks < 2 ) {
printf("Need at least two MPI tasks. Quitting...\n");
MPI_Abort(MPI_COMM_WORLD, rc);
exit(1);
}
numworkers = numtasks-1;
/* Print results */
printf("******************************************************\n");
printf("Result Matrix:\n");
for (i=0; i<NRA; i++)
{
printf("\n");
for (j=0; j<NCB; j++)
printf("%6.2f ", c[i][j]);
}
printf("\n******************************************************\n");
printf ("Done.\n");
}
avepi = 0;
for (i = 0; i < ROUNDS; i++) {
/* All tasks calculate pi using dartboard algorithm */
homepi = dboard(DARTS);
if (taskid == MASTER)
printf ("\nReal value of PI: 3.1415926535897 \n");
MPI_Finalize();
return 0;
}
/* calculate pi */
pi = 4.0 * (double)score/(double)darts;
return(pi);
}