1 /* 2 Defines the vector component of PETSc. Vectors generally represent 3 degrees of freedom for finite element/finite difference functions 4 on a grid. They have more mathematical structure then simple arrays. 5 */ 6 7 #ifndef __PETSCVEC_H 8 #define __PETSCVEC_H 9 #include "petscis.h" 10 11 PETSC_EXTERN_CXX_BEGIN 12 13 /*S 14 Vec - Abstract PETSc vector object 15 16 Level: beginner 17 18 Concepts: field variables, unknowns, arrays 19 20 .seealso: VecCreate(), VecType, VecSetType() 21 S*/ 22 typedef struct _p_Vec* Vec; 23 24 /*S 25 VecScatter - Object used to manage communication of data 26 between vectors in parallel. Manages both scatters and gathers 27 28 Level: beginner 29 30 Concepts: scatter 31 32 .seealso: VecScatterCreate(), VecScatterBegin(), VecScatterEnd() 33 S*/ 34 typedef struct _p_VecScatter* VecScatter; 35 36 /*E 37 ScatterMode - Determines the direction of a scatter 38 39 Level: beginner 40 41 .seealso: VecScatter, VecScatterBegin(), VecScatterEnd() 42 E*/ 43 typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode; 44 45 /*MC 46 SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call 47 48 Level: beginner 49 50 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL, 51 SCATTER_REVERSE_LOCAL 52 53 M*/ 54 55 /*MC 56 SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in 57 in the VecScatterCreate() 58 59 Level: beginner 60 61 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL, 62 SCATTER_REVERSE_LOCAL 63 64 M*/ 65 66 /*MC 67 SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication 68 is done. Any variables that have be moved between processes are ignored 69 70 Level: developer 71 72 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD, 73 SCATTER_REVERSE_LOCAL 74 75 M*/ 76 77 /*MC 78 SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in 79 in the VecScatterCreate() except NO parallel communication 80 is done. Any variables that have be moved between processes are ignored 81 82 Level: developer 83 84 .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL, 85 SCATTER_REVERSE 86 87 M*/ 88 89 /*E 90 VecType - String with the name of a PETSc vector or the creation function 91 with an optional dynamic library name, for example 92 http://www.mcs.anl.gov/petsc/lib.a:myveccreate() 93 94 Level: beginner 95 96 .seealso: VecSetType(), Vec 97 E*/ 98 #define VecType char* 99 #define VECSEQ "seq" 100 #define VECMPI "mpi" 101 #define VECSTANDARD "standard" /* seq on one process and mpi on several */ 102 #define VECSHARED "shared" 103 #define VECSIEVE "sieve" 104 #define VECSEQCUDA "seqcuda" 105 #define VECMPICUDA "mpicuda" 106 #define VECCUDA "cuda" /* seqcuda on one process and mpicuda on several */ 107 #define VECDD "vecdd" 108 #define VECNEST "nest" 109 110 111 /* Logging support */ 112 #define VEC_FILE_CLASSID 1211214 113 extern PETSCVEC_DLLEXPORT PetscClassId VEC_CLASSID; 114 extern PETSCVEC_DLLEXPORT PetscClassId VEC_SCATTER_CLASSID; 115 116 117 extern PetscErrorCode PETSCVEC_DLLEXPORT VecInitializePackage(const char[]); 118 extern PetscErrorCode PETSCVEC_DLLEXPORT VecFinalizePackage(void); 119 120 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreate(MPI_Comm,Vec*); 121 PetscPolymorphicSubroutine(VecCreate,(Vec *x),(PETSC_COMM_SELF,x)) 122 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateSeq(MPI_Comm,PetscInt,Vec*); 123 PetscPolymorphicSubroutine(VecCreateSeq,(PetscInt n,Vec *x),(PETSC_COMM_SELF,n,x)) 124 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateMPI(MPI_Comm,PetscInt,PetscInt,Vec*); 125 PetscPolymorphicSubroutine(VecCreateMPI,(PetscInt n,PetscInt N,Vec *x),(PETSC_COMM_WORLD,n,N,x)) 126 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateSeqWithArray(MPI_Comm,PetscInt,const PetscScalar[],Vec*); 127 PetscPolymorphicSubroutine(VecCreateSeqWithArray,(PetscInt n,PetscScalar s[],Vec *x),(PETSC_COMM_SELF,n,s,x)) 128 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateMPIWithArray(MPI_Comm,PetscInt,PetscInt,const PetscScalar[],Vec*); 129 PetscPolymorphicSubroutine(VecCreateMPIWithArray,(PetscInt n,PetscInt N,PetscScalar s[],Vec *x),(PETSC_COMM_WORLD,n,N,s,x)) 130 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateShared(MPI_Comm,PetscInt,PetscInt,Vec*); 131 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetFromOptions(Vec); 132 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetUp(Vec); 133 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDestroy(Vec); 134 extern PetscErrorCode PETSCVEC_DLLEXPORT VecZeroEntries(Vec); 135 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetOptionsPrefix(Vec,const char[]); 136 extern PetscErrorCode PETSCVEC_DLLEXPORT VecAppendOptionsPrefix(Vec,const char[]); 137 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetOptionsPrefix(Vec,const char*[]); 138 139 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetSizes(Vec,PetscInt,PetscInt); 140 141 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDotNorm2(Vec,Vec,PetscScalar*,PetscScalar*); 142 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDot(Vec,Vec,PetscScalar*); 143 PetscPolymorphicFunction(VecDot,(Vec x,Vec y),(x,y,&s),PetscScalar,s) 144 extern PetscErrorCode PETSCVEC_DLLEXPORT VecTDot(Vec,Vec,PetscScalar*); 145 PetscPolymorphicFunction(VecTDot,(Vec x,Vec y),(x,y,&s),PetscScalar,s) 146 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMDot(Vec,PetscInt,const Vec[],PetscScalar[]); 147 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMTDot(Vec,PetscInt,const Vec[],PetscScalar[]); 148 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetSubVector(Vec,IS,Vec*); 149 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreSubVector(Vec,IS,Vec*); 150 151 /*E 152 NormType - determines what type of norm to compute 153 154 Level: beginner 155 156 .seealso: VecNorm(), VecNormBegin(), VecNormEnd(), MatNorm() 157 E*/ 158 typedef enum {NORM_1=0,NORM_2=1,NORM_FROBENIUS=2,NORM_INFINITY=3,NORM_1_AND_2=4} NormType; 159 extern const char *NormTypes[]; 160 #define NORM_MAX NORM_INFINITY 161 162 /*MC 163 NORM_1 - the one norm, ||v|| = sum_i | v_i |. ||A|| = max_j || v_*j ||, maximum column sum 164 165 Level: beginner 166 167 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_2, NORM_FROBENIUS, 168 NORM_INFINITY, NORM_1_AND_2 169 170 M*/ 171 172 /*MC 173 NORM_2 - the two norm, ||v|| = sqrt(sum_i (v_i)^2) (vectors only) 174 175 Level: beginner 176 177 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_FROBENIUS, 178 NORM_INFINITY, NORM_1_AND_2 179 180 M*/ 181 182 /*MC 183 NORM_FROBENIUS - ||A|| = sqrt(sum_ij (A_ij)^2), same as NORM_2 for vectors 184 185 Level: beginner 186 187 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 188 NORM_INFINITY, NORM_1_AND_2 189 190 M*/ 191 192 /*MC 193 NORM_INFINITY - ||v|| = max_i |v_i|. ||A|| = max_i || v_i* ||, maximum row sum 194 195 Level: beginner 196 197 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 198 NORM_FROBINIUS, NORM_1_AND_2 199 200 M*/ 201 202 /*MC 203 NORM_1_AND_2 - computes both the 1 and 2 norm of a vector 204 205 Level: beginner 206 207 .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 208 NORM_FROBINIUS, NORM_INFINITY 209 210 M*/ 211 212 /*MC 213 NORM_MAX - see NORM_INFINITY 214 215 Level: beginner 216 217 M*/ 218 219 extern PetscErrorCode PETSCVEC_DLLEXPORT VecNorm(Vec,NormType,PetscReal *); 220 extern PetscErrorCode PETSCVEC_DLLEXPORT VecNormAvailable(Vec,NormType,PetscBool *,PetscReal *); 221 PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) 222 PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) 223 PetscPolymorphicFunction(VecNorm,(Vec x),(x,NORM_2,&r),PetscReal,r) 224 extern PetscErrorCode PETSCVEC_DLLEXPORT VecNormalize(Vec,PetscReal *); 225 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSum(Vec,PetscScalar*); 226 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMax(Vec,PetscInt*,PetscReal *); 227 PetscPolymorphicSubroutine(VecMax,(Vec x,PetscReal *r),(x,PETSC_NULL,r)) 228 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMin(Vec,PetscInt*,PetscReal *); 229 PetscPolymorphicSubroutine(VecMin,(Vec x,PetscReal *r),(x,PETSC_NULL,r)) 230 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScale(Vec,PetscScalar); 231 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCopy(Vec,Vec); 232 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetRandom(Vec,PetscRandom); 233 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSet(Vec,PetscScalar); 234 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSwap(Vec,Vec); 235 extern PetscErrorCode PETSCVEC_DLLEXPORT VecAXPY(Vec,PetscScalar,Vec); 236 extern PetscErrorCode PETSCVEC_DLLEXPORT VecAXPBY(Vec,PetscScalar,PetscScalar,Vec); 237 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMAXPY(Vec,PetscInt,const PetscScalar[],Vec[]); 238 extern PetscErrorCode PETSCVEC_DLLEXPORT VecAYPX(Vec,PetscScalar,Vec); 239 extern PetscErrorCode PETSCVEC_DLLEXPORT VecWAXPY(Vec,PetscScalar,Vec,Vec); 240 extern PetscErrorCode PETSCVEC_DLLEXPORT VecAXPBYPCZ(Vec,PetscScalar,PetscScalar,PetscScalar,Vec,Vec); 241 extern PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseMax(Vec,Vec,Vec); 242 PetscPolymorphicSubroutine(VecPointwiseMax,(Vec x,Vec y),(x,y,y)) 243 extern PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseMaxAbs(Vec,Vec,Vec); 244 PetscPolymorphicSubroutine(VecPointwiseMaxAbs,(Vec x,Vec y),(x,y,y)) 245 extern PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseMin(Vec,Vec,Vec); 246 PetscPolymorphicSubroutine(VecPointwiseMin,(Vec x,Vec y),(x,y,y)) 247 extern PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseMult(Vec,Vec,Vec); 248 PetscPolymorphicSubroutine(VecPointwiseMult,(Vec x,Vec y),(x,x,y)) 249 extern PetscErrorCode PETSCVEC_DLLEXPORT VecPointwiseDivide(Vec,Vec,Vec); 250 PetscPolymorphicSubroutine(VecPointwiseDivide,(Vec x,Vec y),(x,x,y)) 251 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMaxPointwiseDivide(Vec,Vec,PetscReal*); 252 extern PetscErrorCode PETSCVEC_DLLEXPORT VecShift(Vec,PetscScalar); 253 extern PetscErrorCode PETSCVEC_DLLEXPORT VecReciprocal(Vec); 254 extern PetscErrorCode PETSCVEC_DLLEXPORT VecPermute(Vec, IS, PetscBool ); 255 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSqrtAbs(Vec); 256 extern PetscErrorCode PETSCVEC_DLLEXPORT VecLog(Vec); 257 extern PetscErrorCode PETSCVEC_DLLEXPORT VecExp(Vec); 258 extern PetscErrorCode PETSCVEC_DLLEXPORT VecAbs(Vec); 259 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDuplicate(Vec,Vec*); 260 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDuplicateVecs(Vec,PetscInt,Vec*[]); 261 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDestroyVecs(Vec[],PetscInt); 262 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideNormAll(Vec,NormType,PetscReal[]); 263 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideMaxAll(Vec,PetscInt [],PetscReal []); 264 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideMinAll(Vec,PetscInt [],PetscReal []); 265 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideScaleAll(Vec,PetscScalar[]); 266 267 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideNorm(Vec,PetscInt,NormType,PetscReal*); 268 PetscPolymorphicFunction(VecStrideNorm,(Vec x,PetscInt i),(x,i,NORM_2,&r),PetscReal,r) 269 PetscPolymorphicFunction(VecStrideNorm,(Vec x,PetscInt i,NormType t),(x,i,t,&r),PetscReal,r) 270 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideMax(Vec,PetscInt,PetscInt *,PetscReal *); 271 PetscPolymorphicFunction(VecStrideMax,(Vec x,PetscInt i),(x,i,PETSC_NULL,&r),PetscReal,r) 272 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideMin(Vec,PetscInt,PetscInt *,PetscReal *); 273 PetscPolymorphicFunction(VecStrideMin,(Vec x,PetscInt i),(x,i,PETSC_NULL,&r),PetscReal,r) 274 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideScale(Vec,PetscInt,PetscScalar); 275 276 277 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideGather(Vec,PetscInt,Vec,InsertMode); 278 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideScatter(Vec,PetscInt,Vec,InsertMode); 279 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideGatherAll(Vec,Vec[],InsertMode); 280 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStrideScatterAll(Vec[],Vec,InsertMode); 281 282 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetValues(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 283 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetValues(Vec,PetscInt,const PetscInt[],PetscScalar[]); 284 extern PetscErrorCode PETSCVEC_DLLEXPORT VecAssemblyBegin(Vec); 285 extern PetscErrorCode PETSCVEC_DLLEXPORT VecAssemblyEnd(Vec); 286 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStashSetInitialSize(Vec,PetscInt,PetscInt); 287 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStashView(Vec,PetscViewer); 288 extern PetscErrorCode PETSCVEC_DLLEXPORT VecStashGetInfo(Vec,PetscInt*,PetscInt*,PetscInt*,PetscInt*); 289 290 /*MC 291 VecSetValue - Set a single entry into a vector. 292 293 Synopsis: 294 PetscErrorCode VecSetValue(Vec v,int row,PetscScalar value, InsertMode mode); 295 296 Not Collective 297 298 Input Parameters: 299 + v - the vector 300 . row - the row location of the entry 301 . value - the value to insert 302 - mode - either INSERT_VALUES or ADD_VALUES 303 304 Notes: 305 For efficiency one should use VecSetValues() and set several or 306 many values simultaneously if possible. 307 308 These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd() 309 MUST be called after all calls to VecSetValues() have been completed. 310 311 VecSetValues() uses 0-based indices in Fortran as well as in C. 312 313 Level: beginner 314 315 .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValueLocal() 316 M*/ 317 PETSC_STATIC_INLINE PetscErrorCode VecSetValue(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValues(v,1,&i,&va,mode);} 318 319 320 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetBlockSize(Vec,PetscInt); 321 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetBlockSize(Vec,PetscInt*); 322 PetscPolymorphicFunction(VecGetBlockSize,(Vec x),(x,&i),PetscInt,i) 323 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetValuesBlocked(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 324 325 /* Dynamic creation and loading functions */ 326 extern PetscFList VecList; 327 extern PetscBool VecRegisterAllCalled; 328 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetType(Vec, const VecType); 329 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetType(Vec, const VecType *); 330 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRegister(const char[],const char[],const char[],PetscErrorCode (*)(Vec)); 331 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRegisterAll(const char []); 332 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRegisterDestroy(void); 333 334 /*MC 335 VecRegisterDynamic - Adds a new vector component implementation 336 337 Synopsis: 338 PetscErrorCode VecRegisterDynamic(const char *name, const char *path, const char *func_name, PetscErrorCode (*create_func)(Vec)) 339 340 Not Collective 341 342 Input Parameters: 343 + name - The name of a new user-defined creation routine 344 . path - The path (either absolute or relative) of the library containing this routine 345 . func_name - The name of routine to create method context 346 - create_func - The creation routine itself 347 348 Notes: 349 VecRegisterDynamic() may be called multiple times to add several user-defined vectors 350 351 If dynamic libraries are used, then the fourth input argument (routine_create) is ignored. 352 353 Sample usage: 354 .vb 355 VecRegisterDynamic("my_vec","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyVectorCreate", MyVectorCreate); 356 .ve 357 358 Then, your vector type can be chosen with the procedural interface via 359 .vb 360 VecCreate(MPI_Comm, Vec *); 361 VecSetType(Vec,"my_vector_name"); 362 .ve 363 or at runtime via the option 364 .vb 365 -vec_type my_vector_name 366 .ve 367 368 Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 369 If your function is not being put into a shared library then use VecRegister() instead 370 371 Level: advanced 372 373 .keywords: Vec, register 374 .seealso: VecRegisterAll(), VecRegisterDestroy(), VecRegister() 375 M*/ 376 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 377 #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,0) 378 #else 379 #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,d) 380 #endif 381 382 383 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreate(Vec,IS,Vec,IS,VecScatter *); 384 PetscPolymorphicFunction(VecScatterCreate,(Vec x,IS is1,Vec y,IS is2),(x,is1,y,is2,&s),VecScatter,s) 385 PetscPolymorphicSubroutine(VecScatterCreate,(Vec x,IS is,Vec y,VecScatter *s),(x,is,y,PETSC_NULL,s)) 386 PetscPolymorphicFunction(VecScatterCreate,(Vec x,IS is,Vec y),(x,is,y,PETSC_NULL,&s),VecScatter,s) 387 PetscPolymorphicSubroutine(VecScatterCreate,(Vec x,Vec y,IS is,VecScatter *s),(x,PETSC_NULL,y,is,s)) 388 PetscPolymorphicFunction(VecScatterCreate,(Vec x,Vec y,IS is),(x,PETSC_NULL,y,is,&s),VecScatter,s) 389 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreateEmpty(MPI_Comm,VecScatter *); 390 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreateLocal(VecScatter,PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],PetscInt); 391 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterBegin(VecScatter,Vec,Vec,InsertMode,ScatterMode); 392 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterEnd(VecScatter,Vec,Vec,InsertMode,ScatterMode); 393 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterDestroy(VecScatter); 394 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCopy(VecScatter,VecScatter *); 395 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterView(VecScatter,PetscViewer); 396 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterRemap(VecScatter,PetscInt *,PetscInt*); 397 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterGetMerged(VecScatter,PetscBool *); 398 399 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]); 400 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]); 401 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]); 402 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]); 403 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]); 404 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]); 405 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]); 406 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]); 407 408 extern PetscErrorCode PETSCVEC_DLLEXPORT VecPlaceArray(Vec,const PetscScalar[]); 409 extern PetscErrorCode PETSCVEC_DLLEXPORT VecResetArray(Vec); 410 extern PetscErrorCode PETSCVEC_DLLEXPORT VecReplaceArray(Vec,const PetscScalar[]); 411 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetArrays(const Vec[],PetscInt,PetscScalar**[]); 412 extern PetscErrorCode PETSCVEC_DLLEXPORT VecRestoreArrays(const Vec[],PetscInt,PetscScalar**[]); 413 414 extern PetscErrorCode PETSCVEC_DLLEXPORT VecValid(Vec,PetscBool *); 415 extern PetscErrorCode PETSCVEC_DLLEXPORT VecView(Vec,PetscViewer); 416 extern PetscErrorCode PETSCVEC_DLLEXPORT VecViewFromOptions(Vec, const char *); 417 extern PetscErrorCode PETSCVEC_DLLEXPORT VecEqual(Vec,Vec,PetscBool *); 418 PetscPolymorphicFunction(VecEqual,(Vec x,Vec y),(x,y,&s),PetscBool ,s) 419 extern PetscErrorCode PETSCVEC_DLLEXPORT VecLoad(Vec, PetscViewer); 420 421 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetSize(Vec,PetscInt*); 422 PetscPolymorphicFunction(VecGetSize,(Vec x),(x,&s),PetscInt,s) 423 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetLocalSize(Vec,PetscInt*); 424 PetscPolymorphicFunction(VecGetLocalSize,(Vec x),(x,&s),PetscInt,s) 425 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetOwnershipRange(Vec,PetscInt*,PetscInt*); 426 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGetOwnershipRanges(Vec,const PetscInt *[]); 427 428 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping); 429 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetValuesLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 430 431 /*MC 432 VecSetValueLocal - Set a single entry into a vector using the local numbering 433 434 Synopsis: 435 PetscErrorCode VecSetValueLocal(Vec v,int row,PetscScalar value, InsertMode mode); 436 437 Not Collective 438 439 Input Parameters: 440 + v - the vector 441 . row - the row location of the entry 442 . value - the value to insert 443 - mode - either INSERT_VALUES or ADD_VALUES 444 445 Notes: 446 For efficiency one should use VecSetValues() and set several or 447 many values simultaneously if possible. 448 449 These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd() 450 MUST be called after all calls to VecSetValues() have been completed. 451 452 VecSetValues() uses 0-based indices in Fortran as well as in C. 453 454 Level: beginner 455 456 .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValue() 457 M*/ 458 PETSC_STATIC_INLINE PetscErrorCode VecSetValueLocal(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValuesLocal(v,1,&i,&va,mode);} 459 460 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetLocalToGlobalMappingBlock(Vec,ISLocalToGlobalMapping); 461 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetValuesBlockedLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 462 463 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDotBegin(Vec,Vec,PetscScalar *); 464 PetscPolymorphicSubroutine(VecDotBegin,(Vec x,Vec y),(x,y,PETSC_NULL)) 465 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDotEnd(Vec,Vec,PetscScalar *); 466 PetscPolymorphicFunction(VecDotEnd,(Vec x,Vec y),(x,y,&s),PetscScalar,s) 467 extern PetscErrorCode PETSCVEC_DLLEXPORT VecTDotBegin(Vec,Vec,PetscScalar *); 468 PetscPolymorphicSubroutine(VecTDotBegin,(Vec x,Vec y),(x,y,PETSC_NULL)) 469 extern PetscErrorCode PETSCVEC_DLLEXPORT VecTDotEnd(Vec,Vec,PetscScalar *); 470 PetscPolymorphicFunction(VecTDotEnd,(Vec x,Vec y),(x,y,&s),PetscScalar,s) 471 extern PetscErrorCode PETSCVEC_DLLEXPORT VecNormBegin(Vec,NormType,PetscReal *); 472 PetscPolymorphicSubroutine(VecNormBegin,(Vec x,NormType t),(x,t,PETSC_NULL)) 473 PetscPolymorphicSubroutine(VecNormBegin,(Vec x),(x,NORM_2,PETSC_NULL)) 474 extern PetscErrorCode PETSCVEC_DLLEXPORT VecNormEnd(Vec,NormType,PetscReal *); 475 PetscPolymorphicFunction(VecNormEnd,(Vec x,NormType t),(x,t,&s),PetscReal,s) 476 PetscPolymorphicFunction(VecNormEnd,(Vec x),(x,NORM_2,&s),PetscReal,s) 477 478 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]); 479 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]); 480 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMTDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]); 481 extern PetscErrorCode PETSCVEC_DLLEXPORT VecMTDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]); 482 483 484 typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES,VEC_IGNORE_NEGATIVE_INDICES} VecOption; 485 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetOption(Vec,VecOption,PetscBool ); 486 487 /* 488 Expose VecGetArray()/VecRestoreArray() to users. Allows this to work without any function 489 call overhead on any 'native' Vecs. 490 */ 491 492 #include "private/vecimpl.h" 493 494 extern PetscErrorCode PETSCVEC_DLLEXPORT VecContourScale(Vec,PetscReal,PetscReal); 495 496 /* 497 These numbers need to match the entries in 498 the function table in vecimpl.h 499 */ 500 typedef enum { VECOP_VIEW = 33, VECOP_LOAD = 41, VECOP_DUPLICATE = 0} VecOperation; 501 extern PetscErrorCode PETSCVEC_DLLEXPORT VecSetOperation(Vec,VecOperation,void(*)(void)); 502 503 /* 504 Routines for dealing with ghosted vectors: 505 vectors with ghost elements at the end of the array. 506 */ 507 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateGhost(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*); 508 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateGhostWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*); 509 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateGhostBlock(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*); 510 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateGhostBlockWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*); 511 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGhostGetLocalForm(Vec,Vec*); 512 PetscPolymorphicFunction(VecGhostGetLocalForm,(Vec x),(x,&s),Vec,s) 513 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGhostRestoreLocalForm(Vec,Vec*); 514 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGhostUpdateBegin(Vec,InsertMode,ScatterMode); 515 extern PetscErrorCode PETSCVEC_DLLEXPORT VecGhostUpdateEnd(Vec,InsertMode,ScatterMode); 516 517 extern PetscErrorCode PETSCVEC_DLLEXPORT VecConjugate(Vec); 518 519 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreateToAll(Vec,VecScatter*,Vec*); 520 extern PetscErrorCode PETSCVEC_DLLEXPORT VecScatterCreateToZero(Vec,VecScatter*,Vec*); 521 522 extern PetscErrorCode PETSCVEC_DLLEXPORT PetscViewerMathematicaGetVector(PetscViewer, Vec); 523 extern PetscErrorCode PETSCVEC_DLLEXPORT PetscViewerMathematicaPutVector(PetscViewer, Vec); 524 525 /*S 526 Vecs - Collection of vectors where the data for the vectors is stored in 527 one contiguous memory 528 529 Level: advanced 530 531 Notes: 532 Temporary construct for handling multiply right hand side solves 533 534 This is faked by storing a single vector that has enough array space for 535 n vectors 536 537 Concepts: parallel decomposition 538 539 S*/ 540 struct _n_Vecs {PetscInt n; Vec v;}; 541 typedef struct _n_Vecs* Vecs; 542 #define VecsDestroy(x) (VecDestroy((x)->v) || PetscFree(x)) 543 #define VecsCreateSeq(comm,p,m,x) (PetscNew(struct _n_Vecs,x) || VecCreateSeq(comm,p*m,&(*(x))->v) || (-1 == ((*(x))->n = (m)))) 544 #define VecsCreateSeqWithArray(comm,p,m,a,x) (PetscNew(struct _n_Vecs,x) || VecCreateSeqWithArray(comm,p*m,a,&(*(x))->v) || (-1 == ((*(x))->n = (m)))) 545 #define VecsDuplicate(x,y) (PetscNew(struct _n_Vecs,y) || VecDuplicate(x->v,&(*(y))->v) || (-1 == ((*(y))->n = (x)->n))) 546 547 #if defined(PETSC_HAVE_CUDA) 548 typedef struct _p_PetscCUSPIndices* PetscCUSPIndices; 549 extern PetscErrorCode PetscCUSPIndicesCreate(PetscInt,const PetscInt*,PetscCUSPIndices*); 550 extern PetscErrorCode PetscCUSPIndicesDestroy(PetscCUSPIndices); 551 extern PetscErrorCode VecCUDACopyToGPUSome_Public(Vec,PetscCUSPIndices); 552 extern PetscErrorCode VecCUDACopyFromGPUSome_Public(Vec,PetscCUSPIndices); 553 #endif 554 555 #if defined PETSC_HAVE_VECDD 556 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDDSetDomainsLocal(Vec v, PetscInt domain_count, PetscInt supported_domains[], PetscInt domain_limits[], PetscBool covering); 557 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDDSetDomainsLocalIS(Vec v, IS supported_domains, IS domain_limits[], PetscBool covering); 558 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDDGetDomainInfoLocal(Vec v, PetscInt i, PetscInt *d, PetscInt *size); 559 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDDGetDomainArrayLocal(Vec v, PetscInt i, PetscScalar **array); 560 extern PetscErrorCode PETSCVEC_DLLEXPORT VecDDRestoreDomainArrayLocal(Vec v, PetscInt i, PetscScalar **array); 561 #endif 562 563 extern PetscErrorCode PETSCVEC_DLLEXPORT VecNestGetSubVecs(Vec,PetscInt*,Vec**); 564 extern PetscErrorCode PETSCVEC_DLLEXPORT VecNestGetSubVec(Vec,PetscInt,Vec*); 565 extern PetscErrorCode PETSCVEC_DLLEXPORT VecCreateNest(MPI_Comm,PetscInt,IS*,Vec*,Vec*); 566 extern PetscErrorCode PETSCVEC_DLLEXPORT VecNestGetSize(Vec,PetscInt*); 567 568 PETSC_EXTERN_CXX_END 569 #endif 570