00001 /* 00002 * ----------------------------------------------------------------- 00003 * $Revision: 1.2 $ 00004 * $Date: 2006/11/29 00:05:07 $ 00005 * ----------------------------------------------------------------- 00006 * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, 00007 * and Aaron Collier @ LLNL 00008 * ----------------------------------------------------------------- 00009 * Copyright (c) 2002, The Regents of the University of California. 00010 * Produced at the Lawrence Livermore National Laboratory. 00011 * All rights reserved. 00012 * For details, see the LICENSE file. 00013 * ----------------------------------------------------------------- 00014 * This is the main header file for the MPI-enabled implementation 00015 * of the NVECTOR module. 00016 * 00017 * Part I contains declarations specific to the parallel 00018 * implementation of the supplied NVECTOR module. 00019 * 00020 * Part II defines accessor macros that allow the user to efficiently 00021 * use the type N_Vector without making explicit references to the 00022 * underlying data structure. 00023 * 00024 * Part III contains the prototype for the constructor 00025 * N_VNew_Parallel as well as implementation-specific prototypes 00026 * for various useful vector operations. 00027 * 00028 * Notes: 00029 * 00030 * - The definition of the generic N_Vector structure can be 00031 * found in the header file sundials_nvector.h. 00032 * 00033 * - The definition of the type realtype can be found in the 00034 * header file sundials_types.h, and it may be changed (at the 00035 * configuration stage) according to the user's needs. 00036 * The sundials_types.h file also contains the definition 00037 * for the type booleantype. 00038 * 00039 * - N_Vector arguments to arithmetic vector operations need not 00040 * be distinct. For example, the following call: 00041 * 00042 * N_VLinearSum_Parallel(a,x,b,y,y); 00043 * 00044 * (which stores the result of the operation a*x+b*y in y) 00045 * is legal. 00046 * ----------------------------------------------------------------- 00047 */ 00048 00049 #ifndef _NVECTOR_PARALLEL_H 00050 #define _NVECTOR_PARALLEL_H 00051 00052 #ifdef __cplusplus /* wrapper to enable C++ usage */ 00053 extern "C" { 00054 #endif 00055 00056 #include <mpi.h> 00057 00058 #include <sundials/sundials_nvector.h> 00059 00060 00061 /* 00062 * ----------------------------------------------------------------- 00063 * PART I: PARALLEL implementation of N_Vector 00064 * ----------------------------------------------------------------- 00065 */ 00066 00067 /* define MPI data types */ 00068 00069 #if defined(SUNDIALS_SINGLE_PRECISION) 00070 00071 #define PVEC_REAL_MPI_TYPE MPI_FLOAT 00072 00073 #elif defined(SUNDIALS_DOUBLE_PRECISION) 00074 00075 #define PVEC_REAL_MPI_TYPE MPI_DOUBLE 00076 00077 #elif defined(SUNDIALS_EXTENDED_PRECISION) 00078 00079 #define PVEC_REAL_MPI_TYPE MPI_LONG_DOUBLE 00080 00081 #endif 00082 00083 #define PVEC_INTEGER_MPI_TYPE MPI_LONG 00084 00085 /* parallel implementation of the N_Vector 'content' structure 00086 contains the global and local lengths of the vector, a pointer 00087 to an array of 'realtype components', the MPI communicator, 00088 and a flag indicating ownership of the data */ 00089 00090 struct _N_VectorContent_Parallel { 00091 long int local_length; /* local vector length */ 00092 long int global_length; /* global vector length */ 00093 booleantype own_data; /* ownership of data */ 00094 realtype *data; /* local data array */ 00095 MPI_Comm comm; /* pointer to MPI communicator */ 00096 }; 00097 00098 typedef struct _N_VectorContent_Parallel *N_VectorContent_Parallel; 00099 00100 /* 00101 * ----------------------------------------------------------------- 00102 * PART II: macros NV_CONTENT_P, NV_DATA_P, NV_OWN_DATA_P, 00103 * NV_LOCLENGTH_P, NV_GLOBLENGTH_P,NV_COMM_P, and NV_Ith_P 00104 * ----------------------------------------------------------------- 00105 * In the descriptions below, the following user declarations 00106 * are assumed: 00107 * 00108 * N_Vector v; 00109 * long int v_len, s_len, i; 00110 * 00111 * (1) NV_CONTENT_P 00112 * 00113 * This routines gives access to the contents of the parallel 00114 * vector N_Vector. 00115 * 00116 * The assignment v_cont = NV_CONTENT_P(v) sets v_cont to be 00117 * a pointer to the parallel N_Vector content structure. 00118 * 00119 * (2) NV_DATA_P, NV_OWN_DATA_P, NV_LOCLENGTH_P, NV_GLOBLENGTH_P, 00120 * and NV_COMM_P 00121 * 00122 * These routines give access to the individual parts of 00123 * the content structure of a parallel N_Vector. 00124 * 00125 * The assignment v_data = NV_DATA_P(v) sets v_data to be 00126 * a pointer to the first component of the local data for 00127 * the vector v. The assignment NV_DATA_P(v) = data_v sets 00128 * the component array of v to be data_V by storing the 00129 * pointer data_v. 00130 * 00131 * The assignment v_llen = NV_LOCLENGTH_P(v) sets v_llen to 00132 * be the length of the local part of the vector v. The call 00133 * NV_LOCLENGTH_P(v) = llen_v sets the local length 00134 * of v to be llen_v. 00135 * 00136 * The assignment v_glen = NV_GLOBLENGTH_P(v) sets v_glen to 00137 * be the global length of the vector v. The call 00138 * NV_GLOBLENGTH_P(v) = glen_v sets the global length of v to 00139 * be glen_v. 00140 * 00141 * The assignment v_comm = NV_COMM_P(v) sets v_comm to be the 00142 * MPI communicator of the vector v. The assignment 00143 * NV_COMM_C(v) = comm_v sets the MPI communicator of v to be 00144 * comm_v. 00145 * 00146 * (3) NV_Ith_P 00147 * 00148 * In the following description, the components of the 00149 * local part of an N_Vector are numbered 0..n-1, where n 00150 * is the local length of (the local part of) v. 00151 * 00152 * The assignment r = NV_Ith_P(v,i) sets r to be the value 00153 * of the ith component of the local part of the vector v. 00154 * The assignment NV_Ith_P(v,i) = r sets the value of the 00155 * ith local component of v to be r. 00156 * 00157 * Note: When looping over the components of an N_Vector v, it is 00158 * more efficient to first obtain the component array via 00159 * v_data = NV_DATA_P(v) and then access v_data[i] within the 00160 * loop than it is to use NV_Ith_P(v,i) within the loop. 00161 * ----------------------------------------------------------------- 00162 */ 00163 00164 #define NV_CONTENT_P(v) ( (N_VectorContent_Parallel)(v->content) ) 00165 00166 #define NV_LOCLENGTH_P(v) ( NV_CONTENT_P(v)->local_length ) 00167 00168 #define NV_GLOBLENGTH_P(v) ( NV_CONTENT_P(v)->global_length ) 00169 00170 #define NV_OWN_DATA_P(v) ( NV_CONTENT_P(v)->own_data ) 00171 00172 #define NV_DATA_P(v) ( NV_CONTENT_P(v)->data ) 00173 00174 #define NV_COMM_P(v) ( NV_CONTENT_P(v)->comm ) 00175 00176 #define NV_Ith_P(v,i) ( NV_DATA_P(v)[i] ) 00177 00178 /* 00179 * ----------------------------------------------------------------- 00180 * PART III: functions exported by nvector_parallel 00181 * 00182 * CONSTRUCTORS: 00183 * N_VNew_Parallel 00184 * N_VNewEmpty_Parallel 00185 * N_VMake_Parallel 00186 * N_VCloneVectorArray_Parallel 00187 * N_VCloneVectorArrayEmpty_Parallel 00188 * DESTRUCTORS: 00189 * N_VDestroy_Parallel 00190 * N_VDestroyVectorArray_Parallel 00191 * OTHER: 00192 * N_VPrint_Parallel 00193 * ----------------------------------------------------------------- 00194 */ 00195 00196 /* 00197 * ----------------------------------------------------------------- 00198 * Function : N_VNew_Parallel 00199 * ----------------------------------------------------------------- 00200 * This function creates and allocates memory for a parallel vector. 00201 * ----------------------------------------------------------------- 00202 */ 00203 00204 SUNDIALS_EXPORT N_Vector N_VNew_Parallel(MPI_Comm comm, 00205 long int local_length, 00206 long int global_length); 00207 00208 /* 00209 * ----------------------------------------------------------------- 00210 * Function : N_VNewEmpty_Parallel 00211 * ----------------------------------------------------------------- 00212 * This function creates a new parallel N_Vector with an empty 00213 * (NULL) data array. 00214 * ----------------------------------------------------------------- 00215 */ 00216 00217 SUNDIALS_EXPORT N_Vector N_VNewEmpty_Parallel(MPI_Comm comm, 00218 long int local_length, 00219 long int global_length); 00220 00221 /* 00222 * ----------------------------------------------------------------- 00223 * Function : N_VMake_Parallel 00224 * ----------------------------------------------------------------- 00225 * This function creates and allocates memory for a parallel vector 00226 * with a user-supplied data array. 00227 * ----------------------------------------------------------------- 00228 */ 00229 00230 SUNDIALS_EXPORT N_Vector N_VMake_Parallel(MPI_Comm comm, 00231 long int local_length, 00232 long int global_length, 00233 realtype *v_data); 00234 00235 /* 00236 * ----------------------------------------------------------------- 00237 * Function : N_VCloneVectorArray_Parallel 00238 * ----------------------------------------------------------------- 00239 * This function creates an array of 'count' PARALLEL vectors by 00240 * cloning a given vector w. 00241 * ----------------------------------------------------------------- 00242 */ 00243 00244 SUNDIALS_EXPORT N_Vector *N_VCloneVectorArray_Parallel(int count, N_Vector w); 00245 00246 /* 00247 * ----------------------------------------------------------------- 00248 * Function : N_VCloneVectorArrayEmpty_Parallel 00249 * ----------------------------------------------------------------- 00250 * This function creates an array of 'count' PARALLEL vectors each 00251 * with an empty (NULL) data array by cloning w. 00252 * ----------------------------------------------------------------- 00253 */ 00254 00255 SUNDIALS_EXPORT N_Vector *N_VCloneVectorArrayEmpty_Parallel(int count, N_Vector w); 00256 00257 /* 00258 * ----------------------------------------------------------------- 00259 * Function : N_VDestroyVectorArray_Parallel 00260 * ----------------------------------------------------------------- 00261 * This function frees an array of N_Vector created with 00262 * N_VCloneVectorArray_Parallel or N_VCloneVectorArrayEmpty_Parallel. 00263 * ----------------------------------------------------------------- 00264 */ 00265 00266 SUNDIALS_EXPORT void N_VDestroyVectorArray_Parallel(N_Vector *vs, int count); 00267 00268 /* 00269 * ----------------------------------------------------------------- 00270 * Function : N_VPrint_Parallel 00271 * ----------------------------------------------------------------- 00272 * This function prints the content of a parallel vector to stdout. 00273 * ----------------------------------------------------------------- 00274 */ 00275 00276 SUNDIALS_EXPORT void N_VPrint_Parallel(N_Vector v); 00277 00278 /* 00279 * ----------------------------------------------------------------- 00280 * parallel implementations of the vector operations 00281 * ----------------------------------------------------------------- 00282 */ 00283 00284 SUNDIALS_EXPORT N_Vector N_VCloneEmpty_Parallel(N_Vector w); 00285 SUNDIALS_EXPORT N_Vector N_VClone_Parallel(N_Vector w); 00286 SUNDIALS_EXPORT void N_VDestroy_Parallel(N_Vector v); 00287 SUNDIALS_EXPORT void N_VSpace_Parallel(N_Vector v, long int *lrw, long int *liw); 00288 SUNDIALS_EXPORT realtype *N_VGetArrayPointer_Parallel(N_Vector v); 00289 SUNDIALS_EXPORT void N_VSetArrayPointer_Parallel(realtype *v_data, N_Vector v); 00290 SUNDIALS_EXPORT void N_VLinearSum_Parallel(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z); 00291 SUNDIALS_EXPORT void N_VConst_Parallel(realtype c, N_Vector z); 00292 SUNDIALS_EXPORT void N_VProd_Parallel(N_Vector x, N_Vector y, N_Vector z); 00293 SUNDIALS_EXPORT void N_VDiv_Parallel(N_Vector x, N_Vector y, N_Vector z); 00294 SUNDIALS_EXPORT void N_VScale_Parallel(realtype c, N_Vector x, N_Vector z); 00295 SUNDIALS_EXPORT void N_VAbs_Parallel(N_Vector x, N_Vector z); 00296 SUNDIALS_EXPORT void N_VInv_Parallel(N_Vector x, N_Vector z); 00297 SUNDIALS_EXPORT void N_VAddConst_Parallel(N_Vector x, realtype b, N_Vector z); 00298 SUNDIALS_EXPORT realtype N_VDotProd_Parallel(N_Vector x, N_Vector y); 00299 SUNDIALS_EXPORT realtype N_VMaxNorm_Parallel(N_Vector x); 00300 SUNDIALS_EXPORT realtype N_VWrmsNorm_Parallel(N_Vector x, N_Vector w); 00301 SUNDIALS_EXPORT realtype N_VWrmsNormMask_Parallel(N_Vector x, N_Vector w, N_Vector id); 00302 SUNDIALS_EXPORT realtype N_VMin_Parallel(N_Vector x); 00303 SUNDIALS_EXPORT realtype N_VWL2Norm_Parallel(N_Vector x, N_Vector w); 00304 SUNDIALS_EXPORT realtype N_VL1Norm_Parallel(N_Vector x); 00305 SUNDIALS_EXPORT void N_VCompare_Parallel(realtype c, N_Vector x, N_Vector z); 00306 SUNDIALS_EXPORT booleantype N_VInvTest_Parallel(N_Vector x, N_Vector z); 00307 SUNDIALS_EXPORT booleantype N_VConstrMask_Parallel(N_Vector c, N_Vector x, N_Vector m); 00308 SUNDIALS_EXPORT realtype N_VMinQuotient_Parallel(N_Vector num, N_Vector denom); 00309 00310 #ifdef __cplusplus 00311 } 00312 #endif 00313 00314 #endif