-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenblas_dgemm.c
66 lines (56 loc) · 1.68 KB
/
openblas_dgemm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "stdio.h"
#include "stdlib.h"
#include "sys/time.h"
#include "time.h"
#include <cblas.h>
void run(const int N, const double* A, const double* B,
double* C, double* duration, double* gflops)
{
const int nbTests = 10;
const double iNbTests = 1./nbTests;
struct timeval start, finish;
for (int test = 0; test < nbTests; test++) {
srand((unsigned)time(NULL));
printf ("%d run via CBLAS interface ...", test);
gettimeofday(&start, NULL);
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
N, N, N, 1.0, A, N, B, N, 1.0, C, N);
gettimeofday(&finish, NULL);
printf ("done.\n");
double test_duration = ((double)(finish.tv_sec-start.tv_sec)*1000000 +
(double)(finish.tv_usec-start.tv_usec)) / 1000000;
double test_gflops = 2. * N * N * N;
test_gflops = test_gflops/test_duration*1.0e-9;
printf("%d: \t %lfs \t %lfgflops\n\n", test, test_duration, test_gflops);
*duration += iNbTests*test_duration;
*gflops += iNbTests*test_gflops;
}
}
int main(int argc, char** argv) {
if (argc != 2) {
printf("error");
return 1;
}
int N = atoi(argv[1]);
int N2 = N*N;
//Memory allocation for the arrays:
double *A,*B,*C;
A = (double *)malloc( N2*sizeof( double ) );
B = (double *)malloc( N2*sizeof( double ) );
C = (double *)malloc( N2*sizeof( double ) );
for (int i = 0; i < N2; i++) {
A[i] = (double)(i+1);
B[i] = (double)(-i-1);
C[i] = 0.0;
}
double duration, gflops;
run(N, A, B, C, &duration, &gflops);
FILE *fp;
fp = fopen("timeDGEMM.txt", "a");
fprintf(fp, "%d \t %lfs \t %lfgflops\n", N, duration, gflops);
fclose(fp);
free(A);
free(B);
free(C);
return 0;
}