Skip to content

Commit

Permalink
Merge branch 'master' into 1uc/issue-2457
Browse files Browse the repository at this point in the history
  • Loading branch information
nrnhines authored Aug 16, 2023
2 parents d97001a + df99e4c commit 094bd39
Show file tree
Hide file tree
Showing 27 changed files with 81 additions and 356 deletions.
3 changes: 0 additions & 3 deletions cmake/ConfigFileSetting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ set(HAVE_NAMESPACES "/**/")
set(HAVE_STTY 0)
# below two are universal nowadays
set(IVOS_FABS "::fabs")
set(HAVE_STL "/**/")
set(prefix ${CMAKE_INSTALL_PREFIX})
set(host_cpu ${CMAKE_SYSTEM_PROCESSOR})
set(exec_prefix ${prefix})
Expand Down Expand Up @@ -223,8 +222,6 @@ nrn_check_symbol_exists("vprintf" "" HAVE_VPRINTF)
nrn_check_cxx_symbol_exists("getpw" "sys/types.h;pwd.h" HAVE_GETPW)
nrn_check_cxx_symbol_exists("fesetround" "" HAVE_FESETROUND)
nrn_check_cxx_symbol_exists("feenableexcept" "" HAVE_FEENABLEEXCEPT)
# not necessary to check as it should be always there
set(HAVE_SSTREAM /**/)

# =============================================================================
# Check data types
Expand Down
3 changes: 0 additions & 3 deletions cmake_nrnconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@
/* (Define if this signal exists) */
#undef HAVE_SIGSEGV

/* define if the compiler has stringstream */
#undef HAVE_SSTREAM

/* Define to 1 if you have the <stdarg.h> header file. */
#undef HAVE_STDARG_H

Expand Down
9 changes: 6 additions & 3 deletions share/lib/python/neuron/rxd/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ def _do_ion_register():

_init_lock = RLock()
has_initialized = False
is_initializing = False


def _do_init():
global has_initialized, _init_lock
global has_initialized, is_initializing, _init_lock
with _init_lock:
if not has_initialized:
if not has_initialized and not is_initializing:
from . import species, region, rxd

if len(species._all_species) > 0:
has_initialized = True
is_initializing = True
# TODO: clean this up so not repetitive; can't do it super cleanly because of the multiple phases of species
for obj in region._all_regions:
obj = obj()
Expand Down Expand Up @@ -55,6 +56,8 @@ def _do_init():
if obj is not None:
obj._do_init()
rxd._init()
has_initialized = True
is_initializing = False


def is_initialized():
Expand Down
6 changes: 4 additions & 2 deletions share/lib/python/neuron/rxd/rxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,10 @@ def _update_node_data(force=False, newspecies=False):
# TODO: separate compiling reactions -- so the indices can be updated without recompiling
_include_flux(True)
_setup_units(force=True)

# end#if
else:
# don't call _setup_memb_currents if nsegs changed -- because
# it is called by change units.
_setup_memb_currents()


def _matrix_to_rxd_sparse(m):
Expand Down
11 changes: 8 additions & 3 deletions share/lib/python/neuron/rxdtests/do_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ def collect_data():
data["data"] = []
data["record_count"] = 1
# remove previous record if h.t is the same
if data["record_count"] > 1 and h.t == data["data"][-len(local_data)]:
data["record_count"] -= 1
del data["data"][-len(local_data) :]
if data["record_count"] > 1:
if len(local_data) > len(data["data"]):
# model changed -- reset data collection
data["data"] = []
data["record_count"] = 1
elif h.t == data["data"][-len(local_data)]:
data["record_count"] -= 1
del data["data"][-len(local_data) :]
# add new data record
data["data"].extend(local_data)
# print correct record length
Expand Down
31 changes: 2 additions & 29 deletions src/ivoc/ivocmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,6 @@ extern void setneuronhome(const char*) {
}
#endif

#if 0
void penv() {
int i;
for (i=0; environ[i]; ++i) {
printf("%p %s\n", environ[i], environ[i]);
}
}
#endif

#if DARWIN || defined(__linux__)
#include "nrnwrap_dlfcn.h"
#include <string>
Expand Down Expand Up @@ -238,7 +229,7 @@ extern int nrn_is_python_extension;
extern void hoc_nrnmpi_init();
#if NRNMPI_DYNAMICLOAD
extern void nrnmpi_stubs();
extern std::string nrnmpi_load(int is_python);
extern std::string nrnmpi_load();
#endif

