NEURON
test_multicore.h
Go to the documentation of this file.
1 #pragma once
2 #include <algorithm>
3 #include <cmath>
4 #include <string>
5 #include <vector>
6 
7 namespace nrn::test {
8 extern int MAX_PROCESSORS;
9 // generate a range starting from 1 and doubling until we reach the nof concurrent threads
11  auto nof_threads_range = std::vector<int>(1 + static_cast<int>(std::log2(MAX_PROCESSORS - 1)),
12  1);
13  std::generate(nof_threads_range.begin() + 1, nof_threads_range.end(), [n = 1]() mutable {
14  return n *= 2;
15  });
16  return nof_threads_range;
17 }
18 } // namespace nrn::test
19 
20 // pass_cell_template is a string containing a template for a Cell with inserted pas mechanism
21 constexpr auto pass_cell_template = R"(
22 begintemplate PasCell
23 public init, topol, basic_shape, subsets, geom, biophys, geom_nseg, biophys_inhomo
24 public synlist, x, y, z, position, connect2target
25 public icl
26 
27 public soma, dend
28 public all
29 
30 objref synlist, icl
31 
32 create soma, dend
33 
34 proc init() {
35  topol()
36  subsets()
37  geom()
38  biophys()
39  geom_nseg()
40  synlist = new List()
41  synapses()
42  x = y = z = 0 // only change via position
43  soma {icl = new IClamp(0.5)}
44  icl.del = 1
45  icl.dur = 3
46  icl.amp = 0
47 }
48 
49 proc topol() { local i
50  connect dend(0), soma(1)
51  basic_shape()
52 }
53 proc basic_shape() {
54  soma {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(15, 0, 0, 1)}
55  dend {pt3dclear() pt3dadd(15, 0, 0, 1) pt3dadd(90, 0, 0, 1)}
56 }
57 
58 objref all
59 proc subsets() { local i
60  objref all
61  all = new SectionList()
62  soma all.append()
63  dend all.append()
64 
65 }
66 proc geom() {
67  forsec all { }
68  soma.L = 10
69  dend.L = 1000
70  soma.diam = 10
71  dend.diam = 1
72  dend { }
73 }
74 
75 proc geom_nseg() {
76  dend { nseg = 100 }
77 }
78 proc biophys() {
79  forsec all {
80  Ra = 100
81  cm = 1
82  insert pas
83  g_pas = 0.001
84  e_pas = -65
85  }
86 }
87 proc biophys_inhomo(){}
88 proc position() { local i
89  soma for i = 0, n3d()-1 {
90  pt3dchange(i, $1-x+x3d(i), $2-y+y3d(i), $3-z+z3d(i), diam3d(i))
91  }
92  x = $1 y = $2 z = $3
93 }
94 obfunc connect2target() { localobj nc //$o1 target point process, optional $o2 returned NetCon
95  soma nc = new NetCon(&v(1), $o1)
96  nc.threshold = 10
97  if (numarg() == 2) { $o2 = nc } // for backward compatibility
98  return nc
99 }
100 proc synapses() {}
101 endtemplate PasCell
102 )";
103 
104 /**
105  * @brief prun
106  * requires a parallel context to be created before -> pc
107  */
108 constexpr auto prun = R"(
109 load_file("nrngui.hoc")
110 load_file("stdlib.hoc")
111 func prun() {local runtime
112  pc.set_maxstep(10)
113  finitialize(-65)
114  runtime=startsw()
115  stdinit()
116  batch_run(tstop, tstop)
117  runtime=startsw()-runtime
118  return runtime
119 }
120 )";
121 
122 
123 // utility to create a given number of passive membrane cells (nof_cells)
124 std::string operator"" _pas_cells(unsigned long long nof_cells) {
125  std::string cells = "ncell = " + std::to_string(nof_cells);
126  cells += R"(
127  objref cell[ncell]
128  for i=0, ncell - 1 {
129  cell[i] = new PasCell()
130  cell[i].icl.amp = i/ncell
131  cell[i].position(0, 100*i, 0)
132  }
133  )";
134  return cells;
135 };
std::string to_string(const T &obj)
int MAX_PROCESSORS
Definition: catch2_main.cpp:25
auto make_available_threads_range()
int const size_t const size_t n
Definition: nrngsl.h:10
constexpr auto pass_cell_template
constexpr auto prun
prun requires a parallel context to be created before -> pc