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