NEURON
finitialize.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
8 
9 #include "coreneuron/nrnconf.h"
16 
17 namespace coreneuron {
18 
20 
22  // In case some nrn_init allocates data that we need. In this case
23  // we want to call nrn_init but not execute initmodel i.e. INITIAL
24  // block. For this, set _nrn_skip_initmodel to True temporarily
25  // , execute nrn_init and return.
26  _nrn_skip_initmodel = true;
27  for (int i = 0; i < nrn_nthread; ++i) { // could be parallel
28  NrnThread& nt = nrn_threads[i];
29  for (NrnThreadMembList* tml = nt.tml; tml; tml = tml->next) {
30  Memb_list* ml = tml->ml;
31  mod_f_t s = corenrn.get_memb_func(tml->index).initialize;
32  if (s) {
33  (*s)(&nt, ml, tml->index);
34  }
35  }
36  }
37  _nrn_skip_initmodel = false;
38 }
39 
40 void nrn_finitialize(int setv, double v) {
41  Instrumentor::phase_begin("finitialize");
42  t = 0.;
43  dt2thread(-1.);
47 #if VECTORIZE
48  nrn_play_init(); /* Vector.play */
49  /// Play events should be executed before initializing events
50  for (int i = 0; i < nrn_nthread; ++i) {
51  nrn_deliver_events(nrn_threads + i); /* The play events at t=0 */
52  }
53  if (setv) {
54  for (auto _nt = nrn_threads; _nt < nrn_threads + nrn_nthread; ++_nt) {
55  double* vec_v = &(VEC_V(0));
57  parallel loop present(_nt [0:1], vec_v [0:_nt->end]) if (_nt->compute_gpu))
58  nrn_pragma_omp(target teams distribute parallel for simd if(_nt->compute_gpu))
59  for (int i = 0; i < _nt->end; ++i) {
60  vec_v[i] = v;
61  }
62  }
63  }
64 
65  if (nrn_have_gaps) {
66  Instrumentor::phase p("gap-v-transfer");
68  for (int i = 0; i < nrn_nthread; ++i) {
70  }
71  }
72 
73  for (int i = 0; i < nrn_nthread; ++i) {
75  }
76  /* the INITIAL blocks are ordered so that mechanisms that write
77  concentrations are after ions and before mechanisms that read
78  concentrations.
79  */
80  /* the memblist list in NrnThread is already so ordered */
81  for (int i = 0; i < nrn_nthread; ++i) {
82  NrnThread* nt = nrn_threads + i;
83  for (auto tml = nt->tml; tml; tml = tml->next) {
84  mod_f_t s = corenrn.get_memb_func(tml->index).initialize;
85  if (s) {
86  (*s)(nt, tml->ml, tml->index);
87  }
88  }
89  }
90 #endif
91 
93  for (int i = 0; i < nrn_nthread; ++i) {
95  }
96  for (int i = 0; i < nrn_nthread; ++i) {
97  nrn_deliver_events(nrn_threads + i); /* The INITIAL sent events at t=0 */
98  }
99  for (int i = 0; i < nrn_nthread; ++i) {
101  if (nrn_use_fast_imem) {
103  }
104  }
105  for (int i = 0; i < nrn_nthread; ++i) {
107  }
109  for (int i = 0; i < nrn_nthread; ++i) {
111  }
112  // Consistent with NEURON. BEFORE_STEP and fixed_record_continuous before nrn_deliver_events.
113  for (int i = 0; i < nrn_nthread; ++i) {
114  nrn_deliver_events(nrn_threads + i); /* The record events at t=0 */
115  }
116 #if NRNMPI
118 #endif
119  Instrumentor::phase_end("finitialize");
120 }
121 } // namespace coreneuron
auto & get_memb_func(size_t idx)
Definition: coreneuron.hpp:135
#define v
Definition: md1redef.h:11
#define i
Definition: md1redef.h:19
nrn_pragma_acc(routine seq) nrn_pragma_omp(declare target) philox4x32_ctr_t coreneuron_random123_philox4x32_helper(coreneuron nrn_pragma_omp(end declare target) namespace coreneuron
Provide a helper function in global namespace that is declared target for OpenMP offloading to functi...
Definition: nrnran123.h:66
#define BEFORE_INITIAL
Definition: membfunc.hpp:67
#define BEFORE_STEP
Definition: membfunc.hpp:71
#define AFTER_INITIAL
Definition: membfunc.hpp:68
static void phase_end(const char *name)
static void phase_begin(const char *name)
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
NrnThread * nrn_threads
Definition: multicore.cpp:56
bool _nrn_skip_initmodel
Definition: finitialize.cpp:19
void clear_event_queue()
Definition: cvodestb.cpp:47
void(*)(NrnThread *, Memb_list *, int) mod_f_t
Definition: membfunc.hpp:24
void nrn_finitialize(int setv, double v)
Definition: finitialize.cpp:40
void nrnmpi_v_transfer()
Definition: partrans.cpp:35
void init_net_events()
Definition: cvodestb.cpp:53
void nrn_spike_exchange(NrnThread *nt)
int nrn_nthread
Definition: multicore.cpp:55
void nrncore2nrn_send_values(NrnThread *nth)
void nrn_calc_fast_imem_init(NrnThread *nt)
Definition: fast_imem.cpp:62
bool nrn_have_gaps
variables defined in coreneuron library
Definition: partrans.cpp:21
void nrn_thread_table_check()
Definition: multicore.cpp:168
void nrnthread_v_transfer(NrnThread *_nt)
Definition: partrans.cpp:108
void * setup_tree_matrix_minimal(NrnThread *)
CoreNeuron corenrn
Definition: multicore.cpp:53
void nrn_deliver_events(NrnThread *nt)
Definition: cvodestb.cpp:32
nrn_pragma_acc(routine seq) int vector_capacity(void *v)
Definition: ivocvect.cpp:30
bool nrn_use_fast_imem
Definition: fast_imem.cpp:19
void nrn_spike_exchange_init()
Definition: netpar.cpp:238
void dt2thread(double adt)
void allocate_data_in_mechanism_nrn_init()
Definition: finitialize.cpp:21
void nrncore2nrn_send_init()
void nrn_play_init()
Definition: cvodestb.cpp:72
void nrn_ba(NrnThread *nt, int bat)
if(ncell==0)
Definition: cellorder.cpp:785
#define VEC_V(i)
Definition: nrnconf.h:31
size_t p
s
Definition: multisend.cpp:521
NrnThreadMembList * tml
Definition: multicore.hpp:80
NrnThreadMembList * next
Definition: multicore.hpp:33