Skip to content

Commit

Permalink
New mpi way
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino committed Jun 6, 2023
1 parent 6c529a4 commit 7a34d78
Show file tree
Hide file tree
Showing 26 changed files with 453 additions and 803 deletions.
6 changes: 1 addition & 5 deletions cmake/NeuronFileLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,6 @@ set(NMODL_FILES_LIST

set(IVOS_FILES_LIST listimpl.cpp string.cpp observe.cpp regexp.cpp resource.cpp)

set(MPI_DYNAMIC_INCLUDE nrnmpi_dynam.h nrnmpi_dynam_cinc nrnmpi_dynam_wrappers.inc)

set(NRN_MUSIC_FILES_LIST nrnmusic.cpp)

# =============================================================================
Expand Down Expand Up @@ -570,7 +568,7 @@ nrn_create_file_list(NRN_SPARSE13_SRC_FILES ${PROJECT_SOURCE_DIR}/src/sparse13
${SPARSE13_FILES_LIST})
nrn_create_file_list(NRN_SCOPMATH_SRC_FILES ${PROJECT_SOURCE_DIR}/src/scopmath
${SCOPMATH_FILES_LIST})
nrn_create_file_list(NRN_NRNMPI_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnmpi ${NRNMPI_FILES_LIST})
nrn_create_file_list(NRN_NRNMPI_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnmpi/lib ${NRNMPI_FILES_LIST})
nrn_create_file_list(NRN_NRNGNU_SRC_FILES ${PROJECT_SOURCE_DIR}/src/gnu ${NRNGNU_FILES_LIST})
nrn_create_file_list(NRN_NRNPYTHON_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnpython
${NRNPYTHON_FILES_LIST})
Expand All @@ -579,8 +577,6 @@ nrn_create_file_list(NRN_BIN_SRC_FILES ${PROJECT_SOURCE_DIR}/src/ivoc/ nrnmain.c
nrn_create_file_list(NRN_BIN_SRC_FILES ${PROJECT_SOURCE_DIR}/src/oc/ ockludge.cpp modlreg.cpp)
nrn_create_file_list(NRN_MODLUNIT_SRC_FILES ${NRN_MODLUNIT_SRC_DIR} ${MODLUNIT_FILES_LIST})
nrn_create_file_list(NRN_NMODL_SRC_FILES ${NRN_NMODL_SRC_DIR} ${NMODL_FILES_LIST})
nrn_create_file_list(NRNMPI_DYNAMIC_INCLUDE_FILE ${PROJECT_SOURCE_DIR}/src/nrnmpi
${MPI_DYNAMIC_INCLUDE})
nrn_create_file_list(NRN_IVOS_SRC_FILES ${NRN_IVOS_SRC_DIR} ${IVOS_FILES_LIST})
nrn_create_file_list(NRN_MUSIC_SRC_FILES ${NRN_MUSIC_SRC_DIR} ${NRN_MUSIC_FILES_LIST})
list(APPEND NRN_OC_SRC_FILES ${PROJECT_BINARY_DIR}/src/oc/hocusr.h)
Expand Down
3 changes: 0 additions & 3 deletions src/ivoc/nrnmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ void nrnmpi_load_or_exit(bool is_python);
void nrnmusic_load();
#endif // NRN_MUSIC
#endif // NRNMPI_DYNAMICLOAD
#if NRNMPI
extern "C" void nrnmpi_init(int nrnmpi_under_nrncontrol, int* pargc, char*** pargv);
#endif

int main(int argc, char** argv, char** env) {
nrn_main_launch = 1;
Expand Down
34 changes: 11 additions & 23 deletions src/nrniv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,17 @@ set(NRN_NRNIV_LIB_SRC_FILES
${NRN_SPARSE13_SRC_FILES}
${NRN_SUNDIALS_SRC_FILES})

set(NRN_MPI_LIB_NAME "nrn_mpi" CACHE INTERNAL "")
if(NRN_ENABLE_MPI)
list(APPEND NRN_NRNIV_LIB_SRC_FILES ${NRN_PARALLEL_SRC_FILES})
endif()

if(NRN_ENABLE_MPI_DYNAMIC)
list(APPEND NRN_NRNIV_LIB_SRC_FILES ${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi_dynam.cpp)
else()
list(APPEND NRN_NRNIV_LIB_SRC_FILES ${NRN_NRNMPI_SRC_FILES})
if(NRN_ENABLE_MPI_DYNAMIC)
add_library(${NRN_MPI_LIB_NAME} OBJECT ${NRN_NRNMPI_SRC_FILES})
target_include_directories(
${NRN_MPI_LIB_NAME} PRIVATE ${MPI_C_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/src)
set_property(TARGET ${NRN_MPI_LIB_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
set(CORENRN_MPI_OBJ $<TARGET_OBJECTS:${NRN_MPI_LIB_NAME})
endif()
endif()

if(MINGW)
Expand Down Expand Up @@ -268,16 +271,6 @@ add_custom_command(
add_custom_target(generate_hocusr_header DEPENDS "${PROJECT_BINARY_DIR}/src/oc/hocusr.h")
add_dependencies(generated_source_files generate_hocusr_header)

# header for dynamic mpi
if(NRN_ENABLE_MPI_DYNAMIC)
add_custom_command(
OUTPUT ${NRNMPI_DYNAMIC_INCLUDE_FILE}
COMMAND sh mkdynam.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src/nrnmpi
DEPENDS ${PROJECT_SOURCE_DIR}/src/nrnmpi/mkdynam.sh
${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpidec.h)
endif()

# =============================================================================
# Various macro definitions for compiling different files
# =============================================================================
Expand Down Expand Up @@ -379,13 +372,8 @@ elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
PROPERTY COMPILE_OPTIONS -O1)
endif()

if(NRN_ENABLE_MPI_DYNAMIC)
set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi_dynam.cpp
PROPERTIES OBJECT_DEPENDS ${NRNMPI_DYNAMIC_INCLUDE_FILE})
set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/nrnmpi.cpp
PROPERTIES OBJECT_DEPENDS ${NRNMPI_DYNAMIC_INCLUDE_FILE})
set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrnmpi/bbsmpipack.cpp
PROPERTIES OBJECT_DEPENDS ${NRNMPI_DYNAMIC_INCLUDE_FILE})
if(NRN_ENABLE_MPI)
set(NRN_NRNIV_MPI_DYNAM "../nrnmpi/core/resolve.cpp")
endif()

if(NRN_ENABLE_MUSIC)
Expand All @@ -410,7 +398,7 @@ include_directories(${NRN_INCLUDE_DIRS})
# =============================================================================
# All source directories to include
# =============================================================================
add_library(nrniv_lib ${NRN_LIBRARY_TYPE} ${NRN_NRNIV_LIB_SRC_FILES})
add_library(nrniv_lib ${NRN_LIBRARY_TYPE} ${NRN_NRNIV_LIB_SRC_FILES} ${NRN_NRNIV_MPI_DYNAM})
cpp_cc_configure_sanitizers(TARGET nrniv_lib)
# Source-directory .cpp needs to find generated .hpp.
target_include_directories(nrniv_lib PUBLIC "${NRN_OC_GEN}")
Expand Down
7 changes: 0 additions & 7 deletions src/nrniv/bbsavestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,6 @@ extern PreSyn* nrn_gid2presyn(int gid);
extern int nrn_gid_exists(int gid);

#if NRNMPI
extern void nrnmpi_barrier();
extern void nrnmpi_int_alltoallv(int*, int*, int*, int*, int*, int*);
extern void nrnmpi_dbl_alltoallv(double*, int*, int*, double*, int*, int*);
extern int nrnmpi_int_allmax(int);
extern void nrnmpi_int_allgather(int* s, int* r, int n);
extern void nrnmpi_int_allgatherv(int* s, int* r, int* n, int* dspl);
extern void nrnmpi_dbl_allgatherv(double* s, double* r, int* n, int* dspl);
#else
static void nrnmpi_barrier() {}
static void nrnmpi_int_alltoallv(int* s, int* scnt, int* sdispl, int* r, int* rcnt, int* rdispl) {
Expand Down
5 changes: 0 additions & 5 deletions src/nrniv/multisend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,6 @@ double nrn_multisend_receive_time(int type) { // and others
return rt;
}

extern void nrnmpi_multisend_comm();
extern void nrnmpi_multisend_multisend(NRNMPI_Spike*, int, int*);
extern int nrnmpi_multisend_single_advance(NRNMPI_Spike*);
extern int nrnmpi_multisend_conserve(int nsend, int nrecv);

static void nrn_multisend_init() {
for (int i = 0; i < n_multisend_interval; ++i) {
multisend_receive_buffer[i]->init(i);
Expand Down
57 changes: 52 additions & 5 deletions src/nrniv/netpar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,55 @@ static int n_multisend_interval;
int nrnmusic;
#endif

#ifndef nrn_spikebuf_size
#define nrn_spikebuf_size 0
#endif

// Variable from MPI
#if nrn_spikebuf_size > 0
typedef struct {
int nspike;
int gid[nrn_spikebuf_size];
double spiketime[nrn_spikebuf_size];
} NRNMPI_Spikebuf;
#endif


#define icapacity_ nrnmpi_i_capacity_
#define spikeout_ nrnmpi_spikeout_
#define spikein_ nrnmpi_spikein_
#define nout_ nrnmpi_nout_
#define nin_ nrnmpi_nin_
extern int nout_;
extern int* nin_;
extern int icapacity_;
extern NRNMPI_Spike* spikeout_;
extern NRNMPI_Spike* spikein_;

#define spfixout_ nrnmpi_spikeout_fixed_
#define spfixin_ nrnmpi_spikein_fixed_
#define spfixin_ovfl_ nrnmpi_spikein_fixed_ovfl_
#define localgid_size_ nrnmpi_localgid_size_
#define ag_send_size_ nrnmpi_ag_send_size_
#define ag_send_nspike_ nrnmpi_send_nspike_
#define ovfl_capacity_ nrnmpi_ovfl_capacity_
#define ovfl_ nrnmpi_ovfl_
extern int localgid_size_; /* bytes */
extern int ag_send_size_; /* bytes */
extern int ag_send_nspike_; /* spikes */
extern int ovfl_capacity_; /* spikes */
extern int ovfl_; /* spikes */
extern unsigned char* spfixout_;
extern unsigned char* spfixin_;
extern unsigned char* spfixin_ovfl_;
//end variables

#if nrn_spikebuf_size > 0
#define spbufout_ nrnmpi_spbufout_
#define spbufin_ nrnmpi_spbufin_
extern NRNMPI_Spikebuf* spbufout_;
extern NRNMPI_Spikebuf* spbufin_;
#endif
static Symbol* netcon_sym_;
static Gid2PreSyn gid2out_;
static Gid2PreSyn gid2in_;
Expand Down Expand Up @@ -88,11 +137,9 @@ static double set_mindelay(double maxdelay);

#if NRNMPI

#include "../nrnmpi/mpispike.h"
// #include "../nrnmpi/mpispike.h"

void nrn_timeout(int);
extern int nrnmpi_int_allmax(int);
extern void nrnmpi_int_allgather(int*, int*, int);
void nrn2ncs_outputevent(int netcon_output_index, double firetime);
bool nrn_use_compress_; // global due to bbsavestate
#define use_compress_ nrn_use_compress_
Expand Down Expand Up @@ -574,7 +621,7 @@ void nrn_spike_exchange(NrnThread* nt) {
nrnmpi_barrier();
nrnmpi_step_wait_ += nrnmpi_wtime() - wt;
}
n = nrnmpi_spike_exchange();
n = nrnmpi_spike_exchange(nin_, &nout_, &icapacity_, &spikein_, &spikeout_);
wt_ = nrnmpi_wtime() - wt;
wt = nrnmpi_wtime();
TBUF
Expand Down Expand Up @@ -670,7 +717,7 @@ void nrn_spike_exchange_compressed(NrnThread* nt) {
nrnmpi_barrier();
nrnmpi_step_wait_ += nrnmpi_wtime() - wt;
}
n = nrnmpi_spike_exchange_compressed();
n = nrnmpi_spike_exchange_compressed(nin_, spfixin_ovfl_, spfixout_, spfixin_, ag_send_size_, ag_send_nspike_, localgid_size_, &ovfl_capacity_, &ovfl_);
wt_ = nrnmpi_wtime() - wt;
wt = nrnmpi_wtime();
TBUF
Expand Down
2 changes: 0 additions & 2 deletions src/nrniv/splitcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ the subtrees is no longer required by this implementation.
#if PARANEURON
void nrnmpi_split_clear();
extern void (*nrnmpi_splitcell_compute_)();
extern void nrnmpi_send_doubles(double*, int cnt, int dest, int tag);
extern void nrnmpi_recv_doubles(double*, int cnt, int src, int tag);
extern double nrnmpi_splitcell_wait_;

static int change_cnt_;
Expand Down
25 changes: 25 additions & 0 deletions src/nrnmpi/core/resolve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <dlfcn.h>
#include <sstream>
#include "../nrnmpi.h"

// Those functions are part of a mechanism to dynamically load mpi or not
void mpi_manager_t::resolve_symbols(void* handle) {
for (auto* ptr: m_function_ptrs) {
assert(!(*ptr));
ptr->resolve(handle);
assert(*ptr);
}
}

void mpi_function_base::resolve(void* handle) {
dlerror();
void* ptr = dlsym(handle, m_name);
const char* error = dlerror();
if (error) {
std::ostringstream oss;
oss << "Could not get symbol " << m_name << " from handle " << handle << ": " << error;
throw std::runtime_error(oss.str());
}
assert(ptr);
m_fptr = ptr;
}
Loading

0 comments on commit 7a34d78

Please sign in to comment.