From 1e8e707351b080befdea3a5c8b5d94fd2f5cca4e Mon Sep 17 00:00:00 2001 From: adamjhn Date: Tue, 15 Aug 2023 21:33:09 +0200 Subject: [PATCH 1/3] Bugfix: Update rxd currents when the model structure is changed. (#2320) --- share/lib/python/neuron/rxd/initializer.py | 9 ++++--- share/lib/python/neuron/rxd/rxd.py | 6 +++-- share/lib/python/neuron/rxdtests/do_test.py | 11 ++++++--- src/nrnpython/rxd.cpp | 3 +-- test/rxd/conftest.py | 7 ++++++ test/rxd/test_currents.py | 27 +++++++++++++++++++++ test/rxd/testdata | 2 +- test/rxd/testutils.py | 11 ++++++--- 8 files changed, 62 insertions(+), 14 deletions(-) diff --git a/share/lib/python/neuron/rxd/initializer.py b/share/lib/python/neuron/rxd/initializer.py index 1db3a2faab..40f7c1eb86 100644 --- a/share/lib/python/neuron/rxd/initializer.py +++ b/share/lib/python/neuron/rxd/initializer.py @@ -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() @@ -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(): diff --git a/share/lib/python/neuron/rxd/rxd.py b/share/lib/python/neuron/rxd/rxd.py index 8449de0a27..4c382b7ad3 100644 --- a/share/lib/python/neuron/rxd/rxd.py +++ b/share/lib/python/neuron/rxd/rxd.py @@ -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): diff --git a/share/lib/python/neuron/rxdtests/do_test.py b/share/lib/python/neuron/rxdtests/do_test.py index 70dbafb052..03654a5b3b 100644 --- a/share/lib/python/neuron/rxdtests/do_test.py +++ b/share/lib/python/neuron/rxdtests/do_test.py @@ -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 diff --git a/src/nrnpython/rxd.cpp b/src/nrnpython/rxd.cpp index ded394b1a3..a182438174 100644 --- a/src/nrnpython/rxd.cpp +++ b/src/nrnpython/rxd.cpp @@ -483,7 +483,6 @@ extern "C" void set_setup_matrices(fptr setup_matrices) { extern "C" void set_setup_units(fptr setup_units) { _setup_units = setup_units; - _setup_units(); } /* nrn_tree_solve modified from nrnoc/ldifus.c */ @@ -884,7 +883,7 @@ extern "C" void register_rate(int nspecies, } else { react->vptrs = NULL; } - react->state_idx = (int***) malloc(nseg * sizeof(double**)); + react->state_idx = (int***) malloc(nseg * sizeof(int**)); for (i = 0, idx = 0; i < nseg; i++) { react->state_idx[i] = (int**) malloc((nspecies + nparam) * sizeof(int*)); for (j = 0; j < nspecies + nparam; j++) { diff --git a/test/rxd/conftest.py b/test/rxd/conftest.py index 77d315f98d..40768662a9 100644 --- a/test/rxd/conftest.py +++ b/test/rxd/conftest.py @@ -67,11 +67,18 @@ def neuron_nosave_instance(neuron_import): s().__del__() gc.enable() rxd.region._all_regions = [] + rxd.rxd.node._states = numpy.array([]) + rxd.rxd.node._volumes = numpy.array([]) + rxd.rxd.node._surface_area = numpy.array([]) + rxd.rxd.node._diffs = numpy.array([]) + rxd.rxd.node._states = numpy.array([]) rxd.region._region_count = 0 rxd.region._c_region_lookup = None rxd.species._species_counts = 0 rxd.section1d._purge_cptrs() rxd.initializer.has_initialized = False + rxd.initializer.is_initializing = False + rxd.rxd.last_nrn_legacy_units = False rxd.rxd.free_conc_ptrs() rxd.rxd.free_curr_ptrs() rxd.rxd.rxd_include_node_flux1D(0, None, None, None) diff --git a/test/rxd/test_currents.py b/test/rxd/test_currents.py index 4415fae8f0..6443190f5d 100644 --- a/test/rxd/test_currents.py +++ b/test/rxd/test_currents.py @@ -87,3 +87,30 @@ def test_currents_cvode(model_pump): if not save_path: max_err = compare_data(data) assert max_err < tol + + +def test_currents_stucture_change(model_pump): + """Test currents generated by a Na/K-pump with change to structure""" + + neuron_instance, model = model_pump + h, rxd, data, save_path = neuron_instance + # check changing structure_change_cnt after initialization + h.finitialize(-65) + h.MechanismStandard("pas", 0) + h.continuerun(10) + if not save_path: + max_err = compare_data(data) + assert max_err < tol + + +def test_currents_model_change(model_pump): + """Test currents generated by a Na/K-pump with post-initialization changes to the model""" + neuron_instance, model = model_pump + h, rxd, data, save_path = neuron_instance + # check changing the model after initialization + h.finitialize(-65) + model[0].nseg = 11 + h.continuerun(10) + if not save_path: + max_err = compare_data(data) + assert max_err < tol diff --git a/test/rxd/testdata b/test/rxd/testdata index be297655ab..e531eaa704 160000 --- a/test/rxd/testdata +++ b/test/rxd/testdata @@ -1 +1 @@ -Subproject commit be297655abf0f98be95a051576d43aad23cebbf0 +Subproject commit e531eaa704108fd1c880905484a28c15e5402e59 diff --git a/test/rxd/testutils.py b/test/rxd/testutils.py index 7e1683337e..2c8ca2670c 100644 --- a/test/rxd/testutils.py +++ b/test/rxd/testutils.py @@ -63,9 +63,14 @@ def collect_data(h, rxd, data, save_path, num_record=10): 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) if data["record_count"] == 2: From 7f0c2914ec5a5d6ff351cf8d60185429c60bc51f Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 16 Aug 2023 10:29:31 +0200 Subject: [PATCH 2/3] Handle dynamic vs. static MPI only inside nrnmpi Currently we consider dynamic MPI both inside nrnmpi as well as throughout the code (using the NRNMPI_DYNAMICLOAD macro). This PR should remove NRNMPI_DYNAMICLOAD from the rest of the code and access MPI routines through one API. Inside nrnmpi we can then provide both static and dynamic loading. Co-authored-by: nrnhines --- src/ivoc/ivocmain.cpp | 27 -------------- src/ivoc/nrnmain.cpp | 45 ----------------------- src/nrniv/nvector_nrnparallel_ld.cpp | 51 +------------------------- src/nrniv/nvector_nrnparallel_ld.h | 8 +--- src/nrnmpi/mpispike.cpp | 3 +- src/nrnmpi/nrnmpidec.h | 4 +- src/oc/nrnmpi.h | 4 +- src/sundials/shared/nvector_parallel.c | 34 ----------------- src/sundials/shared/nvector_parallel.h | 6 --- 9 files changed, 9 insertions(+), 173 deletions(-) diff --git a/src/ivoc/ivocmain.cpp b/src/ivoc/ivocmain.cpp index 3907dba074..8f5cf346d1 100644 --- a/src/ivoc/ivocmain.cpp +++ b/src/ivoc/ivocmain.cpp @@ -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 @@ -314,16 +305,6 @@ 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) { @@ -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: diff --git a/src/ivoc/nrnmain.cpp b/src/ivoc/nrnmain.cpp index 8fdc510a9b..153e9d4559 100644 --- a/src/ivoc/nrnmain.cpp +++ b/src/ivoc/nrnmain.cpp @@ -27,12 +27,6 @@ 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(); @@ -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 -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 diff --git a/src/nrniv/nvector_nrnparallel_ld.cpp b/src/nrniv/nvector_nrnparallel_ld.cpp index 7c2448f04b..ffa410c0fe 100644 --- a/src/nrniv/nvector_nrnparallel_ld.cpp +++ b/src/nrniv/nvector_nrnparallel_ld.cpp @@ -21,23 +21,11 @@ #include #include -/* for NRNMPI_DYNAMICLOAD */ #include -#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 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" @@ -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); @@ -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; @@ -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) { @@ -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; } diff --git a/src/nrniv/nvector_nrnparallel_ld.h b/src/nrniv/nvector_nrnparallel_ld.h index 89508a7c68..4684857d45 100644 --- a/src/nrniv/nvector_nrnparallel_ld.h +++ b/src/nrniv/nvector_nrnparallel_ld.h @@ -65,13 +65,7 @@ mv temp nvector_nrnparallel_ld.cpp #include -#if NRNMPI_DYNAMICLOAD -#define MPI_DOUBLE double -#define MPI_LONG long -#define MPI_Comm int -#else -#include -#endif +#define MPI_Comm int #include "nvector.h" #include "sundialstypes.h" diff --git a/src/nrnmpi/mpispike.cpp b/src/nrnmpi/mpispike.cpp index 920421d008..317f27f7b9 100644 --- a/src/nrnmpi/mpispike.cpp +++ b/src/nrnmpi/mpispike.cpp @@ -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; diff --git a/src/nrnmpi/nrnmpidec.h b/src/nrnmpi/nrnmpidec.h index 979152bc8a..883f0b8924 100644 --- a/src/nrnmpi/nrnmpidec.h +++ b/src/nrnmpi/nrnmpidec.h @@ -7,7 +7,7 @@ the prototypes be of the form "type foo(type arg, ...)" #define nrnmpidec_h #include #include -typedef long double longdbl; +using longdbl = long double; #if NRNMPI #include #include @@ -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" { diff --git a/src/oc/nrnmpi.h b/src/oc/nrnmpi.h index c18669d8f4..259e4fa094 100644 --- a/src/oc/nrnmpi.h +++ b/src/oc/nrnmpi.h @@ -14,10 +14,10 @@ extern int nrnmpi_myid; /* rank in subworld */ extern int nrnmpi_numprocs_bbs; /* number of subworlds */ extern int nrnmpi_myid_bbs; /* rank in nrn_bbs_comm of rank 0 of a subworld */ -typedef struct { +struct NRNMPI_Spike { int gid; double spiketime; -} NRNMPI_Spike; +}; #if NRNMPI diff --git a/src/sundials/shared/nvector_parallel.c b/src/sundials/shared/nvector_parallel.c index 92aff83d31..6b843651e0 100755 --- a/src/sundials/shared/nvector_parallel.c +++ b/src/sundials/shared/nvector_parallel.c @@ -19,19 +19,12 @@ #include #include -/* for NRNMPI_DYNAMICLOAD */ #include -#if NRNMPI_DYNAMICLOAD extern void nrnmpi_dbl_allreduce_vec(double* src, double* dest, int cnt, int type); extern void nrnmpi_long_allreduce_vec(long* src, long* dest, int cnt, int type); extern int nrnmpi_numprocs; -#endif #include "nvector_parallel.h" -#if NRNMPI_DYNAMICLOAD -#else -extern MPI_Comm nrnmpi_comm; -#endif #include "sundialsmath.h" #include "sundialstypes.h" @@ -92,12 +85,7 @@ N_Vector N_VNewEmpty_Parallel(MPI_Comm comm, /* 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, PVEC_INTEGER_MPI_TYPE, MPI_SUM, comm); -#endif if (Nsum != global_length) { printf(BAD_N); return(NULL); @@ -411,11 +399,7 @@ void N_VSpace_Parallel(N_Vector v, long int *lrw, long int *liw) int npes; comm = NV_COMM_P(v); -#if NRNMPI_DYNAMICLOAD npes = nrnmpi_numprocs; -#else - MPI_Comm_size(comm, &npes); -#endif *lrw = NV_GLOBLENGTH_P(v); *liw = 2 * npes; @@ -881,26 +865,8 @@ static realtype VAllReduce_Parallel(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, PVEC_REAL_MPI_TYPE, MPI_SUM, comm); - break; - - case 2: MPI_Allreduce(&d, &out, 1, PVEC_REAL_MPI_TYPE, MPI_MAX, comm); - break; - - case 3: MPI_Allreduce(&d, &out, 1, PVEC_REAL_MPI_TYPE, MPI_MIN, comm); - break; - - default: break; - } -#endif - return(out); } diff --git a/src/sundials/shared/nvector_parallel.h b/src/sundials/shared/nvector_parallel.h index 9e0ccc688f..8eaa2a0efe 100755 --- a/src/sundials/shared/nvector_parallel.h +++ b/src/sundials/shared/nvector_parallel.h @@ -49,13 +49,7 @@ #ifndef _NVECTOR_PARALLEL_H #define _NVECTOR_PARALLEL_H -#if NRNMPI_DYNAMICLOAD -#define MPI_DOUBLE double -#define MPI_LONG long #define MPI_Comm int -#else -#include -#endif #if defined(__cplusplus) extern "C" { From df99e4cc09652ec948542154c3d84c076b17819e Mon Sep 17 00:00:00 2001 From: Nicolas Cornu Date: Wed, 16 Aug 2023 14:51:54 +0200 Subject: [PATCH 3/3] HAVE_STL is always true (#2464) --- cmake/ConfigFileSetting.cmake | 3 --- cmake_nrnconf.h.in | 3 --- src/parallel/bbsclimpi.cpp | 17 ------------ src/parallel/bbsconf.h.in | 3 --- src/parallel/bbsdirectmpi.cpp | 18 ------------- src/parallel/bbslocal.cpp | 16 ----------- src/parallel/bbslsrv.cpp | 50 ----------------------------------- src/parallel/bbssrv2mpi.cpp | 49 ---------------------------------- 8 files changed, 159 deletions(-) diff --git a/cmake/ConfigFileSetting.cmake b/cmake/ConfigFileSetting.cmake index 9a8dbbed80..df997e11c0 100644 --- a/cmake/ConfigFileSetting.cmake +++ b/cmake/ConfigFileSetting.cmake @@ -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}) @@ -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 diff --git a/cmake_nrnconf.h.in b/cmake_nrnconf.h.in index c9ad0198c4..cb84789c33 100644 --- a/cmake_nrnconf.h.in +++ b/cmake_nrnconf.h.in @@ -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 header file. */ #undef HAVE_STDARG_H diff --git a/src/parallel/bbsclimpi.cpp b/src/parallel/bbsclimpi.cpp index 61387bbc71..0b903e1f95 100644 --- a/src/parallel/bbsclimpi.cpp +++ b/src/parallel/bbsclimpi.cpp @@ -17,13 +17,7 @@ extern void nrnmpi_int_broadcast(int*, int, int); #define debug 0 -#if defined(HAVE_STL) -#if defined(HAVE_SSTREAM) // the standard ... #include -#else -#include -#include -#endif struct ltint { bool operator()(int i, int j) const { @@ -33,8 +27,6 @@ struct ltint { class KeepArgs: public std::map {}; -#endif - int BBSClient::sid_; BBSClient::BBSClient() { @@ -42,9 +34,7 @@ BBSClient::BBSClient() { recvbuf_ = nil; request_ = nrnmpi_newbuf(100); nrnmpi_ref(request_); -#if defined(HAVE_STL) keepargs_ = new KeepArgs(); -#endif BBSClient::start(); } @@ -52,9 +42,7 @@ BBSClient::~BBSClient() { nrnmpi_unref(sendbuf_); nrnmpi_unref(recvbuf_); nrnmpi_unref(request_); -#if defined(HAVE_STL) delete keepargs_; -#endif } void BBSClient::perror(const char* s) { @@ -267,16 +255,12 @@ int BBSClient::look_take_result(int pid) { } void BBSClient::save_args(int userid) { -#if defined(HAVE_STL) nrnmpi_ref(sendbuf_); keepargs_->insert(std::pair(userid, sendbuf_)); - -#endif post_todo(working_id_); } void BBSClient::return_args(int userid) { -#if defined(HAVE_STL) KeepArgs::iterator i = keepargs_->find(userid); nrnmpi_unref(recvbuf_); recvbuf_ = nil; @@ -287,7 +271,6 @@ void BBSClient::return_args(int userid) { upkbegin(); BBSImpl::return_args(userid); } -#endif } void BBSClient::done() { diff --git a/src/parallel/bbsconf.h.in b/src/parallel/bbsconf.h.in index d139df47c9..3d343efae0 100755 --- a/src/parallel/bbsconf.h.in +++ b/src/parallel/bbsconf.h.in @@ -1,9 +1,6 @@ #ifndef H_bbsconfig_included #define H_bbsconfig_included 1 -/* following are relevant to src/parallel implmentation of ParallelContext */ -/* Set to 1 if the standard template library exists */ -#undef HAVE_STL /* Set to 1 if SIGPOLL is a possible signal */ #undef HAVE_SIGPOLL diff --git a/src/parallel/bbsdirectmpi.cpp b/src/parallel/bbsdirectmpi.cpp index fc1e4f67e5..3230b4c744 100644 --- a/src/parallel/bbsdirectmpi.cpp +++ b/src/parallel/bbsdirectmpi.cpp @@ -14,13 +14,7 @@ extern void nrnmpi_int_broadcast(int*, int, int); -#if defined(HAVE_STL) -#if defined(HAVE_SSTREAM) // the standard ... #include -#else -#include -#include -#endif #define debug 0 @@ -32,9 +26,6 @@ struct ltint { class KeepArgs: public std::map {}; -#endif - - BBSDirect::BBSDirect() { if (!BBSDirectServer::server_) { BBSDirectServer::server_ = new BBSDirectServer(); @@ -42,17 +33,13 @@ BBSDirect::BBSDirect() { sendbuf_ = nil; recvbuf_ = nil; BBSDirect::start(); -#if defined(HAVE_STL) keepargs_ = new KeepArgs(); -#endif } BBSDirect::~BBSDirect() { nrnmpi_unref(sendbuf_); nrnmpi_unref(recvbuf_); -#if defined(HAVE_STL) delete keepargs_; -#endif } void BBSDirect::perror(const char* s) { @@ -263,16 +250,12 @@ int BBSDirect::master_take_result(int pid) { } void BBSDirect::save_args(int userid) { -#if defined(HAVE_STL) nrnmpi_ref(sendbuf_); keepargs_->insert(std::pair(userid, sendbuf_)); - -#endif post_todo(working_id_); } void BBSDirect::return_args(int userid) { -#if defined(HAVE_STL) KeepArgs::iterator i = keepargs_->find(userid); nrnmpi_unref(recvbuf_); recvbuf_ = nil; @@ -282,7 +265,6 @@ void BBSDirect::return_args(int userid) { nrnmpi_upkbegin(recvbuf_); BBSImpl::return_args(userid); } -#endif } bool BBSDirect::look_take(const char* key) { diff --git a/src/parallel/bbslocal.cpp b/src/parallel/bbslocal.cpp index 6d7a8688a6..948252d656 100644 --- a/src/parallel/bbslocal.cpp +++ b/src/parallel/bbslocal.cpp @@ -6,15 +6,9 @@ #include "bbslsrv.h" #include -#if defined(HAVE_STL) -#if defined(HAVE_SSTREAM) // the standard ... #include #include #include -#else -#include -#include -#endif struct ltint { bool operator()(int i, int j) const { @@ -24,8 +18,6 @@ struct ltint { class KeepArgs: public std::map {}; -#endif - static MessageValue* posting_; static MessageValue* taking_; static BBSLocalServer* server_; @@ -37,16 +29,12 @@ BBSLocal::BBSLocal() { taking_ = nil; } start(); -#if defined(HAVE_STL) keepargs_ = new KeepArgs(); -#endif } BBSLocal::~BBSLocal() { // need to unref anything in keepargs_; -#if defined(HAVE_STL) delete keepargs_; -#endif } void BBSLocal::context() {} @@ -218,14 +206,11 @@ int BBSLocal::take_todo() { void BBSLocal::save_args(int userid) { server_->post_todo(working_id_, posting_); -#if defined(HAVE_STL) keepargs_->insert(std::pair(userid, posting_)); -#endif posting_ = nil; } void BBSLocal::return_args(int userid) { -#if defined(HAVE_STL) KeepArgs::iterator i = keepargs_->find(userid); assert(i != keepargs_->end()); Resource::unref(taking_); @@ -233,7 +218,6 @@ void BBSLocal::return_args(int userid) { keepargs_->erase(i); taking_->init_unpack(); BBSImpl::return_args(userid); -#endif } void BBSLocal::done() { diff --git a/src/parallel/bbslsrv.cpp b/src/parallel/bbslsrv.cpp index 402423dd4a..8880139bb3 100644 --- a/src/parallel/bbslsrv.cpp +++ b/src/parallel/bbslsrv.cpp @@ -11,18 +11,9 @@ #define VECTOR 4 #define PICKLE 5 -#if defined(HAVE_STL) -#if defined(HAVE_SSTREAM) // the standard ... #include #include #include -#else -#include -#include -#include -#include -#include -#endif // debug is 0 1 or 2 #define debug 0 @@ -99,15 +90,6 @@ class MessageList: public std::multimap class WorkList: public std::map {}; class ReadyList: public std::set {}; class ResultList: public std::multimap {}; -#else -class MessageList {}; -class WorkList {}; -class ReadyList {}; -class ResultList {}; -static void nostl() { - hoc_execerror("BBSLocalServer not working", "Compiled without STL"); -} -#endif MessageItem::MessageItem() { next_ = nil; @@ -250,17 +232,14 @@ int MessageValue::upkpickle(char* s, size_t* n) { } BBSLocalServer::BBSLocalServer() { -#if defined(HAVE_STL) messages_ = new MessageList(); work_ = new WorkList(); todo_ = new ReadyList(); results_ = new ResultList(); next_id_ = 1; -#endif } BBSLocalServer::~BBSLocalServer() { -#if defined(HAVE_STL) delete todo_; delete results_; @@ -268,11 +247,9 @@ BBSLocalServer::~BBSLocalServer() { // need to unref MessageValue in messages_ and delete WorkItem in work_ delete messages_; delete work_; -#endif } bool BBSLocalServer::look_take(const char* key, MessageValue** val) { -#if defined(HAVE_STL) MessageList::iterator m = messages_->find(key); if (m != messages_->end()) { *val = (MessageValue*) ((*m).second); @@ -286,15 +263,11 @@ bool BBSLocalServer::look_take(const char* key, MessageValue** val) { } #if debug printf("fail srvr_look_take |%s|\n", key); -#endif -#else - nostl(); #endif return false; } bool BBSLocalServer::look(const char* key, MessageValue** val) { -#if defined(HAVE_STL) MessageList::iterator m = messages_->find(key); if (m != messages_->end()) { *val = (MessageValue*) ((*m).second); @@ -308,28 +281,20 @@ bool BBSLocalServer::look(const char* key, MessageValue** val) { } #if debug printf("srvr_look false |%s|\n", key); -#endif -#else - nostl(); #endif return false; } void BBSLocalServer::post(const char* key, MessageValue* val) { -#if defined(HAVE_STL) MessageList::iterator m = messages_->insert( std::pair(newstr(key), val)); Resource::ref(val); #if debug printf("srvr_post |%s|\n", key); #endif -#else - nostl(); -#endif } void BBSLocalServer::post_todo(int parentid, MessageValue* val) { -#if defined(HAVE_STL) WorkItem* w = new WorkItem(next_id_++, val); WorkList::iterator p = work_->find(parentid); if (p != work_->end()) { @@ -340,13 +305,9 @@ void BBSLocalServer::post_todo(int parentid, MessageValue* val) { #if debug printf("srvr_post_todo id=%d pid=%d\n", w->id_, parentid); #endif -#else - nostl(); -#endif } void BBSLocalServer::post_result(int id, MessageValue* val) { -#if defined(HAVE_STL) WorkList::iterator i = work_->find(id); WorkItem* w = (WorkItem*) ((*i).second); val->ref(); @@ -356,11 +317,9 @@ void BBSLocalServer::post_result(int id, MessageValue* val) { #if debug printf("srvr_post_done id=%d pid=%d\n", id, w->parent_ ? w->parent_->id_ : 0); #endif -#endif } int BBSLocalServer::look_take_todo(MessageValue** m) { -#if defined(HAVE_STL) ReadyList::iterator i = todo_->begin(); if (i != todo_->end()) { WorkItem* w = (*i); @@ -377,14 +336,9 @@ int BBSLocalServer::look_take_todo(MessageValue** m) { #endif return 0; } -#else - nostl(); - return 0; -#endif } int BBSLocalServer::look_take_result(int pid, MessageValue** m) { -#if defined(HAVE_STL) ResultList::iterator i = results_->find(pid); if (i != results_->end()) { WorkItem* w = (WorkItem*) ((*i).second); @@ -405,8 +359,4 @@ int BBSLocalServer::look_take_result(int pid, MessageValue** m) { #endif return 0; } -#else - nostl(); - return 0; -#endif } diff --git a/src/parallel/bbssrv2mpi.cpp b/src/parallel/bbssrv2mpi.cpp index 8a624ede13..5110424bca 100644 --- a/src/parallel/bbssrv2mpi.cpp +++ b/src/parallel/bbssrv2mpi.cpp @@ -14,17 +14,8 @@ void nrnbbs_context_wait(); BBSDirectServer* BBSDirectServer::server_; -#if defined(HAVE_STL) -#if defined(HAVE_SSTREAM) // the standard ... #include #include -#else -#include -#include -#include -#include -#include -#endif #define debug 0 @@ -109,17 +100,8 @@ class WorkList: public std::map {}; class LookingToDoList: public std::set {}; class ReadyList: public std::set {}; class ResultList: public std::multimap {}; -#else -class MessageList {}; -class PendingList {}; -class WorkList {}; -class LookingToDoList {}; -class ReadyList {}; -class ResultList {}; -#endif BBSDirectServer::BBSDirectServer() { -#if defined(HAVE_STL) messages_ = new MessageList(); work_ = new WorkList(); todo_ = new ReadyList(); @@ -130,11 +112,9 @@ BBSDirectServer::BBSDirectServer() { next_id_ = FIRSTID; context_buf_ = nil; remaining_context_cnt_ = 0; -#endif } BBSDirectServer::~BBSDirectServer() { -#if defined(HAVE_STL) delete todo_; delete results_; delete looking_todo_; @@ -144,7 +124,6 @@ BBSDirectServer::~BBSDirectServer() { delete messages_; delete work_; delete send_context_; -#endif } bool BBSDirectServer::look_take(const char* key, bbsmpibuf** recv) { @@ -152,7 +131,6 @@ bool BBSDirectServer::look_take(const char* key, bbsmpibuf** recv) { printf("DirectServer::look_take |%s|\n", key); #endif bool b = false; -#if defined(HAVE_STL) nrnmpi_unref(*recv); *recv = nil; MessageList::iterator m = messages_->find(key); @@ -166,7 +144,6 @@ bool BBSDirectServer::look_take(const char* key, bbsmpibuf** recv) { } #if debug printf("DirectServer::look_take |%s| recv=%p return %d\n", key, (*recv), b); -#endif #endif return b; } @@ -178,7 +155,6 @@ bool BBSDirectServer::look(const char* key, bbsmpibuf** recv) { bool b = false; nrnmpi_unref(*recv); *recv = nil; -#if defined(HAVE_STL) MessageList::iterator m = messages_->find(key); if (m != messages_->end()) { b = true; @@ -189,24 +165,20 @@ bool BBSDirectServer::look(const char* key, bbsmpibuf** recv) { } #if debug printf("DirectServer::look |%s| recv=%p return %d\n", key, (*recv), b); -#endif #endif return b; } void BBSDirectServer::put_pending(const char* key, int cid) { -#if defined(HAVE_STL) #if debug printf("put_pending |%s| %d\n", key, cid); #endif char* s = newstr(key); pending_->insert(std::pair(s, cid)); -#endif } bool BBSDirectServer::take_pending(const char* key, int* cid) { bool b = false; -#if defined(HAVE_STL) PendingList::iterator p = pending_->find(key); if (p != pending_->end()) { *cid = (*p).second; @@ -218,12 +190,10 @@ bool BBSDirectServer::take_pending(const char* key, int* cid) { delete[] s; b = true; } -#endif return b; } void BBSDirectServer::post(const char* key, bbsmpibuf* send) { -#if defined(HAVE_STL) int cid; #if debug printf("DirectServer::post |%s| send=%p\n", key, send); @@ -235,17 +205,13 @@ void BBSDirectServer::post(const char* key, bbsmpibuf* send) { std::pair(newstr(key), send)); nrnmpi_ref(send); } -#endif } void BBSDirectServer::add_looking_todo(int cid) { -#if defined(HAVE_STL) looking_todo_->insert(cid); -#endif } void BBSDirectServer::post_todo(int pid, int cid, bbsmpibuf* send) { -#if defined(HAVE_STL) #if debug printf("BBSDirectServer::post_todo pid=%d cid=%d send=%p\n", pid, cid, send); #endif @@ -271,11 +237,9 @@ void BBSDirectServer::post_todo(int pid, int cid, bbsmpibuf* send) { #endif todo_->insert(w); } -#endif } void BBSDirectServer::context(bbsmpibuf* send) { -#if defined(HAVE_STL) int cid, j; #if debug printf("numprocs_bbs=%d\n", nrnmpi_numprocs_bbs); @@ -315,7 +279,6 @@ void BBSDirectServer::context(bbsmpibuf* send) { nrnmpi_ref(context_buf_); handle(); } -#endif } void nrnbbs_context_wait() { @@ -333,7 +296,6 @@ void BBSDirectServer::context_wait() { } bool BBSDirectServer::send_context(int cid) { -#if defined(HAVE_STL) LookingToDoList::iterator i = send_context_->find(cid); if (i != send_context_->end()) { send_context_->erase(i); @@ -347,12 +309,10 @@ bool BBSDirectServer::send_context(int cid) { } return true; } -#endif return false; } void BBSDirectServer::post_result(int id, bbsmpibuf* send) { -#if defined(HAVE_STL) #if debug printf("DirectServer::post_result id=%d send=%p\n", id, send); #endif @@ -362,11 +322,9 @@ void BBSDirectServer::post_result(int id, bbsmpibuf* send) { nrnmpi_unref(w->buf_); w->buf_ = send; results_->insert(std::pair(w->parent_ ? w->parent_->id_ : 0, w)); -#endif } int BBSDirectServer::look_take_todo(bbsmpibuf** recv) { -#if defined(HAVE_STL) #if debug printf("DirectServer::look_take_todo\n"); #endif @@ -388,16 +346,12 @@ int BBSDirectServer::look_take_todo(bbsmpibuf** recv) { } else { return 0; } -#else - return 0; -#endif } int BBSDirectServer::look_take_result(int pid, bbsmpibuf** recv) { #if debug printf("DirectServer::look_take_result pid=%d\n", pid); #endif -#if defined(HAVE_STL) nrnmpi_unref(*recv); *recv = nil; ResultList::iterator i = results_->find(pid); @@ -416,9 +370,6 @@ int BBSDirectServer::look_take_result(int pid, bbsmpibuf** recv) { } else { return 0; } -#else - return 0; -#endif } #endif // NRNMPI