From ee108efd5c5ef5e984f55bd9939fcba7e9a29478 Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Tue, 1 Nov 2022 14:42:14 +0100 Subject: [PATCH 1/4] Bump submodule past iv#45. --- external/iv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/iv b/external/iv index 24df191936..52e1946edf 160000 --- a/external/iv +++ b/external/iv @@ -1 +1 @@ -Subproject commit 24df191936b1c634eda706775e199f256639d2da +Subproject commit 52e1946edf8f9b607ea180387b40093f1dd3ee5b From 69d0565eded6b57d7b861138724194b826ade8aa Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Tue, 1 Nov 2022 14:42:32 +0100 Subject: [PATCH 2/4] PyObject_HEAD contains an ; --- .clang-format.changes | 2 +- src/nrnpython/nrn_pyhocobject.h | 3 ++- src/nrnpython/nrnpy_hoc.cpp | 3 ++- src/nrnpython/nrnpy_nrn.cpp | 27 ++++++++++++++++++--------- src/nrnpython/nrnpy_p2h.cpp | 3 ++- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.clang-format.changes b/.clang-format.changes index 2dfdcb6540..511d5f916c 100644 --- a/.clang-format.changes +++ b/.clang-format.changes @@ -1,6 +1,6 @@ SortIncludes: false Standard: c++17 -StatementMacros: [MKDLL, MKDLLdec, MKDLLif, MKDLLvp, MKDLLvpf, +StatementMacros: [MKDLL, MKDLLdec, MKDLLif, MKDLLvp, MKDLLvpf, PyObject_HEAD, declareActionCallback, declareAdjustStepper, declareArrowGlyph, declareFieldEditorCallback, declareFieldSEditorCallback, declareFileChooserCallback, declareIOCallback, declareList, declarePool, declarePtrList, declareRubberCallback, declareSelectionCallback, declareTable, declareTable2, diff --git a/src/nrnpython/nrn_pyhocobject.h b/src/nrnpython/nrn_pyhocobject.h index dfc841819f..0c1db3eb68 100644 --- a/src/nrnpython/nrn_pyhocobject.h +++ b/src/nrnpython/nrn_pyhocobject.h @@ -4,7 +4,8 @@ struct Object; struct Symbol; struct PyHocObject { - PyObject_HEAD Object* ho_; + PyObject_HEAD + Object* ho_; union { double x_; char* s_; diff --git a/src/nrnpython/nrnpy_hoc.cpp b/src/nrnpython/nrnpy_hoc.cpp index 8b552a78d8..96f732258b 100644 --- a/src/nrnpython/nrnpy_hoc.cpp +++ b/src/nrnpython/nrnpy_hoc.cpp @@ -26,7 +26,8 @@ extern PyTypeObject* psection_type; // copied from nrnpy_nrn typedef struct { - PyObject_HEAD Section* sec_; + PyObject_HEAD + Section* sec_; char* name_; PyObject* cell_; } NPySecObj; diff --git a/src/nrnpython/nrnpy_nrn.cpp b/src/nrnpython/nrnpy_nrn.cpp index 451db4b5ac..535e92e3e8 100644 --- a/src/nrnpython/nrnpy_nrn.cpp +++ b/src/nrnpython/nrnpy_nrn.cpp @@ -28,50 +28,59 @@ double* nrnpy_rangepointer(Section*, Symbol*, double, int*); extern PyObject* nrn_ptr_richcmp(void* self_ptr, void* other_ptr, int op); extern int has_membrane(char*, Section*); typedef struct { - PyObject_HEAD Section* sec_; + PyObject_HEAD + Section* sec_; char* name_; PyObject* cell_weakref_; } NPySecObj; NPySecObj* newpysechelp(Section* sec); typedef struct { - PyObject_HEAD NPySecObj* pysec_; + PyObject_HEAD + NPySecObj* pysec_; int allseg_iter_; } NPyAllSegOfSecIter; typedef struct { - PyObject_HEAD NPySecObj* pysec_; + PyObject_HEAD + NPySecObj* pysec_; int seg_iter_; } NPySegOfSecIter; typedef struct { - PyObject_HEAD NPySecObj* pysec_; + PyObject_HEAD + NPySecObj* pysec_; double x_; } NPySegObj; typedef struct { - PyObject_HEAD NPySegObj* pyseg_; + PyObject_HEAD + NPySegObj* pyseg_; Prop* prop_; } NPyMechOfSegIter; typedef struct { - PyObject_HEAD NPySegObj* pyseg_; + PyObject_HEAD + NPySegObj* pyseg_; Prop* prop_; } NPyMechObj; typedef struct { - PyObject_HEAD NPyMechObj* pymech_; + PyObject_HEAD + NPyMechObj* pymech_; Symbol* msym_; int i_; } NPyVarOfMechIter; typedef struct { - PyObject_HEAD NPyMechObj* pymech_; + PyObject_HEAD + NPyMechObj* pymech_; int index_; } NPyRVItr; typedef struct { - PyObject_HEAD NPyMechObj* pymech_; + PyObject_HEAD + NPyMechObj* pymech_; Symbol* sym_; int isptr_; int attr_from_sec_; // so section.xraxial[0] = e assigns to all segments. diff --git a/src/nrnpython/nrnpy_p2h.cpp b/src/nrnpython/nrnpy_p2h.cpp index 54ae62a8a3..fdba4ca41d 100644 --- a/src/nrnpython/nrnpy_p2h.cpp +++ b/src/nrnpython/nrnpy_p2h.cpp @@ -48,7 +48,8 @@ extern char* (*nrnpy_callpicklef)(char*, size_t size, int narg, size_t* retsize) extern int (*nrnpy_pysame)(Object*, Object*); // contain same Python object extern Object* (*nrnpympi_alltoall_type)(int, int); typedef struct { - PyObject_HEAD Section* sec_; + PyObject_HEAD + Section* sec_; char* name_; PyObject* cell_; } NPySecObj; From 3fb93a0db15e5eaffe751d4d5dfb43cfda693446 Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Tue, 1 Nov 2022 14:47:36 +0100 Subject: [PATCH 3/4] drop nrn_isdouble --- cmake/CompilerHelper.cmake | 1 - cmake/NeuronFileLists.cmake | 2 -- src/ivoc/nrnmain.cpp | 2 -- src/nrnoc/treeset.cpp | 7 +++---- src/oc/isoc99.cpp | 27 --------------------------- src/oc/isoc99.h | 2 -- src/oc/ocmain.cpp | 2 -- 7 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 src/oc/isoc99.cpp delete mode 100644 src/oc/isoc99.h diff --git a/cmake/CompilerHelper.cmake b/cmake/CompilerHelper.cmake index 4ceb413db8..d1a23de983 100644 --- a/cmake/CompilerHelper.cmake +++ b/cmake/CompilerHelper.cmake @@ -24,7 +24,6 @@ if(CMAKE_C_COMPILER_ID MATCHES "PGI" OR CMAKE_C_COMPILER_ID MATCHES "NVHPC") # August 2021. It would clearly be nicer to apply these suppressions only to relevant files. # Examples of the suppressed warnings are given below. # ~~~ - # "src/oc/isoc99.h", warning #1-D: last line of file ends without a newline # "src/nrniv/nvector_nrnserial_ld.cpp", warning #47-D: incompatible redefinition of macro "..." # "src/nmodl/kinetic.cpp", warning #111-D: statement is unreachable # "src/nmodl/parsact.cpp", warning #128-D: loop is not reachable diff --git a/cmake/NeuronFileLists.cmake b/cmake/NeuronFileLists.cmake index 67209288f6..dd92a92161 100644 --- a/cmake/NeuronFileLists.cmake +++ b/cmake/NeuronFileLists.cmake @@ -13,7 +13,6 @@ set(HEADER_FILES_TO_INSTALL hocgetsym.h hoclist.h hocparse.h - isoc99.h ivstream.h mcran4.h md1redef.h @@ -79,7 +78,6 @@ set(OC_FILE_LIST hocusr.cpp hoc_init.cpp hoc_oop.cpp - isoc99.cpp list.cpp math.cpp mswinprt.cpp diff --git a/src/ivoc/nrnmain.cpp b/src/ivoc/nrnmain.cpp index f2612aa9b9..6bc0482624 100644 --- a/src/ivoc/nrnmain.cpp +++ b/src/ivoc/nrnmain.cpp @@ -1,4 +1,3 @@ -#include "isoc99.h" #include "nrnconf.h" #include "nrnmpi.h" #include "../nrncvode/nrnneosm.h" @@ -19,7 +18,6 @@ extern "C" void nrnmpi_init(int nrnmpi_under_nrncontrol, int* pargc, char*** par #endif int main(int argc, char** argv, char** env) { - nrn_isdouble(0, 0, 0); nrn_main_launch = 1; #if defined(AUTO_DLOPEN_NRNMECH) && AUTO_DLOPEN_NRNMECH == 0 diff --git a/src/nrnoc/treeset.cpp b/src/nrnoc/treeset.cpp index b6b78d4229..d7a788fdf4 100644 --- a/src/nrnoc/treeset.cpp +++ b/src/nrnoc/treeset.cpp @@ -2,7 +2,6 @@ /* /local/src/master/nrn/src/nrnoc/treeset.cpp,v 1.39 1999/07/08 14:25:07 hines Exp */ #include "cvodeobj.h" -#include "isoc99.h" #include "membfunc.h" #include "multisplit.h" #include "neuron.h" @@ -2172,7 +2171,7 @@ double* nrn_recalc_ptr(double* old) { if (!recalc_ptr_old_vp_) { return old; } - if (nrn_isdouble(old, 0.0, (double) recalc_cnt_)) { + if (old && *old >= 0 && *old <= recalc_cnt_) { int k = (int) (*old); if (old == recalc_ptr_old_vp_[k]) { return recalc_ptr_new_vp_[k]; @@ -2249,8 +2248,8 @@ void nrn_recalc_node_ptrs(void) { } dpend = nrn_dparam_ptr_end_[p->_type]; for (j = nrn_dparam_ptr_start_[p->_type]; j < dpend; ++j) { - double* pval = p->dparam[j].pval; - if (nrn_isdouble(pval, 0., (double) recalc_cnt_)) { + if (double* pval = p->dparam[j].pval; + pval && *pval >= 0.0 && *pval <= recalc_cnt_) { /* possible pointer to v */ k = (int) (*pval); if (pval == recalc_ptr_old_vp_[k]) { diff --git a/src/oc/isoc99.cpp b/src/oc/isoc99.cpp deleted file mode 100644 index 48d21dcf07..0000000000 --- a/src/oc/isoc99.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "isoc99.h" - -#include -#include - -/* trying to safely determine if a pointer is a pointer to a double where the -double value would be in a specific range without causing floating exceptions -Of course this founders in general on the dereferencing of invalid memory -so it can only be used when pd is valid over sizeof(double). -*/ - -int nrn_isdouble(double* pd, double min, double max) { - int i; - if (!pd) { - return 0; - } -#if defined(fpclassify) - i = fpclassify(*((double*) pd)); - if (i == FP_NORMAL || i == FP_ZERO) { - return *((double*) pd) >= min && *((double*) pd) <= max; - } else { - return 0; - } -#else - return *((double*) pd) >= min && *((double*) pd) <= max; -#endif -} diff --git a/src/oc/isoc99.h b/src/oc/isoc99.h deleted file mode 100644 index 779921c470..0000000000 --- a/src/oc/isoc99.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -int nrn_isdouble(double* pd, double min, double max); diff --git a/src/oc/ocmain.cpp b/src/oc/ocmain.cpp index f3d4ad4064..e5b6f09a9c 100644 --- a/src/oc/ocmain.cpp +++ b/src/oc/ocmain.cpp @@ -1,6 +1,5 @@ #include <../../nrnconf.h> /* /local/src/master/nrn/src/oc/ocmain.cpp,v 1.7 1997/07/29 20:23:33 hines Exp */ -#include "isoc99.h" #include #include @@ -56,7 +55,6 @@ static void setnrnhome(const char* arg) { int main(int argc, const char** argv, const char** envp) { int err; - nrn_isdouble(nullptr, 0., 0.); #if MAC int our_argc = 1; char* our_argv[1]; From 735935d19d9c2337bae7e0826780ad454de58adf Mon Sep 17 00:00:00 2001 From: Olli Lupton Date: Tue, 1 Nov 2022 14:59:13 +0100 Subject: [PATCH 4/4] drop unused memory pool code --- src/ivoc/ocnotify.h | 2 + src/nrniv/cxprop.cpp | 352 ++++--------------------------------------- 2 files changed, 30 insertions(+), 324 deletions(-) diff --git a/src/ivoc/ocnotify.h b/src/ivoc/ocnotify.h index bdf0bd5c4a..96459b6686 100644 --- a/src/ivoc/ocnotify.h +++ b/src/ivoc/ocnotify.h @@ -1,6 +1,8 @@ #pragma once #include +#include // std::size_t + void nrn_notify_freed(void (*pf)(void*, int)); void nrn_notify_when_void_freed(void* p, Observer* ob); void nrn_notify_when_double_freed(double* p, Observer* ob); diff --git a/src/nrniv/cxprop.cpp b/src/nrniv/cxprop.cpp index 5825760a8b..2c590b53e3 100644 --- a/src/nrniv/cxprop.cpp +++ b/src/nrniv/cxprop.cpp @@ -17,242 +17,22 @@ greater cache efficiency #include #include -extern void nrn_mk_prop_pools(int); -extern void nrn_cache_prop_realloc(); extern int nrn_is_ion(int); -void nrn_delete_prop_pool(int type); #if EXTRACELLULAR extern void nrn_extcell_update_param(); #endif extern void nrn_recalc_ptrs(double* (*) (double*) ); -static double* recalc_ptr(double*); +static constexpr auto APSIZE = 1000; using CharArrayPool = ArrayPool; - -#define APSIZE 1000 using DoubleArrayPool = ArrayPool; using DatumArrayPool = ArrayPool; +using SectionPool = Pool
; -static int force; static int npools_; static DoubleArrayPool** dblpools_; static DatumArrayPool** datumpools_; -static void mk_prop_pools(int n); - -#define NRN_MECH_REORDER 1 - -/* -Based on the nrn_threads tml->ml->nodelist order from the last -call to nrn_cache_prop_realloc() (which writes a data file) from -a previous launch, on this launch, read that file and create -pools matched to the space needed by each thread and which, from -the sequence of data allocation requests returns space that ends -up being laid out in memory in just the way we want. -The data file format is -maxtype // so we can be sure we have large enough npools_ -nthread // number of threads -nmech // number of mechanisms used in this thread -type sz1 sz2 ntget cnt // mechanism type, double/Datum array size total number of times alloc was -called, how many needed for this thread -// the above specifies the pool allocation -// note that the pool chain order is the same as the thread order -// there are nthread of the following lists -cnt // number of mechanisms in thread -type i seq // i is the tml->ml->_data[i], seq is the allocation order -// ie we want - -Note that the overall memory allocation sequence has to be identical -to the original sequence in terms of get/put for the final -layout to be exactly right for cache efficiency and for threads not -to share cache lines. However, if this is not the case, the memory allocation -is still correct, just not as efficient. -*/ - -#if NRN_MECH_REORDER - -static void read_temp1() { - // return; - FILE* f; - int nscan, maxtype, imech, nmech, type, sz1, sz2, ntget, ith, nth, i, j, cnt, seq; - char line[200]; - sprintf(line, "temp_%d_%d", nrnmpi_myid, nrnmpi_numprocs); - f = fopen(line, "r"); - if (!f) { - return; - } - force = 1; - nrn_assert(fgets(line, 200, f)); - nrn_assert(sscanf(line, "%d", &maxtype) == 1); - mk_prop_pools(maxtype); - long* ntget1 = new long[maxtype]; - for (i = 0; i < maxtype; ++i) { - ntget1[i] = 0; - } - - // allocate the pool space - nrn_assert(fgets(line, 200, f)); - nrn_assert(sscanf(line, "%d", &nth) == 1); - for (ith = 0; ith < nth; ++ith) { - nrn_assert(fgets(line, 200, f)); - nrn_assert(sscanf(line, "%d", &nmech) == 1); - for (imech = 0; imech < nmech; ++imech) { - nrn_assert(fgets(line, 200, f)); - nrn_assert(sscanf(line, "%d %d %d %d %d", &type, &sz1, &sz2, &ntget, &cnt) == 5); - // printf("(%d %d %d %d %d) %s", type, sz1, sz2, ntget, cnt, line); - ntget1[type] = ntget; - if (sz1) { - if (!dblpools_[type]) { - dblpools_[type] = new DoubleArrayPool(cnt, sz1); - } else { - dblpools_[type]->grow(cnt); - } - } - if (sz2) { - if (!datumpools_[type]) { - datumpools_[type] = new DatumArrayPool(cnt, sz2); - } else { - datumpools_[type]->grow(cnt); - } - } - } - } - for (i = 0; i < maxtype; ++i) { - if (dblpools_[i] && dblpools_[i]->size() < ntget1[i]) { - dblpools_[i]->grow(ntget1[i] - dblpools_[i]->size()); - } - if (datumpools_[i] && datumpools_[i]->size() < ntget1[i]) { - datumpools_[i]->grow(ntget1[i] - datumpools_[i]->size()); - } - } - delete[] ntget1; - - // now the tricky part, put items in an unnatural order - // first set all pointers to 0 - for (i = 0; i < maxtype; ++i) { - if (dblpools_[i]) { - double** items = dblpools_[i]->items(); - int sz = dblpools_[i]->size(); - for (int j = 0; j < sz; ++j) { - items[j] = 0; - } - } - if (datumpools_[i]) { - Datum** items = datumpools_[i]->items(); - int sz = datumpools_[i]->size(); - for (int j = 0; j < sz; ++j) { - items[j] = 0; - } - } - } - - // then set the proper seq pointers - DoubleArrayPool** p1 = new DoubleArrayPool*[npools_]; - DatumArrayPool** p2 = new DatumArrayPool*[npools_]; - int* chain = new int[npools_]; - for (i = 0; i < npools_; ++i) { - p1[i] = dblpools_[i]; - p2[i] = datumpools_[i]; - chain[i] = 0; - } - for (ith = 0; ith < nth; ++ith) { - nrn_assert(fgets(line, 200, f)); - nrn_assert(sscanf(line, "%d", &cnt) == 1); - for (i = 0; i < cnt; ++i) { - nrn_assert(fgets(line, 200, f)); - nrn_assert(sscanf(line, "%d %d %d", &type, &j, &seq)); - if (dblpools_[type]) { - double** items = dblpools_[type]->items(); - assert(items[seq] == 0); - items[seq] = p1[type]->element(j); - ++chain[type]; - } - if (datumpools_[type]) { - Datum** items = datumpools_[type]->items(); - assert(items[seq] == 0); - items[seq] = p2[type]->element(j); - ++chain[type]; - } - } - for (i = 0; i < npools_; ++i) { - if (chain[i]) { - if (p1[i] && p2[i]) { - assert(chain[i] == (p1[i]->chain_size() + p2[i]->chain_size())); - } else if (p1[i]) { - assert(chain[i] == p1[i]->chain_size()); - } else if (p2[i]) { - assert(chain[i] == p2[i]->chain_size()); - } - if (p1[i]) { - p1[i] = p1[i]->chain(); - } - if (p2[i]) { - p2[i] = p2[i]->chain(); - } - chain[i] = 0; - } - } - } - // finally set the rest - for (i = 0; i < npools_; ++i) { - if (p1[i]) { - int j = 0; - int k = 0; - int n = dblpools_[i]->size(); - int sz = p1[i]->chain_size(); - double** items = dblpools_[i]->items(); - for (j = 0; j < n; ++j) { - if (items[j] == 0) { - assert(k < sz); - items[j] = p1[i]->element(k); - ++k; - } - } - assert(k == sz); - } - if (p2[i]) { - int j = 0; - int k = 0; - int n = datumpools_[i]->size(); - int sz = p2[i]->chain_size(); - Datum** items = datumpools_[i]->items(); - for (j = 0; j < n; ++j) { - if (items[j] == 0) { - assert(k < sz); - items[j] = p2[i]->element(k); - ++k; - } - } - assert(k == sz); - } - } - delete[] p1; - delete[] p2; - fclose(f); -} -#endif // NRN_MECH_REORDER - -static void mk_prop_pools(int n) { - int i; - if (n > npools_) { - DoubleArrayPool** p1 = new DoubleArrayPool*[n]; - DatumArrayPool** p2 = new DatumArrayPool*[n]; - for (i = 0; i < n; ++i) { - p1[i] = 0; - p2[i] = 0; - } - if (dblpools_) { - for (i = 0; i < npools_; ++i) { - p1[i] = dblpools_[i]; - p2[i] = datumpools_[i]; - } - delete[] dblpools_; - delete[] datumpools_; - } - dblpools_ = p1; - datumpools_ = p2; - npools_ = n; - } -} +static SectionPool* secpool_; void nrn_delete_prop_pool(int type) { assert(type < npools_); @@ -266,12 +46,26 @@ void nrn_delete_prop_pool(int type) { } void nrn_mk_prop_pools(int n) { -#if NRN_MECH_REORDER - if (force == 0) { - read_temp1(); + if (n <= npools_) { + return; } -#endif - mk_prop_pools(n); + DoubleArrayPool** p1 = new DoubleArrayPool*[n]; + DatumArrayPool** p2 = new DatumArrayPool*[n]; + for (int i = 0; i < n; ++i) { + p1[i] = 0; + p2[i] = 0; + } + if (dblpools_) { + for (int i = 0; i < npools_; ++i) { + p1[i] = dblpools_[i]; + p2[i] = datumpools_[i]; + } + delete[] dblpools_; + delete[] datumpools_; + } + dblpools_ = p1; + datumpools_ = p2; + npools_ = n; } double* nrn_prop_data_alloc(int type, int count, Prop* p) { @@ -317,10 +111,6 @@ void nrn_prop_datum_free(int type, Datum* ppd) { } } -using SectionPool = Pool
; - -static SectionPool* secpool_; - Section* nrn_section_alloc() { if (!secpool_) { secpool_ = new SectionPool(1000); @@ -328,6 +118,7 @@ Section* nrn_section_alloc() { Section* s = secpool_->alloc(); return s; } + void nrn_section_free(Section* s) { secpool_->hpfree(s); } @@ -632,111 +423,24 @@ void nrn_poolshrink(int shrink) { void nrn_cache_prop_realloc() { if (!nrn_prop_is_cache_efficient()) { - // printf("begin nrn_prop_is_cache_efficient %d\n", nrn_prop_is_cache_efficient()); in_place_data_realloc(); - // printf("end nrn_prop_is_cache_efficient %d\n", nrn_prop_is_cache_efficient()); - } - return; - - -#if NRN_MECH_REORDER - nrn_prop_is_cache_efficient(); - FILE* f; - char buf[100]; - int i, it, type; - // we wish to rearrange the arrays so that they are in memb_list->data order within - // the ArrayPools. We do not want to use up a lot of temporary space to do this - // because there may not be much left. - // In each pool all the pointers between put and get (nget of them) are in use. - if (force) { - sprintf(buf, "temp2_%d", nrnmpi_myid); - } else { - sprintf(buf, "temp_%d_%d", nrnmpi_myid, nrnmpi_numprocs); - } - f = fopen(buf, "w"); - fprintf(f, "%d\n", n_memb_func); - fprintf(f, "%d\n", nrn_nthread); - for (it = 0; it < nrn_nthread; ++it) { - NrnThread* nt = nrn_threads + it; - // how many mechanisms used in this thread - i = 0; - for (NrnThreadMembList* tml = nt->tml; tml; tml = tml->next) { - ++i; - } - fprintf(f, "%d\n", i); - for (NrnThreadMembList* tml = nt->tml; tml; tml = tml->next) { - Memb_list* ml = tml->ml; - i = tml->index; - int j, cnt = ml->nodecount; - int sz1 = 0, sz2 = 0, ntget = 0; - if (dblpools_[i]) { - sz1 = dblpools_[i]->d2(); - ntget = dblpools_[i]->ntget(); - } - if (datumpools_[i]) { - sz2 = datumpools_[i]->d2(); - } - fprintf(f, "%d %d %d %d %d %s\n", i, sz1, sz2, ntget, cnt, memb_func[i].sym->name); - } - } - // above is enough for allocating the pools. Now the proper order info. - Memb_list** mlmap = new Memb_list*[n_memb_func]; - for (it = 0; it < nrn_nthread; ++it) { - NrnThread* nt = nrn_threads + it; - for (i = 0; i < n_memb_func; ++i) { - mlmap[i] = 0; - } // unnecessary but ... - // how many prop used in this thread - int cnt = 0; - for (NrnThreadMembList* tml = nt->tml; tml; tml = tml->next) { - cnt += tml->ml->nodecount; - tml->ml->nodecount = 0; // recount them below - mlmap[tml->index] = tml->ml; - } - fprintf(f, "%d\n", cnt); - int cnt2 = 0; - for (i = 0; i < nt->end; ++i) { - Node* nd = nt->_v_node[i]; - for (Prop* p = nd->prop; p; p = p->next) { - if (memb_func[p->_type].current || memb_func[p->_type].state || - memb_func[p->_type].initialize) { - Memb_list* ml = mlmap[p->_type]; - if (!ml || nd != ml->nodelist[ml->nodecount]) { - abort(); - } - assert(ml && nd == ml->nodelist[ml->nodecount]); - nrn_assert(fprintf(f, "%d %d %ld\n", p->_type, ml->nodecount++, p->_alloc_seq) > - 0); - ++cnt2; - } - } - } - assert(cnt == cnt2); } - delete[] mlmap; - fclose(f); -#endif } // for avoiding interthread cache line sharing // each thread needs its own pool instance extern "C" void* nrn_pool_create(long count, int itemsize) { - CharArrayPool* p = new CharArrayPool(count, itemsize); - return (void*) p; + return new CharArrayPool(count, itemsize); } extern "C" void nrn_pool_delete(void* pool) { - CharArrayPool* p = (CharArrayPool*) pool; - delete p; + delete static_cast(pool); } extern "C" void* nrn_pool_alloc(void* pool) { - CharArrayPool* p = (CharArrayPool*) pool; - return (void*) p->alloc(); + return static_cast(pool)->alloc(); } extern "C" void nrn_pool_free(void* pool, void* item) { - CharArrayPool* p = (CharArrayPool*) pool; - p->hpfree(static_cast(item)); + static_cast(pool)->hpfree(static_cast(item)); } extern "C" void nrn_pool_freeall(void* pool) { - CharArrayPool* p = (CharArrayPool*) pool; - p->free_all(); + static_cast(pool)->free_all(); }