CoreNEURON
capac.cpp
Go to the documentation of this file.
1 /***
2  THIS FILE IS AUTO GENERATED DONT MODIFY IT.
3  ***/
4 /*
5 # =============================================================================
6 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
7 #
8 # See top-level LICENSE file for details.
9 # =============================================================================.
10 */
11 
14 
15 #define _PRAGMA_FOR_INIT_ACC_LOOP_ \
16  nrn_pragma_acc(parallel loop present(vdata [0:_cntml_padded * nparm]) if (_nt->compute_gpu)) \
17  nrn_pragma_omp(target teams distribute parallel for simd if(_nt->compute_gpu))
18 #define _STRIDE _cntml_padded + _iml
19 
20 namespace coreneuron {
21 
22 static const char* mechanism[] = {"0", "capacitance", "cm", 0, "i_cap", 0, 0};
23 void nrn_alloc_capacitance(double*, Datum*, int);
24 void nrn_init_capacitance(NrnThread*, Memb_list*, int);
25 void nrn_jacob_capacitance(NrnThread*, Memb_list*, int);
26 void nrn_div_capacity(NrnThread*, Memb_list*, int);
27 void nrn_mul_capacity(NrnThread*, Memb_list*, int);
28 
29 #define nparm 2
30 
31 void capacitance_reg(void) {
32  /* all methods deal with capacitance in special ways */
35  nullptr,
36  nullptr,
37  nullptr,
39  nullptr,
40  nullptr,
41  -1,
42  1);
43  int mechtype = nrn_get_mechtype(mechanism[1]);
44  _nrn_layout_reg(mechtype, SOA_LAYOUT);
45  hoc_register_prop_size(mechtype, nparm, 0);
46 }
47 
48 #define cm vdata[0 * _STRIDE]
49 #define i_cap vdata[1 * _STRIDE]
50 
51 /*
52 cj is analogous to 1/dt for cvode and daspk
53 for fixed step second order it is 2/dt and
54 for pure implicit fixed step it is 1/dt
55 It used to be static but is now a thread data variable
56 */
57 
58 void nrn_jacob_capacitance(NrnThread* _nt, Memb_list* ml, int /* type */) {
59  int _cntml_actual = ml->nodecount;
60  int _cntml_padded = ml->_nodecount_padded;
61  int _iml;
62  double* vdata;
63  double cfac = .001 * _nt->cj;
64  (void) _cntml_padded; /* unused when layout=1*/
65 
66  double* _vec_d = _nt->_actual_d;
67 
68  { /*if (use_cachevec) {*/
69  int* ni = ml->nodeindices;
70 
71  vdata = ml->data;
72  nrn_pragma_acc(parallel loop present(vdata [0:_cntml_padded * nparm],
73  ni [0:_cntml_actual],
74  _vec_d [0:_nt->end]) if (_nt->compute_gpu)
75  async(_nt->stream_id))
76  nrn_pragma_omp(target teams distribute parallel for simd if(_nt->compute_gpu))
77  for (_iml = 0; _iml < _cntml_actual; _iml++) {
78  _vec_d[ni[_iml]] += cfac * cm;
79  }
80  }
81 }
82 
83 void nrn_init_capacitance(NrnThread* _nt, Memb_list* ml, int /* type */) {
84  int _cntml_actual = ml->nodecount;
85  int _cntml_padded = ml->_nodecount_padded;
86  double* vdata;
87  (void) _cntml_padded; /* unused */
88 
89  // skip initialization if restoring from checkpoint
90  if (_nrn_skip_initmodel == 1) {
91  return;
92  }
93 
94  vdata = ml->data;
96  for (int _iml = 0; _iml < _cntml_actual; _iml++) {
97  i_cap = 0;
98  }
99 }
100 
101 void nrn_cur_capacitance(NrnThread* _nt, Memb_list* ml, int /* type */) {
102  int _cntml_actual = ml->nodecount;
103  int _cntml_padded = ml->_nodecount_padded;
104  double* vdata;
105  double cfac = .001 * _nt->cj;
106 
107  /*@todo: verify cfac is being copied !! */
108 
109  (void) _cntml_padded; /* unused when layout=1*/
110 
111  /* since rhs is dvm for a full or half implicit step */
112  /* (nrn_update_2d() replaces dvi by dvi-dvx) */
113  /* no need to distinguish secondorder */
114  int* ni = ml->nodeindices;
115  double* _vec_rhs = _nt->_actual_rhs;
116 
117  vdata = ml->data;
118  nrn_pragma_acc(parallel loop present(vdata [0:_cntml_padded * nparm],
119  ni [0:_cntml_actual],
120  _vec_rhs [0:_nt->end]) if (_nt->compute_gpu)
121  async(_nt->stream_id))
122  nrn_pragma_omp(target teams distribute parallel for simd if(_nt->compute_gpu))
123  for (int _iml = 0; _iml < _cntml_actual; _iml++) {
124  i_cap = cfac * cm * _vec_rhs[ni[_iml]];
125  }
126 }
127 
128 /* the rest can be constructed automatically from the above info*/
129 
130 void nrn_alloc_capacitance(double* data, Datum* pdata, int type) {
131  (void) pdata;
132  (void) type; /* unused */
133  data[0] = DEF_cm; /*default capacitance/cm^2*/
134 }
135 
136 void nrn_div_capacity(NrnThread* _nt, Memb_list* ml, int type) {
137  (void) type;
138  int _cntml_actual = ml->nodecount;
139  int _cntml_padded = ml->_nodecount_padded;
140  int _iml;
141  double* vdata;
142  (void) _nt;
143  (void) type;
144  (void) _cntml_padded; /* unused */
145 
146  int* ni = ml->nodeindices;
147 
148  vdata = ml->data;
150  for (_iml = 0; _iml < _cntml_actual; _iml++) {
151  i_cap = VEC_RHS(ni[_iml]);
152  VEC_RHS(ni[_iml]) /= 1.e-3 * cm;
153  // fprintf(stderr, "== nrn_div_cap: RHS[%d]=%.12f\n", ni[_iml], VEC_RHS(ni[_iml])) ;
154  }
155 }
156 
157 void nrn_mul_capacity(NrnThread* _nt, Memb_list* ml, int type) {
158  (void) type;
159  int _cntml_actual = ml->nodecount;
160  int _cntml_padded = ml->_nodecount_padded;
161  int _iml;
162  double* vdata;
163  (void) _nt;
164  (void) type;
165  (void) _cntml_padded; /* unused */
166 
167  int* ni = ml->nodeindices;
168 
169  const double cfac = .001 * _nt->cj;
170 
171  vdata = ml->data;
173  for (_iml = 0; _iml < _cntml_actual; _iml++) {
174  VEC_RHS(ni[_iml]) *= cfac * cm;
175  }
176 }
177 } // namespace coreneuron
VEC_RHS
#define VEC_RHS(i)
Definition: nrnconf.h:30
coreneuron::nrn_get_mechtype
int nrn_get_mechtype(const char *name)
Get mechanism type by the mechanism name.
Definition: mk_mech.cpp:138
coreneuron::nrn_jacob_capacitance
void nrn_jacob_capacitance(NrnThread *, Memb_list *, int)
Definition: capac.cpp:58
coreneuron::Datum
int Datum
Definition: nrnconf.h:23
SOA_LAYOUT
#define SOA_LAYOUT
Definition: data_layout.hpp:11
data
Definition: alignment.cpp:18
coreneuron::NrnThread::cj
double cj
Definition: multicore.hpp:78
nrn_pragma_omp
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:69
coreneuron::register_mech
int register_mech(const char **m, mod_alloc_t alloc, mod_f_t cur, mod_f_t jacob, mod_f_t stat, mod_f_t initialize, mod_f_t private_constructor, mod_f_t private_destructor, int nrnpointerindex, int vectorized)
Definition: register_mech.cpp:112
i_cap
#define i_cap
Definition: capac.cpp:49
coreneuron::Memb_list
Definition: mechanism.hpp:131
coreneuron::mechanism
static const char * mechanism[]
Definition: capac.cpp:22
coreneuron::NrnThread::_actual_rhs
double * _actual_rhs
Definition: multicore.hpp:111
coreneuron::NrnThread::compute_gpu
int compute_gpu
Definition: multicore.hpp:136
pdata
#define pdata
Definition: md1redef.h:37
coreneuron.hpp
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::_nrn_layout_reg
void _nrn_layout_reg(int, int)
Definition: register_mech.cpp:176
_PRAGMA_FOR_INIT_ACC_LOOP_
#define _PRAGMA_FOR_INIT_ACC_LOOP_
Definition: capac.cpp:15
coreneuron::capacitance_reg
void capacitance_reg(void)
Definition: capac.cpp:31
nparm
#define nparm
Definition: capac.cpp:29
coreneuron::_nrn_skip_initmodel
bool _nrn_skip_initmodel
Definition: finitialize.cpp:19
coreneuron::NrnThread
Definition: multicore.hpp:75
coreneuron::NrnThread::stream_id
int stream_id
Definition: multicore.hpp:137
cm
#define cm
Definition: capac.cpp:48
coreneuron::nrn_alloc_capacitance
void nrn_alloc_capacitance(double *data, Datum *pdata, int type)
Definition: capac.cpp:130
coreneuron::NrnThread::_actual_d
double * _actual_d
Definition: multicore.hpp:112
coreneuron::nrn_init_capacitance
void nrn_init_capacitance(NrnThread *, Memb_list *, int)
Definition: capac.cpp:83
coreneuron::Memb_list::nodecount
int nodecount
Definition: mechanism.hpp:144
coreneuron::nrn_cur_capacitance
void nrn_cur_capacitance(NrnThread *_nt, Memb_list *ml, int type)
Definition: capac.cpp:101
coreneuron::nrn_div_capacity
void nrn_div_capacity(NrnThread *, Memb_list *, int)
Definition: capac.cpp:136
coreneuron::nrn_mul_capacity
void nrn_mul_capacity(NrnThread *, Memb_list *, int)
Definition: capac.cpp:157
data_layout.hpp
coreneuron::Memb_list::_nodecount_padded
int _nodecount_padded
Definition: mechanism.hpp:145
coreneuron::Memb_list::data
double * data
Definition: mechanism.hpp:139
coreneuron::NrnThread::end
int end
Definition: multicore.hpp:98
coreneuron::nrn_pragma_acc
nrn_pragma_acc(routine vector) static void triang_interleaved2(NrnThread *nt
Definition: ivocvect.cpp:30
coreneuron::hoc_register_prop_size
void hoc_register_prop_size(int, int, int)
Definition: register_mech.cpp:192
coreneuron::if
if(ncell==0)
Definition: cellorder.cpp:637
coreneuron::Memb_list::nodeindices
int * nodeindices
Definition: mechanism.hpp:137
DEF_cm
#define DEF_cm
Definition: membrane_definitions.h:37