Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 8659c7b

Browse files
authored
Bugfix : Support for using CoreNEURON in embedded mode with external mechanisms (#275)
- modl_reg was not called when corenrn_embedded_run was used for running simulations with in-memory mode transfer - move corenrn_embedded_run() into enginemech.cpp to avoid link error for calling coreneuron::modl_reg - add test for external mechanism in embedded mode - source setup-env.sh to use neuron@develop module fixes #274
1 parent 172c41d commit 8659c7b

File tree

9 files changed

+157
-33
lines changed

9 files changed

+157
-33
lines changed

coreneuron/apps/main1.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,6 @@ char* prepare_args(int& argc, char**& argv, int use_mpi, const char* arg) {
126126
return first;
127127
}
128128

129-
int corenrn_embedded_run(int nthread, int have_gaps, int use_mpi, int use_fast_imem, const char* arg) {
130-
corenrn_embedded = true;
131-
corenrn_embedded_nthread = nthread;
132-
coreneuron::nrn_have_gaps = have_gaps != 0;
133-
if (use_fast_imem != 0) {
134-
coreneuron::nrn_use_fast_imem = true;
135-
}
136-
137-
set_openmp_threads(nthread);
138-
int argc = 0;
139-
char** argv;
140-
char* new_arg = prepare_args(argc, argv, use_mpi, arg);
141-
mk_mech_init(argc, argv);
142-
run_solve_core(argc, argv);
143-
free(new_arg);
144-
delete[] argv;
145-
146-
return corenrn_embedded ? 1 : 0;
147-
}
148129
}
149130

