Skip to content

Commit

Permalink
CVode.poolshrink(1) deletes unused mechanism pools.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrnhines committed Oct 21, 2022
1 parent 3e0e1eb commit d2256f2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/nrncvode/cvodeobj.cpp
Expand Up @@ -580,6 +580,16 @@ static double use_fast_imem(void* v) {
return double(i);
}

static double poolshrink(void*) {
extern void nrn_poolshrink(int);
int i = 0;
if (ifarg(1)) {
i = int(chkarg(1, 0., 1.));
}
nrn_poolshrink(i);
return double(i);
}

static Member_func members[] = {{"solve", solve},
{"atol", nrn_atol},
{"rtol", rtol},
Expand Down Expand Up @@ -628,6 +638,7 @@ static Member_func members[] = {{"solve", solve},
{"extra_scatter_gather", extra_scatter_gather},
{"extra_scatter_gather_remove", extra_scatter_gather_remove},
{"use_fast_imem", use_fast_imem},
{"poolshrink", poolshrink},
{nullptr, nullptr}};

static Member_ret_obj_func omembers[] = {{"netconlist", netconlist}, {nullptr, nullptr}};
Expand Down
32 changes: 32 additions & 0 deletions src/nrniv/cxprop.cpp
Expand Up @@ -598,6 +598,38 @@ void nrn_update_ion_pointer(Symbol* sion, Datum* dp, int id, int ip) {
dp[id].pval = pvar + ip;
}


void nrn_poolshrink(int shrink) {
if (shrink) {
for (int i = 0; i < npools_; ++i) {
auto& pdbl = dblpools_[i];
auto& pdatum = datumpools_[i];
if ((pdbl && pdbl->nget() == 0)) {
nrn_delete_prop_pool(i);
}
if ((pdatum && pdatum->nget() == 0) && pdatum->size() > 10) {
delete datumpools_[i];
datumpools_[i] = NULL;
}
}
} else {
Printf("poolshrink --- type name (dbluse, size) (datumuse, size)\n");
for (int i = 0; i < npools_; ++i) {
auto& pdbl = dblpools_[i];
auto& pdatum = datumpools_[i];
if (pdbl || pdatum) {
Printf("%d %s (%ld, %d) (%ld, %d)\n",
i,
(memb_func[i].sym ? memb_func[i].sym->name : "noname"),
(pdbl ? pdbl->nget() : 0),
(pdbl ? pdbl->size() : 0),
(pdatum ? pdatum->nget() : 0),
(pdatum ? pdatum->size() : 0));
}
}
}
}

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());
Expand Down

0 comments on commit d2256f2

Please sign in to comment.