int main(int argc, char* argv[])
{	
  double before, after;

  int M = atoi(argv[1]);
  int N = atoi(argv[2]);
  int P = atoi(argv[3]);

  int **A = Allocate2DArray< int >(M, P);
  int **B = Allocate2DArray< int >(P, N);
  int **C = Allocate2DArray< int >(M, N);
  int **C4 = Allocate2DArray< int >(M, N);

  int i, j;

  for (i = 0; i < M; i++) {
	for (j = 0; j < P; j++) {   
		A[i][j] = ((int)(rand()%100) /10);  
	 } 
  } 

  for (i = 0; i < P; i++) {	
	 for (j = 0; j < N; j++) {
	B[i][j] = ((int)(rand()%100) / 10.0);   
	 } 
  } 

  printf("Execute Standard matmult\n\n");
  before = omp_get_wtime();
  seqMatMult(M, N, P, A, B, C);
  after = omp_get_wtime();
  printf("Standard matrix function done in %10f secs\n\n\n",(after - before));
  
  //printf("The number of cores is %d\n",omp_get_num_procs());
  omp_set_num_threads(8);
  GRAIN = (long)(M*N*2);
  before = omp_get_wtime();
  matmultS(M, N, P, A, B, C4);
  after = omp_get_wtime();
  printf("Strassen matrix function done in %10f secs\n\n\n",(after - before));

  if (CheckResults(M, N, C, C4)) 
	 printf("Error in matmultS\n\n");
  else
	 printf("OKAY\n\n");

  Free2DArray(A);
  Free2DArray(B);
  Free2DArray(C);
  Free2DArray(C4);

  return 0;
}
예제 #2
0
int main(int argc, char* argv[])   
{      
  double before, time1, time2;
  int M = MM;
  int N = NN;
  int P = PP;
 
  if (argc != 4) {
          printf("Suggested Usage: %s <M> <N> <P> \n", argv[0]);
     printf("Using default values\n");
  }
  else {
     M = atoi(argv[1]);
     N = atoi(argv[2]);
     P = atoi(argv[3]);
  }

  double **A = Allocate2DArray< double >(M, P);
  double **B = Allocate2DArray< double >(P, N);
  double **C = Allocate2DArray< double >(M, N);
  double **C4 = Allocate2DArray< double >(M, N);

  int i, j;   

  for (i = 0; i < M; ++i) {   
    for (j = 0; j < P; ++j) {   
      A[i][j] = 5.0 - ((double)(rand()%100) / 10.0);  
    }      
  }   

  for (i = 0; i < P; ++i) {   
    for (j = 0; j < N; ++j) {   
      B[i][j] = 5.0 - ((double)(rand()%100) / 10.0);   
    }      
  }   

  for (i = 0; i < M; ++i) {   
    for (j = 0; j < N; ++j) {   
      C[i][j] = 0.0;
      C4[i][j] = 0.0;
    }      
  }   

  printf("Execute Standard matmult  M = %d  N = %d  P = %d\n\n", M, N, P);
  before = omp_get_wtime();
  seqMatMult(M, N, P, A, B, C);
  time1 = omp_get_wtime() - before;
  printf("Standard matrix function done in %7.2f secs\n\n\n",(float)time1);

  before = omp_get_wtime();
  matmultS(M, N, P, A, B, C4);
  time2 = omp_get_wtime() - before;
  printf("Strassen matrix function done in %7.2f secs\n\n\n",time2);

   printf("Checking...");
   if (CheckResults(M, N, C, C4))
     printf("Error in Strassen Matrix Multiplication\n\n");
   else {
     printf("OKAY\n\n");
     printf("Speedup = %5.1fX\n", time1/time2);
   }

  Free2DArray< double >(A);
  Free2DArray< double >(B);
  Free2DArray< double >(C);
  Free2DArray< double >(C4);

  return 0;   
}