// some things are defined in libraries earlier than they are used so...
Expand Down Expand Up @@ -314,22 +305,12 @@ static int nrn_optargint(const char* opt, int* pargc, const char** argv, int dfl
void nrn_InitializeJavaVM();
#endif

#if 0 // for debugging
void prargs(const char* s, int argc, const char** argv) {
int i;
printf("%s argc=%d\n", s, argc);
for (i=0; i < argc; ++i) {
printf(" %d |%s|\n", i, argv[i]);
}
}
#endif

void hoc_nrnmpi_init() {
#if NRNMPI
if (!nrnmpi_use) {
#if NRNMPI_DYNAMICLOAD
nrnmpi_stubs();
auto const pmes = nrnmpi_load(1);
auto const pmes = nrnmpi_load();
if (!pmes.empty()) {
std::cout << pmes << std::endl;
}
Expand Down Expand Up @@ -529,14 +510,6 @@ int ivocmain_session(int argc, const char** argv, const char** env, int start_se
#endif
// putenv and setenv may invalidate env but we no longer
// use it so following should not be needed
#if 0
#if HAVE_UNISTD_H && !defined(__APPLE__)
env = environ;
#endif
#if defined(__APPLE__)
env = (*_NSGetEnviron());
#endif
#endif
}

#else // Not unix:
Expand Down
51 changes: 3 additions & 48 deletions src/ivoc/nrnmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern int nrn_main_launch;
extern int nrn_noauto_dlopen_nrnmech;
#if NRNMPI_DYNAMICLOAD
void nrnmpi_stubs();
void nrnmpi_load_or_exit(bool is_python);
void nrnmpi_load_or_exit();
#if NRN_MUSIC
void nrnmusic_load();
#endif // NRN_MUSIC
Expand All @@ -27,19 +27,13 @@ int main(int argc, char** argv, char** env) {
nrn_noauto_dlopen_nrnmech = 1;
#endif

#if 0
printf("argc=%d\n", argc);
for (int i=0; i < argc; ++i) {
printf("argv[%d]=|%s|\n", i, argv[i]);
}
#endif
#if NRNMPI
#if NRNMPI_DYNAMICLOAD
nrnmpi_stubs();
bool mpi_loaded = false;
for (int i = 0; i < argc; ++i) {
if (strcmp("-mpi", argv[i]) == 0) {
nrnmpi_load_or_exit(false);
nrnmpi_load_or_exit();
mpi_loaded = true;
break;
}
Expand All @@ -65,7 +59,7 @@ printf("argv[%d]=|%s|\n", i, argv[i]);
}
if (load_music) {
if (!mpi_loaded) {
nrnmpi_load_or_exit(false);
nrnmpi_load_or_exit();
}
nrnmusic_load();
}
Expand All @@ -80,42 +74,3 @@ printf("argv[%d]=|%s|\n", i, argv[i]);
#if USENCS
void nrn2ncs_outputevent(int, double) {}
#endif

// moving following to src/oc/ockludge.cpp since on
// Darwin Kernel Version 8.9.1 on apple i686 (and the newest config.guess
// thinks it is a i386, but that is a different story)
// including mpi.h gives some errors like:
// /Users/hines/mpich2-1.0.5p4/instl/include/mpicxx.h:26:2: error: #error
// SEEK_SET is #defined but must not be for the C++ binding of MPI"

#if 0 && NRNMPI && DARWIN
// For DARWIN I do not really know the proper way to avoid
// dyld: lazy symbol binding failed: Symbol not found: _MPI_Init
// when the MPI functions are all used in the libnrnmpi.dylib
// but the libmpi.a is statically linked. Therefore I am forcing
// the linking here by listing all the MPI functions being used.
#include <mpi.h>
static void work_around() {
MPI_Comm c = MPI_COMM_WORLD;
MPI_Init(0, 0);
MPI_Comm_rank(c, 0);
MPI_Comm_size(c, 0);
MPI_Wtime();
MPI_Finalize();
MPI_Unpack(0, 0, 0, 0, 0, 0, c);
MPI_Pack(0, 0, 0, 0, 0, 0, c);
MPI_Pack_size(0, 0, c, 0);
MPI_Send(0,0,0,0,0,c);
MPI_Probe(0, 0, c, 0);
MPI_Get_count(0, 0, 0);
MPI_Recv(0,0,0,0,0,c,0);
MPI_Sendrecv(0,0,0,0,0,0,0,0,0,0,c,0);
MPI_Iprobe(0,0,c,0,0);
MPI_Get_address(0,0);
MPI_Type_create_struct(0,0,0,0,0);
MPI_Type_commit(0);
MPI_Allgather(0,0,0,0,0,0,c);
MPI_Allgatherv(0,0,0,0,0,0,0,c);
MPI_Allreduce(0,0,0,0,0,c);
}
#endif
51 changes: 2 additions & 49 deletions src/nrniv/nvector_nrnparallel_ld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,11 @@
#include <stdio.h>
#include <stdlib.h>

/* for NRNMPI_DYNAMICLOAD */
#include <nrnmpiuse.h>
#if NRNMPI_DYNAMICLOAD
extern "C" void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type);
extern "C" void nrnmpi_longdbl_allreduce_vec(long double* src,
long double* dest,
int cnt,
int type);
extern "C" void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type);
#include <nrnmpidec.h>
extern int nrnmpi_numprocs;
#endif

#include "nvector_nrnparallel_ld.h"
#if NRNMPI_DYNAMICLOAD
#else
extern MPI_Comm nrnmpi_comm;
#endif
#include "sundialsmath.h"
#include "sundialstypes.h"

Expand Down Expand Up @@ -97,12 +85,7 @@ N_Vector N_VNewEmpty_NrnParallelLD(MPI_Comm comm, long int local_length, long in

/* Compute global length as sum of local lengths */
n = local_length;
#if NRNMPI_DYNAMICLOAD
nrnmpi_long_allreduce_vec(&n, &Nsum, 1, 1);
#else
comm = nrnmpi_comm;
MPI_Allreduce(&n, &Nsum, 1, MPI_LONG, MPI_SUM, comm);
#endif
if (Nsum != global_length) {
printf(BAD_N);
return (NULL);
Expand Down Expand Up @@ -428,11 +411,7 @@ void N_VSpace_NrnParallelLD(N_Vector v, long int* lrw, long int* liw) {
int npes;

comm = NV_COMM_P_LD(v);
#if NRNMPI_DYNAMICLOAD
npes = nrnmpi_numprocs;
#else
MPI_Comm_size(comm, &npes);
#endif

*lrw = NV_GLOBLENGTH_P_LD(v);
*liw = 2 * npes;
Expand Down Expand Up @@ -905,31 +884,9 @@ static realtype VAllReduce_NrnParallelLD(realtype d, int op, MPI_Comm comm) {
* min if op = 3.
* The operation is over all processors in the communicator
*/

realtype out = 0.0;

#if NRNMPI_DYNAMICLOAD
nrnmpi_dbl_allreduce_vec(&d, &out, 1, op);
#else
switch (op) {
case 1:
MPI_Allreduce(&d, &out, 1, MPI_DOUBLE, MPI_SUM, comm);
break;

case 2:
MPI_Allreduce(&d, &out, 1, MPI_DOUBLE, MPI_MAX, comm);
break;

case 3:
MPI_Allreduce(&d, &out, 1, MPI_DOUBLE, MPI_MIN, comm);
break;

default:
break;
}
#endif

return (out);
return out;
}

static realtype VAllReduce_long_NrnParallelLD(realtype d, int op, MPI_Comm comm) {
Expand All @@ -942,11 +899,7 @@ static realtype VAllReduce_long_NrnParallelLD(realtype d, int op, MPI_Comm comm)
*/
assert(op == 1);
long double ld_in{d}, ld_out{};
#if NRNMPI_DYNAMICLOAD
nrnmpi_longdbl_allreduce_vec(&ld_in, &ld_out, 1, op);
#else
MPI_Allreduce(&ld_in, &ld_out, 1, MPI_LONG_DOUBLE, MPI_SUM, comm);
#endif
return ld_out;
}

Expand Down
8 changes: 1 addition & 7 deletions src/nrniv/nvector_nrnparallel_ld.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ mv temp nvector_nrnparallel_ld.cpp


#include <nrnmpiuse.h>
#if NRNMPI_DYNAMICLOAD
#define MPI_DOUBLE double
#define MPI_LONG long
#define MPI_Comm int
#else
#include <mpi.h>
#endif
#define MPI_Comm int

#include "nvector.h"
#include "sundialstypes.h"
Expand Down
3 changes: 1 addition & 2 deletions src/nrnmpi/mpispike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,10 @@ double nrnmpi_dbl_allreduce(double x, int type) {
}

extern "C" void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type) {
int i;
MPI_Op t;
assert(src != dest);
if (nrnmpi_numprocs < 2) {
for (i = 0; i < cnt; ++i) {
for (int i = 0; i < cnt; ++i) {
dest[i] = src[i];
}
return;
Expand Down
6 changes: 3 additions & 3 deletions src/nrnmpi/nrnmpi_dynam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void* load_nrnmpi(const char* name, std::string& mes) {
return handle;
}

std::string nrnmpi_load(int is_python) {
std::string nrnmpi_load() {
std::string pmes;
void* handle = nullptr;
// If libmpi already in memory, find name and dlopen that.
Expand Down Expand Up @@ -255,8 +255,8 @@ std::string nrnmpi_load(int is_python) {
// nrnmpi_load cannot safely be called from nrnmpi.cpp because of pre/post-C++11
// ABI compatibility issues with std::string. See
// https://github.com/neuronsimulator/nrn/issues/1963 for more information.
void nrnmpi_load_or_exit(bool is_python) {
auto const err = nrnmpi_load(is_python);
void nrnmpi_load_or_exit() {
auto const err = nrnmpi_load();
if (!err.empty()) {
std::cout << err << std::endl;
std::exit(1);
Expand Down
4 changes: 3 additions & 1 deletion src/nrnmpi/nrnmpidec.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ the prototypes be of the form "type foo(type arg, ...)"
#define nrnmpidec_h
#include <nrnmpiuse.h>
#include <cstdint>
typedef long double longdbl;
using longdbl = long double;
#if NRNMPI
#include <stdlib.h>
#include <string>
Expand All @@ -22,6 +22,8 @@ typedef struct bbsmpibuf {
int refcount;
} bbsmpibuf;

struct NRNMPI_Spike;

// olupton 2022-07-06: dynamic MPI needs to dlopen some of these (slightly
// redefined) symbol names, so keep C linkage for simplicity
extern "C" {
Expand Down
Loading

0 comments on commit 094bd39

Please sign in to comment.