/*** Author : Nicholas N. Bali 1996-Feb-26 Adapted for Maisie v. 3.0 on 2-28-97 Usage : mm2-new -input filename1 -output filename2 [-block n] Notes : The driver entity issues and exit command at the end, thereby killing all processes. A segmentation fault will result if the input and output filenames are not specified. The default block size is set to 4. The largest block size is 16. ***/ /*** Algorithm : This Parallel Matrix Multiply algorithm is based on Canon's algorithm but has been extended to allow block sizes of greater than 1. First, the initial A and B matrices are read in. Each matrix has its elements shifted. The A matrix has its elements shifted left on a row - subblock basis. Thus the 0th subblock row is shifted left 0, and the 1st subblock row shifted left 1, and so on. The B matrix is shifted up on a row - subblock basis. These larger matrices are then checkerboard partitioned into smaller submatrices which are then passed to the matrix multiply entities. These entities multiply their A and B submatrices and then give their A submatrix to their left neighbor and their B submatrix to their up neighbor. This process continues until each entity has had a chance to multiply/add each subblock in its row and column. These entities then pass their computed submatrix to the printer which collects and stores the submatrices into their correct position in the larger matrix and the proceeds to print out the matrix, nicely. ***/ #include #include #include #include "maisie.h" #define MAX_MATRIX_SIZE 64 /* maximum NxN size of the matrix */ #define MAX_SUBMATRIX_SIZE 16 /* maximum NxN size of submatrix */ /*** printMatrix : neatly prints a matrix Parameters : outFile : handle to output file matrix : matrix to be printed numberOfRows : number of rows in the matrix numberOfColumns : number of columns in the matrix padding : width of each printed element Return : integer (not used) ***/ int printMatrix(outFile, matrix, numberOfRows, numberOfColumns,padding) FILE *outFile; int matrix[MAX_MATRIX_SIZE][MAX_MATRIX_SIZE]; int numberOfRows; int numberOfColumns; int padding; { int i,j; /* loop indices for extracting matrix elements */ int temp; /* temporary holding place for matrix element */ int spaces; /* number of spaces to print */ for(i=0;i highestDigitCount) highestDigitCount = currentDigitCount; } } } } /*** Print the final matrix and exit ***/ outFile = fopen(outFileName,"w"); printMatrix(outFile,finishedMatrix, matrixSize,matrixSize,highestDigitCount); close(outFile); terminate(); }