preview

R10 Unit 3 Array For Library System

Good Essays

#include #include "mpi.h" //mpi library contains mpi fucn like MPI_comm,MPI_Status... #include //library of time and date #include #define N 10 //size of row and column MPI_Status statusofprocess; //It gives current status of process running double MatA[N][N],MatB[N][N],MatC[N][N];//declared three array for matrix--multiplication int main(int argc, char **argv) { int numoftasks,tasknumber,numofslaves,counter,i,j,k,otherPart,mainrows,src,dest, rows,offset; struct timeval begin,endd; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &tasknumber); MPI_Comm_size(MPI_COMM_WORLD, &numoftasks); numofslaves = numoftasks-1; int N1=0; //now lets start following the master program which is below if (tasknumber …show more content…

mainrows = rows; ++rows; otherPart--; MPI_Send(&offset, 1, MPI_INT, dest, 1, MPI_COMM_WORLD); MPI_Send(&rows, 1, MPI_INT, dest, 1, MPI_COMM_WORLD); MPI_Send(&MatA[offset][0], rows*N, MPI_DOUBLE,dest,1, MPI_COMM_WORLD); MPI_Send(&MatB, N*N, MPI_DOUBLE, dest, 1, MPI_COMM_WORLD); offset = offset + rows; rows = mainrows; } else { MPI_Send(&offset, 1, MPI_INT, dest, 1, MPI_COMM_WORLD); MPI_Send(&rows, 1, MPI_INT, dest, 1, MPI_COMM_WORLD); MPI_Send(&MatA[offset][0], rows*N, MPI_DOUBLE,dest,1, MPI_COMM_WORLD); MPI_Send(&MatB, N*N, MPI_DOUBLE, dest, 1, MPI_COMM_WORLD); offset = offset + rows; } } //now the result by slave will be obtained or hold till it return the response for (i=1; i 0) { src = 0; MPI_Recv(&offset, 1, MPI_INT, src, 1, MPI_COMM_WORLD, &statusofprocess); MPI_Recv(&rows, 1, MPI_INT, src, 1, MPI_COMM_WORLD, &statusofprocess); MPI_Recv(&MatA, rows*N, MPI_DOUBLE, src, 1, MPI_COMM_WORLD, &statusofprocess); MPI_Recv(&MatB, N*N, MPI_DOUBLE, src, 1, MPI_COMM_WORLD, &statusofprocess); //following is the calculation for logic for (k=0;

Get Access