NEURON
rxd.h
Go to the documentation of this file.
1 #pragma once
2 #include <condition_variable>
3 #include <mutex>
4 #include <thread>
5 #include <vector>
6 
7 #define SPECIES_ABSENT -1
8 #define PREFETCH 4
9 
10 using fptr = void(void);
11 
12 // @olupton 2022-09-16: deleted a declaration of OcPtrVector that did not match
13 // the one in ocptrvector.h
14 
15 struct ReactSet {
17  int idx;
18 };
19 
20 struct ReactGridData {
23 };
24 
25 
26 struct CurrentData {
28  int onset, offset;
29  double* val;
30 };
31 
32 
34  int id;
35  double atolscale;
36  int* indices;
37  int length;
39 };
40 
41 struct ICSReactions {
47  int*** state_idx; /*[segment][species][region]*/
48  int icsN; /*total number species*regions per segment*/
49  /*NOTE: icsN != num_species*num_regions as every species may not be defined
50  *on every region - the missing elements of state_idx are SPECIES_ABSENT*/
51 
52  /*ECS for MultiCompartment reactions*/
55  double*** ecs_state; /*[segment][ecs_species]*/
58  int** ecs_index;
59  int ecsN; /*total number of ecs species*regions per segment*/
60 
61  int num_mult;
62  double** mc_multiplier;
64  double** vptrs;
68  double** result_array;
69  double** result_array_dx;
70  double* mc_mult;
71  double** flux;
72 
76  double* ecs_result;
77  double* ecs_result_dx;
78  int* ecsindex;
79  struct ICSReactions* next;
80 };
81 
82 struct TaskList {
83  void* (*task)(void*);
84  void* args;
85  void* result;
86  struct TaskList* next;
87 };
88 
89 struct TaskQueue {
90  std::condition_variable task_cond, waiting_cond;
92  std::vector<bool> exit;
93  int length{};
94  struct TaskList* first;
95  struct TaskList* last;
96 };
97 
98 extern "C" void set_num_threads(const int);
99 void _fadvance(void);
100 void _fadvance_fixed_step_3D(void);
101 
102 extern "C" int get_num_threads(void);
106 
107 void dg_transfer_data(AdiLineData* const, double* const, int const, int const, int const);
108 void ecs_run_threaded_dg_adi(const int, const int, ECS_Grid_node*, ECSAdiDirection*, const int);
110 void* do_reactions(void*);
111 
112 void current_reaction(double* states);
113 
114 void run_threaded_deltas(ICS_Grid_node* g, ICSAdiDirection* ics_adi_dir);
117  int,
118  int,
119  int,
120  double,
121  double*,
122  double*,
123  double*,
124  double*,
125  double*,
126  double*);
128  int,
129  int,
130  int,
131  double,
132  double*,
133  double*,
134  double*,
135  double*,
136  double*,
137  double*);
139  int,
140  int,
141  int,
142  double,
143  double*,
144  double*,
145  double*,
146  double*,
147  double*,
148  double*);
150  int,
151  int,
152  int,
153  double,
154  double*,
155  double*,
156  double*,
157  double*,
158  double*,
159  double*);
161  int,
162  int,
163  int,
164  double,
165  double*,
166  double*,
167  double*,
168  double*,
169  double*,
170  double*);
172  int,
173  int,
174  int,
175  double,
176  double*,
177  double*,
178  double*,
179  double*,
180  double*,
181  double*);
182 
183 /*Variable step function declarations*/
184 void _rhs_variable_step(const double*, double*);
185 
186 void _ode_reinit(double*);
187 
188 int ode_count(const int);
189 
190 extern "C" void scatter_concentrations(void);
191 
192 
193 int find(const int, const int, const int, const int, const int);
194 
197  const double*,
198  double* const,
199  const double*,
200  double* const);
201 
202 void _ics_rhs_variable_step_helper(ICS_Grid_node*, double const* const, double*);
203 void _rhs_variable_step_helper(Grid_node*, double const* const, double*);
204 
205 void ics_ode_solve(double, double*, const double*);
206 void ics_ode_solve_helper(ICS_Grid_node*, double, double*);
207 
208 void _rhs_variable_step_helper_tort(Grid_node*, double const* const, double*);
209 
210 void _rhs_variable_step_helper_vol(Grid_node*, double const* const, double*);
211 
212 void set_num_threads_3D(int n);
213 
214 void _rhs_variable_step_ecs(const double*, double*);
215 
216 void clear_rates_ecs();
217 void do_ics_reactions(double*, double*, double*, double*);
218 void get_all_reaction_rates(double*, double*, double*);
219 void _ecs_ode_reinit(double*);
220 void do_currents(Grid_node*, double*, double, int);
221 void TaskQueue_add_task(TaskQueue*, void* (*task)(void* args), void*, void*);
222 void TaskQueue_exe_tasks(std::size_t, TaskQueue*);
224 void ecs_atolscale(double*);
225 void apply_node_flux3D(Grid_node*, double, double*);
void(double **, double **, double **, double *, double *, double *, double *, double **, double) ReactionRate
Definition: grids.h:57
int const size_t const size_t n
Definition: nrngsl.h:10
double * states
Definition: rxd.cpp:75
void _ics_variable_hybrid_helper(ICS_Grid_node *, const double *, double *const, const double *, double *const)
void _ics_rhs_variable_step_helper(ICS_Grid_node *, double const *const, double *)
void _rhs_variable_step_ecs(const double *, double *)
void ecs_atolscale(double *)
void _rhs_variable_step(const double *, double *)
Definition: rxd.cpp:1336
void dg_transfer_data(AdiLineData *const, double *const, int const, int const, int const)
void _ecs_ode_reinit(double *)
void set_num_threads(const int)
Definition: rxd.cpp:1209
void set_num_threads_3D(int n)
void clear_rates_ecs()
void ecs_run_threaded_dg_adi(const int, const int, ECS_Grid_node *, ECSAdiDirection *, const int)
ReactGridData * create_threaded_reactions(const int)
void ecs_set_adi_tort(ECS_Grid_node *)
Definition: rxd_vol.cpp:772
void ics_dg_adi_z(ICS_Grid_node *g, int, int, int, double, double *, double *, double *, double *, double *, double *)
void ecs_set_adi_vol(ECS_Grid_node *)
Definition: rxd_vol.cpp:410
void run_threaded_deltas(ICS_Grid_node *g, ICSAdiDirection *ics_adi_dir)
void ics_ode_solve(double, double *, const double *)
void ics_ode_solve_helper(ICS_Grid_node *, double, double *)
void scatter_concentrations(void)
void do_currents(Grid_node *, double *, double, int)
void _rhs_variable_step_helper(Grid_node *, double const *const, double *)
void * do_reactions(void *)
void ics_dg_adi_x_inhom(ICS_Grid_node *g, int, int, int, double, double *, double *, double *, double *, double *, double *)
void TaskQueue_sync(TaskQueue *)
Definition: rxd.cpp:1257
int find(const int, const int, const int, const int, const int)
void TaskQueue_exe_tasks(std::size_t, TaskQueue *)
Definition: rxd.cpp:1171
void ics_dg_adi_z_inhom(ICS_Grid_node *g, int, int, int, double, double *, double *, double *, double *, double *, double *)
void TaskQueue_add_task(TaskQueue *, void *(*task)(void *args), void *, void *)
void run_threaded_ics_dg_adi(ICS_Grid_node *g, ICSAdiDirection *ics_adi_dir)
void ecs_set_adi_homogeneous(ECS_Grid_node *)
void _rhs_variable_step_helper_tort(Grid_node *, double const *const, double *)
Definition: rxd_vol.cpp:785
void _ode_reinit(double *)
Definition: rxd.cpp:1317
void(void) fptr
Definition: rxd.h:10
void do_ics_reactions(double *, double *, double *, double *)
Definition: rxd.cpp:1752
int get_num_threads(void)
Definition: rxd.cpp:1263
int ode_count(const int)
void _fadvance_fixed_step_3D(void)
void ics_dg_adi_y(ICS_Grid_node *g, int, int, int, double, double *, double *, double *, double *, double *, double *)
void _ics_hybrid_helper(ICS_Grid_node *)
void get_all_reaction_rates(double *, double *, double *)
Definition: rxd.cpp:1760
void apply_node_flux3D(Grid_node *, double, double *)
void _rhs_variable_step_helper_vol(Grid_node *, double const *const, double *)
Definition: rxd_vol.cpp:894
void ics_dg_adi_x(ICS_Grid_node *g, int, int, int, double, double *, double *, double *, double *, double *, double *)
void _fadvance(void)
Definition: rxd.cpp:1268
void current_reaction(double *states)
void ics_dg_adi_y_inhom(ICS_Grid_node *g, int, int, int, double, double *, double *, double *, double *, double *, double *)
double * val
Definition: rxd.h:29
int onset
Definition: rxd.h:28
Grid_node * g
Definition: rxd.h:27
int offset
Definition: rxd.h:28
double ** flux
Definition: rxd.h:71
int num_segments
Definition: rxd.h:46
double ** result_array_dx
Definition: rxd.h:69
ReactionRate * reaction
Definition: rxd.h:42
struct ICSReactions * next
Definition: rxd.h:79
int num_species
Definition: rxd.h:43
double * ecs_states_for_reaction
Definition: rxd.h:73
double ** states_for_reaction_dx
Definition: rxd.h:66
int ** ecs_index
Definition: rxd.h:58
double ** params_for_reaction
Definition: rxd.h:67
int * ecs_offset_index
Definition: rxd.h:56
ECS_Grid_node ** ecs_grid
Definition: rxd.h:57
double ** result_array
Definition: rxd.h:68
double ** states_for_reaction
Definition: rxd.h:65
int icsN
Definition: rxd.h:48
int num_params
Definition: rxd.h:45
int num_ecs_params
Definition: rxd.h:54
int num_ecs_species
Definition: rxd.h:53
int * mc_flux_idx
Definition: rxd.h:63
double * mc_mult
Definition: rxd.h:70
double ** vptrs
Definition: rxd.h:64
double * ecs_states_for_reaction_dx
Definition: rxd.h:74
int * ecsindex
Definition: rxd.h:78
double *** ecs_state
Definition: rxd.h:55
double * ecs_result_dx
Definition: rxd.h:77
double * ecs_result
Definition: rxd.h:76
int ecsN
Definition: rxd.h:59
int num_mult
Definition: rxd.h:61
double * ecs_params_for_reaction
Definition: rxd.h:75
double ** mc_multiplier
Definition: rxd.h:62
int num_regions
Definition: rxd.h:44
int *** state_idx
Definition: rxd.h:47
ReactSet * onset
Definition: rxd.h:21
ReactSet * offset
Definition: rxd.h:22
Definition: rxd.h:15
int idx
Definition: rxd.h:17
Reaction * reaction
Definition: rxd.h:16
int length
Definition: rxd.h:37
int * indices
Definition: rxd.h:36
struct SpeciesIndexList * next
Definition: rxd.h:38
double atolscale
Definition: rxd.h:35
Definition: rxd.h:82
struct TaskList * next
Definition: rxd.h:86
void *(* task)(void *)
Definition: rxd.h:83
void * result
Definition: rxd.h:85
void * args
Definition: rxd.h:84
Definition: rxd.h:89
int length
Definition: rxd.h:93
struct TaskList * first
Definition: rxd.h:94
std::mutex task_mutex
Definition: rxd.h:91
std::vector< bool > exit
Definition: rxd.h:92
struct TaskList * last
Definition: rxd.h:95
std::condition_variable task_cond
Definition: rxd.h:90
std::condition_variable waiting_cond
Definition: rxd.h:90
std::mutex waiting_mutex
Definition: rxd.h:91