NEURON
capac.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 
11 
12 #define _PRAGMA_FOR_INIT_ACC_LOOP_ \
13  nrn_pragma_acc(parallel loop present(vdata [0:_cntml_padded * nparm]) if (_nt->compute_gpu)) \
14  nrn_pragma_omp(target teams distribute parallel for simd if(_nt->compute_gpu))
15 #define CNRN_FLAT_INDEX_IML_ROW(i) ((i) * (_cntml_padded) + (_iml))
16 
17 namespace coreneuron {
18 
19 static const char* mechanism[] = {"0", "capacitance", "cm", 0, "i_cap", 0, 0};
20 void nrn_alloc_capacitance(double*, Datum*, int);
25 
26 #define nparm 2
27 
28 void capacitance_reg(void) {
29  /* all methods deal with capacitance in special ways */
32  nullptr,
33  nullptr,
34  nullptr,
36  nullptr,
37  nullptr,
38  -1,
39  1);
40  int mechtype = nrn_get_mechtype(mechanism[1]);
41  _nrn_layout_reg(mechtype, SOA_LAYOUT);
42  hoc_register_prop_size(mechtype, nparm, 0);
43 }
44 
45 #define cm vdata[CNRN_FLAT_INDEX_IML_ROW(0)]
46 #define i_cap vdata[CNRN_FLAT_INDEX_IML_ROW(1)]
47 
48 /*
49 cj is analogous to 1/dt for cvode and daspk
50 for fixed step second order it is 2/dt and
51 for pure implicit fixed step it is 1/dt
52 It used to be static but is now a thread data variable
53 */
54 
55 void nrn_jacob_capacitance(NrnThread* _nt, Memb_list* ml, int /* type */) {
56  int _cntml_actual = ml->nodecount;
57  int _cntml_padded = ml->_nodecount_padded;
58  int _iml;
59  double* vdata;
60  double cfac = .001 * _nt->cj;
61  (void) _cntml_padded; /* unused when layout=1*/
62 
63  double* _vec_d = _nt->_actual_d;
64 
65  { /*if (use_cachevec) {*/
66  int* ni = ml->nodeindices;
67 
68  vdata = ml->data;
69  nrn_pragma_acc(parallel loop present(vdata [0:_cntml_padded * nparm],
70  ni [0:_cntml_actual],
71  _vec_d [0:_nt->end]) if (_nt->compute_gpu)
72  async(_nt->stream_id))
73  nrn_pragma_omp(target teams distribute parallel for simd if(_nt->compute_gpu))
74  for (_iml = 0; _iml < _cntml_actual; _iml++) {
75  _vec_d[ni[_iml]] += cfac * cm;
76  }
77  }
78 }
79 
80 void nrn_init_capacitance(NrnThread* _nt, Memb_list* ml, int /* type */) {
81  int _cntml_actual = ml->nodecount;
82  int _cntml_padded = ml->_nodecount_padded;
83  double* vdata;
84  (void) _cntml_padded; /* unused */
85 
86  // skip initialization if restoring from checkpoint
87  if (_nrn_skip_initmodel == 1) {
88  return;
89  }
90 
91  vdata = ml->data;
93  for (int _iml = 0; _iml < _cntml_actual; _iml++) {
94  i_cap = 0;
95  }
96 }
97 
98 void nrn_cur_capacitance(NrnThread* _nt, Memb_list* ml, int /* type */) {
99  int _cntml_actual = ml->nodecount;
100  int _cntml_padded = ml->_nodecount_padded;
101  double* vdata;
102  double cfac = .001 * _nt->cj;
103 
104  /*@todo: verify cfac is being copied !! */
105 
106  (void) _cntml_padded; /* unused when layout=1*/
107 
108  /* since rhs is dvm for a full or half implicit step */
109  /* (nrn_update_2d() replaces dvi by dvi-dvx) */
110  /* no need to distinguish secondorder */
111  int* ni = ml->nodeindices;
112  double* _vec_rhs = _nt->_actual_rhs;
113 
114  vdata = ml->data;
115  nrn_pragma_acc(parallel loop present(vdata [0:_cntml_padded * nparm],
116  ni [0:_cntml_actual],
117  _vec_rhs [0:_nt->end]) if (_nt->compute_gpu)
118  async(_nt->stream_id))
119  nrn_pragma_omp(target teams distribute parallel for simd if(_nt->compute_gpu))
120  for (int _iml = 0; _iml < _cntml_actual; _iml++) {
121  i_cap = cfac * cm * _vec_rhs[ni[_iml]];
122  }
123 }
124 
125 /* the rest can be constructed automatically from the above info*/
126 
127 void nrn_alloc_capacitance(double* data, Datum* pdata, int type) {
128  (void) pdata;
129  (void) type; /* unused */
130  data[0] = DEF_cm; /*default capacitance/cm^2*/
131 }
132 
133 void nrn_div_capacity(NrnThread* _nt, Memb_list* ml, int type) {
134  (void) type;
135  int _cntml_actual = ml->nodecount;
136  int _cntml_padded = ml->_nodecount_padded;
137  int _iml;
138  double* vdata;
139  (void) _nt;
140  (void) type;
141  (void) _cntml_padded; /* unused */
142 
143  int* ni = ml->nodeindices;
144 
145  vdata = ml->data;
147  for (_iml = 0; _iml < _cntml_actual; _iml++) {
148  i_cap = VEC_RHS(ni[_iml]);
149  VEC_RHS(ni[_iml]) /= 1.e-3 * cm;
150  // fprintf(stderr, "== nrn_div_cap: RHS[%d]=%.12f\n", ni[_iml], VEC_RHS(ni[_iml])) ;
151  }
152 }
153 
154 void nrn_mul_capacity(NrnThread* _nt, Memb_list* ml, int type) {
155  (void) type;
156  int _cntml_actual = ml->nodecount;
157  int _cntml_padded = ml->_nodecount_padded;
158  int _iml;
159  double* vdata;
160  (void) _nt;
161  (void) type;
162  (void) _cntml_padded; /* unused */
163 
164  int* ni = ml->nodeindices;
165 
166  const double cfac = .001 * _nt->cj;
167 
168  vdata = ml->data;
170  for (_iml = 0; _iml < _cntml_actual; _iml++) {
171  VEC_RHS(ni[_iml]) *= cfac * cm;
172  }
173 }
174 } // namespace coreneuron
#define i_cap
Definition: capac.cpp:46
#define cm
Definition: capac.cpp:45
#define nparm
Definition: capac.cpp:26
#define _PRAGMA_FOR_INIT_ACC_LOOP_
Definition: capac.cpp:12
#define pdata
Definition: md1redef.h:37
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 SOA_LAYOUT
Definition: data_layout.hpp:11
#define DEF_cm
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
void capacitance_reg(void)
Definition: capac.cpp:28
bool _nrn_skip_initmodel
Definition: finitialize.cpp:19
void _nrn_layout_reg(int, int)
void nrn_mul_capacity(NrnThread *, Memb_list *, int)
Definition: capac.cpp:154
void nrn_div_capacity(NrnThread *, Memb_list *, int)
Definition: capac.cpp:133
static const char * mechanism[]
Definition: capac.cpp:19
void nrn_cur_capacitance(NrnThread *_nt, Memb_list *ml, int type)
Definition: capac.cpp:98
int Datum
Definition: nrnconf.h:23
void nrn_alloc_capacitance(double *data, Datum *pdata, int type)
Definition: capac.cpp:127
int nrn_get_mechtype(const char *name)
Get mechanism type by the mechanism name.
Definition: mk_mech.cpp:145
nrn_pragma_acc(routine seq) int vector_capacity(void *v)
Definition: ivocvect.cpp:30
void hoc_register_prop_size(int, int, int)
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)
void nrn_init_capacitance(NrnThread *, Memb_list *, int)
Definition: capac.cpp:80
void nrn_jacob_capacitance(NrnThread *, Memb_list *, int)
Definition: capac.cpp:55
if(ncell==0)
Definition: cellorder.cpp:785
#define VEC_RHS(i)
Definition: nrnconf.h:30
short type
Definition: cabvars.h:10
A view into a set of mechanism instances.
Definition: nrnoc_ml.h:34
Represent main neuron object computed by single thread.
Definition: multicore.h:58
Non-template stable handle to a generic value.