CoreNEURON
mod2c_core_thread.hpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================
7 */
8 
9 #pragma once
10 
14 
15 namespace coreneuron {
16 
17 #define _STRIDE _cntml_padded + _iml
18 
19 #define _threadargscomma_ _iml, _cntml_padded, _p, _ppvar, _thread, _nt, _ml, _v,
20 #define _threadargsprotocomma_ \
21  int _iml, int _cntml_padded, double *_p, Datum *_ppvar, ThreadDatum *_thread, NrnThread *_nt, \
22  Memb_list *_ml, double _v,
23 #define _threadargs_ _iml, _cntml_padded, _p, _ppvar, _thread, _nt, _ml, _v
24 #define _threadargsproto_ \
25  int _iml, int _cntml_padded, double *_p, Datum *_ppvar, ThreadDatum *_thread, NrnThread *_nt, \
26  Memb_list *_ml, double _v
27 
28 struct Elm {
29  unsigned row; /* Row location */
30  unsigned col; /* Column location */
31  double* value; /* The value SOA _cntml_padded of them*/
32  struct Elm* r_up; /* Link to element in same column */
33  struct Elm* r_down; /* in solution order */
34  struct Elm* c_left; /* Link to left element in same row */
35  struct Elm* c_right; /* in solution order (see getelm) */
36 };
37 
38 struct Item {
39  Elm* elm{};
40  unsigned norder{}; /* order of a row */
41  Item* next{};
42  Item* prev{};
43 };
44 
45 using List = Item; /* list of mixed items */
46 
47 struct SparseObj { /* all the state information */
48  Elm** rowst{}; /* link to first element in row (solution order)*/
49  Elm** diag{}; /* link to pivot element in row (solution order)*/
50  void* elmpool{}; /* no interthread cache line sharing for elements */
51  unsigned neqn{}; /* number of equations */
52  unsigned _cntml_padded{}; /* number of instances */
53  unsigned* varord{}; /* row and column order for pivots */
54  double* rhs{}; /* initially- right hand side finally - answer */
55  unsigned* ngetcall{}; /* per instance counter for number of calls to _getelm */
56  int phase{}; /* 0-solution phase; 1-count phase; 2-build list phase */
57  int numop{};
58  unsigned coef_list_size{};
59  double** coef_list{}; /* pointer to (first instance) value in _getelm order */
60  /* don't really need the rest */
61  int nroworder{}; /* just for freeing */
62  Item** roworder{}; /* roworder[i] is pointer to order item for row i.
63  Does not have to be in orderlist */
64  List* orderlist{}; /* list of rows sorted by norder
65  that haven't been used */
66  int do_flag{};
67 };
68 
69 extern void _nrn_destroy_sparseobj_thread(SparseObj* so);
70 
71 // derived from nrn/src/scopmath/euler.c
72 // updated for aos/soa layout index
73 template <typename F>
74 int euler_thread(int neqn, int* var, int* der, F fun, _threadargsproto_) {
75  double const dt{_nt->_dt};
76  /* calculate the derivatives */
77  fun(_threadargs_); // std::invoke in C++17
78  /* update dependent variables */
79  for (int i = 0; i < neqn; i++) {
80  _p[var[i] * _STRIDE] += dt * (_p[der[i] * _STRIDE]);
81  }
82  return 0;
83 }
84 
85 template <typename F>
86 int derivimplicit_thread(int n, int* slist, int* dlist, F fun, _threadargsproto_) {
87  fun(_threadargs_); // std::invoke in C++17
88  return 0;
89 }
90 
91 void nrn_sparseobj_copyto_device(SparseObj* so);
92 void nrn_sparseobj_delete_from_device(SparseObj* so);
93 
94 } // namespace coreneuron
coreneuron::SparseObj::rowst
Elm ** rowst
Definition: mod2c_core_thread.hpp:48
mechanism.hpp
coreneuron::SparseObj::do_flag
int do_flag
Definition: mod2c_core_thread.hpp:66
coreneuron::Elm::value
double * value
Definition: mod2c_core_thread.hpp:31
_STRIDE
#define _STRIDE
Definition: mod2c_core_thread.hpp:17
coreneuron::SparseObj::elmpool
void * elmpool
Definition: mod2c_core_thread.hpp:50
coreneuron::SparseObj::roworder
Item ** roworder
Definition: mod2c_core_thread.hpp:62
coreneuron::SparseObj::numop
int numop
Definition: mod2c_core_thread.hpp:57
coreneuron::SparseObj::coef_list_size
unsigned coef_list_size
Definition: mod2c_core_thread.hpp:58
coreneuron::SparseObj::nroworder
int nroworder
Definition: mod2c_core_thread.hpp:61
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::nrn_sparseobj_delete_from_device
void nrn_sparseobj_delete_from_device(SparseObj *so)
Definition: nrn_acc_manager.cpp:1392
coreneuron::i
int i
Definition: cellorder.cpp:485
_threadargs_
#define _threadargs_
Definition: mod2c_core_thread.hpp:23
coreneuron::dt
double dt
Definition: register_mech.cpp:22
coreneuron::Elm::r_down
struct Elm * r_down
Definition: mod2c_core_thread.hpp:33
coreneuron::SparseObj::varord
unsigned * varord
Definition: mod2c_core_thread.hpp:53
coreneuron::Elm::row
unsigned row
Definition: mod2c_core_thread.hpp:29
coreneuron::SparseObj
Definition: mod2c_core_thread.hpp:47
coreneuron::SparseObj::diag
Elm ** diag
Definition: mod2c_core_thread.hpp:49
coreneuron::SparseObj::phase
int phase
Definition: mod2c_core_thread.hpp:56
coreneuron::SparseObj::orderlist
List * orderlist
Definition: mod2c_core_thread.hpp:64
coreneuron::derivimplicit_thread
int derivimplicit_thread(int n, int *slist, int *dlist, F fun, _threadargsproto_)
Definition: mod2c_core_thread.hpp:86
coreneuron::SparseObj::_cntml_padded
unsigned _cntml_padded
Definition: mod2c_core_thread.hpp:52
coreneuron::Elm
Definition: mod2c_core_thread.hpp:28
_threadargsproto_
#define _threadargsproto_
Definition: mod2c_core_thread.hpp:24
coreneuron::Item::norder
unsigned norder
Definition: mod2c_core_thread.hpp:40
coreneuron::euler_thread
int euler_thread(int neqn, int *var, int *der, F fun, _threadargsproto_)
Definition: mod2c_core_thread.hpp:74
coreneuron::SparseObj::coef_list
double ** coef_list
Definition: mod2c_core_thread.hpp:59
coreneuron::Elm::c_left
struct Elm * c_left
Definition: mod2c_core_thread.hpp:34
coreneuron::Elm::col
unsigned col
Definition: mod2c_core_thread.hpp:30
coreneuron::SparseObj::neqn
unsigned neqn
Definition: mod2c_core_thread.hpp:51
coreneuron::Elm::c_right
struct Elm * c_right
Definition: mod2c_core_thread.hpp:35
multicore.hpp
coreneuron::_nrn_destroy_sparseobj_thread
void _nrn_destroy_sparseobj_thread(SparseObj *so)
Definition: sparse_thread.hpp:628
coreneuron::Item::next
Item * next
Definition: mod2c_core_thread.hpp:41
coreneuron::nrn_sparseobj_copyto_device
void nrn_sparseobj_copyto_device(SparseObj *so)
Definition: nrn_acc_manager.cpp:1309
coreneuron::SparseObj::rhs
double * rhs
Definition: mod2c_core_thread.hpp:54
coreneuron::Item
Definition: mod2c_core_thread.hpp:38
coreneuron::Elm::r_up
struct Elm * r_up
Definition: mod2c_core_thread.hpp:32
offload.hpp
coreneuron::Item::elm
Elm * elm
Definition: mod2c_core_thread.hpp:39
coreneuron::Item::prev
Item * prev
Definition: mod2c_core_thread.hpp:42
coreneuron::SparseObj::ngetcall
unsigned * ngetcall
Definition: mod2c_core_thread.hpp:55