Advertisement
mahmoodn

mm-test

Mar 6th, 2022
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <cblas.h>
  5. #include <omp.h>
  6.  
  7. #define N 8192
  8.  
  9. int main()
  10. {
  11.     double *first = (double *)malloc( N*N*sizeof( double ) );
  12.     double *second = (double *)malloc( N*N*sizeof( double ) );
  13.     double *result = (double *)malloc( N*N*sizeof( double ) );
  14.     int i;
  15.     srand(time(NULL));
  16.     double start1, start2, stop1, stop2, execution_time1, execution_time2;
  17.    
  18.     start1 = omp_get_wtime();
  19.     for (i = 0; i < (N*N); i++) {
  20.         first[i] = (double)(rand() % 10);
  21.     }
  22.  
  23.     for (i = 0; i < (N*N); i++) {
  24.         second[i] = (double)(rand() % 10);
  25.     }
  26.  
  27.     for (i = 0; i < (N*N); i++) {
  28.         result[i] = 0.0;
  29.     }
  30.     stop1 = omp_get_wtime();
  31.     printf("read\n");
  32.     start2 = omp_get_wtime();
  33.     cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, N,N,N, 1.0, first, N, second, N, 0.0, result, N);
  34.     stop2 = omp_get_wtime();
  35.    
  36.     /*for (i = 0; i < (N*N); i++) {
  37.         printf("%f ", first[i]);
  38.     }
  39.     printf("\n\n");
  40.     for (i = 0; i < (N*N); i++) {
  41.         printf("%f ", second[i]);
  42.     }
  43.     printf("\n\n");
  44.     for (i = 0; i < (N*N); i++) {
  45.         printf("%f ", result[i]);
  46.     }
  47.     printf("\n");*/
  48.     execution_time1 = stop2 - start1;
  49.     execution_time2 = stop2 - start2;
  50.     printf("Total execution Time in seconds: %.10lf\n", execution_time1 );
  51.     printf("MM execution Time in seconds: %.10lf\n", execution_time2 );
  52.    
  53.     free(first);
  54.     free(second);
  55.     free(result);
  56.     return 0;
  57. }
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement