#include "mat_mul.h" #include #include #include #include "util.h" #include #define MASTER 0 #define FROM_MASTER 1 #define FROM_WORKER 2 #define ITILESIZE (32) #define JTILESIZE (1024) #define KTILESIZE (1024) static float *A, *B, *C; static int M, N, K; static int num_threads; static int mpi_rank, mpi_world_size; MPI_Status status; MPI_Request request; int numworkers, source, dest, mtype, rows, averow, extra, offset, i, j, k; static int min(int x, int y) { return (x 0) ? averow+1:averow; rows=averow; mat_mul_omp(); mtype=FROM_WORKER; for(i=1;i MASTER) { alloc_mat(&A, M, K); alloc_mat(&B, K, N); alloc_mat(&C, M, N); zero_mat(C,M,N); mtype=FROM_MASTER; MPI_Recv(&offset, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD,&status); MPI_Recv(&rows, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD,&status); MPI_Recv(A, rows*K, MPI_FLOAT, MASTER, mtype, MPI_COMM_WORLD,&status); MPI_Recv(B, K*N, MPI_FLOAT, MASTER, mtype, MPI_COMM_WORLD,&status); mat_mul_omp(); mtype = FROM_WORKER; MPI_Isend(&offset, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD,&request); MPI_Isend(&rows, 1, MPI_INT, MASTER, mtype, MPI_COMM_WORLD,&request); MPI_Isend(C, rows*N, MPI_FLOAT, MASTER, mtype, MPI_COMM_WORLD,&request); } } }