150131
namespace coreneuron {
Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,107 @@
1-
/// Corenrnmech is a wrapper lib providing a single solve_core function
2-
/// which initializes the solver, loads the external mechanisms and launches the simulation
1+
/**
2+
* \file
3+
* \brief Provides interface function for CoreNEURON mechanism library and NEURON
4+
*
5+
* libcorenrnmech is a interface library provided to building standalone executable
6+
* special-core. Also, it is used by NEURON to run CoreNEURON via dlopen to execute
7+
* models via in-memory transfer.
8+
*/
39

10+
#include <cstdlib>
411
#include <coreneuron/engine.h>
512

6-
#ifdef ADDITIONAL_MECHS
713
namespace coreneuron {
14+
15+
/** Mechanism registration function
16+
*
17+
* If external mechanisms present then use modl_reg function generated
18+
* in mod_func.cpp otherwise use empty one.
19+
*/
20+
#ifdef ADDITIONAL_MECHS
821
extern void modl_reg();
22+
#else
23+
void modl_reg() {
924
}
1025
#endif
1126

27+
/// variables defined in coreneuron library
28+
extern bool nrn_have_gaps;
29+
extern bool nrn_use_fast_imem;
30+
31+
} // namespace coreneuron
32+
33+
/** Initialize mechanisms and run simulation using CoreNEURON
34+
*
35+
* This is mainly used to build nrniv-core executable
36+
*/
1237
int solve_core(int argc, char** argv) {
1338
mk_mech_init(argc, argv);
39+
coreneuron::modl_reg();
40+
return run_solve_core(argc, argv);
41+
}
1442

15-
#ifdef ADDITIONAL_MECHS
16-
/// Initializing additional Neurodamus mechanisms (in mod_func.c, built by mech/mod_func.c.pl)
43+
extern "C" {
44+
45+
/// global variables from coreneuron library
46+
extern bool corenrn_embedded;
47+
extern int corenrn_embedded_nthread;
48+
49+
/// parse arguments from neuron and prepare new one for coreneuron
50+
char* prepare_args(int& argc, char**& argv, int use_mpi, const char* nrn_arg);
51+
52+
/// initialize standard mechanisms from coreneuron
53+
void mk_mech_init(int argc, char** argv);
54+
55+
/// set openmp threads equal to neuron's pthread
56+
void set_openmp_threads(int nthread);
57+
58+
/** Run CoreNEURON in embedded mode with NEURON
59+
*
60+
* @param nthread Number of Pthreads on NEURON side
61+
* @param have_gaps True if gap junctions are used
62+
* @param use_mpi True if MPI is used on NEURON side
63+
* @param use_fast_imem True if fast imembrance calculation enabled
64+
* @param nrn_arg Command line arguments passed by NEURON
65+
* @return 1 if embedded mode is used otherwise 0
66+
* \todo Change return type semantics
67+
*/
68+
int corenrn_embedded_run(int nthread,
69+
int have_gaps,
70+
int use_mpi,
71+
int use_fast_imem,
72+
const char* nrn_arg) {
73+
// set coreneuron's internal variable based on neuron arguments
74+
corenrn_embedded = true;
75+
corenrn_embedded_nthread = nthread;
76+
coreneuron::nrn_have_gaps = have_gaps != 0;
77+
78+
if (use_fast_imem != 0) {
79+
coreneuron::nrn_use_fast_imem = true;
80+
}
81+
82+
// set number of openmp threads
83+
set_openmp_threads(nthread);
84+
85+
// pre-process argumnets from neuron and prepare new for coreneuron
86+
int argc;
87+
char** argv;
88+
char* new_arg = prepare_args(argc, argv, use_mpi, nrn_arg);
89+
90+
// initialize internal arguments
91+
mk_mech_init(argc, argv);
92+
93+
// initialize extra arguments built into special-core
1794
coreneuron::modl_reg();
18-
#endif
1995

20-
return run_solve_core(argc, argv);
96+
// run simulation
97+
run_solve_core(argc, argv);
98+
99+
// free temporary string created from prepare_args
100+
free(new_arg);
101+
102+
// delete array for argv
103+
delete[] argv;
104+
105+
return corenrn_embedded ? 1 : 0;
106+
}
21107
}

tests/jenkins/_env_setup.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ INSTALL_HOME="${WORKSPACE}/INSTALL_HOME"
99
export SPACK_ROOT="${BUILD_HOME}/spack"
1010
export SPACK_INSTALL_PREFIX="${SPACK_INSTALL_PREFIX:-${INSTALL_HOME}}"
1111
export SOFTS_DIR_PATH=$SPACK_INSTALL_PREFIX # Deprecated, but might still be reqd
12-
export PATH=$SPACK_ROOT/bin:/usr/bin:$PATH
13-
export MODULEPATH=$SPACK_INSTALL_PREFIX/modules/tcl/$(spack arch):$MODULEPATH
12+
export PATH=/usr/bin:$PATH
13+
14+
if [ -d "$SPACK_ROOT" ]; then
15+
source $SPACK_ROOT/share/spack/setup-env.sh
16+
fi
1417

1518
# Common init
1619
unset $(env|awk -F= '/^(PMI|SLURM)_/ {if ($1 != "SLURM_ACCOUNT") print $1}')

tests/jenkins/install_neuron.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ patch_neuron() (
2121
set -e
2222
source ${JENKINS_DIR:-.}/_env_setup.sh
2323

24-
set -x
2524
patch_neuron
2625
spack install neuron+debug@develop
26+
source $SPACK_ROOT/share/spack/setup-env.sh
2727
module av neuron
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
: Dynamics that track inside calcium concentration
2+
: modified from Destexhe et al. 1994
3+
4+
NEURON {
5+
SUFFIX CaDynamics_E2
6+
USEION ca READ ica WRITE cai
7+
RANGE decay, gamma, minCai, depth
8+
}
9+
10+
UNITS {
11+
(mV) = (millivolt)
12+
(mA) = (milliamp)
13+
FARADAY = (faraday) (coulombs)
14+
(molar) = (1/liter)
15+
(mM) = (millimolar)
16+
(um) = (micron)
17+
}
18+
19+
PARAMETER {
20+
gamma = 0.05 : percent of free calcium (not buffered)
21+
decay = 80 (ms) : rate of removal of calcium
22+
depth = 0.1 (um) : depth of shell
23+
minCai = 1e-4 (mM)
24+
}
25+
26+
ASSIGNED {ica (mA/cm2)}
27+
28+
STATE {
29+
cai (mM)
30+
}
31+
32+
BREAKPOINT { SOLVE states METHOD cnexp }
33+
34+
DERIVATIVE states {
35+
cai' = -(10000)*(ica*gamma/(2*FARADAY*depth)) - (cai - minCai)/decay
36+
}

tests/jenkins/neuron_direct.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
ic.dur = 0.1
1111
ic.amp = 0.3
1212

13+
# for testing external mod file
14+
h.soma.insert("CaDynamics_E2")
15+
1316
h.cvode.use_fast_imem(1)
1417
h.cvode.cache_efficient(1)
1518

tests/jenkins/nrnivmodl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44
source ${JENKINS_DIR:-.}/_env_setup.sh
5-
module load neuron
5+
module load neuron/develop
66

77
set -x
88
TEST_DIR="$1"

tests/jenkins/run_neuron_direct.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@
22

33
set -e
44
source ${JENKINS_DIR:-.}/_env_setup.sh
5-
module load neuron
5+
module load neuron/develop intel
66

77
set -x
88
CORENRN_TYPE="$1"
9-
export CORENEURONLIB=$WORKSPACE/install_${CORENRN_TYPE}/lib/libcoreneuron.so
9+
export PATH=$WORKSPACE/install_${CORENRN_TYPE}/bin:$PATH
10+
11+
# temporary build directory
12+
build_dir=$(mktemp -d $(pwd)/build_XXXX)
13+
cd $build_dir
14+
15+
# build special and special-core
16+
nrnivmodl ../tests/jenkins/mod
17+
nrnivmodl-core ../tests/jenkins/mod
18+
ls -la x86_64
19+
20+
# run test sim with external mechanism
1021
python $WORKSPACE/tests/jenkins/neuron_direct.py
22+
23+
# remove build directory
24+
cd -
25+
rm -rf $build_dir

tests/jenkins/spack_setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ install_spack() (
2323
# Use BBP configs
2424
mkdir -p $SPACK_ROOT/etc/spack/defaults/linux
2525
cp /gpfs/bbp.cscs.ch/apps/hpc/jenkins/config/*.yaml $SPACK_ROOT/etc/spack/
26-
26+
sed -i -e 's/neuron+mpi~debug%intel/neuron+mpi/g' $SPACK_ROOT/etc/spack/modules.yaml
2727
# Remove configs from $HOME/.spack
2828
rm -rf $HOME/.spack
2929
)

0 commit comments

Comments
 (0)