Skip to content

Commit 6ec6acd

Browse files
committed
create a seperate directory for the python interfaces
1 parent 1be9cbe commit 6ec6acd

11 files changed

+127
-30
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ option(enable_complex16 "Enable complex16 precision library" ON)
2525
option(enable_tests "Build tests" ON)
2626
option(enable_examples "Build examples" ON)
2727
option(XSDK_ENABLE_Fortran "Enable Fortran" ON)
28+
option(enable_python "Enable Python" ON)
2829

2930
#-- BLAS
3031
option(TPL_ENABLE_INTERNAL_BLASLIB "Build the CBLAS library" ${enable_blaslib_DEFAULT})
@@ -619,6 +620,14 @@ if (XSDK_ENABLE_Fortran)
619620
add_subdirectory(FORTRAN)
620621
endif()
621622

623+
if (enable_python)
624+
if (BUILD_SHARED_LIBS)
625+
add_subdirectory(PYTHON)
626+
else()
627+
message("-- Not building Python interface, which requires shared build.")
628+
endif()
629+
endif()
630+
622631
# superlu_dist uses c++11. PUBLIC means that the other codes linking to it need c++11
623632
#target_compile_features(SuperLU_DIST PUBLIC cxx_std_11)
624633

EXAMPLE/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ if(enable_double)
118118
target_link_libraries(pddrive_spawn ${all_link_libs})
119119
install(TARGETS pddrive_spawn RUNTIME DESTINATION "${INSTALL_LIB_DIR}/EXAMPLE")
120120

121-
install(FILES pddrive.py DESTINATION "${INSTALL_LIB_DIR}/EXAMPLE")
122-
123121
endif() #### end enable_double
124122

125123
if(enable_single)

PYTHON/CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# include the paths for header files
2+
include_directories(${SuperLU_DIST_SOURCE_DIR}/SRC)
3+
include_directories(${SuperLU_DIST_BINARY_DIR}/PYTHON)
4+
5+
set(sources
6+
pdbridge.h
7+
pdbridge.c
8+
)
9+
10+
# if(enable_complex16)
11+
# list(APPEND sources pzbridge.h pzbridge.c)
12+
# endif()
13+
14+
add_library(superlu_dist_python ${sources})
15+
get_target_property(superlu_dist_version superlu_dist VERSION)
16+
get_target_property(superlu_dist_soversion superlu_dist SOVERSION)
17+
set_target_properties(superlu_dist_python PROPERTIES VERSION ${superlu_dist_version})
18+
set_target_properties(superlu_dist_python PROPERTIES SOVERSION ${superlu_dist_soversion})
19+
target_link_libraries(superlu_dist_python superlu_dist)
20+
add_dependencies(superlu_dist_python config_f)
21+
22+
set(PY_SCRIPT_SOURCE ${CMAKE_SOURCE_DIR}/PYTHON/pddrive.py)
23+
set(PY_SCRIPT_DEST ${CMAKE_BINARY_DIR}/PYTHON/pddrive.py)
24+
# Create a custom command to copy the Python script
25+
add_custom_command(
26+
OUTPUT ${PY_SCRIPT_DEST}
27+
COMMAND ${CMAKE_COMMAND} -E copy ${PY_SCRIPT_SOURCE} ${PY_SCRIPT_DEST}
28+
DEPENDS ${PY_SCRIPT_SOURCE}
29+
COMMENT "Copying pddrive.py to ${CMAKE_BINARY_DIR}/PYTHON"
30+
)
31+
32+
# Create a custom target named 'python' that depends on the output file
33+
add_custom_target(python
34+
DEPENDS ${PY_SCRIPT_DEST}
35+
)
36+
37+
add_dependencies(python superlu_dist_python)
38+
39+
install(TARGETS superlu_dist_python
40+
# DESTINATION ${CMAKE_INSTALL_LIBDIR}
41+
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
42+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
43+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
44+
)
45+
install(FILES pddrive.py DESTINATION "${INSTALL_LIB_DIR}/PYTHON")
46+
47+
48+
49+
50+
51+
52+

