int main(int argc, char ** argv) { double ** A, ** B, ** C; double ** control_matrix; long long mul_time; int a_dim1, a_dim2, b_dim1, b_dim2; struct timeval start_time; struct timeval stop_time; if ( argc != 5 ) { fprintf(stderr, "Usage: matmul-harness <A nrows> <A ncols> <B nrows> <B ncols>\n"); exit(1); } else { a_dim1 = atoi(argv[1]); a_dim2 = atoi(argv[2]); b_dim1 = atoi(argv[3]); b_dim2 = atoi(argv[4]); } /* check the matrix sizes are compatible */ if ( a_dim2 != b_dim1 ) { fprintf(stderr, "FATAL number of columns of A (%d) does not match number of rows of B (%d)\n", a_dim2, b_dim1); exit(1); } /* allocate the matrices */ A = gen_random_matrix(a_dim1, a_dim2); B = gen_random_matrix(b_dim1, b_dim2); C = new_empty_matrix(a_dim1, b_dim2); control_matrix = new_empty_matrix(a_dim1, b_dim2); DEBUGGING(write_out(A, a_dim1, a_dim2)); /* use a simple matmul routine to produce control result */ matmul(A, B, control_matrix, a_dim1, a_dim2, b_dim2); /* record starting time */ gettimeofday(&start_time, NULL); /* perform matrix multiplication */ team_matmul(A, B, C, a_dim1, a_dim2, b_dim2); /* record finishing time */ gettimeofday(&stop_time, NULL); mul_time = (stop_time.tv_sec - start_time.tv_sec) * 1000000L + (stop_time.tv_usec - start_time.tv_usec); printf("Matmul time: %lld microseconds\n", mul_time); DEBUGGING(write_out(C, a_dim1, b_dim2)); /* now check that the team's matmul routine gives the same answer as the known working version */ check_result(C, control_matrix, a_dim1, b_dim2); return 0; }
int main(int argc, char ** argv) { struct complex ** A, ** B, ** C; struct complex ** control_matrix; long long control_time, mul_time; double speedup; int a_dim1, a_dim2, b_dim1, b_dim2, errs; struct timeval pre_time, start_time, stop_time; if ( argc != 5 ) { fprintf(stderr, "Usage: matmul-harness <A nrows> <A ncols> <B nrows> <B ncols>\n"); exit(1); } else { a_dim1 = atoi(argv[1]); a_dim2 = atoi(argv[2]); b_dim1 = atoi(argv[3]); b_dim2 = atoi(argv[4]); } /* check the matrix sizes are compatible */ if ( a_dim2 != b_dim1 ) { fprintf(stderr, "FATAL number of columns of A (%d) does not match number of rows of B (%d)\n", a_dim2, b_dim1); exit(1); } /* allocate the matrices */ A = gen_random_matrix(a_dim1, a_dim2); B = gen_random_matrix(b_dim1, b_dim2); C = new_empty_matrix(a_dim1, b_dim2); control_matrix = new_empty_matrix(a_dim1, b_dim2); DEBUGGING( { printf("matrix A:\n"); write_out(A, a_dim1, a_dim2); printf("\nmatrix B:\n"); write_out(A, a_dim1, a_dim2); printf("\n"); } )