aboutsummaryrefslogtreecommitdiff
path: root/rcc-legacy/tests/performance/04_spmv3.sy
blob: 2fddb8fe29eca24a94febb3ced371ae2add0188d (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
void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){
    int i, j, k;
    i = 0;
    while (i < n){
        x[i] = 0;
        i = i + 1;
    }

    i = 0;
    while (i < n){
        j = xptr[i];
        while (j < xptr[i + 1]){
            x[yidx[j]] = x[yidx[j]] + vals[j];
            j = j + 1;
        }

        j = xptr[i];
        while (j < xptr[i + 1]){
            x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1);
            j = j + 1;
        }
        i = i + 1;
    }
}

const int N = 100010;
const int M = 3000000;

int x[N], y[M], v[M];
int a[N], b[N], c[N];

int main(){
    int n = getarray(x) - 1;
    int m = getarray(y);
    getarray(v);

    getarray(a);

    starttime();

    int i = 0;
    while (i < 100){
        spmv(n, x, y, v, a, b);
        spmv(n, x, y, v, b, a);
        i=i+1;
    }
    stoptime();
    putarray(n, b);
    return 0;
}