SRC/double/pdbridge.c renamed to PYTHON/pdbridge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ at the top-level directory.
2222
* </pre>
2323
*/
2424

25-
#include "superlu_ddefs.h"
25+
#include "pdbridge.h"
2626
#include <math.h>
2727
#include <stdbool.h>
2828

PYTHON/pdbridge.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*! \file
2+
Copyright (c) 2003, The Regents of the University of California, through
3+
Lawrence Berkeley National Laboratory (subject to receipt of any required
4+
approvals from U.S. Dept. of Energy)
5+
6+
All rights reserved.
7+
8+
The source code is distributed under BSD license, see the file License.txt
9+
at the top-level directory.
10+
*/
11+
12+
/*! @file
13+
* \brief Distributed SuperLU data types and function prototypes
14+
*
15+
* <pre>
16+
* -- Distributed SuperLU routine (version 9.0) --
17+
* Lawrence Berkeley National Lab, Univ. of California Berkeley,
18+
* Georgia Institute of Technology
19+
* November 1, 2007
20+
* April 5, 2015
21+
* September 18, 2018 version 6.0
22+
* February 8, 2019 version 6.1.1
23+
* May 10, 2019 version 7.0.0
24+
* </pre>
25+
*/
26+
27+
28+
#ifndef __SUPERLU_DIST_PDBRIDGE /* allow multiple inclusions */
29+
#define __SUPERLU_DIST_PDBRIDGE
30+
#include "superlu_ddefs.h"
31+
32+
typedef struct {
33+
superlu_dist_options_t options;
34+
SuperLUStat_t stat;
35+
SuperMatrix A;
36+
dScalePermstruct_t ScalePermstruct;
37+
dLUstruct_t LUstruct;
38+
dSOLVEstruct_t SOLVEstruct;
39+
gridinfo_t grid;
40+
} slu_handle;
41+
42+
#ifdef __cplusplus
43+
extern "C" {
44+
#endif
45+
46+
/*== APIs for python caller =======*/
47+
extern void pdbridge_init(int_t m, int_t n, int_t nnz, int_t *rowind, int_t *colptr, double *nzval, void ** pyobj, int argc, char *argv[]);
48+
extern void pdbridge_solve(void ** pyobj, int nrhs, double *b_global);
49+
extern void pdbridge_free(void ** pyobj);
50+
extern void pdbridge_factor(void ** pyobj);
51+
extern void pdbridge_logdet(void ** pyobj, int * sign, double * logdet);
52+
53+
#ifdef __cplusplus
54+
}
55+
#endif
56+
#endif
57+

EXAMPLE/pddrive.py renamed to PYTHON/pddrive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ def setup_pdbridge(sp,INT64):
132132
raise Exception(f"Windows is not yet supported")
133133

134134
DLLFOUND=False
135-
INSTALLDIR=os.getenv('SUPERLU_LIB_PATH')
135+
INSTALLDIR=os.getenv('SUPERLU_PYTHON_LIB_PATH')
136136

137-
DLL = os.path.abspath(__file__ + "/../../")+'/libsuperlu_dist%s'%(pos)
137+
DLL = os.path.abspath(__file__ + "/../../")+'/libsuperlu_dist_python%s'%(pos)
138138
if(os.path.exists(DLL)):
139139
DLLFOUND=True
140140
elif(INSTALLDIR is not None):
141-
DLL = INSTALLDIR+'/libsuperlu_dist%s'%(pos)
141+
DLL = INSTALLDIR+'/libsuperlu_dist_python%s'%(pos)
142142
if(os.path.exists(DLL)):
143143
DLLFOUND=True
144144
if(DLLFOUND == True):
145145
sp = ctypes.cdll.LoadLibrary(DLL)
146146
setup_pdbridge(sp,INT64)
147147
else:
148-
raise Exception(f"Cannot find the superlu_dist library. Try to set env variable SUPERLU_LIB_PATH correctly.")
148+
raise Exception(f"Cannot find the superlu_dist_python library. Try to set env variable SUPERLU_PYTHON_LIB_PATH correctly.")
149149

