aboutsummaryrefslogtreecommitdiff
path: root/tests/performance/04_spmv3.sy
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
committerRichard Qin <richard.qin.001@gmail.com>2026-09-15 08:16:43 +0800
commit4022e5c95210631e4aceb08eaf9d9071aa5aefc4 (patch)
treea5922559836e45fb3459a3d070367912e1035b1a /tests/performance/04_spmv3.sy
downloadrcc-4022e5c95210631e4aceb08eaf9d9071aa5aefc4.tar.gz
rcc-4022e5c95210631e4aceb08eaf9d9071aa5aefc4.tar.xz
Set up a git repoHEADmaster
Diffstat (limited to 'tests/performance/04_spmv3.sy')
-rw-r--r--tests/performance/04_spmv3.sy50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/performance/04_spmv3.sy b/tests/performance/04_spmv3.sy
new file mode 100644
index 0000000..2fddb8f
--- /dev/null
+++ b/tests/performance/04_spmv3.sy
@@ -0,0 +1,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;
+}