1 /* -----------------------------------------------------------------
2  * Programmer(s): Daniel R. Reynolds @ SMU
3  * -----------------------------------------------------------------
4  * SUNDIALS Copyright Start
5  * Copyright (c) 2002-2021, Lawrence Livermore National Security
6  * and Southern Methodist University.
7  * All rights reserved.
8  *
9  * See the top-level LICENSE and NOTICE files for details.
10  *
11  * SPDX-License-Identifier: BSD-3-Clause
12  * SUNDIALS Copyright End
13  * -----------------------------------------------------------------
14  * This is the main header file for the "MPIManyVector" implementation
15  * of the NVECTOR module.
16  *
17  * Notes:
18  *
19  *   - The definition of the generic N_Vector structure can be found
20  *     in the header file sundials_nvector.h.
21  *
22  *   - The definitions of the types 'realtype' and 'sunindextype' can
23  *     be found in the header file sundials_types.h, and it may be
24  *     changed (at the configuration stage) according to the user's needs.
25  *     The sundials_types.h file also contains the definition
26  *     for the type 'booleantype'.
27  *
28  *   - N_Vector arguments to arithmetic vector operations need not
29  *     be distinct. For example, the following call:
30  *
31  *       N_VLinearSum_MPIManyVector(a,x,b,y,y);
32  *
33  *     (which stores the result of the operation a*x+b*y in y)
34  *     is legal.
35  * -----------------------------------------------------------------*/
36 
37 #ifndef _NVECTOR_MANY_VECTOR_H
38 #define _NVECTOR_MANY_VECTOR_H
39 
40 #include <mpi.h>
41 #include <sundials/sundials_mpi_types.h>
42 #include <stdio.h>
43 #include <sundials/sundials_nvector.h>
44 
45 #ifdef __cplusplus  /* wrapper to enable C++ usage */
46 extern "C" {
47 #endif
48 
49 /* -----------------------------------------------------------------
50    ManyVector implementation of N_Vector
51    ----------------------------------------------------------------- */
52 
53 struct _N_VectorContent_MPIManyVector {
54   MPI_Comm      comm;            /* overall MPI communicator        */
55   sunindextype  num_subvectors;  /* number of vectors attached      */
56   sunindextype  global_length;   /* overall manyvector length       */
57   N_Vector*     subvec_array;    /* pointer to N_Vector array       */
58   booleantype   own_data;        /* flag indicating data ownership  */
59 };
60 
61 typedef struct _N_VectorContent_MPIManyVector *N_VectorContent_MPIManyVector;
62 
63 /* -----------------------------------------------------------------
64    functions exported by ManyVector
65    ----------------------------------------------------------------- */
66 
67 SUNDIALS_EXPORT N_Vector N_VMake_MPIManyVector(MPI_Comm comm,
68                                                sunindextype num_subvectors,
69                                                N_Vector *vec_array);
70 
71 SUNDIALS_EXPORT N_Vector N_VNew_MPIManyVector(sunindextype num_subvectors,
72                                               N_Vector *vec_array);
73 
74 SUNDIALS_EXPORT N_Vector N_VGetSubvector_MPIManyVector(N_Vector v,
75                                                        sunindextype vec_num);
76 
77 SUNDIALS_EXPORT realtype *N_VGetSubvectorArrayPointer_MPIManyVector(N_Vector v,
78                                                                     sunindextype vec_num);
79 
80 SUNDIALS_EXPORT int N_VSetSubvectorArrayPointer_MPIManyVector(realtype *v_data, N_Vector v,
81                                                               sunindextype vec_num);
82 
83 SUNDIALS_EXPORT sunindextype N_VGetNumSubvectors_MPIManyVector(N_Vector v);
84 
85 /* standard vector operations */
86 SUNDIALS_EXPORT N_Vector_ID N_VGetVectorID_MPIManyVector(N_Vector v);
87 SUNDIALS_EXPORT N_Vector N_VCloneEmpty_MPIManyVector(N_Vector w);
88 SUNDIALS_EXPORT N_Vector N_VClone_MPIManyVector(N_Vector w);
89 SUNDIALS_EXPORT void N_VDestroy_MPIManyVector(N_Vector v);
90 SUNDIALS_EXPORT void N_VSpace_MPIManyVector(N_Vector v, sunindextype *lrw,
91                                             sunindextype *liw);
92 SUNDIALS_EXPORT void *N_VGetCommunicator_MPIManyVector(N_Vector v);
93 SUNDIALS_EXPORT sunindextype N_VGetLength_MPIManyVector(N_Vector v);
94 SUNDIALS_EXPORT void N_VLinearSum_MPIManyVector(realtype a, N_Vector x,
95                                                 realtype b, N_Vector y,
96                                                 N_Vector z);
97 SUNDIALS_EXPORT void N_VConst_MPIManyVector(realtype c, N_Vector z);
98 SUNDIALS_EXPORT void N_VProd_MPIManyVector(N_Vector x, N_Vector y, N_Vector z);
99 SUNDIALS_EXPORT void N_VDiv_MPIManyVector(N_Vector x, N_Vector y, N_Vector z);
100 SUNDIALS_EXPORT void N_VScale_MPIManyVector(realtype c, N_Vector x, N_Vector z);
101 SUNDIALS_EXPORT void N_VAbs_MPIManyVector(N_Vector x, N_Vector z);
102 SUNDIALS_EXPORT void N_VInv_MPIManyVector(N_Vector x, N_Vector z);
103 SUNDIALS_EXPORT void N_VAddConst_MPIManyVector(N_Vector x, realtype b,
104                                                N_Vector z);
105 SUNDIALS_EXPORT realtype N_VDotProd_MPIManyVector(N_Vector x, N_Vector y);
106 SUNDIALS_EXPORT realtype N_VMaxNorm_MPIManyVector(N_Vector x);
107 SUNDIALS_EXPORT realtype N_VWrmsNorm_MPIManyVector(N_Vector x, N_Vector w);
108 SUNDIALS_EXPORT realtype N_VWrmsNormMask_MPIManyVector(N_Vector x, N_Vector w,
109                                                        N_Vector id);
110 SUNDIALS_EXPORT realtype N_VMin_MPIManyVector(N_Vector x);
111 SUNDIALS_EXPORT realtype N_VWL2Norm_MPIManyVector(N_Vector x, N_Vector w);
112 SUNDIALS_EXPORT realtype N_VL1Norm_MPIManyVector(N_Vector x);
113 SUNDIALS_EXPORT void N_VCompare_MPIManyVector(realtype c, N_Vector x, N_Vector z);
114 SUNDIALS_EXPORT booleantype N_VInvTest_MPIManyVector(N_Vector x, N_Vector z);
115 SUNDIALS_EXPORT booleantype N_VConstrMask_MPIManyVector(N_Vector c, N_Vector x,
116                                                         N_Vector m);
117 SUNDIALS_EXPORT realtype N_VMinQuotient_MPIManyVector(N_Vector num,
118                                                       N_Vector denom);
119 
120 /* fused vector operations */
121 SUNDIALS_EXPORT int N_VLinearCombination_MPIManyVector(int nvec, realtype* c,
122                                                        N_Vector* V, N_Vector z);
123 SUNDIALS_EXPORT int N_VScaleAddMulti_MPIManyVector(int nvec, realtype* a,
124                                                    N_Vector x, N_Vector* Y,
125                                                    N_Vector* Z);
126 SUNDIALS_EXPORT int N_VDotProdMulti_MPIManyVector(int nvec, N_Vector x,
127                                                   N_Vector *Y,
128                                                   realtype* dotprods);
129 
130 /* vector array operations */
131 SUNDIALS_EXPORT int N_VLinearSumVectorArray_MPIManyVector(int nvec,
132                                                           realtype a, N_Vector* X,
133                                                           realtype b, N_Vector* Y,
134                                                           N_Vector* Z);
135 SUNDIALS_EXPORT int N_VScaleVectorArray_MPIManyVector(int nvec, realtype* c,
136                                                       N_Vector* X, N_Vector* Z);
137 SUNDIALS_EXPORT int N_VConstVectorArray_MPIManyVector(int nvecs, realtype c,
138                                                       N_Vector* Z);
139 SUNDIALS_EXPORT int N_VWrmsNormVectorArray_MPIManyVector(int nvecs, N_Vector* X,
140                                                          N_Vector* W, realtype* nrm);
141 SUNDIALS_EXPORT int N_VWrmsNormMaskVectorArray_MPIManyVector(int nvec,
142                                                              N_Vector* X,
143                                                              N_Vector* W,
144                                                              N_Vector id,
145                                                              realtype* nrm);
146 
147 /* OPTIONAL local reduction kernels (no parallel communication) */
148 SUNDIALS_EXPORT realtype N_VDotProdLocal_MPIManyVector(N_Vector x, N_Vector y);
149 SUNDIALS_EXPORT realtype N_VMaxNormLocal_MPIManyVector(N_Vector x);
150 SUNDIALS_EXPORT realtype N_VMinLocal_MPIManyVector(N_Vector x);
151 SUNDIALS_EXPORT realtype N_VL1NormLocal_MPIManyVector(N_Vector x);
152 SUNDIALS_EXPORT realtype N_VWSqrSumLocal_MPIManyVector(N_Vector x, N_Vector w);
153 SUNDIALS_EXPORT realtype N_VWSqrSumMaskLocal_MPIManyVector(N_Vector x, N_Vector w,
154                                                            N_Vector id);
155 SUNDIALS_EXPORT booleantype N_VInvTestLocal_MPIManyVector(N_Vector x, N_Vector z);
156 SUNDIALS_EXPORT booleantype N_VConstrMaskLocal_MPIManyVector(N_Vector c, N_Vector x,
157                                                              N_Vector m);
158 SUNDIALS_EXPORT realtype N_VMinQuotientLocal_MPIManyVector(N_Vector num,
159                                                            N_Vector denom);
160 
161 /* OPTIONAL XBraid interface operations */
162 SUNDIALS_EXPORT int N_VBufSize_MPIManyVector(N_Vector x, sunindextype *size);
163 SUNDIALS_EXPORT int N_VBufPack_MPIManyVector(N_Vector x, void *buf);
164 SUNDIALS_EXPORT int N_VBufUnpack_MPIManyVector(N_Vector x, void *buf);
165 
166 /* -----------------------------------------------------------------
167    Enable / disable fused vector operations
168    ----------------------------------------------------------------- */
169 
170 SUNDIALS_EXPORT int N_VEnableFusedOps_MPIManyVector(N_Vector v, booleantype tf);
171 
172 SUNDIALS_EXPORT int N_VEnableLinearCombination_MPIManyVector(N_Vector v, booleantype tf);
173 SUNDIALS_EXPORT int N_VEnableScaleAddMulti_MPIManyVector(N_Vector v, booleantype tf);
174 SUNDIALS_EXPORT int N_VEnableDotProdMulti_MPIManyVector(N_Vector v, booleantype tf);
175 
176 SUNDIALS_EXPORT int N_VEnableLinearSumVectorArray_MPIManyVector(N_Vector v, booleantype tf);
177 SUNDIALS_EXPORT int N_VEnableScaleVectorArray_MPIManyVector(N_Vector v, booleantype tf);
178 SUNDIALS_EXPORT int N_VEnableConstVectorArray_MPIManyVector(N_Vector v, booleantype tf);
179 SUNDIALS_EXPORT int N_VEnableWrmsNormVectorArray_MPIManyVector(N_Vector v, booleantype tf);
180 SUNDIALS_EXPORT int N_VEnableWrmsNormMaskVectorArray_MPIManyVector(N_Vector v, booleantype tf);
181 
182 #ifdef __cplusplus
183 }
184 #endif
185 #endif
186