/* Heterogeneous and Grid Computing: Assignment 2 * MPI Implementation of the 2-dimensional ScaLAPACK * algorithm for matrix-multiplication * Author: Donal Simmie * Student No: 06160719 */ #include #include #include #include #include #define MASTER 0 // function prototypes // allocate memory for matrices double** allocateMatrixMemory( double** matrix, int rows, int cols ); // initialise a matrix to a given value void initialiseMatrix( double** matrix, int rows, int cols, double value ); // print matrix void printMatrix( double** matrix, int rows, int cols ); int main( int argc, char** argv ) { // variabe declarations int n; // matrix dimension int proc_count; // process count int proc_rank; // process rank int root_p; // square root of p int m; // n/r int i,j; // matrix indices int k; // loop index int ind1, ind2; // for recalculating Bcols indices int prow, pcol; // current processes processor grid indices int rank=0; int **proc_grid = NULL; // 2d processor grid double **A = NULL, **B = NULL, **C = NULL; // the matrices double **Arows = NULL; // n/r * n matrix of A data for a process row double **Bcols = NULL; // n/r * n matrix of B data for a process column (stored as horizontal blocks) time_t start, end; // for timing MPI_Status status; MPI_Comm row_com, col_com; // row and clumn communicators MPI_Init(&argc, &argv); // determine processor count and relative rank MPI_Comm_size (MPI_COMM_WORLD, &proc_count); MPI_Comm_rank (MPI_COMM_WORLD, &proc_rank ); printf("Process %d\n", proc_rank); MPI_Finalize(); return 0; root_p = sqrt(proc_count); n = 600; m = n/root_p; // create 2d array of processors proc_grid =(int **)malloc(root_p*sizeof(int *)); proc_grid[0] = (int *)malloc(root_p*root_p*sizeof(int)); if(!proc_grid) { printf("Memory allocation failed \n"); exit(1); } for(i=1; i