summarylogtreecommitdiffstats
path: root/r840.patch
blob: eede3cd2b80e65f975a6fa5e87143cdd83f74d03 (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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
Index: setup.py
===================================================================
--- setup.py	(revision 839)
+++ setup.py	(revision 840)
@@ -24,10 +24,17 @@
 import argparse
 import numpy.distutils as nd
 from distutils.version import StrictVersion
+from os import listdir
+from os.path import isfile, join
 
 def str2bool(v):
-  return v.lower() in ("yes", "true", "t", "1")
+    return v.lower() in ("yes", "true", "t", "1")
 
+def remove_prefix(name, prefix):
+    if name.startswith(prefix):
+        return name[len(prefix):]
+    return name
+
 parser = argparse.ArgumentParser(description='Assimulo setup script.')
 parser.register('type','bool',str2bool)
 package_arguments=['plugins','sundials','blas','superlu','lapack']
@@ -36,7 +43,8 @@
     parser.add_argument("--{}-home".format(pg), 
            help="Location of the {} directory".format(pg.upper()),type=str,default='')
 parser.add_argument("--blas-name", help="name of the blas package",default='blas')   
-parser.add_argument("--extra-c-flags", help='Extra C-flags (a list enclosed in " ")',default='')                  
+parser.add_argument("--extra-c-flags", help='Extra C-flags (a list enclosed in " ")',default='')
+parser.add_argument("--with_openmp", type='bool', help="set to true if present",default=False)
 parser.add_argument("--is_static", type='bool', help="set to true if present",default=False)
 parser.add_argument("--sundials-with-superlu", type='bool', help="set to true if Sundials has been compiled with SuperLU",default=False)
 parser.add_argument("--debug", type='bool', help="set to true if present",default=False)
@@ -120,7 +128,6 @@
         self.static = args[0].is_static 
         self.static_link_gcc = ["-static-libgcc"] if self.static else []
         self.static_link_gfortran = ["-static-libgfortran"] if self.static else []
-        self.debug_flag = args[0].debug 
         self.force_32bit = args[0].force_32bit
         self.flag_32bit = ["-m32"] if self.force_32bit else [] 
         self.no_mvscr = args[0].no_msvcr 
@@ -128,7 +135,7 @@
         self.extra_fortran_link_flags = args[0].extra_fortran_link_flags.split()
         self.extra_fortran_link_files = args[0].extra_fortran_link_files.split()
         self.thirdparty_methods  = thirdparty_methods
-        
+        self.with_openmp = args[0].with_openmp
 
         
         if self.no_mvscr:
@@ -270,12 +277,10 @@
         """
         Check if SuperLU package installed
         """
-        self.with_SLU = self.with_BLAS
-        kinsol_msg='KINSOL will not be compiled with support for SuperLU'
+        self.with_SLU = True
+        sundials_msg='SUNDIALS will not be compiled with support for SuperLU'
         
-        if not self.with_BLAS:
-            L.warning(kinsol_msg+' as BLAS is missing.')
-        elif self.SLUdir != "":    
+        if self.SLUdir != "":    
             self.SLUincdir = os.path.join(self.SLUdir,'SRC')
             self.SLUlibdir = os.path.join(self.SLUdir,'lib')
             if not os.path.exists(os.path.join(self.SLUincdir,'supermatrix.h')):
@@ -283,16 +288,18 @@
                 L.warning("Could not find SuperLU, disabling support. View more information using --log=DEBUG")
                 L.debug("Could not find SuperLU at the given path {}.".format(self.SLUdir))
                 L.debug("usage: --superlu-home path")
-                L.debug(kinsol_msg+'.')
+                L.debug(sundials_msg+'.')
             else:
                 L.debug("SuperLU found in {} and {}: ".format(self.SLUincdir, self.SLUlibdir))
+            
+            self.superLUFiles = [remove_prefix(f.split(".")[0],"lib") for f in listdir(self.SLUlibdir) if isfile(join(self.SLUlibdir, f)) and f.endswith(".a")]
+            self.superLUFiles.sort(reverse=True)
         else:
             L.warning("No path to SuperLU supplied, disabling support. View more information using --log=DEBUG")
-            L.debug("No path to SuperLU supplied, KINSOL will not be compiled with support for SUperLU.")
+            L.debug("No path to SuperLU supplied, SUNDIALS will not be compiled with support for SuperLU.")
             L.debug("usage: --superlu-home=path")
             L.debug("Note: the path required is to the folder where the folders 'SRC' and 'lib' are found.")
             self.with_SLU = False
-            L.debug(kinsol_msg+'.')
     
     def check_SUNDIALS(self):
         """
@@ -301,13 +308,22 @@
         if os.path.exists(os.path.join(os.path.join(self.incdirs,'cvodes'), 'cvodes.h')):
             self.with_SUNDIALS=True
             L.debug('SUNDIALS found.')
+            sundials_version = None
             
-            if os.path.exists(os.path.join(os.path.join(self.incdirs,'arkode'), 'arkode.h')): #This was added in 2.6
-                sundials_version = (2,6,0)
-                L.debug('SUNDIALS 2.6 found.')
-            else:
-                sundials_version = (2,5,0)
-                L.debug('SUNDIALS 2.5 found.')
+            try:
+                if os.path.exists(os.path.join(os.path.join(self.incdirs,'sundials'), 'sundials_config.h')):
+                    with open(os.path.join(os.path.join(self.incdirs,'sundials'), 'sundials_config.h')) as f:
+                        for line in f:
+                            if "SUNDIALS_PACKAGE_VERSION" in line:
+                                sundials_version = tuple([int(f) for f in line.split()[-1][1:-1].split(".")])
+                                L.debug('SUNDIALS %d.%d found.'%(sundials_version[0], sundials_version[1]))
+            except Exception:
+                if os.path.exists(os.path.join(os.path.join(self.incdirs,'arkode'), 'arkode.h')): #This was added in 2.6
+                    sundials_version = (2,6,0)
+                    L.debug('SUNDIALS 2.6 found.')
+                else:
+                    sundials_version = (2,5,0)
+                    L.debug('SUNDIALS 2.5 found.')
                 
             self.SUNDIALS_version = sundials_version
             
@@ -367,6 +383,10 @@
             ext_list[-1].include_dirs = [np.get_include(), "assimulo","assimulo"+os.sep+"lib", self.incdirs]
             ext_list[-1].library_dirs = [self.libdirs]
             ext_list[-1].libraries = ["sundials_cvodes", "sundials_nvecserial", "sundials_idas"]
+            if self.with_SLU: #If SUNDIALS is compiled with support for SuperLU
+                ext_list[-1].include_dirs.append(self.SLUincdir)
+                ext_list[-1].library_dirs.append(self.SLUlibdir)
+                ext_list[-1].libraries.extend(self.superLUFiles)
         
             #Kinsol
             ext_list += cythonize(["assimulo"+os.path.sep+"solvers"+os.path.sep+"kinsol.pyx"], 
@@ -386,6 +406,9 @@
                 el.extra_compile_args = ["-O2", "-fno-strict-aliasing"]
             if self.platform == "mac":
                 el.extra_compile_args += ["-Wno-error=return-type"]
+            if self.with_openmp:
+                el.extra_link_args.append("-fopenmp")
+                el.extra_compile_args.append("-fopenmp")
             el.extra_compile_args += self.flag_32bit + self.extra_c_flags
 
         for el in ext_list:
Index: src/lib/sundials_callbacks.pxi
===================================================================
--- assimulo/lib/sundials_callbacks.pxi	(revision 839)
+++ assimulo/lib/sundials_callbacks.pxi	(revision 840)
@@ -110,9 +110,14 @@
     cdef int ret_nnz
     cdef int dim = Jacobian.N
     cdef realtype* data = Jacobian.data
-    cdef int* rowvals = Jacobian.rowvals
-    cdef int* colptrs = Jacobian.colptrs
     
+    IF SUNDIALS_VERSION >= (2,6,3):
+        cdef int* rowvals = Jacobian.rowvals[0]
+        cdef int* colptrs = Jacobian.colptrs[0]
+    ELSE:
+        cdef int* rowvals = Jacobian.rowvals
+        cdef int* colptrs = Jacobian.colptrs
+    
     nv2arr_inplace(yv, y)
     """
         realtype *data;
@@ -136,9 +141,9 @@
             jac = sparse.csc.csc_matrix(jac)
             raise AssimuloException("The Jacobian must be stored on Scipy's CSC format.")
         ret_nnz = jac.nnz
-        if ret_nnz> nnz:
+        if ret_nnz > nnz:
             raise AssimuloException("The Jacobian has more entries than supplied to the problem class via 'jac_nnz'")    
-            
+
         for i in range(min(ret_nnz,nnz)):
             data[i]    = jac.data[i]
             rowvals[i] = jac.indices[i]
Index: src/lib/sundials_includes.pxd
===================================================================
--- assimulo/lib/sundials_includes.pxd	(revision 839)
+++ assimulo/lib/sundials_includes.pxd	(revision 840)
@@ -93,13 +93,29 @@
     ctypedef _DlsMat* DlsMat
     cdef realtype* DENSE_COL(DlsMat A, int j)
 
-IF SUNDIALS_VERSION >= (2,6,0):
+IF SUNDIALS_VERSION >= (2,6,3):
     cdef extern from "sundials/sundials_sparse.h":
         cdef struct _SlsMat:
             int M
             int N
             int NNZ
+            int NP
             realtype *data
+            int sparsetype
+            int *indexvals
+            int *indexptrs
+            int **rowvals
+            int **colptrs
+            int **colvals
+            int **rowptrs
+        ctypedef _SlsMat* SlsMat
+ELIF SUNDIALS_VERSION >= (2,6,0):
+    cdef extern from "sundials/sundials_sparse.h":
+        cdef struct _SlsMat:
+            int M
+            int N
+            int NNZ
+            realtype *data
             int *rowvals
             int *colptrs
         ctypedef _SlsMat* SlsMat