forked from sysprog21/rv32emu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SparseCompRow.c
37 lines (36 loc) · 1.32 KB
/
SparseCompRow.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
/* multiple iterations used to make kernel have roughly same granulairty as
* other Scimark kernels.
*/
double SparseCompRow_num_flops(int N, int nz, int num_iterations)
{
/* Note that if nz does not divide N evenly, then the actual number of
* nonzeros used is adjusted slightly.
*/
int actual_nz = (nz / N) * N;
return ((double) actual_nz) * 2.0 * ((double) num_iterations);
}
/* computes a matrix-vector multiply with a sparse matrix held in compress-row
* format. If the size of the matrix in MxN with nz nonzeros, then the val[]
* is the nz nonzeros, with its ith entry in column col[i]. The integer vector
* row[] is of size M+1 and row[i] points to the begining of the ith row in
* col[].
*/
void SparseCompRow_matmult(int M,
double *y,
const double *val,
const int *row,
const int *col,
const double *x,
int NUM_ITERATIONS)
{
for (int reps = 0; reps < NUM_ITERATIONS; reps++) {
for (int r = 0; r < M; r++) {
double sum = 0.0;
int rowR = row[r];
int rowRp1 = row[r + 1];
for (int i = rowR; i < rowRp1; i++)
sum += x[col[i]] * val[i];
y[r] = sum;
}
}
}