-
Notifications
You must be signed in to change notification settings - Fork 0
/
mat_mul_blas.c
71 lines (61 loc) · 1.67 KB
/
mat_mul_blas.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
67
68
69
70
71
#include <stdio.h> /* I/O lib ISOC */
#include <stdlib.h> /* Standard Lib ISOC */
#include <cblas.h> /* Basic Linear Algebra I/O */
#include <sys/time.h>
#define M 1024
#define N 1024
#ifdef TIME
#define IF_TIME(foo) foo;
#else
#define IF_TIME(foo)
#endif
double rtclock()
{
struct timezone Tzp;
struct timeval Tp;
int stat;
stat = gettimeofday (&Tp, &Tzp);
if (stat != 0) printf("Error return from gettimeofday: %d",stat);
return(Tp.tv_sec + Tp.tv_usec*1.0e-6);
}
void printMatrix(int m, int n, double *a, const char* str)
{
int i,j;
printf("%s\n",str);
for(i =0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%lf ",a[i*n+j]);
printf("\n");
}
}
void init_array(double* A, double* B)
{
int i, j;
printf("inside init array\n");
for (i=0; i<M; i++) {
for (j=0; j<N; j++) {
A[i*N + j] = (i + j);
B[i*N + j] = (double)(i*j);
}
}
}
int main(int argc, char **argv) {
printf("inside main\n");
double *a, *b, *c;
double t_start, t_end;
a = (double *) malloc( M*N*sizeof( double ));
b = (double *) malloc( N*M*sizeof( double ));
c = (double *) malloc( M*M*sizeof( double ));
init_array(a,b);
IF_TIME(t_start = rtclock());
/* row_order transform transform rowsA colsB K alpha a lda b ldb beta c ldc */
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, M, M, N, 1.0, a, N, b, M, 0.0, c, M);
IF_TIME(t_end = rtclock());
IF_TIME(fprintf(stderr, "%0.6lfs\n", t_end - t_start));
printf("Done\n");
free(a);
free(b);
free(c);
return 0;
}