From 5c47f32a5c47a089ccb77e4ebda6c51c48ee1b4d Mon Sep 17 00:00:00 2001
From: "L. Riha" <lubomir.riha@vsb.cz>
Date: Thu, 4 Apr 2019 10:43:46 +0200
Subject: [PATCH] update2

---
 CSparse/Demo/Makefile.orig            | 39 +++++++++++++++
 CSparse/Source/cs_lsolve.xxx_cubackup | 34 +++++++++++++
 CSparse/Source/cs_lsolve_gpu.cu       | 72 +++++++++++++++++++++++++++
 3 files changed, 145 insertions(+)
 create mode 100644 CSparse/Demo/Makefile.orig
 create mode 100644 CSparse/Source/cs_lsolve.xxx_cubackup
 create mode 100644 CSparse/Source/cs_lsolve_gpu.cu

diff --git a/CSparse/Demo/Makefile.orig b/CSparse/Demo/Makefile.orig
new file mode 100644
index 0000000..6fda174
--- /dev/null
+++ b/CSparse/Demo/Makefile.orig
@@ -0,0 +1,39 @@
+CF = $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -O 
+I = -I../Include
+CC = /usr/local/cuda/bin/nvcc -g
+
+LDLIBS += -lm
+CS = $(LDFLAGS) ../Lib/libcsparse.a $(LDLIBS)
+
+all: lib cs_demo1 cs_demo2 cs_demo3
+	- ./cs_demo1 < ../Matrix/t1
+	- ./cs_demo2 < ../Matrix/t1
+	- ./cs_demo2 < ../Matrix/ash219
+	- ./cs_demo2 < ../Matrix/bcsstk01
+	- ./cs_demo2 < ../Matrix/fs_183_1
+	- ./cs_demo2 < ../Matrix/mbeacxc
+	- ./cs_demo2 < ../Matrix/west0067
+	- ./cs_demo2 < ../Matrix/lp_afiro
+	- ./cs_demo2 < ../Matrix/bcsstk16
+	- ./cs_demo3 < ../Matrix/bcsstk01
+	- ./cs_demo3 < ../Matrix/bcsstk16
+
+lib:
+	( cd ../Lib ; $(MAKE) )
+
+cs_demo1: lib cs_demo1.c Makefile
+	$(CC) $(CF) $(I) -o cs_demo1 cs_demo1.c $(CS)
+
+cs_demo2: lib cs_demo2.c cs_demo.c cs_demo.h Makefile
+	$(CC) $(CF) $(I) -o cs_demo2 cs_demo2.c cs_demo.c $(CS)
+
+cs_demo3: lib cs_demo3.c cs_demo.c cs_demo.h Makefile
+	$(CC) $(CF) $(I) -o cs_demo3 cs_demo3.c cs_demo.c $(CS)
+
+clean:
+	- $(RM) *.o
+
+purge: distclean
+
+distclean: clean
+	- $(RM) -r cs_demo1 cs_demo2 cs_demo3 *.a *.dSYM *.obj *.dll
diff --git a/CSparse/Source/cs_lsolve.xxx_cubackup b/CSparse/Source/cs_lsolve.xxx_cubackup
new file mode 100644
index 0000000..e4fea88
--- /dev/null
+++ b/CSparse/Source/cs_lsolve.xxx_cubackup
@@ -0,0 +1,34 @@
+#include "cs.h"
+///* solve Lx=b where x and b are dense.  x=b on input, solution on output. */
+
+
+
+
+//__global__
+//void cs_lsolve_gpu (int n, const int *Lp, const int *Li, const double *Lx, double *x)
+//{
+//   int p, j;
+//    
+//    // double *Lx ;
+//    // n = L->n ; 
+//    // Lp = L->p ; 
+//    // Li = L->i ; 
+//    // Lx = L->x ;
+//      
+//    for (j = 0 ; j < n ; j++)
+//    {
+//        x [j] /= Lx [Lp [j]] ;
+//        for (p = Lp [j]+1 ; p < Lp [j+1] ; p++)
+//        {
+//            x [Li [p]] -= Lx [p] * x [j] ;
+//        }
+//    }
+//    
+//    //return (1);
+//}
+
+
+
+
+
+
diff --git a/CSparse/Source/cs_lsolve_gpu.cu b/CSparse/Source/cs_lsolve_gpu.cu
new file mode 100644
index 0000000..c21ff84
--- /dev/null
+++ b/CSparse/Source/cs_lsolve_gpu.cu
@@ -0,0 +1,72 @@
+#include "cs.h"
+///* solve Lx=b where x and b are dense.  x=b on input, solution on output. */
+///*
+//csi cs_lsolve (const cs *L, double *x)
+//{
+//   csi p, j, n, *Lp, *Li ;
+//    double *Lx ;
+//    if (!CS_CSC (L) || !x) return (0) ;                     /* check inputs */
+//    n = L->n ; Lp = L->p ; Li = L->i ; Lx = L->x ;
+//    for (j = 0 ; j < n ; j++)
+//    {
+//        x [j] /= Lx [Lp [j]] ;
+//        for (p = Lp [j]+1 ; p < Lp [j+1] ; p++)
+//        {
+//            x [Li [p]] -= Lx [p] * x [j] ;
+//        }
+//    }
+//    return (1) ;
+//}
+//*/
+
+/* solve Lx=b where x and b are dense.  x=b on input, solution on output. */
+
+//csi cs_lsolve_gpu (const cs *L, double *x)
+// typedef struct cs_sparse    /* matrix in compressed-column or triplet form */
+// {
+//     csi nzmax ;     /* maximum number of entries */
+//     csi m ;         /* number of rows */
+//     csi n ;         /* number of columns */
+//     csi *p ;        /* column pointers (size n+1) or col indices (size nzmax) */
+//     csi *i ;        /* row indices, size nzmax */
+//     double *x ;     /* numerical values, size nzmax */
+//     csi nz ;        /* # of entries in triplet matrix, -1 for compressed-col */
+// } cs ;
+
+
+
+
+
+__global__
+void cs_lsolve_gpu (int n, const int *Lp, const int *Li, const double *Lx, double *x)
+{
+    int p, j;
+    
+    // double *Lx ;
+    // n = L->n ; 
+    // Lp = L->p ; 
+    // Li = L->i ; 
+    // Lx = L->x ;
+      
+    for (j = 0 ; j < n ; j++)
+    {
+        x [j] /= Lx [Lp [j]] ;
+        for (p = Lp [j]+1 ; p < Lp [j+1] ; p++)
+        {
+            x [Li [p]] -= Lx [p] * x [j] ;
+            printf("GPU: %f", x [Li [p]]);
+        }
+    }
+    
+    //return (1);
+}
+
+
+
+
+extern "C" {
+    void cs_lsolve_acc (int n, const int *Lp, const int *Li, const double *Lx, double *x)
+    {
+      cs_lsolve_gpu <<<1, 1>>> (n, Lp, Li, Lx, x);
+    }
+}
-- 
GitLab