Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions coreneuron/io/nrn_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,11 +985,34 @@ inline void mech_layout(FileHandler& F, T* data, int cnt, int sz, int layout) {
}
}

/**
* Cleanup global ion map created during mechanism registration
*
* In case of coreneuron standalone execution nrn_ion_global_map
* can be deleted at the end of execution. But in case embedded
* run via neuron, mechanisms are registered only once i.e. during
* first call to coreneuron. This is why we call cleanup only in
* case of standalone coreneuron execution via nrniv-core or
* special-core.
*
* @todo coreneuron should have finalise callback which can be
* called from NEURON for final memory cleanup including global
* state like registered mechanisms and ions map.
*/
void nrn_cleanup_ion_map() {
for (int i = 0; i < nrn_ion_global_map_size; i++) {
free_memory(nrn_ion_global_map[i]);
}
free_memory(nrn_ion_global_map);
nrn_ion_global_map = nullptr;
nrn_ion_global_map_size = 0;
}

/* nrn_threads_free() presumes all NrnThread and NrnThreadMembList data is
* allocated with malloc(). This is not the case here, so let's try and fix
* things up first. */

void nrn_cleanup(bool clean_ion_global_map) {
void nrn_cleanup() {
clear_event_queue(); // delete left-over TQItem
gid2in.clear();
gid2out.clear();
Expand All @@ -1000,15 +1023,6 @@ void nrn_cleanup(bool clean_ion_global_map) {
nrnthread_chkpnt = nullptr;
}

// clean ions global maps
if (clean_ion_global_map) {
for (int i = 0; i < nrn_ion_global_map_size; i++)
free_memory(nrn_ion_global_map[i]);
free_memory(nrn_ion_global_map);
nrn_ion_global_map = nullptr;
nrn_ion_global_map_size = 0;
}

// clean NrnThreads
for (int it = 0; it < nrn_nthread; ++it) {
NrnThread* nt = nrn_threads + it;
Expand Down
6 changes: 5 additions & 1 deletion coreneuron/mechanism/mech/enginemech.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void modl_reg() {
extern bool nrn_have_gaps;
extern bool nrn_use_fast_imem;

/// function defined in coreneuron library
extern void nrn_cleanup_ion_map();
} // namespace coreneuron

/** Initialize mechanisms and run simulation using CoreNEURON
Expand All @@ -37,7 +39,9 @@ extern bool nrn_use_fast_imem;
int solve_core(int argc, char** argv) {
mk_mech_init(argc, argv);
coreneuron::modl_reg();
return run_solve_core(argc, argv);
int ret = run_solve_core(argc, argv);
coreneuron::nrn_cleanup_ion_map();
return ret;
}

extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion coreneuron/nrniv/nrniv_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ extern double* stdindex2ptr(int mtype, int index, NrnThread&);
extern void delete_trajectory_requests(NrnThread&);
extern int nrn_setup_multiple;
extern int nrn_setup_extracon;
extern void nrn_cleanup(bool clean_ion_global_map = true);
extern void nrn_cleanup();
extern void nrn_cleanup_ion_map();
extern void BBS_netpar_solve(double);
extern void nrn_mkPatternStim(const char* filename);
extern int nrn_extra_thread0_vdata;
Expand Down
4 changes: 3 additions & 1 deletion tests/jenkins/neuron_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
tvstd = tv.cl()
i_memstd = i_mem.cl()

#h.CoreNeuronRun[0].run()
pc = h.ParallelContext()
h.stdinit()
pc.nrncore_run("-e %g"%h.tstop, 0)
# running second time for testing multiple executions
h.stdinit()
pc.nrncore_run("-e %g"%h.tstop, 0)

if not bool(tv.eq(tvstd)):
print("Voltage times are different")
Expand Down