NEURON
nvector_nrnthread.h
Go to the documentation of this file.
1 /*
2  * N_Vector_NrnThread derived from N_Vector_Serial SunDials version
3  * by replacing every occurrence of nrnthread with nrnthread in the various
4  * cases and then modifying the relevant prototypes.
5  * We only re-implement the ones that are used by cvodes and ida
6  */
7 
8 /*
9  * -----------------------------------------------------------------
10  * $Revision: 855 $
11  * $Date: 2005-02-09 18:15:46 -0500 (Wed, 09 Feb 2005) $
12  * -----------------------------------------------------------------
13  * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban,
14  * and Aaron Collier @ LLNL
15  * -----------------------------------------------------------------
16  * Copyright (c) 2002, The Regents of the University of California.
17  * Produced at the Lawrence Livermore National Laboratory.
18  * All rights reserved.
19  * For details, see sundials/shared/LICENSE.
20  * -----------------------------------------------------------------
21  * This is the header file for the nrnthread implementation of the
22  * NVECTOR module.
23  *
24  * Part I contains declarations specific to the nrnthread
25  * implementation of the supplied NVECTOR module.
26  *
27  * Part II defines accessor macros that allow the user to
28  * efficiently use the type N_Vector without making explicit
29  * references to the underlying data structure.
30  *
31  * Part III contains the prototype for the constructor N_VNew_NrnThread
32  * as well as implementation-specific prototypes for various useful
33  * vector operations.
34  *
35  * Notes:
36  *
37  * - The definition of the generic N_Vector structure can be found
38  * in the header file shared/include/nvector.h.
39  *
40  * - The definition of the type realtype can be found in the
41  * header file shared/include/sundialstypes.h, and it may be
42  * changed (at the configuration stage) according to the user's
43  * needs. The sundialstypes.h file also contains the definition
44  * for the type booleantype.
45  *
46  * - N_Vector arguments to arithmetic vector operations need not
47  * be distinct. For example, the following call:
48  *
49  * N_VLinearSum_NrnThread(a,x,b,y,y);
50  *
51  * (which stores the result of the operation a*x+b*y in y)
52  * is legal.
53  * -----------------------------------------------------------------
54  */
55 
56 #pragma once
57 
58 #include "nvector.h"
59 #include "sundialstypes.h"
60 extern "C" {
61 extern void N_VOneMask_Serial(N_Vector x);
62 }
63 
64 /*
65  * -----------------------------------------------------------------
66  * PART I: NRNTHREAD implementation of N_Vector
67  * -----------------------------------------------------------------
68  */
69 
70 /* nrnthread implementation of the N_Vector 'content' structure
71  contains the length of the vector, nthread, and a pointer to
72  nthread N_Vector (serial)
73 */
74 
76  long int length;
77  int nt; /* number of threads */
78  booleantype own_data;
79  N_Vector* data; /* nt of them (N_Vector_Serial) */
80 };
81 
83 
84 /* Note: documentation below may not be completely transformed from the
85  N_Vector_Serial case
86 */
87 
88 /*
89  * -----------------------------------------------------------------
90  * PART II: macros NV_CONTENT_S, NV_DATA_S, NV_OWN_DATA_S,
91  * NV_LENGTH_S, and NV_Ith_S
92  * -----------------------------------------------------------------
93  * In the descriptions below, the following user declarations
94  * are assumed:
95  *
96  * N_Vector v;
97  * long int i;
98  *
99  * (1) NV_CONTENT_NT
100  *
101  * This routines gives access to the contents of the nrnthread
102  * vector N_Vector.
103  *
104  * The assignment v_cont = NV_CONTENT_NT(v) sets v_cont to be
105  * a pointer to the nrnthread N_Vector content structure.
106  *
107  * (2) NV_SUBVEC_NT and NV_LENGTH_NT
108  *
109  * These routines give access to the individual parts of
110  * the content structure of a nrnthread N_Vector.
111  *
112  * The assignment v_data = NV_SUBVEC_NT(v, i) sets v_data to be
113  * a pointer to the ith N_Vector of v. The assignment
114  * NV_SUBVEC_NT(v, i) = data_V sets the ith component N_Vector of v to
115  * be data_v by storing the pointer data_v.
116  *
117  * The assignment v_llen = NV_SIZE_NT(v,i) sets v_llen to be
118  * the length of the ith component of v. The call NV_LENGTH_NT(v) = len_v sets
119  * the length of v to be len_v.
120  *
121  * (3) NV_Ith_NT
122  *
123  * In the following description, the components of an
124  * N_Vector are numbered 0..n-1, where n is the length of v.
125  *
126  * The assignment r = NV_Ith_S(v,i) sets r to be the value of
127  * the ith component of v. The assignment NV_Ith_S(v,i) = r
128  * sets the value of the ith component of v to be r.
129  *
130  * Note: When looping over the components of an N_Vector v, it is
131  * more efficient to first obtain the component array via
132  * v_data = NV_DATA_S(v) and then access v_data[i] within the
133  * loop than it is to use NV_Ith_S(v,i) within the loop.
134  * -----------------------------------------------------------------
135  */
136 
137 #define NV_CONTENT_NT(v) ((N_VectorContent_NrnThread) (v->content))
138 
139 #define NV_LENGTH_NT(v) (NV_CONTENT_NT(v)->length)
140 
141 #define NV_NT_NT(v) (NV_CONTENT_NT(v)->nt)
142 
143 #define NV_OWN_DATA_NT(v) (NV_CONTENT_NT(v)->own_data)
144 
145 #define NV_DATA_NT(v) (NV_CONTENT_NT(v)->data)
146 
147 #define NV_SUBVEC_NT(v, i) (NV_CONTENT_NT(v)->data[i])
148 
149 #define NV_Ith_NT(v, i) (NV_DATA_NT(v)[i]) /* wrong but not needed */
150 
151 /*
152  * -----------------------------------------------------------------
153  * PART III: functions exported by nvector_nrnthread
154  *
155  * CONSTRUCTORS:
156  * N_VNew_NrnThread
157  * N_VNewEmpty_NrnThread
158  * N_VClone_NrnThread
159  * N_VCloneEmpty_NrnThread
160  * N_VMake_NrnThread
161  * N_VNewVectorArray_NrnThread
162  * N_VNewVectorArrayEmpty_NrnThread
163  * DESTRUCTORS:
164  * N_VDestroy_NrnThread
165  * N_VDestroyVectorArray_NrnThread
166  * -----------------------------------------------------------------
167  */
168 
169 /*
170  * -----------------------------------------------------------------
171  * Function : N_VNew_NrnThread
172  * -----------------------------------------------------------------
173  * This function creates and allocates memory for a nrnthread vector.
174  * -----------------------------------------------------------------
175  */
176 
177 N_Vector N_VNew_NrnThread(long int vec_length, int nthread, long int* sizes);
178 
179 /*
180  * -----------------------------------------------------------------
181  * Function : N_VNewEmpty_NrnThread
182  * -----------------------------------------------------------------
183  * This function creates a new nrnthread N_Vector with an empty (NULL)
184  * data array.
185  * -----------------------------------------------------------------
186  */
187 
188 N_Vector N_VNewEmpty_NrnThread(long int vec_length, int nthread, long int* sizes);
189 
190 /*
191  * -----------------------------------------------------------------
192  * Function : N_VCloneEmpty_NrnThread
193  * -----------------------------------------------------------------
194  * This function creates a new nrnthread N_Vector with an empty (NULL)
195  * data array.
196  * -----------------------------------------------------------------
197  */
198 
199 N_Vector N_VCloneEmpty_NrnThread(N_Vector w);
200 
201 /*
202  * -----------------------------------------------------------------
203  * Function : N_VMake_NrnThread
204  * -----------------------------------------------------------------
205  * This function creates and allocates memory for a nrnthread vector
206  * with a user-supplied data array.
207  * -----------------------------------------------------------------
208  */
209 
210 /*not implemented*/
211 N_Vector N_VMake_NrnThread(long int vec_length, realtype* v_data);
212 
213 /*
214  * -----------------------------------------------------------------
215  * Function : N_VNewVectorArray_NrnThread
216  * -----------------------------------------------------------------
217  * This function creates an array of 'count' nrnthread vectors. This
218  * array of N_Vectors can be freed using N_VDestroyVectorArray
219  * (defined by the generic NVECTOR module).
220  * -----------------------------------------------------------------
221  */
222 
223 N_Vector* N_VNewVectorArray_NrnThread(int count, long int vec_length, int nthread, long int* sizes);
224 
225 /*
226  * -----------------------------------------------------------------
227  * Function : N_VNewVectorArrayEmpty_NrnThread
228  * -----------------------------------------------------------------
229  * This function creates an array of 'count' nrnthread vectors each
230  * with an empty (NULL) data array.
231  * -----------------------------------------------------------------
232  */
233 
234 N_Vector* N_VNewVectorArrayEmpty_NrnThread(int count,
235  long int vec_length,
236  int nthread,
237  long int* sizes);
238 
239 /*
240  * -----------------------------------------------------------------
241  * Function : N_VDestroyVectorArray_NrnThread
242  * -----------------------------------------------------------------
243  * This function frees an array of N_Vector created with
244  * N_VNewVectorArray_NrnThread.
245  * -----------------------------------------------------------------
246  */
247 
248 void N_VDestroyVectorArray_NrnThread(N_Vector* vs, int count);
249 
250 /*
251  * -----------------------------------------------------------------
252  * Function : N_VPrint_NrnThread
253  * -----------------------------------------------------------------
254  * This function prints the content of a nrnthread vector to stdout.
255  * -----------------------------------------------------------------
256  */
257 
258 void N_VPrint_NrnThread(N_Vector v);
259 
260 /*
261  * -----------------------------------------------------------------
262  * nrnthread implementations of various useful vector operations
263  * -----------------------------------------------------------------
264  */
265 
266 N_Vector N_VClone_NrnThread(N_Vector w);
267 void N_VDestroy_NrnThread(N_Vector v);
268 void N_VSpace_NrnThread(N_Vector v, long int* lrw, long int* liw);
269 realtype* N_VGetArrayPointer_NrnThread(N_Vector v);
270 void N_VSetArrayPointer_NrnThread(realtype* v_data, N_Vector v);
271 void N_VLinearSum_NrnThread(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z);
272 void N_VConst_NrnThread(realtype c, N_Vector z);
273 void N_VProd_NrnThread(N_Vector x, N_Vector y, N_Vector z);
274 void N_VDiv_NrnThread(N_Vector x, N_Vector y, N_Vector z);
275 void N_VScale_NrnThread(realtype c, N_Vector x, N_Vector z);
276 void N_VAbs_NrnThread(N_Vector x, N_Vector z);
277 void N_VInv_NrnThread(N_Vector x, N_Vector z);
278 void N_VAddConst_NrnThread(N_Vector x, realtype b, N_Vector z);
279 realtype N_VDotProd_NrnThread(N_Vector x, N_Vector y);
280 realtype N_VMaxNorm_NrnThread(N_Vector x);
281 realtype N_VWrmsNorm_NrnThread(N_Vector x, N_Vector w);
282 realtype N_VWrmsNormMask_NrnThread(N_Vector x, N_Vector w, N_Vector id);
283 realtype N_VMin_NrnThread(N_Vector x);
284 realtype N_VWL2Norm_NrnThread(N_Vector x, N_Vector w);
285 realtype N_VL1Norm_NrnThread(N_Vector x);
286 void N_VCompare_NrnThread(realtype c, N_Vector x, N_Vector z);
287 booleantype N_VInvTest_NrnThread(N_Vector x, N_Vector z);
288 booleantype N_VConstrMask_NrnThread(N_Vector c, N_Vector x, N_Vector m);
289 realtype N_VMinQuotient_NrnThread(N_Vector num, N_Vector denom);
#define v
Definition: md1redef.h:11
static int c
Definition: hoc.cpp:169
void N_VSetArrayPointer_NrnThread(realtype *v_data, N_Vector v)
booleantype N_VInvTest_NrnThread(N_Vector x, N_Vector z)
void N_VSpace_NrnThread(N_Vector v, long int *lrw, long int *liw)
N_Vector * N_VNewVectorArrayEmpty_NrnThread(int count, long int vec_length, int nthread, long int *sizes)
realtype N_VMinQuotient_NrnThread(N_Vector num, N_Vector denom)
void N_VConst_NrnThread(realtype c, N_Vector z)
realtype N_VMin_NrnThread(N_Vector x)
realtype N_VDotProd_NrnThread(N_Vector x, N_Vector y)
void N_VLinearSum_NrnThread(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z)
void N_VCompare_NrnThread(realtype c, N_Vector x, N_Vector z)
void N_VAbs_NrnThread(N_Vector x, N_Vector z)
void N_VDiv_NrnThread(N_Vector x, N_Vector y, N_Vector z)
void N_VOneMask_Serial(N_Vector x)
void N_VAddConst_NrnThread(N_Vector x, realtype b, N_Vector z)
void N_VScale_NrnThread(realtype c, N_Vector x, N_Vector z)
void N_VDestroyVectorArray_NrnThread(N_Vector *vs, int count)
N_Vector N_VCloneEmpty_NrnThread(N_Vector w)
void N_VInv_NrnThread(N_Vector x, N_Vector z)
N_Vector N_VNewEmpty_NrnThread(long int vec_length, int nthread, long int *sizes)
N_Vector * N_VNewVectorArray_NrnThread(int count, long int vec_length, int nthread, long int *sizes)
booleantype N_VConstrMask_NrnThread(N_Vector c, N_Vector x, N_Vector m)
void N_VDestroy_NrnThread(N_Vector v)
N_Vector N_VMake_NrnThread(long int vec_length, realtype *v_data)
void N_VPrint_NrnThread(N_Vector v)
realtype N_VWL2Norm_NrnThread(N_Vector x, N_Vector w)
realtype N_VWrmsNormMask_NrnThread(N_Vector x, N_Vector w, N_Vector id)
realtype N_VWrmsNorm_NrnThread(N_Vector x, N_Vector w)
void N_VProd_NrnThread(N_Vector x, N_Vector y, N_Vector z)
struct _N_VectorContent_NrnThread * N_VectorContent_NrnThread
realtype N_VL1Norm_NrnThread(N_Vector x)
realtype N_VMaxNorm_NrnThread(N_Vector x)
N_Vector N_VClone_NrnThread(N_Vector w)
realtype * N_VGetArrayPointer_NrnThread(N_Vector v)
N_Vector N_VNew_NrnThread(long int vec_length, int nthread, long int *sizes)