Skip to content

Commit

Permalink
create a seperate directory for the python interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyangzhuan committed Oct 31, 2024
1 parent 1be9cbe commit 6ec6acd
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 30 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions EXAMPLE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions PYTHON/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")







2 changes: 1 addition & 1 deletion SRC/double/pdbridge.c → PYTHON/pdbridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ at the top-level directory.
* </pre>
*/

#include "superlu_ddefs.h"
#include "pdbridge.h"
#include <math.h>
#include <stdbool.h>

Expand Down
57 changes: 57 additions & 0 deletions PYTHON/pdbridge.h
Original file line number Diff line number Diff line change
@@ -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
*
* <pre>
* -- 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
* </pre>
*/


#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

8 changes: 4 additions & 4 deletions EXAMPLE/pddrive.py → PYTHON/pddrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion SRC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 0 additions & 19 deletions SRC/include/superlu_ddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;



/*=====================*/

/***********************************************************************
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Original file line number Diff line number Diff line change
Expand Up @@ -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 \

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6ec6acd

Please sign in to comment.