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 #ifndef _NVECTOR_NRNPARALLEL_LD_H
64 #define _NVECTOR_NRNPARALLEL_LD_H
65 
66 
67 #include <nrnmpiuse.h>
68 #if NRNMPI_DYNAMICLOAD
69 #define MPI_DOUBLE double
70 #define MPI_LONG long
71 #define MPI_Comm int
72 #else
73 #include <mpi.h>
74 #endif
75 
76 #include "nvector.h"
77 #include "sundialstypes.h"
78 
79 /*
80  * -----------------------------------------------------------------
81  * PART I: PARALLEL implementation of N_Vector
82  * -----------------------------------------------------------------
83  */
84 
85 /* define MPI data types */
86 
87 #if defined(SUNDIALS_SINGLE_PRECISION)
88 
89 #define PVEC_REAL_MPI_TYPE MPI_FLOAT
90 
91 #elif defined(SUNDIALS_DOUBLE_PRECISION)
92 
93 #define PVEC_REAL_MPI_TYPE MPI_DOUBLE
94 
95 #elif defined(SUNDIALS_EXTENDED_PRECISION)
96 
97 #define PVEC_REAL_MPI_TYPE MPI_LONG_DOUBLE
98 
99 #endif
100 
101 #define PVEC_INTEGER_MPI_TYPE MPI_LONG
102 
103 /* parallel implementation of the N_Vector 'content' structure
104  contains the global and local lengths of the vector, a pointer
105  to an array of realtype components, the MPI communicator,
106  and a flag indicating ownership of the data */
107 
109  long int local_length; /* local vector length */
110  long int global_length; /* global vector length */
111  booleantype own_data; /* ownership of data */
112  realtype *data; /* local data array */
113  MPI_Comm comm; /* pointer to MPI communicator */
114 };
115 
117 
118 /*
119  * -----------------------------------------------------------------
120  * PART II: macros NV_CONTENT_P_LD, NV_DATA_P_LD, NV_OWN_DATA_P_LD,
121  * NV_LOCLENGTH_P_LD, NV_GLOBLENGTH_P_LD,NV_COMM_P_LD, and NV_Ith_P_LD
122  * -----------------------------------------------------------------
123  * In the descriptions below, the following user declarations
124  * are assumed:
125  *
126  * N_Vector v;
127  * long int v_len, s_len, i;
128  *
129  * (1) NV_CONTENT_P_LD
130  *
131  * This routines gives access to the contents of the parallel
132  * vector N_Vector.
133  *
134  * The assignment v_cont = NV_CONTENT_P_LD(v) sets v_cont to be
135  * a pointer to the parallel N_Vector content structure.
136  *
137  * (2) NV_DATA_P_LD, NV_OWN_DATA_P_LD, NV_LOCLENGTH_P_LD, NV_GLOBLENGTH_P_LD,
138  * and NV_COMM_P_LD
139  *
140  * These routines give access to the individual parts of
141  * the content structure of a parallel N_Vector.
142  *
143  * The assignment v_data = NV_DATA_P_LD(v) sets v_data to be
144  * a pointer to the first component of the local data for
145  * the vector v. The assignment NV_DATA_P_LD(v) = data_v sets
146  * the component array of v to be data_V by storing the
147  * pointer data_v.
148  *
149  * The assignment v_llen = NV_LOCLENGTH_P_LD(v) sets v_llen to
150  * be the length of the local part of the vector v. The call
151  * NV_LOCLENGTH_P_LD(v) = llen_v sets the local length
152  * of v to be llen_v.
153  *
154  * The assignment v_glen = NV_GLOBLENGTH_P_LD(v) sets v_glen to
155  * be the global length of the vector v. The call
156  * NV_GLOBLENGTH_P_LD(v) = glen_v sets the global length of v to
157  * be glen_v.
158  *
159  * The assignment v_comm = NV_COMM_P_LD(v) sets v_comm to be the
160  * MPI communicator of the vector v. The assignment
161  * NV_COMM_C(v) = comm_v sets the MPI communicator of v to be
162  * comm_v.
163  *
164  * (3) NV_Ith_P_LD
165  *
166  * In the following description, the components of the
167  * local part of an N_Vector are numbered 0..n-1, where n
168  * is the local length of (the local part of) v.
169  *
170  * The assignment r = NV_Ith_P_LD(v,i) sets r to be the value
171  * of the ith component of the local part of the vector v.
172  * The assignment NV_Ith_P_LD(v,i) = r sets the value of the
173  * ith local component of v to be r.
174  *
175  * Note: When looping over the components of an N_Vector v, it is
176  * more efficient to first obtain the component array via
177  * v_data = NV_DATA_P_LD(v) and then access v_data[i] within the
178  * loop than it is to use NV_Ith_P_LD(v,i) within the loop.
179  * -----------------------------------------------------------------
180  */
181 
182 #define NV_CONTENT_P_LD(v) ( (N_VectorContent_NrnParallelLD)(v->content) )
183 
184 #define NV_LOCLENGTH_P_LD(v) ( NV_CONTENT_P_LD(v)->local_length )
185 
186 #define NV_GLOBLENGTH_P_LD(v) ( NV_CONTENT_P_LD(v)->global_length )
187 
188 #define NV_OWN_DATA_P_LD(v) ( NV_CONTENT_P_LD(v)->own_data )
189 
190 #define NV_DATA_P_LD(v) ( NV_CONTENT_P_LD(v)->data )
191 
192 #define NV_COMM_P_LD(v) ( NV_CONTENT_P_LD(v)->comm )
193 
194 #define NV_Ith_P_LD(v,i) ( NV_DATA_P_LD(v)[i] )
195 
196 /*
197  * -----------------------------------------------------------------
198  * PART III: functions exported by nvector_parallel
199  *
200  * CONSTRUCTORS:
201  * N_VNew_NrnParallelLD
202  * N_VNewEmpty_NrnParallelLD
203  * N_VClone_NrnParallelLD
204  * N_VCloneEmpty_NrnParallelLD
205  * N_VMake_NrnParallelLD
206  * N_VNewVectorArray_NrnParallelLD
207  * N_VNewVectorArrayEmpty_NrnParallelLD
208  * DESTRUCTORS:
209  * N_VDestroy_NrnParallelLD
210  * N_VDestroyVectorArray_NrnParallelLD
211  * -----------------------------------------------------------------
212  */
213 
214 /*
215  * -----------------------------------------------------------------
216  * Function : N_VNew_NrnParallelLD
217  * -----------------------------------------------------------------
218  * This function creates and allocates memory for a parallel vector.
219  * -----------------------------------------------------------------
220  */
221 
222 extern "C" N_Vector N_VNew_NrnParallelLD(MPI_Comm comm,
223  long int local_length,
224  long int global_length);
225 
226 /*
227  * -----------------------------------------------------------------
228  * Function : N_VNewEmpty_NrnParallelLD
229  * -----------------------------------------------------------------
230  * This function creates a new parallel N_Vector with an empty
231  * (NULL) data array.
232  * -----------------------------------------------------------------
233  */
234 
235 N_Vector N_VNewEmpty_NrnParallelLD(MPI_Comm comm,
236  long int local_length,
237  long int global_length);
238 
239 /*
240  * -----------------------------------------------------------------
241  * Function : N_VCloneEmpty_NrnParallelLD
242  * -----------------------------------------------------------------
243  * This function creates a new parallel N_Vector with an empty (NULL)
244  * data array using the vector w as a template
245  * (sets own_data = FALSE).
246  * -----------------------------------------------------------------
247  */
248 
249 N_Vector N_VCloneEmpty_NrnParallelLD(N_Vector w);
250 
251 /*
252  * -----------------------------------------------------------------
253  * Function : N_VMake_NrnParallelLD
254  * -----------------------------------------------------------------
255  * This function creates and allocates memory for a parallel vector
256  * with a user-supplied data array.
257  * -----------------------------------------------------------------
258  */
259 
260 N_Vector N_VMake_NrnParallelLD(MPI_Comm comm,
261  long int local_length,
262  long int global_length,
263  realtype *v_data);
264 
265 /*
266  * -----------------------------------------------------------------
267  * Function : N_VNewVectorArray_NrnParallelLD
268  * -----------------------------------------------------------------
269  * This function creates an array of 'count' parallel vectors. This
270  * array of N_Vectors can be freed using N_VDestroyVectorArray
271  * (defined by the generic NVECTOR module).
272  * -----------------------------------------------------------------
273  */
274 
275 N_Vector *N_VNewVectorArray_NrnParallelLD(int count,
276  MPI_Comm comm,
277  long int local_length,
278  long int global_length);
279 
280 /*
281  * -----------------------------------------------------------------
282  * Function : N_VNewVectorArrayEmpty_NrnParallelLD
283  * -----------------------------------------------------------------
284  * This function creates an array of 'count' parallel vectors each
285  * with an empty (NULL) data array.
286  * -----------------------------------------------------------------
287  */
288 
289 N_Vector *N_VNewVectorArrayEmpty_NrnParallelLD(int count,
290  MPI_Comm comm,
291  long int local_length,
292  long int global_length);
293 
294 /*
295  * -----------------------------------------------------------------
296  * Function : N_VDestroyVectorArray_NrnParallelLD
297  * -----------------------------------------------------------------
298  * This function frees an array of N_Vector created with
299  * N_VNewVectorArray_NrnParallelLD.
300  * -----------------------------------------------------------------
301  */
302 
303 void N_VDestroyVectorArray_NrnParallelLD(N_Vector *vs, int count);
304 
305 /*
306  * -----------------------------------------------------------------
307  * Function : N_VPrint_NrnParallelLD
308  * -----------------------------------------------------------------
309  * This function prints the content of a parallel vector to stdout.
310  * -----------------------------------------------------------------
311  */
312 
313 void N_VPrint_NrnParallelLD(N_Vector v);
314 
315 /*
316  * -----------------------------------------------------------------
317  * parallel implementations of the vector operations
318  * -----------------------------------------------------------------
319  */
320 
321 N_Vector N_VClone_NrnParallelLD(N_Vector w);
322 void N_VDestroy_NrnParallelLD(N_Vector v);
323 void N_VSpace_NrnParallelLD(N_Vector v, long int *lrw, long int *liw);
324 realtype *N_VGetArrayPointer_NrnParallelLD(N_Vector v);
325 void N_VSetArrayPointer_NrnParallelLD(realtype *v_data, N_Vector v);
326 void N_VLinearSum_NrnParallelLD(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z);
327 void N_VConst_NrnParallelLD(realtype c, N_Vector z);
328 void N_VProd_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z);
329 void N_VDiv_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z);
330 void N_VScale_NrnParallelLD(realtype c, N_Vector x, N_Vector z);
331 void N_VAbs_NrnParallelLD(N_Vector x, N_Vector z);
332 void N_VInv_NrnParallelLD(N_Vector x, N_Vector z);
333 void N_VAddConst_NrnParallelLD(N_Vector x, realtype b, N_Vector z);
334 realtype N_VDotProd_NrnParallelLD(N_Vector x, N_Vector y);
335 realtype N_VMaxNorm_NrnParallelLD(N_Vector x);
336 realtype N_VWrmsNorm_NrnParallelLD(N_Vector x, N_Vector w);
337 realtype N_VWrmsNormMask_NrnParallelLD(N_Vector x, N_Vector w, N_Vector id);
338 realtype N_VMin_NrnParallelLD(N_Vector x);
339 realtype N_VWL2Norm_NrnParallelLD(N_Vector x, N_Vector w);
340 realtype N_VL1Norm_NrnParallelLD(N_Vector x);
341 void N_VCompare_NrnParallelLD(realtype c, N_Vector x, N_Vector z);
342 booleantype N_VInvTest_NrnParallelLD(N_Vector x, N_Vector z);
343 booleantype N_VConstrMask_NrnParallelLD(N_Vector c, N_Vector x, N_Vector m);
344 realtype N_VMinQuotient_NrnParallelLD(N_Vector num, N_Vector denom);
345 
346 
347 #endif
N_Vector N_VCloneEmpty_NrnParallelLD(N_Vector w)
void N_VSetArrayPointer_NrnParallelLD(realtype *v_data, N_Vector v)
void N_VCompare_NrnParallelLD(realtype c, N_Vector x, N_Vector z)
booleantype N_VConstrMask_NrnParallelLD(N_Vector c, N_Vector x, N_Vector m)
void N_VDestroyVectorArray_NrnParallelLD(N_Vector *vs, int count)
void N_VDiv_NrnParallelLD(N_Vector x, N_Vector y, N_Vector z)
realtype * N_VGetArrayPointer_NrnParallelLD(N_Vector v)
#define v
Definition: md1redef.h:4
void N_VConst_NrnParallelLD(realtype c, N_Vector z)
struct _N_VectorContent_NrnParallelLD * N_VectorContent_NrnParallelLD
void N_VAddConst_NrnParallelLD(N_Vector x, realtype b, N_Vector z)
N_Vector N_VNew_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length)
realtype N_VMaxNorm_NrnParallelLD(N_Vector x)
N_Vector N_VMake_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length, realtype *v_data)
realtype N_VWrmsNormMask_NrnParallelLD(N_Vector x, N_Vector w, N_Vector id)
realtype N_VMin_NrnParallelLD(N_Vector x)
realtype N_VWL2Norm_NrnParallelLD(N_Vector x, N_Vector w)
realtype N_VMinQuotient_NrnParallelLD(N_Vector num, N_Vector denom)
booleantype N_VInvTest_NrnParallelLD(N_Vector x, N_Vector z)
N_Vector N_VNewEmpty_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length)
N_Vector * N_VNewVectorArrayEmpty_NrnParallelLD(int count, MPI_Comm comm, long int local_length, long int global_length)
void N_VInv_NrnParallelLD(N_Vector x, N_Vector z)
void N_VLinearSum_NrnParallelLD(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z)
N_Vector N_VClone_NrnParallelLD(N_Vector w)
realtype N_VDotProd_NrnParallelLD(N_Vector x, N_Vector y)
#define c
void N_VPrint_NrnParallelLD(N_Vector v)
void N_VScale_NrnParallelLD(realtype c, 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)
N_Vector * N_VNewVectorArray_NrnParallelLD(int count, MPI_Comm comm, long int local_length, long int global_length)
void N_VDestroy_NrnParallelLD(N_Vector v)
realtype N_VWrmsNorm_NrnParallelLD(N_Vector x, N_Vector w)
void N_VAbs_NrnParallelLD(N_Vector x, N_Vector z)
void N_VSpace_NrnParallelLD(N_Vector v, long int *lrw, long int *liw)