// Main method int main(int argc, char* argv[]) { int N; double elapsedTime; // checking parameters if (argc != 2 && argc != 4) { printf("Parameters: <N> [<fileA> <fileB>]\n"); return 1; } N = atoi(argv[1]); initMatrixes(N); // reading files (optional) if(argc == 4){ readMatrixFile(A,N,argv[2]); readMatrixFile(B,N,argv[3]); } else { // Otherwise, generate two random matrix. for (int i=0; i<N; i++) { for (int j=0; j<N; j++) { A[i][j] = rand() % 5; B[i][j] = rand() % 5; } } } // Do simple multiplication and time it. timerStart(); simpleMM(N); printf("Simple MM took %ld ms\n", timerStop()); // Do strassen multiplication and time it. timerStart(); strassenMM(N); printf("Strassen MM took %ld ms\n", timerStop()); if (compareMatrix(C, R, N) != 0) { if (N < 20) { printf("\n\n------- MATRIX C\n"); printMatrix(C,N); printf("\n------- MATRIX R\n"); printMatrix(R,N); } printf("Matrix C doesn't match Matrix R, if N < 20 they will be printed above.\n"); } // stopping timer cleanup(); return 0; }
int main() { int row, col, i; time_t seed; // for random srand((unsigned) time(&seed)); m1 = (double **) malloc(sizeof (double *) * MAX); for (i = 0; i < MAX; i++) m1[i] = (double *) malloc(sizeof (double) * MAX); m2 = (double **) malloc(sizeof (double *) * MAX); for (i = 0; i < MAX; i++) m2[i] = (double *) malloc(sizeof (double) * MAX); for (row = 0; row < MAX; row++) for (col = 0; col < MAX; col++) m1[row][col] = rand() % LARGEST; for (row = 0; row < MAX; row++) for (col = 0; col < MAX; col++) m2[row][col] = rand() % LARGEST; int exponent = 1; while (pow(2, exponent) < MAX) // compare 2^n to see if it is < than input size, if it is then increment exponent. exponent++; int c; c = pow(2, exponent); //c = 2^n perfectMatrix = 2; if (c >= MAX) perfectMatrix = c; pm1 = (double **) malloc(sizeof (double *) * perfectMatrix); for (i = 0; i < perfectMatrix; i++) pm1[i] = (double *) malloc(sizeof (double) * perfectMatrix); pm2 = (double **) malloc(sizeof (double *) * perfectMatrix); for (i = 0; i < perfectMatrix; i++) pm2[i] = (double *) malloc(sizeof (double) * perfectMatrix); pm3 = (double **) malloc(sizeof (double *) * perfectMatrix); for (i = 0; i < perfectMatrix; i++) pm3[i] = (double *) malloc(sizeof (double) * perfectMatrix); // all trailling zeros for (row = 0; row < perfectMatrix; row++) { for (col = 0; col < perfectMatrix; col++) { pm1[row][col] = 0; pm2[row][col] = 0; pm3[row][col] = 0; } } for (row = 0; row < MAX; row++) { for (col = 0; col < MAX; col++) { pm1[row][col] = m1[row][col]; pm2[row][col] = m2[row][col]; } } initMatrixes(perfectMatrix); printf("Done initiate\n"); time_t start = time(NULL); strassenMM(perfectMatrix); //printf("Matrix Perfect Size = %d\n",perfectMatrix); printf("Calculation Time:%.2f\n", (double)(time(NULL) - start)); //print_perfect_matrices(); return 0; }