/** * Matrix Multiply API * **/ #ifndef MATRIX_MULTIPLY_H_INCLUDED #define MATRIX_MULTIPLY_H_INCLUDED #include #include #include #include #include #include #include #include #include #include #include #include #define min(x,y) ((x)<(y)? (x) : (y)) #define max(x,y) ((x)>(y)? (x) : (y)) /** * A matrix_t stores a matrix with all its elements * in a single one-dimensional vector in memory, in * column major order, that is, with all the elements * in a column lined up next to each other in order. * * "colstride" is the distance in memory from the * beginning of one column to the beginning of the next. * Ordinarily this is equal to the number of rows; * colstride will be used when we start breaking matrices * up into blocks. The BLAS library calls this "lda". * * The macro "element(X,i,j)" expands to a pointer to * the element X(i,j) in storage. * * Rows and columns of a matrix_t are indexed starting at 0. * A matrix_t doesn't have to be square. */ typedef struct { int rows; // number of rows int cols; // number of columns int colstride; // distance between column starts double *values; // elements in column major order } matrix_t; #define element(X,i,j) ((X)->values[(i) + (j)*(X)->colstride]) int matrix_multiply_run_1(matrix_t *A, matrix_t *B, matrix_t *C); int matrix_multiply_run_2(matrix_t *A, matrix_t *B, matrix_t *C); int matrix_multiply_run_3(matrix_t *A, matrix_t *B, matrix_t *C); int matrix_multiply_run_4(matrix_t *A, matrix_t *B, matrix_t *C, int nblocks, int minblock); int matrix_multiply_run_5(matrix_t *A, matrix_t *B, matrix_t *C); matrix_t * make_matrix(int rows, int cols); int make_submatrix(matrix_t *new_matrix, matrix_t *A, int start_row, int start_col, int rows, int cols); void free_matrix(matrix_t *m); void print_matrix(matrix_t *m); int check_answer(matrix_t *A, matrix_t *B, matrix_t *C); double elapsed_seconds(); #endif