blob: f5392c87289e2003e3dde7a9db504fce13030ea5 (
plain)
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
|
#include <u.h>
#include <libn.h>
#include <libmath.h>
#include <libmath/blas.h>
#include <time.h>
#include <vendor/blas/cblas.h>
#define LEN 2000000
#define NIT 2000
#define INC 2
error
main()
{
int i, nit;
double *x, *y, res[2];
clock_t t;
double tprof[2] = { 0 };
rng·init(0);
x = malloc(sizeof(*x)*LEN);
y = malloc(sizeof(*x)*LEN);
#define DO_0 t = clock(); \
res[0] += blas·sumd(LEN/INC, x, INC); \
t = clock() - t; \
tprof[0] += 1000.*t/CLOCKS_PER_SEC; \
#define DO_1 t = clock(); \
res[1] += cblas_dsum(LEN/INC, x, INC); \
t = clock() - t; \
tprof[1] += 1000.*t/CLOCKS_PER_SEC;
for (nit = 0; nit < NIT; nit++) {
for (i = 0; i < LEN; i++) {
x[i] = rng·random();
y[i] = rng·random();
}
switch (nit % 2) {
case 0: DO_0; DO_1; break;
case 1: DO_1; DO_0; break;
}
}
printf("mean time/iteration (mine): %fms\n", tprof[0]/NIT);
printf("--> result (mine): %f\n", res[0]);
printf("mean time/iteration (openblas): %fms\n", tprof[1]/NIT);
printf("--> result (openblas): %f\n", res[1]);
return 0;
}
|