NEURON
nvector_nrnparallel_ld.h
Go to the documentation of this file.
1 /*
2  * N_Vector_NrnParallelLD derived from N_Vector_Parallel Sundials version
3  * by replacing every occurrence of Parallel with NrnParallelLD and then
4  * modifying relevant method implementations to allow long double
5  * accumulation.
6  */
7 /*
8 Macros changed with
9 sed 's/NV_\‍([A-Za-z_]*\‍)_P/NV_\1_P_LD/g' nvector_nrnparallel_ld.h >temp
10 mv temp nvector_nrnparallel_ld.h
11 sed 's/NV_\‍([A-Za-z_]*\‍)_P/NV_\1_P_LD/g' nvector_nrnparallel_ld.cpp >temp
12 mv temp nvector_nrnparallel_ld.cpp
13 */
14 
15 /*
16  * -----------------------------------------------------------------
17  * $Revision: 855 $
18  * $Date: 2005-02-10 00:15:46 +0100 (Thu, 10 Feb 2005) $
19  * -----------------------------------------------------------------
20  * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban,
21  * and Aaron Collier @ LLNL
22  * -----------------------------------------------------------------
23  * Copyright (c) 2002, The Regents of the University of California.
24  * Produced at the Lawrence Livermore National Laboratory.
25  * All rights reserved.
26  * For details, see sundials/shared/LICENSE.
27  * -----------------------------------------------------------------
28  * This is the main header file for the MPI-enabled implementation
29  * of the NVECTOR module.
30  *
31  * Part I contains declarations specific to the parallel
32  * implementation of the supplied NVECTOR module.
33  *
34  * Part II defines accessor macros that allow the user to efficiently
35  * use the type N_Vector without making explicit references to the
36  * underlying data structure.
37  *
38  * Part III contains the prototype for the constructor
39  * N_VNew_Parallel as well as implementation-specific prototypes
40  * for various useful vector operations.
41  *
42  * Notes:
43  *
44  * - The definition of the generic N_Vector structure can be
45  * found in the header file shared/include/nvector.h.
46  *
47  * - The definition of the type realtype can be found in the
48  * header file shared/include/sundialstypes.h, and it may be
49  * changed (at the configuration stage) according to the user's
50  * needs. The sundialstypes.h file also contains the definition
51  * for the type booleantype.
52  *
53  * - N_Vector arguments to arithmetic vector operations need not
54  * be distinct. For example, the following call:
55  *
56  * N_VLinearSum_Parallel(a,x,b,y,y);
57  *
58  * (which stores the result of the operation a*x+b*y in y)
59  * is legal.
60  * -----------------------------------------------------------------
61  */
62 
63 #pragma once
64 
65 #include <nrnmpiuse.h>
66 #define MPI_Comm int
67 
68 #include "nvector.h"
69 #include "sundialstypes.h"
70 
71 /*
72  * -----------------------------------------------------------------
73  * PART I: PARALLEL implementation of N_Vector
74  * -----------------------------------------------------------------
75  */
76 
77 /* parallel implementation of the N_Vector 'content' structure
78  contains the global and local lengths of the vector, a pointer
79  to an array of realtype components, the MPI communicator,
80  and a flag indicating ownership of the data */
81 
83  long int local_length; /* local vector length */
84  long int global_length; /* global vector length */
85  booleantype own_data; /* ownership of data */
86  realtype* data; /* local data array */
87  MPI_Comm comm; /* pointer to MPI communicator */
88 };
89 
91 
92 /*
93  * -----------------------------------------------------------------
94  * PART II: macros NV_CONTENT_P_LD, NV_DATA_P_LD, NV_OWN_DATA_P_LD,
95  * NV_LOCLENGTH_P_LD, NV_GLOBLENGTH_P_LD,NV_COMM_P_LD, and NV_Ith_P_LD
96  * -----------------------------------------------------------------
97  * In the descriptions below, the following user declarations
98  * are assumed:
99  *
100  * N_Vector v;
101  * long int v_len, s_len, i;
102  *
103  * (1) NV_CONTENT_P_LD
104  *
105  * This routines gives access to the contents of the parallel
106  * vector N_Vector.
107  *
108  * The assignment v_cont = NV_CONTENT_P_LD(v) sets v_cont to be
109  * a pointer to the parallel N_Vector content structure.
110  *
111  * (2) NV_DATA_P_LD, NV_OWN_DATA_P_LD, NV_LOCLENGTH_P_LD, NV_GLOBLENGTH_P_LD,
112  * and NV_COMM_P_LD
113  *
114  * These routines give access to the individual parts of
115  * the content structure of a parallel N_Vector.
116  *
117  * The assignment v_data = NV_DATA_P_LD(v) sets v_data to be
118  * a pointer to the first component of the local data for
119  * the vector v. The assignment NV_DATA_P_LD(v) = data_v sets
120  * the component array of v to be data_V by storing the
121  * pointer data_v.
122  *
123  * The assignment v_llen = NV_LOCLENGTH_P_LD(v) sets v_llen to
124  * be the length of the local part of the vector v. The call
125  * NV_LOCLENGTH_P_LD(v) = llen_v sets the local length
126  * of v to be llen_v.
127  *
128  * The assignment v_glen = NV_GLOBLENGTH_P_LD(v) sets v_glen to
129  * be the global length of the vector v. The call
130  * NV_GLOBLENGTH_P_LD(v) = glen_v sets the global length of v to
131  * be glen_v.
132  *
133  * The assignment v_comm = NV_COMM_P_LD(v) sets v_comm to be the
134  * MPI communicator of the vector v. The assignment
135  * NV_COMM_C(v) = comm_v sets the MPI communicator of v to be
136  * comm_v.
137  *
138  * (3) NV_Ith_P_LD
139  *
140  * In the following description, the components of the
141  * local part of an N_Vector are numbered 0..n-1, where n
142  * is the local length of (the local part of) v.
143  *
144  * The assignment r = NV_Ith_P_LD(v,i) sets r to be the value
145  * of the ith component of the local part of the vector v.
146  * The assignment NV_Ith_P_LD(v,i) = r sets the value of the
147  * ith local component of v to be r.
148  *
149  * Note: When looping over the components of an N_Vector v, it is
150  * more efficient to first obtain the component array via
151  * v_data = NV_DATA_P_LD(v) and then access v_data[i] within the
152  * loop than it is to use NV_Ith_P_LD(v,i) within the loop.
153  * -----------------------------------------------------------------
154  */
155 
156 #define NV_CONTENT_P_LD(v) ((N_VectorContent_NrnParallelLD) (v->content))
157 
158 #define NV_LOCLENGTH_P_LD(v) (NV_CONTENT_P_LD(v)->local_length)
159 
160 #define NV_GLOBLENGTH_P_LD(v) (NV_CONTENT_P_LD(v)->global_length)
161 
162 #define NV_OWN_DATA_P_LD(v) (NV_CONTENT_P_LD(v)->own_data)
163 
164 #define NV_DATA_P_LD(v) (NV_CONTENT_P_LD(v)->data)
165 
166 #define NV_COMM_P_LD(v) (NV_CONTENT_P_LD(v)->comm)
167 
168 #define NV_Ith_P_LD(v, i) (NV_DATA_P_LD(v)[i])
169 
170 /*
171  * -----------------------------------------------------------------
172  * PART III: functions exported by nvector_parallel
173  *
174  * CONSTRUCTORS:
175  * N_VNew_NrnParallelLD
176  * N_VNewEmpty_NrnParallelLD
177  * N_VClone_NrnParallelLD
178  * N_VCloneEmpty_NrnParallelLD
179  * N_VMake_NrnParallelLD
180  * N_VNewVectorArray_NrnParallelLD
181  * N_VNewVectorArrayEmpty_NrnParallelLD
182  * DESTRUCTORS:
183  * N_VDestroy_NrnParallelLD
184  * N_VDestroyVectorArray_NrnParallelLD
185  * -----------------------------------------------------------------
186  */
187 
188 /*
189  * -----------------------------------------------------------------
190  * Function : N_VNew_NrnParallelLD
191  * -----------------------------------------------------------------
192  * This function creates and allocates memory for a parallel vector.
193  * -----------------------------------------------------------------
194  */
195 
196 extern "C" N_Vector N_VNew_NrnParallelLD(MPI_Comm comm,
197  long int local_length,
198  long int global_length);
199 
200 /*
201  * -----------------------------------------------------------------
202  * Function : N_VNewEmpty_NrnParallelLD
203  * -----------------------------------------------------------------
204  * This function creates a new parallel N_Vector with an empty
205  * (NULL) data array.
206  * -----------------------------------------------------------------
207  */
208 
210 
211 /*
212  * -----------------------------------------------------------------
213  * Function : N_VCloneEmpty_NrnParallelLD
214  * -----------------------------------------------------------------
215  * This function creates a new parallel N_Vector with an empty (NULL)
216  * data array using the vector w as a template
217  * (sets own_data = FALSE).
218  * -----------------------------------------------------------------
219  */
220 
221 N_Vector N_VCloneEmpty_NrnParallelLD(N_Vector w);
222 
223 /*
224  * -----------------------------------------------------------------
225  * Function : N_VMake_NrnParallelLD
226  * -----------------------------------------------------------------
227  * This function creates and allocates memory for a parallel vector
228  * with a user-supplied data array.
229  * -----------------------------------------------------------------
230  */
231 
233  long int local_length,
234  long int global_length,
235  realtype* v_data);
236 
237 /*
238  * -----------------------------------------------------------------
239  * Function : N_VNewVectorArray_NrnParallelLD
240  * -----------------------------------------------------------------
241  * This function creates an array of 'count' parallel vectors. This
242  * array of N_Vectors can be freed using N_VDestroyVectorArray
243  * (defined by the generic NVECTOR module).
244  * -----------------------------------------------------------------
245  */
246 
247 N_Vector* N_VNewVectorArray_NrnParallelLD(int count,
248  MPI_Comm comm,
249  long int local_length,
250  long int global_length);
251 
252 /*
253  * -----------------------------------------------------------------
254  * Function : N_VNewVectorArrayEmpty_NrnParallelLD
255  * -----------------------------------------------------------------
256  * This function creates an array of 'count' parallel vectors each
257  * with an empty (NULL) data array.
258  * -----------------------------------------------------------------
259  */
260 
261 N_Vector* N_VNewVectorArrayEmpty_NrnParallelLD(int count,
262  MPI_Comm comm,
263  long int local_length,
264  long int global_length);
265 
266 /*
267  * -----------------------------------------------------------------
268  * Function : N_VDestroyVectorArray_NrnParallelLD
269  * -----------------------------------------------------------------
270  * This function frees an array of N_Vector created with
271  * N_VNewVectorArray_NrnParallelLD.
272  * -----------------------------------------------------------------
273  */
274 
275 void N_VDestroyVectorArray_NrnParallelLD(N_Vector* vs, int count);
276 
277 /*
278  * -----------------------------------------------------------------
279  * Function : N_VPrint_NrnParallelLD
280  * -----------------------------------------------------------------
281  * This function prints the content of a parallel vector to stdout.
282  * -----------------------------------------------------------------
283  */
284 
285 void N_VPrint_NrnParallelLD(N_Vector v);
286 
287 /*
288  * -----------------------------------------------------------------
289  * parallel implementations of the vector operations
290  * -----------------------------------------------------------------
291  */
292 
293 N_Vector N_VClone_NrnParallelLD(N_Vector w);
294 void N_VDestroy_NrnParallelLD(N_Vector v);
295 void N_VSpace_NrnParallelLD(N_Vector v, long int* lrw, long int* liw);
296 realtype* N_VGetArrayPointer_NrnParallelLD(N_Vector v);
297 void N_VSetArrayPointer_NrnParallelLD(realtype* v_data, N_Vector v);
298 void N_VLinearSum_NrnParallelLD(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z);
299 void N_VConst_NrnParallelLD(realtype c, N_Vector z);
300 void N_VProd_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z);
301 void N_VDiv_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z);
302 void N_VScale_NrnParallelLD(realtype c, N_Vector x, N_Vector z);
303 void N_VAbs_NrnParallelLD(N_Vector x, N_Vector z);
304 void N_VInv_NrnParallelLD(N_Vector x, N_Vector z);
305 void N_VAddConst_NrnParallelLD(N_Vector x, realtype b, N_Vector z);
306 realtype N_VDotProd_NrnParallelLD(N_Vector x, N_Vector y);
307 realtype N_VMaxNorm_NrnParallelLD(N_Vector x);
308 realtype N_VWrmsNorm_NrnParallelLD(N_Vector x, N_Vector w);
309 realtype N_VWrmsNormMask_NrnParallelLD(N_Vector x, N_Vector w, N_Vector id);
310 realtype N_VMin_NrnParallelLD(N_Vector x);
311 realtype N_VWL2Norm_NrnParallelLD(N_Vector x, N_Vector w);
312 realtype N_VL1Norm_NrnParallelLD(N_Vector x);
313 void N_VCompare_NrnParallelLD(realtype c, N_Vector x, N_Vector z);
314 booleantype N_VInvTest_NrnParallelLD(N_Vector x, N_Vector z);
315 booleantype N_VConstrMask_NrnParallelLD(N_Vector c, N_Vector x, N_Vector m);
316 realtype N_VMinQuotient_NrnParallelLD(N_Vector num, N_Vector denom);
#define v
Definition: md1redef.h:11
static int c
Definition: hoc.cpp:169
realtype N_VWL2Norm_NrnParallelLD(N_Vector x, N_Vector w)
void N_VSetArrayPointer_NrnParallelLD(realtype *v_data, N_Vector v)
N_Vector N_VClone_NrnParallelLD(N_Vector w)
booleantype N_VInvTest_NrnParallelLD(N_Vector x, N_Vector z)
realtype N_VL1Norm_NrnParallelLD(N_Vector x)
void N_VProd_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z)
void N_VScale_NrnParallelLD(realtype c, N_Vector x, N_Vector z)
N_Vector N_VCloneEmpty_NrnParallelLD(N_Vector w)
N_Vector N_VMake_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length, realtype *v_data)
realtype N_VMin_NrnParallelLD(N_Vector x)
realtype N_VWrmsNormMask_NrnParallelLD(N_Vector x, N_Vector w, N_Vector id)
void N_VDiv_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z)
void N_VSpace_NrnParallelLD(N_Vector v, long int *lrw, long int *liw)
N_Vector N_VNewEmpty_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length)
void N_VAddConst_NrnParallelLD(N_Vector x, realtype b, N_Vector z)
booleantype N_VConstrMask_NrnParallelLD(N_Vector c, N_Vector x, N_Vector m)
void N_VInv_NrnParallelLD(N_Vector x, N_Vector z)
void N_VAbs_NrnParallelLD(N_Vector x, N_Vector z)
void N_VLinearSum_NrnParallelLD(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z)
void N_VConst_NrnParallelLD(realtype c, N_Vector z)
struct _N_VectorContent_NrnParallelLD * N_VectorContent_NrnParallelLD
void N_VDestroyVectorArray_NrnParallelLD(N_Vector *vs, int count)
void N_VDestroy_NrnParallelLD(N_Vector v)
realtype N_VMaxNorm_NrnParallelLD(N_Vector x)
N_Vector * N_VNewVectorArray_NrnParallelLD(int count, MPI_Comm comm, long int local_length, long int global_length)
realtype * N_VGetArrayPointer_NrnParallelLD(N_Vector v)
realtype N_VDotProd_NrnParallelLD(N_Vector x, N_Vector y)
realtype N_VMinQuotient_NrnParallelLD(N_Vector num, N_Vector denom)
realtype N_VWrmsNorm_NrnParallelLD(N_Vector x, N_Vector w)
void N_VCompare_NrnParallelLD(realtype c, N_Vector x, N_Vector z)
N_Vector N_VNew_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length)
#define MPI_Comm
void N_VPrint_NrnParallelLD(N_Vector v)
N_Vector * N_VNewVectorArrayEmpty_NrnParallelLD(int count, MPI_Comm comm, long int local_length, long int global_length)