150150
####################### initialization
151151
pyobj = ctypes.c_void_p()

SRC/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ if(enable_double)
166166
double/pdgssvx3d_csc_batch.c # batch in CSC format
167167
double/dequil_batch.c # batch in CSC format
168168
double/dpivot_batch.c
169-
double/pdbridge.c
170169
)
171170

172171
if (TPL_ENABLE_CUDALIB)

SRC/include/superlu_ddefs.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -485,18 +485,6 @@ typedef struct dlsumBmod_buff_t
485485
}dlsumBmod_buff_t;
486486

487487

488-
typedef struct {
489-
superlu_dist_options_t options;
490-
SuperLUStat_t stat;
491-
SuperMatrix A;
492-
dScalePermstruct_t ScalePermstruct;
493-
dLUstruct_t LUstruct;
494-
dSOLVEstruct_t SOLVEstruct;
495-
gridinfo_t grid;
496-
} slu_handle;
497-
498-
499-
500488
/*=====================*/
501489

502490
/***********************************************************************
@@ -1638,13 +1626,6 @@ extern double *dready_x;
16381626
extern double *dready_lsum;
16391627

16401628

1641-
/*== APIs for python caller =======*/
1642-
extern void pdbridge_init(int_t m, int_t n, int_t nnz, int_t *rowind, int_t *colptr, double *nzval, void ** pyobj, int argc, char *argv[]);
1643-
extern void pdbridge_solve(void ** pyobj, int nrhs, double *b_global);
1644-
extern void pdbridge_free(void ** pyobj);
1645-
extern void pdbridge_factor(void ** pyobj);
1646-
extern void pdbridge_logdet(void ** pyobj, int * sign, double * logdet);
1647-
16481629
#ifdef __cplusplus
16491630
}
16501631
#endif

example_scripts/batch_script_mpi_runit_perlmutter_python_gcc_nvshmem.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ NTH=4 # number of OMP threads
3232

3333
#SUPERLU settings:
3434
#################################################
35-
export SUPERLU_LIB_PATH=/global/cfs/cdirs/m2957/liuyangz/my_research/superlu_dist_python_09_19_2024/build/SRC/
35+
export SUPERLU_PYTHON_LIB_PATH=/global/cfs/cdirs/m2957/liuyangz/my_research/superlu_dist_python_09_19_2024/build/PYTHON/
3636
export SUPERLU_LBS=GD
3737
export SUPERLU_ACC_OFFLOAD=1 # whether to do CPU or GPU numerical factorization
3838
export GPU3DVERSION=0 # whether to do use the latest C++ numerical factorization
@@ -92,7 +92,6 @@ export MPICH_MAX_THREAD_SAFETY=multiple
9292

9393

9494

95-
cd ../EXAMPLE/
96-
srun -n $NCORE_VAL_TOT2D -c $TH_PER_RANK --cpu_bind=cores python ./pddrive.py -c $NCOL -r $NROW -s 1 -q 5 -m 1
95+
srun -n $NCORE_VAL_TOT2D -c $TH_PER_RANK --cpu_bind=cores python ../PYTHON/pddrive.py -c $NCOL -r $NROW -s 1 -q 5 -m 1
9796

9897

example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ make pddrive -j16
8484
make pddrive3d -j16
8585
make pzdrive3d -j16
8686
make f_pddrive
87+
make python
8788

8889
## -DTPL_BLAS_LIBRARIES=/global/cfs/cdirs/m3894/ptlin/tpl/amd_blis/install/amd_blis-20211021-n9-gcc9.3.0/lib/libblis.a \
8990

example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python_longint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ cmake .. \
8888
make pddrive -j16
8989
make pddrive3d -j16
9090
make f_pddrive
91+
make python
9192

9293
## -DTPL_BLAS_LIBRARIES=/global/cfs/cdirs/m3894/ptlin/tpl/amd_blis/install/amd_blis-20211021-n9-gcc9.3.0/lib/libblis.a \
9394
MPICC=cc pip install mpi4py==4.0.0

0 commit comments

Comments
 (0)