7
7
import sys
8
8
import mpi4py
9
9
from mpi4py import MPI
10
-
11
-
12
-
13
- def setup_pdbridge (sp ,INT64 ):
14
- # Define the function signature for pdbridge_init
15
- sp .pdbridge_init .restype = None
16
- if (INT64 == 0 ):
17
- sp .pdbridge_init .argtypes = [
18
- ctypes .c_int , # int_t m
19
- ctypes .c_int , # int_t n
20
- ctypes .c_int , # int_t nnz
21
- ctypes .POINTER (ctypes .c_int ), # int_t *rowind
22
- ctypes .POINTER (ctypes .c_int ), # int_t *colptr
23
- ctypes .POINTER (ctypes .c_double ), # double *nzval
24
- ctypes .POINTER (ctypes .c_void_p ), # void **pyobj
25
- ctypes .c_int , # int argc
26
- ctypes .POINTER (ctypes .c_char_p ) # char *argv[]
27
- ]
28
- else :
29
- sp .pdbridge_init .argtypes = [
30
- ctypes .c_int64 , # int_t m
31
- ctypes .c_int64 , # int_t n
32
- ctypes .c_int64 , # int_t nnz
33
- ctypes .POINTER (ctypes .c_int64 ), # int_t *rowind
34
- ctypes .POINTER (ctypes .c_int64 ), # int_t *colptr
35
- ctypes .POINTER (ctypes .c_double ), # double *nzval
36
- ctypes .POINTER (ctypes .c_void_p ), # void **pyobj
37
- ctypes .c_int , # int argc
38
- ctypes .POINTER (ctypes .c_char_p ) # char *argv[]
39
- ]
40
-
41
-
42
- sp .pdbridge_factor .restype = None
43
- sp .pdbridge_factor .argtypes = [
44
- ctypes .POINTER (ctypes .c_void_p ), # void **pyobj
45
- ]
46
-
47
- sp .pdbridge_solve .restype = None
48
- sp .pdbridge_solve .argtypes = [
49
- ctypes .POINTER (ctypes .c_void_p ), # void **pyobj
50
- ctypes .c_int , # int nrhs
51
- ctypes .POINTER (ctypes .c_double ), # double *b_global
52
- ]
53
- # Define the function signature for pdbridge_logdet
54
- sp .pdbridge_logdet .restype = None
55
- sp .pdbridge_logdet .argtypes = [
56
- ctypes .POINTER (ctypes .c_void_p ), # void **pyobj
57
- ctypes .POINTER (ctypes .c_int ), # int* sign
58
- ctypes .POINTER (ctypes .c_double ), # double *logdet
59
- ]
60
- # Define the function signature for pdbridge_free
61
- sp .pdbridge_free .restype = None
62
- sp .pdbridge_free .argtypes = [
63
- ctypes .POINTER (ctypes .c_void_p ), # void **pyobj
64
- ]
65
-
10
+ import pdbridge
66
11
67
12
68
13
comm = MPI .COMM_WORLD
@@ -74,6 +19,8 @@ def setup_pdbridge(sp,INT64):
74
19
print ('MPI count:' , size )
75
20
76
21
22
+ ####################################################################################################
23
+ ####################################################################################################
77
24
####################### create the matrix
78
25
INT64 = 1 # whether to use 64bit integer (requring superlu_dist to be compiled with 64-bit indexing)
79
26
rng = np .random .default_rng ()
@@ -101,6 +48,11 @@ def setup_pdbridge(sp,INT64):
101
48
nnz = np .int64 (m .nnz )
102
49
n = np .int64 (n )
103
50
51
+
52
+
53
+
54
+ ####################################################################################################
55
+ ####################################################################################################
104
56
####################### handle options
105
57
argv = sys .argv
106
58
if (len (argv )== 1 ): # options are not passed via command line, set them manually here. If they are not set here, default values are used
@@ -121,32 +73,11 @@ def setup_pdbridge(sp,INT64):
121
73
122
74
123
75
124
- ####################### load DLL
125
- import sys
126
- from sys import platform
127
- if platform == "linux" or platform == "linux2" :
128
- pos = '.so'
129
- elif platform == "darwin" :
130
- pos = '.dylib'
131
- elif platform == "win32" :
132
- raise Exception (f"Windows is not yet supported" )
133
-
134
- DLLFOUND = False
135
- INSTALLDIR = os .getenv ('SUPERLU_PYTHON_LIB_PATH' )
136
-
137
- DLL = os .path .abspath (__file__ + "/../../" )+ '/libsuperlu_dist_python%s' % (pos )
138
- if (os .path .exists (DLL )):
139
- DLLFOUND = True
140
- elif (INSTALLDIR is not None ):
141
- DLL = INSTALLDIR + '/libsuperlu_dist_python%s' % (pos )
142
- if (os .path .exists (DLL )):
143
- DLLFOUND = True
144
- if (DLLFOUND == True ):
145
- sp = ctypes .cdll .LoadLibrary (DLL )
146
- setup_pdbridge (sp ,INT64 )
147
- else :
148
- raise Exception (f"Cannot find the superlu_dist_python library. Try to set env variable SUPERLU_PYTHON_LIB_PATH correctly." )
149
76
77
+ ####################################################################################################
78
+ ####################################################################################################
79
+ ####################### call the APIs
80
+ sp = pdbridge .load_library (INT64 )
150
81
####################### initialization
151
82
pyobj = ctypes .c_void_p ()
152
83
if (INT64 == 0 ):
0 commit comments