This repository was archived by the owner on Mar 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathenginemech.cpp
More file actions
114 lines (94 loc) · 3.16 KB
/
Copy pathenginemech.cpp
File metadata and controls
114 lines (94 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* \file
* \brief Provides interface function for CoreNEURON mechanism library and NEURON
*
* libcorenrnmech is a interface library provided to building standalone executable
* special-core. Also, it is used by NEURON to run CoreNEURON via dlopen to execute
* models via in-memory transfer.
*/
#include <cstdlib>
#include <coreneuron/engine.h>
namespace coreneuron {
/** Mechanism registration function
*
* If external mechanisms present then use modl_reg function generated
* in mod_func.cpp otherwise use empty one.
*/
#ifdef ADDITIONAL_MECHS
extern void modl_reg();
#else
void modl_reg() {
}
#endif
/// variables defined in coreneuron library
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
*
* This is mainly used to build nrniv-core executable
*/
int solve_core(int argc, char** argv) {
mk_mech_init(argc, argv);
coreneuron::modl_reg();
int ret = run_solve_core(argc, argv);
coreneuron::nrn_cleanup_ion_map();
return ret;
}
extern "C" {
/// global variables from coreneuron library
extern bool corenrn_embedded;
extern int corenrn_embedded_nthread;
/// parse arguments from neuron and prepare new one for coreneuron
char* prepare_args(int& argc, char**& argv, int use_mpi, const char* nrn_arg);
/// initialize standard mechanisms from coreneuron
void mk_mech_init(int argc, char** argv);
/// set openmp threads equal to neuron's pthread
void set_openmp_threads(int nthread);
/** Run CoreNEURON in embedded mode with NEURON
*
* @param nthread Number of Pthreads on NEURON side
* @param have_gaps True if gap junctions are used
* @param use_mpi True if MPI is used on NEURON side
* @param use_fast_imem True if fast imembrance calculation enabled
* @param nrn_arg Command line arguments passed by NEURON
* @return 1 if embedded mode is used otherwise 0
* \todo Change return type semantics
*/
int corenrn_embedded_run(int nthread,
int have_gaps,
int use_mpi,
int use_fast_imem,
const char* nrn_arg) {
// set coreneuron's internal variable based on neuron arguments
corenrn_embedded = true;
corenrn_embedded_nthread = nthread;
coreneuron::nrn_have_gaps = have_gaps != 0;
if (use_fast_imem != 0) {
coreneuron::nrn_use_fast_imem = true;
}
// set number of openmp threads
set_openmp_threads(nthread);
// pre-process argumnets from neuron and prepare new for coreneuron
int argc;
char** argv;
char* new_arg = prepare_args(argc, argv, use_mpi, nrn_arg);
// initialize internal arguments
mk_mech_init(argc, argv);
// initialize extra arguments built into special-core
static bool modl_reg_called = false;
if (!modl_reg_called) {
coreneuron::modl_reg();
modl_reg_called = true;
}
// run simulation
run_solve_core(argc, argv);
// free temporary string created from prepare_args
free(new_arg);
// delete array for argv
delete[] argv;
return corenrn_embedded ? 1 : 0;
}
}