-
Notifications
You must be signed in to change notification settings - Fork 0
/
mult.c
79 lines (61 loc) · 1.84 KB
/
mult.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
72
73
74
75
76
77
78
79
/* mult.c
Measure matrix multiplication speed.
This code is experimental, and error-handling is primitive.
*/
/* Copyright 2013, NICTA. See COPYRIGHT for license details. */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "sparse.h"
#define REPS 10
int
main(int argc, char *argv[]) {
FILE *in;
csc_mat_t *M;
csc_errno_t e;
dv_t *x, *y;
struct timespec start, end;
double iv;
int i;
if(argc < 2) {
fprintf(stderr, "Usage: %s <matrix_filename>\n", argv[0]);
exit(EXIT_FAILURE);
}
in= fopen(argv[1], "rb");
if(!in) { perror("fopen"); exit(EXIT_FAILURE); }
M= csc_load_binary(in, &e);
if(!M) { csc_perror(e, "csc_load_binary"); exit(EXIT_FAILURE); }
fclose(in);
x= dv_new(M->nrow);
if(!x) { perror("dv_new"); exit(EXIT_FAILURE); }
y= dv_new(M->ncol);
if(!y) { perror("dv_new"); exit(EXIT_FAILURE); }
if(!csc_check(M, 1)) abort();
csc_stats(M);
dv_uniform(x, 1.0);
if(STRIDE_OF(M) > 1) {
if(M->flags & CSC_F_CFREE) {
clock_gettime(CLOCK_REALTIME, &start);
for(i= 0; i < REPS; i++) csc_mult_cf(y, x, M);
clock_gettime(CLOCK_REALTIME, &end);
}
else {
clock_gettime(CLOCK_REALTIME, &start);
for(i= 0; i < REPS; i++) csc_str_mult_nv(y, x, M);
clock_gettime(CLOCK_REALTIME, &end);
}
}
else {
clock_gettime(CLOCK_REALTIME, &start);
for(i= 0; i < REPS; i++) mult_csc_dv(y, x, M);
clock_gettime(CLOCK_REALTIME, &end);
}
iv= end.tv_sec + end.tv_nsec*1e-9
- start.tv_sec - start.tv_nsec*1e-9;
printf("%d reps %lld entries %.2esec %.2fGFLOPs\n", REPS,
(long long int)M->nnz, iv, (REPS * 2 * M->nnz) / iv / 1e9);
dv_destroy(y);
dv_destroy(x);
csc_mat_destroy(M);
return 0;
}