Advertisement
mahmoodn

mm_cblas

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