From 06ce9c7b34dc71407a4449bdf17004d7b2d09ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandru=20S=C4=83vulescu?= Date: Mon, 6 Feb 2023 16:28:28 +0100 Subject: [PATCH 1/2] fix MUSIC setup.py for multiple MPI include dirs add coverage setup --- .github/workflows/coverage.yml | 18 +++++++++++++++++- src/neuronmusic/setup.py.in | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index da9e03d69a..2062d31979 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -49,6 +49,22 @@ jobs: cmake .. make && sudo make install + - name: Setup MUSIC + run: | + python3 -m venv music-venv + source music-venv/bin/activate + python3 -m pip install mpi4py cython numpy + # Stable build: https://github.com/INCF/MUSIC/archive/refs/heads/switch-to-MPI-C-interface.zip @ f33b66ea9348888eed1761738ab48c23ffc8a0d0 + curl -L -o MUSIC.zip https://codeload.github.com/INCF/MUSIC/zip/f33b66ea9348888eed1761738ab48c23ffc8a0d0 && + unzip MUSIC.zip && + mv MUSIC-* MUSIC && + cd MUSIC && + ./autogen.sh && + ./configure --with-python-sys-prefix --disable-anysource && + sudo make -j install + deactivate + working-directory: ${{runner.temp}} + - name: Setup Xvfb run: | sudo apt-get install xvfb @@ -97,7 +113,7 @@ jobs: # CMake options & flags export COVERAGE_FLAGS="--coverage -O0 -fno-inline -g"; - export CMAKE_OPTION="-DNRN_ENABLE_MPI=ON -DNRN_ENABLE_INTERVIEWS=ON -DNRN_ENABLE_PYTHON=ON -DNRN_ENABLE_PYTHON_DYNAMIC=ON -DNRN_PYTHON_DYNAMIC=${PYTHON_MIN};${PYTHON_MAX} -DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_PROFILING=ON -DNRN_ENABLE_BACKTRACE=ON"; + export CMAKE_OPTION="-DNRN_ENABLE_MPI=ON -DNRN_ENABLE_INTERVIEWS=ON -DNRN_ENABLE_PYTHON=ON -DNRN_ENABLE_PYTHON_DYNAMIC=ON -DNRN_PYTHON_DYNAMIC=${PYTHON_MIN};${PYTHON_MAX} -DNRN_ENABLE_CORENEURON=ON -DNRN_ENABLE_PROFILING=ON -DNRN_ENABLE_BACKTRACE=ON -DNRN_ENABLE_MUSIC=ON"; cmake $CMAKE_OPTION -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX -DNRN_ENABLE_TESTS=ON -DCMAKE_C_FLAGS="${COVERAGE_FLAGS}" -DCMAKE_CXX_FLAGS="${COVERAGE_FLAGS}" -DCORENRN_ENABLE_UNIT_TESTS=ON ..; # Coverage diff --git a/src/neuronmusic/setup.py.in b/src/neuronmusic/setup.py.in index c4bd985f40..9bc955e40a 100644 --- a/src/neuronmusic/setup.py.in +++ b/src/neuronmusic/setup.py.in @@ -12,7 +12,7 @@ import os os.environ["CC"]=mpicc_bin os.environ["CXX"]=mpicxx_bin -include_dirs = ['@MUSIC_INCDIR@', '@MPI_INCLUDE_PATH@', nrn_srcdir+'/src/neuronmusic', nrn_srcdir + '/src/nrnpython', '.'] +include_dirs = ['@MUSIC_INCDIR@', nrn_srcdir+'/src/neuronmusic', nrn_srcdir + '/src/nrnpython', '.'] + '@MPI_INCLUDE_PATH@'.split(';') libdirs = ['@MUSIC_LIBDIR@', @NRN_LIBDIR@] From d5df0410d3781f730eaf696b531797358c4b332b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandru=20S=C4=83vulescu?= Date: Tue, 7 Feb 2023 16:14:15 +0100 Subject: [PATCH 2/2] CMake MUSIC setup from #2092 --- cmake/NeuronFileLists.cmake | 4 ++++ src/{nrniv => neuronmusic}/nrnmusic.cpp | 32 +++++++++++++++++-------- src/neuronmusic/nrnmusicapi.h | 14 +++++++++++ src/nrncvode/netcvode.cpp | 2 +- src/nrniv/CMakeLists.txt | 9 ++++++- src/nrniv/netpar.cpp | 13 +++++++++- src/nrniv/netpar.h | 13 ++++++++++ src/nrnmpi/nrnmpi.cpp | 9 ++++--- 8 files changed, 80 insertions(+), 16 deletions(-) rename src/{nrniv => neuronmusic}/nrnmusic.cpp (91%) create mode 100644 src/neuronmusic/nrnmusicapi.h create mode 100644 src/nrniv/netpar.h diff --git a/cmake/NeuronFileLists.cmake b/cmake/NeuronFileLists.cmake index a314ce266b..b525f80d2d 100644 --- a/cmake/NeuronFileLists.cmake +++ b/cmake/NeuronFileLists.cmake @@ -526,6 +526,8 @@ 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) + # ============================================================================= # Top level directories under src # ============================================================================= @@ -538,6 +540,7 @@ set(NRN_NRNIV_SRC_DIR ${PROJECT_SOURCE_DIR}/src/nrniv) set(NRN_MODLUNIT_SRC_DIR ${PROJECT_SOURCE_DIR}/src/modlunit) set(NRN_NMODL_SRC_DIR ${PROJECT_SOURCE_DIR}/src/nmodl) set(NRN_IVOS_SRC_DIR ${PROJECT_SOURCE_DIR}/src/ivos) +set(NRN_MUSIC_SRC_DIR ${PROJECT_SOURCE_DIR}/src/neuronmusic) # ============================================================================= # Create source file lists by gathering from various directories @@ -569,6 +572,7 @@ nrn_create_file_list(NRN_MODLUNIT_SRC_FILES ${NRN_MODLUNIT_SRC_DIR} ${MODLUNIT_F 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_MUSIC_SRC_FILES ${NRN_MUSIC_SRC_DIR} ${NRN_MUSIC_FILES_LIST}) nrn_create_file_list(NRN_IVOS_SRC_FILES ${NRN_IVOS_SRC_DIR} ${IVOS_FILES_LIST}) list(APPEND NRN_OC_SRC_FILES ${PROJECT_BINARY_DIR}/src/oc/hocusr.h) diff --git a/src/nrniv/nrnmusic.cpp b/src/neuronmusic/nrnmusic.cpp similarity index 91% rename from src/nrniv/nrnmusic.cpp rename to src/neuronmusic/nrnmusic.cpp index 94cee3754c..fc972d42c3 100644 --- a/src/nrniv/nrnmusic.cpp +++ b/src/neuronmusic/nrnmusic.cpp @@ -1,5 +1,15 @@ +#include <../../nrnconf.h> #define NO_PYTHON_H 1 -#include <../neuronmusic/nrnmusic.h> +#define IN_NRNMUSIC_CPP +#include "nrnmusicapi.h" +#include "hocdec.h" +#include "nrn_ansi.h" +#include "netcon.h" +#include "cvodeobj.h" +#include "netcvode.h" +#include "multicore.h" +#include "nrnmusic.h" +#include "netpar.h" #include extern int nrnmusic; @@ -15,6 +25,7 @@ void nrnmusic_spikehandle(void* vport, double tt, int gindex); extern Object* nrnpy_po2ho(PyObject*); extern PyObject* nrnpy_ho2po(Object*); extern Object* hoc_new_object(Symbol*, void*); +extern NetCvode* net_cvode_instance; MUSIC::Setup* nrnmusic_setup; MUSIC::Runtime* nrnmusic_runtime; @@ -73,7 +84,7 @@ static PortTable* music_output_ports; NetParMusicEvent::NetParMusicEvent() {} NetParMusicEvent::~NetParMusicEvent() {} void NetParMusicEvent::send(double t, NetCvode* nc, NrnThread* nt) { - nc->event(t + usable_mindelay_, this, nt); + nc->event(t + nrn_usable_mindelay(), this, nt); } void NetParMusicEvent::deliver(double t, NetCvode* nc, NrnThread* nt) { nrnmusic_runtime->tick(); @@ -127,8 +138,8 @@ void NRNMUSIC::EventOutputPort::gid2index(int gid, int gi) { // except pc.cell(gid, nc) has already been called and this // will add this to the PreSyn.music_out_ list. alloc_music_space(); - auto iter = gid2out_.find(gid); - if (iter == gid2out_.end()) { + auto iter = nrn_gid2out().find(gid); + if (iter == nrn_gid2out().end()) { return; } PreSyn* ps = iter->second; @@ -179,7 +190,7 @@ PyObject* NRNMUSIC::EventInputPort::index2target(int gi, PyObject* ptarget) { ps = (*gi_table)[gi]; } NetCon* nc = new NetCon(ps, target); - Object* o = hoc_new_object(netcon_sym_, nc); + Object* o = hoc_new_object(nrn_netcon_sym(), nc); nc->obj_ = o; PyObject* po = nrnpy_ho2po(o); // printf("index2target %d %s\n", gi, hoc_object_name(target)); @@ -198,6 +209,7 @@ void nrnmusic_init(int* pargc, char*** pargv) { nrnmusic = 1; } } + if (getenv("_MUSIC_CONFIG_")) nrnmusic = 1; // temporary kludge if (nrnmusic) { @@ -216,7 +228,7 @@ void nrnmusic_terminate() { // Called from nrn_spike_exchange_init so usable_mindelay is ready to use // For now, can only be called once. -static void nrnmusic_runtime_phase() { +void nrnmusic_runtime_phase() { static int called = 0; assert(!called); called = 1; @@ -237,7 +249,7 @@ static void nrnmusic_runtime_phase() { } eh->filltable(eip, cnt); MUSIC::PermutationIndex indices(&gindices.front(), gindices.size()); - eip->map(&indices, eh, usable_mindelay_ / 1000.0); + eip->map(&indices, eh, nrn_usable_mindelay() / 1000.0); delete eip->gi_table; } delete music_input_ports; @@ -260,8 +272,8 @@ static void nrnmusic_runtime_phase() { delete music_output_ports; // switch to the runtime phase - // printf("usable_mindelay = %g\n", usable_mindelay_); - nrnmusic_runtime = new MUSIC::Runtime(nrnmusic_setup, usable_mindelay_ / 1000.0); + // printf("usable_mindelay = %g\n", nrn_usable_mindelay()); + nrnmusic_runtime = new MUSIC::Runtime(nrnmusic_setup, nrn_usable_mindelay() / 1000.0); npme = new NetParMusicEvent(); npme->send(0, net_cvode_instance, nrn_threads); -} +} \ No newline at end of file diff --git a/src/neuronmusic/nrnmusicapi.h b/src/neuronmusic/nrnmusicapi.h new file mode 100644 index 0000000000..e2ec81752b --- /dev/null +++ b/src/neuronmusic/nrnmusicapi.h @@ -0,0 +1,14 @@ +#pragma once + +extern int nrnmusic; + +extern "C" { + +// Note: MPI_Comm nrnmusic_comm; in nrnmpi.cpp and nrnmusic.cpp + +extern void nrnmusic_runtime_phase(); +extern void nrnmusic_injectlist(void*, double); +extern void nrnmusic_init(int* parg, char*** pargv); +extern void nrnmusic_terminate(); + +} // end of extern "C" \ No newline at end of file diff --git a/src/nrncvode/netcvode.cpp b/src/nrncvode/netcvode.cpp index 49edb90c77..e5545d5427 100644 --- a/src/nrncvode/netcvode.cpp +++ b/src/nrncvode/netcvode.cpp @@ -118,7 +118,7 @@ extern "C" void nrnthread_trajectory_return(int tid, double t); bool nrn_trajectory_request_per_time_step_ = false; #if NRN_MUSIC -extern void nrnmusic_injectlist(void*, double); +#include "nrnmusicapi.h" #endif extern int hoc_return_type_code; diff --git a/src/nrniv/CMakeLists.txt b/src/nrniv/CMakeLists.txt index f4ecefeff0..25e9d70ee2 100644 --- a/src/nrniv/CMakeLists.txt +++ b/src/nrniv/CMakeLists.txt @@ -167,6 +167,10 @@ if(NOT NRN_ENABLE_INTERVIEWS) list(APPEND NRN_NRNIV_LIB_SRC_FILES ${NRN_IVOS_SRC_FILES}) endif() +if(NRN_ENABLE_MUSIC) + list(APPEND NRN_NRNIV_LIB_SRC_FILES ${NRN_MUSIC_SRC_FILES}) +endif() + # ============================================================================= # Include directories for #include <../../nrnconf.h> # ============================================================================= @@ -199,6 +203,9 @@ set(NRN_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/src/sundials/cvodes ${PROJECT_SOURCE_DIR}/src/sundials/ida ${PROJECT_SOURCE_DIR}/src/sundials/shared) +if(NRN_ENABLE_MUSIC) + list(APPEND NRN_INCLUDE_DIRS ${NRN_MUSIC_SRC_DIR}) +endif() set(NRN_INCLUDE_DIRS ${NRN_INCLUDE_DIRS} PARENT_SCOPE) @@ -335,7 +342,7 @@ if(NRN_ENABLE_MPI_DYNAMIC) endif() if(NRN_ENABLE_MUSIC) - set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrniv/netpar.cpp + set_source_files_properties(${PROJECT_SOURCE_DIR}/src/neuronmusic/nrnmusic.cpp PROPERTIES INCLUDE_DIRECTORIES ${MUSIC_INCDIR}) endif() diff --git a/src/nrniv/netpar.cpp b/src/nrniv/netpar.cpp index 4888746e0e..53c1039977 100644 --- a/src/nrniv/netpar.cpp +++ b/src/nrniv/netpar.cpp @@ -202,9 +202,20 @@ static NrnThread* last_nt_; #endif #if NRN_MUSIC -#include "nrnmusic.cpp" +#include "nrnmusicapi.h" +int nrnmusic; #endif +double nrn_usable_mindelay() { + return usable_mindelay_; +} +Symbol* nrn_netcon_sym() { + return netcon_sym_; +} +Gid2PreSyn& nrn_gid2out() { + return gid2out_; +} + NetParEvent::NetParEvent() { wx_ = ws_ = 0.; ithread_ = -1; diff --git a/src/nrniv/netpar.h b/src/nrniv/netpar.h new file mode 100644 index 0000000000..6721ccc610 --- /dev/null +++ b/src/nrniv/netpar.h @@ -0,0 +1,13 @@ +#pragma once + +// Some things in netpar.cpp that were static but needed by nrnmusic.cpp + +#include "netcon.h" +#include +struct Symbol; + +using Gid2PreSyn = std::unordered_map; + +double nrn_usable_mindelay(); +Symbol* nrn_netcon_sym(); +Gid2PreSyn& nrn_gid2out(); \ No newline at end of file diff --git a/src/nrnmpi/nrnmpi.cpp b/src/nrnmpi/nrnmpi.cpp index db7c54dfbe..495177a11c 100644 --- a/src/nrnmpi/nrnmpi.cpp +++ b/src/nrnmpi/nrnmpi.cpp @@ -30,11 +30,10 @@ extern double nrn_timeus(); #include #endif -int nrnmusic; #if NRN_MUSIC MPI_Comm nrnmusic_comm; -extern void nrnmusic_init(int* parg, char*** pargv); -extern void nrnmusic_terminate(); +#include "nrnmusicapi.h" +extern int nrnmusic; #endif MPI_Comm nrnmpi_world_comm; @@ -98,9 +97,11 @@ for (i=0; i < *pargc; ++i) { b = 1; nrnmpi_under_nrncontrol_ = 1; } +#if NRN_MUSIC if (nrnmusic) { b = 1; } +#endif if (!b) { nrnmpi_under_nrncontrol_ = 0; return; @@ -121,7 +122,9 @@ for (i=0; i < *pargc; ++i) { asrt(MPI_Init(pargc, pargv)); #endif nrnmpi_under_nrncontrol_ = 1; +#if NRN_MUSIC } else if (!nrnmusic) { +#endif nrnmpi_under_nrncontrol_ = 0; }