From 6ec6acd0bcc890f96a09bcb90adad4a672c914f8 Mon Sep 17 00:00:00 2001 From: Yang Liu Date: Thu, 31 Oct 2024 12:04:06 -0700 Subject: [PATCH] create a seperate directory for the python interfaces --- CMakeLists.txt | 9 +++ EXAMPLE/CMakeLists.txt | 2 - PYTHON/CMakeLists.txt | 52 +++++++++++++++++ {SRC/double => PYTHON}/pdbridge.c | 2 +- PYTHON/pdbridge.h | 57 +++++++++++++++++++ {EXAMPLE => PYTHON}/pddrive.py | 8 +-- SRC/CMakeLists.txt | 1 - SRC/include/superlu_ddefs.h | 19 ------- ...mpi_runit_perlmutter_python_gcc_nvshmem.sh | 5 +- ...ake_build_perlmutter_gcc_nvshmem_python.sh | 1 + ...d_perlmutter_gcc_nvshmem_python_longint.sh | 1 + 11 files changed, 127 insertions(+), 30 deletions(-) create mode 100644 PYTHON/CMakeLists.txt rename {SRC/double => PYTHON}/pdbridge.c (99%) create mode 100644 PYTHON/pdbridge.h rename {EXAMPLE => PYTHON}/pddrive.py (95%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d944d35a..6917be02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(enable_complex16 "Enable complex16 precision library" ON) option(enable_tests "Build tests" ON) option(enable_examples "Build examples" ON) option(XSDK_ENABLE_Fortran "Enable Fortran" ON) +option(enable_python "Enable Python" ON) #-- BLAS option(TPL_ENABLE_INTERNAL_BLASLIB "Build the CBLAS library" ${enable_blaslib_DEFAULT}) @@ -619,6 +620,14 @@ if (XSDK_ENABLE_Fortran) add_subdirectory(FORTRAN) endif() +if (enable_python) +if (BUILD_SHARED_LIBS) + add_subdirectory(PYTHON) +else() + message("-- Not building Python interface, which requires shared build.") +endif() +endif() + # superlu_dist uses c++11. PUBLIC means that the other codes linking to it need c++11 #target_compile_features(SuperLU_DIST PUBLIC cxx_std_11) diff --git a/EXAMPLE/CMakeLists.txt b/EXAMPLE/CMakeLists.txt index 30696a6a..f8ab9ac2 100755 --- a/EXAMPLE/CMakeLists.txt +++ b/EXAMPLE/CMakeLists.txt @@ -118,8 +118,6 @@ if(enable_double) target_link_libraries(pddrive_spawn ${all_link_libs}) install(TARGETS pddrive_spawn RUNTIME DESTINATION "${INSTALL_LIB_DIR}/EXAMPLE") - install(FILES pddrive.py DESTINATION "${INSTALL_LIB_DIR}/EXAMPLE") - endif() #### end enable_double if(enable_single) diff --git a/PYTHON/CMakeLists.txt b/PYTHON/CMakeLists.txt new file mode 100644 index 00000000..b324deb8 --- /dev/null +++ b/PYTHON/CMakeLists.txt @@ -0,0 +1,52 @@ +# include the paths for header files +include_directories(${SuperLU_DIST_SOURCE_DIR}/SRC) +include_directories(${SuperLU_DIST_BINARY_DIR}/PYTHON) + +set(sources + pdbridge.h + pdbridge.c + ) + +# if(enable_complex16) +# list(APPEND sources pzbridge.h pzbridge.c) +# endif() + +add_library(superlu_dist_python ${sources}) +get_target_property(superlu_dist_version superlu_dist VERSION) +get_target_property(superlu_dist_soversion superlu_dist SOVERSION) +set_target_properties(superlu_dist_python PROPERTIES VERSION ${superlu_dist_version}) +set_target_properties(superlu_dist_python PROPERTIES SOVERSION ${superlu_dist_soversion}) +target_link_libraries(superlu_dist_python superlu_dist) +add_dependencies(superlu_dist_python config_f) + +set(PY_SCRIPT_SOURCE ${CMAKE_SOURCE_DIR}/PYTHON/pddrive.py) +set(PY_SCRIPT_DEST ${CMAKE_BINARY_DIR}/PYTHON/pddrive.py) +# Create a custom command to copy the Python script +add_custom_command( + OUTPUT ${PY_SCRIPT_DEST} + COMMAND ${CMAKE_COMMAND} -E copy ${PY_SCRIPT_SOURCE} ${PY_SCRIPT_DEST} + DEPENDS ${PY_SCRIPT_SOURCE} + COMMENT "Copying pddrive.py to ${CMAKE_BINARY_DIR}/PYTHON" +) + +# Create a custom target named 'python' that depends on the output file +add_custom_target(python + DEPENDS ${PY_SCRIPT_DEST} +) + +add_dependencies(python superlu_dist_python) + +install(TARGETS superlu_dist_python +# DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION "${INSTALL_BIN_DIR}" + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" +) +install(FILES pddrive.py DESTINATION "${INSTALL_LIB_DIR}/PYTHON") + + + + + + + diff --git a/SRC/double/pdbridge.c b/PYTHON/pdbridge.c similarity index 99% rename from SRC/double/pdbridge.c rename to PYTHON/pdbridge.c index 2adfc952..cf776f79 100644 --- a/SRC/double/pdbridge.c +++ b/PYTHON/pdbridge.c @@ -22,7 +22,7 @@ at the top-level directory. * */ -#include "superlu_ddefs.h" +#include "pdbridge.h" #include #include diff --git a/PYTHON/pdbridge.h b/PYTHON/pdbridge.h new file mode 100644 index 00000000..551f754f --- /dev/null +++ b/PYTHON/pdbridge.h @@ -0,0 +1,57 @@ +/*! \file +Copyright (c) 2003, The Regents of the University of California, through +Lawrence Berkeley National Laboratory (subject to receipt of any required +approvals from U.S. Dept. of Energy) + +All rights reserved. + +The source code is distributed under BSD license, see the file License.txt +at the top-level directory. +*/ + +/*! @file + * \brief Distributed SuperLU data types and function prototypes + * + *
+ * -- Distributed SuperLU routine (version 9.0) --
+ * Lawrence Berkeley National Lab, Univ. of California Berkeley,
+ * Georgia Institute of Technology
+ * November 1, 2007
+ * April 5, 2015
+ * September 18, 2018  version 6.0
+ * February 8, 2019  version 6.1.1
+ * May 10, 2019 version 7.0.0
+ * 
+ */ + + +#ifndef __SUPERLU_DIST_PDBRIDGE /* allow multiple inclusions */ +#define __SUPERLU_DIST_PDBRIDGE +#include "superlu_ddefs.h" + +typedef struct { + superlu_dist_options_t options; + SuperLUStat_t stat; + SuperMatrix A; + dScalePermstruct_t ScalePermstruct; + dLUstruct_t LUstruct; + dSOLVEstruct_t SOLVEstruct; + gridinfo_t grid; +} slu_handle; + +#ifdef __cplusplus +extern "C" { +#endif + +/*== APIs for python caller =======*/ +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[]); +extern void pdbridge_solve(void ** pyobj, int nrhs, double *b_global); +extern void pdbridge_free(void ** pyobj); +extern void pdbridge_factor(void ** pyobj); +extern void pdbridge_logdet(void ** pyobj, int * sign, double * logdet); + +#ifdef __cplusplus + } +#endif +#endif + diff --git a/EXAMPLE/pddrive.py b/PYTHON/pddrive.py similarity index 95% rename from EXAMPLE/pddrive.py rename to PYTHON/pddrive.py index cc2ccc11..ba135e5e 100644 --- a/EXAMPLE/pddrive.py +++ b/PYTHON/pddrive.py @@ -132,20 +132,20 @@ def setup_pdbridge(sp,INT64): raise Exception(f"Windows is not yet supported") DLLFOUND=False -INSTALLDIR=os.getenv('SUPERLU_LIB_PATH') +INSTALLDIR=os.getenv('SUPERLU_PYTHON_LIB_PATH') -DLL = os.path.abspath(__file__ + "/../../")+'/libsuperlu_dist%s'%(pos) +DLL = os.path.abspath(__file__ + "/../../")+'/libsuperlu_dist_python%s'%(pos) if(os.path.exists(DLL)): DLLFOUND=True elif(INSTALLDIR is not None): - DLL = INSTALLDIR+'/libsuperlu_dist%s'%(pos) + DLL = INSTALLDIR+'/libsuperlu_dist_python%s'%(pos) if(os.path.exists(DLL)): DLLFOUND=True if(DLLFOUND == True): sp = ctypes.cdll.LoadLibrary(DLL) setup_pdbridge(sp,INT64) else: - raise Exception(f"Cannot find the superlu_dist library. Try to set env variable SUPERLU_LIB_PATH correctly.") + raise Exception(f"Cannot find the superlu_dist_python library. Try to set env variable SUPERLU_PYTHON_LIB_PATH correctly.") ####################### initialization pyobj = ctypes.c_void_p() diff --git a/SRC/CMakeLists.txt b/SRC/CMakeLists.txt index f138c8f3..ac4940dd 100755 --- a/SRC/CMakeLists.txt +++ b/SRC/CMakeLists.txt @@ -166,7 +166,6 @@ if(enable_double) double/pdgssvx3d_csc_batch.c # batch in CSC format double/dequil_batch.c # batch in CSC format double/dpivot_batch.c - double/pdbridge.c ) if (TPL_ENABLE_CUDALIB) diff --git a/SRC/include/superlu_ddefs.h b/SRC/include/superlu_ddefs.h index 348df7f5..ea5dc345 100755 --- a/SRC/include/superlu_ddefs.h +++ b/SRC/include/superlu_ddefs.h @@ -485,18 +485,6 @@ typedef struct dlsumBmod_buff_t }dlsumBmod_buff_t; -typedef struct { - superlu_dist_options_t options; - SuperLUStat_t stat; - SuperMatrix A; - dScalePermstruct_t ScalePermstruct; - dLUstruct_t LUstruct; - dSOLVEstruct_t SOLVEstruct; - gridinfo_t grid; -} slu_handle; - - - /*=====================*/ /*********************************************************************** @@ -1638,13 +1626,6 @@ extern double *dready_x; extern double *dready_lsum; -/*== APIs for python caller =======*/ -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[]); -extern void pdbridge_solve(void ** pyobj, int nrhs, double *b_global); -extern void pdbridge_free(void ** pyobj); -extern void pdbridge_factor(void ** pyobj); -extern void pdbridge_logdet(void ** pyobj, int * sign, double * logdet); - #ifdef __cplusplus } #endif diff --git a/example_scripts/batch_script_mpi_runit_perlmutter_python_gcc_nvshmem.sh b/example_scripts/batch_script_mpi_runit_perlmutter_python_gcc_nvshmem.sh index 78596b66..31b6e1e2 100755 --- a/example_scripts/batch_script_mpi_runit_perlmutter_python_gcc_nvshmem.sh +++ b/example_scripts/batch_script_mpi_runit_perlmutter_python_gcc_nvshmem.sh @@ -32,7 +32,7 @@ NTH=4 # number of OMP threads #SUPERLU settings: ################################################# -export SUPERLU_LIB_PATH=/global/cfs/cdirs/m2957/liuyangz/my_research/superlu_dist_python_09_19_2024/build/SRC/ +export SUPERLU_PYTHON_LIB_PATH=/global/cfs/cdirs/m2957/liuyangz/my_research/superlu_dist_python_09_19_2024/build/PYTHON/ export SUPERLU_LBS=GD export SUPERLU_ACC_OFFLOAD=1 # whether to do CPU or GPU numerical factorization export GPU3DVERSION=0 # whether to do use the latest C++ numerical factorization @@ -92,7 +92,6 @@ export MPICH_MAX_THREAD_SAFETY=multiple -cd ../EXAMPLE/ -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 +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 diff --git a/example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python.sh b/example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python.sh index 84fb377e..15fb249b 100755 --- a/example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python.sh +++ b/example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python.sh @@ -84,6 +84,7 @@ make pddrive -j16 make pddrive3d -j16 make pzdrive3d -j16 make f_pddrive +make python ## -DTPL_BLAS_LIBRARIES=/global/cfs/cdirs/m3894/ptlin/tpl/amd_blis/install/amd_blis-20211021-n9-gcc9.3.0/lib/libblis.a \ diff --git a/example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python_longint.sh b/example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python_longint.sh index c2522355..1c7f01f3 100755 --- a/example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python_longint.sh +++ b/example_scripts/run_cmake_build_perlmutter_gcc_nvshmem_python_longint.sh @@ -88,6 +88,7 @@ cmake .. \ make pddrive -j16 make pddrive3d -j16 make f_pddrive +make python ## -DTPL_BLAS_LIBRARIES=/global/cfs/cdirs/m3894/ptlin/tpl/amd_blis/install/amd_blis-20211021-n9-gcc9.3.0/lib/libblis.a \ MPICC=cc pip install mpi4py==4.0.0 \ No newline at end of file