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 #ifndef PETSCVEC_H 7 #define PETSCVEC_H 8 9 #include <petscsys.h> 10 #include <petscsftypes.h> /* for VecScatter, VecScatterType */ 11 #include <petscis.h> 12 #include <petscdevicetypes.h> 13 #include <petscviewer.h> 14 15 /* SUBMANSEC = Vec */ 16 17 /*S 18 Vec - Abstract PETSc vector object 19 20 Level: beginner 21 22 .seealso: [](chapter_vectors), `VecCreate()`, `VecType`, `VecSetType()` 23 S*/ 24 typedef struct _p_Vec *Vec; 25 26 /*E 27 ScatterMode - Determines the direction of a scatter 28 29 Level: beginner 30 31 Values: 32 + `SCATTER_FORWARD` - Scatters the values as dictated by the `VecScatterCreate()` call 33 . `SCATTER_REVERSE` - Moves the values in the opposite direction than the directions indicated in the `VecScatterCreate()` call 34 . `SCATTER_FORWARD_LOCAL` - Scatters the values as dictated by the `VecScatterCreate()` call except NO MPI communication is done 35 - `SCATTER_REVERSE_LOCAL` - Moves the values in the opposite direction than the directions indicated in the `VecScatterCreate()` call 36 except NO MPI communication is done 37 38 .seealso: [](chapter_vectors), `VecScatter`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_FORWARD`, `SCATTER_REVERSE`, `SCATTER_FORWARD_LOCAL`, `SCATTER_REVERSE_LOCAL` 39 E*/ 40 typedef enum { 41 SCATTER_FORWARD = 0, 42 SCATTER_REVERSE = 1, 43 SCATTER_FORWARD_LOCAL = 2, 44 SCATTER_REVERSE_LOCAL = 3 45 } ScatterMode; 46 47 /*MC 48 SCATTER_FORWARD - Scatters the values as dictated by the `VecScatterCreate()` call 49 50 Level: beginner 51 52 .seealso: [](chapter_vectors), `VecScatter`, `ScatterMode`, `VecScatterCreate()`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_REVERSE`, `SCATTER_FORWARD_LOCAL`, 53 `SCATTER_REVERSE_LOCAL` 54 M*/ 55 56 /*MC 57 SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in 58 in the `VecScatterCreate()` 59 60 Level: beginner 61 62 .seealso: [](chapter_vectors), `VecScatter`, `ScatterMode`, `VecScatterCreate()`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_FORWARD`, `SCATTER_FORWARD_LOCAL`, 63 `SCATTER_REVERSE_LOCAL` 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: [](chapter_vectors), `VecScatter`, `ScatterMode`, `VecScatterCreate()`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_REVERSE`, `SCATTER_FORWARD`, 73 `SCATTER_REVERSE_LOCAL` 74 M*/ 75 76 /*MC 77 SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in 78 in the `VecScatterCreate()` except NO parallel communication 79 is done. Any variables that have be moved between processes are ignored 80 81 Level: developer 82 83 .seealso: [](chapter_vectors), `VecScatter`, `ScatterMode`, `VecScatterCreate()`, `VecScatterBegin()`, `VecScatterEnd()`, `SCATTER_FORWARD`, `SCATTER_FORWARD_LOCAL`, 84 `SCATTER_REVERSE` 85 M*/ 86 87 /*J 88 VecType - String with the name of a PETSc vector 89 90 Level: beginner 91 92 .seealso: [](chapter_vectors), `VecSetType()`, `Vec`, `VecCreate()`, `VecDestroy()` 93 J*/ 94 typedef const char *VecType; 95 #define VECSEQ "seq" 96 #define VECMPI "mpi" 97 #define VECSTANDARD "standard" /* seq on one process and mpi on several */ 98 #define VECSHARED "shared" 99 #define VECSEQVIENNACL "seqviennacl" 100 #define VECMPIVIENNACL "mpiviennacl" 101 #define VECVIENNACL "viennacl" /* seqviennacl on one process and mpiviennacl on several */ 102 #define VECSEQCUDA "seqcuda" 103 #define VECMPICUDA "mpicuda" 104 #define VECCUDA "cuda" /* seqcuda on one process and mpicuda on several */ 105 #define VECSEQHIP "seqhip" 106 #define VECMPIHIP "mpihip" 107 #define VECHIP "hip" /* seqcuda on one process and mpicuda on several */ 108 #define VECNEST "nest" 109 #define VECSEQKOKKOS "seqkokkos" 110 #define VECMPIKOKKOS "mpikokkos" 111 #define VECKOKKOS "kokkos" /* seqkokkos on one process and mpikokkos on several */ 112 113 /* Dynamic creation and loading functions */ 114 PETSC_EXTERN PetscErrorCode VecScatterSetType(VecScatter, VecScatterType); 115 PETSC_EXTERN PetscErrorCode VecScatterGetType(VecScatter, VecScatterType *); 116 PETSC_EXTERN PetscErrorCode VecScatterSetFromOptions(VecScatter); 117 PETSC_EXTERN PetscErrorCode VecScatterRegister(const char[], PetscErrorCode (*)(VecScatter)); 118 PETSC_EXTERN PetscErrorCode VecScatterCreate(Vec, IS, Vec, IS, VecScatter *); 119 120 /* Logging support */ 121 #define REAL_FILE_CLASSID 1211213 122 #define VEC_FILE_CLASSID 1211214 123 PETSC_EXTERN PetscClassId VEC_CLASSID; 124 PETSC_EXTERN PetscClassId PETSCSF_CLASSID; 125 126 PETSC_EXTERN PetscErrorCode VecInitializePackage(void); 127 PETSC_EXTERN PetscErrorCode VecFinalizePackage(void); 128 129 PETSC_EXTERN PetscErrorCode VecCreate(MPI_Comm, Vec *); 130 PETSC_EXTERN PetscErrorCode VecCreateSeq(MPI_Comm, PetscInt, Vec *); 131 PETSC_EXTERN PetscErrorCode VecCreateMPI(MPI_Comm, PetscInt, PetscInt, Vec *); 132 PETSC_EXTERN PetscErrorCode VecCreateSeqWithArray(MPI_Comm, PetscInt, PetscInt, const PetscScalar[], Vec *); 133 PETSC_EXTERN PetscErrorCode VecCreateMPIWithArray(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscScalar[], Vec *); 134 PETSC_EXTERN PetscErrorCode VecCreateShared(MPI_Comm, PetscInt, PetscInt, Vec *); 135 PETSC_EXTERN PetscErrorCode VecCreateNode(MPI_Comm, PetscInt, PetscInt, Vec *); 136 137 PETSC_EXTERN PetscErrorCode VecSetFromOptions(Vec); 138 PETSC_EXTERN PetscErrorCode VecViewFromOptions(Vec, PetscObject, const char[]); 139 140 PETSC_EXTERN PetscErrorCode VecSetUp(Vec); 141 PETSC_EXTERN PetscErrorCode VecDestroy(Vec *); 142 PETSC_EXTERN PetscErrorCode VecZeroEntries(Vec); 143 PETSC_EXTERN PetscErrorCode VecSetOptionsPrefix(Vec, const char[]); 144 PETSC_EXTERN PetscErrorCode VecAppendOptionsPrefix(Vec, const char[]); 145 PETSC_EXTERN PetscErrorCode VecGetOptionsPrefix(Vec, const char *[]); 146 147 PETSC_EXTERN PetscErrorCode VecSetSizes(Vec, PetscInt, PetscInt); 148 149 PETSC_EXTERN PetscErrorCode VecDotNorm2(Vec, Vec, PetscScalar *, PetscReal *); 150 PETSC_EXTERN PetscErrorCode VecDot(Vec, Vec, PetscScalar *); 151 PETSC_EXTERN PetscErrorCode VecDotRealPart(Vec, Vec, PetscReal *); 152 PETSC_EXTERN PetscErrorCode VecTDot(Vec, Vec, PetscScalar *); 153 PETSC_EXTERN PetscErrorCode VecMDot(Vec, PetscInt, const Vec[], PetscScalar[]); 154 PETSC_EXTERN PetscErrorCode VecMTDot(Vec, PetscInt, const Vec[], PetscScalar[]); 155 PETSC_EXTERN PetscErrorCode VecGetSubVector(Vec, IS, Vec *); 156 PETSC_EXTERN PetscErrorCode VecRestoreSubVector(Vec, IS, Vec *); 157 PETSC_EXTERN PetscErrorCode VecConcatenate(PetscInt, const Vec[], Vec *, IS *[]); 158 159 /*E 160 NormType - determines what type of norm to compute 161 162 Level: beginner 163 164 Values: 165 + `NORM_1` - the one norm, ||v|| = sum_i | v_i |. ||A|| = max_j || v_*j ||, maximum column sum 166 . `NORM_2` - the two norm, ||v|| = sqrt(sum_i |v_i|^2) (vectors only) 167 . `NORM_FROBENIUS` - ||A|| = sqrt(sum_ij |A_ij|^2), same as `NORM_2` for vectors 168 . `NORM_INFINITY` - ||v|| = max_i |v_i|. ||A|| = max_i || v_i* ||, maximum row sum 169 - `NORM_1_AND_2` - computes both the 1 and 2 norm of a vector 170 171 Note: 172 The `v` above represents a `Vec` while the `A` represents a `Mat` 173 174 .seealso: [](chapter_vectors), `Vec`, `Mat`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `MatNorm()`, `NORM_1`, 175 `NORM_2`, `NORM_FROBENIUS`, `NORM_INFINITY`, `NORM_1_AND_2` 176 E*/ 177 typedef enum { 178 NORM_1 = 0, 179 NORM_2 = 1, 180 NORM_FROBENIUS = 2, 181 NORM_INFINITY = 3, 182 NORM_1_AND_2 = 4 183 } NormType; 184 PETSC_EXTERN const char *const NormTypes[]; 185 #define NORM_MAX NORM_INFINITY 186 187 /*MC 188 NORM_1 - the one norm, ||v|| = sum_i | v_i |. ||A|| = max_j || v_*j ||, maximum column sum 189 190 Level: beginner 191 192 .seealso: [](chapter_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_2`, `NORM_FROBENIUS`, 193 `NORM_INFINITY`, `NORM_1_AND_2` 194 M*/ 195 196 /*MC 197 NORM_2 - the two norm, ||v|| = sqrt(sum_i |v_i|^2) (vectors only) 198 199 Level: beginner 200 201 .seealso: [](chapter_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_1`, `NORM_FROBENIUS`, 202 `NORM_INFINITY`, `NORM_1_AND_2` 203 M*/ 204 205 /*MC 206 NORM_FROBENIUS - ||A|| = sqrt(sum_ij |A_ij|^2), same as `NORM_2` for vectors 207 208 Level: beginner 209 210 .seealso: [](chapter_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_1`, `NORM_2`, 211 `NORM_INFINITY`, `NORM_1_AND_2` 212 M*/ 213 214 /*MC 215 NORM_INFINITY - ||v|| = max_i |v_i|. ||A|| = max_i || v_i* ||, maximum row sum 216 217 Level: beginner 218 219 .seealso: [](chapter_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_1`, `NORM_2`, 220 `NORM_FROBENIUS`, `NORM_1_AND_2` 221 M*/ 222 223 /*MC 224 NORM_1_AND_2 - computes both the 1 and 2 norm of a vector. The values are stored in two adjacent `PetscReal` memory locations 225 226 Level: beginner 227 228 .seealso: [](chapter_vectors), `NormType`, `MatNorm()`, `VecNorm()`, `VecNormBegin()`, `VecNormEnd()`, `NORM_1`, `NORM_2`, 229 `NORM_FROBENIUS`, `NORM_INFINITY` 230 M*/ 231 232 /*MC 233 NORM_MAX - see `NORM_INFINITY` 234 235 Level: beginner 236 M*/ 237 238 /*E 239 ReductionType - determines what type of column reduction (one that is not a type of norm defined in `NormType`) to compute 240 241 Level: beginner 242 243 Values: 244 + `REDUCTION_SUM_REALPART` - sum of real part of each matrix column 245 . `REDUCTION_SUM_IMAGINARYPART` - sum of imaginary part of each matrix colum 246 . `REDUCTION_MEAN_REALPART` - arithmetic mean of real part of each matrix column 247 - `REDUCTION_MEAN_IMAGINARYPART` - arithmetic mean of imaginary part of each matrix column 248 249 Developer Note: 250 The constants defined in `ReductionType` MUST BE DISTINCT from those defined in `NormType`. 251 This is because `MatGetColumnReductions()` is used to compute both norms and other types of reductions, 252 and the constants defined in both `NormType` and `ReductionType` are used to designate the desired operation. 253 254 .seealso: [](chapter_vectors), `MatGetColumnReductions()`, `MatGetColumnNorms()`, `NormType`, `REDUCTION_SUM_REALPART`, 255 `REDUCTION_SUM_IMAGINARYPART`, `REDUCTION_MEAN_REALPART`, `REDUCTION_NORM_1`, `REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY` 256 E*/ 257 typedef enum { 258 REDUCTION_SUM_REALPART = 10, 259 REDUCTION_MEAN_REALPART = 11, 260 REDUCTION_SUM_IMAGINARYPART = 12, 261 REDUCTION_MEAN_IMAGINARYPART = 13 262 } ReductionType; 263 264 /*MC 265 REDUCTION_SUM_REALPART - sum of real part of matrix column 266 267 Level: beginner 268 269 .seealso: [](chapter_vectors), `ReductionType`, `MatGetColumnReductions()`, `REDUCTION_SUM_IMAGINARYPART`, `REDUCTION_MEAN_REALPART`, `REDUCTION_NORM_1`, 270 `REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY` 271 M*/ 272 273 /*MC 274 REDUCTION_SUM_IMAGINARYPART - sum of imaginary part of matrix column 275 276 Level: beginner 277 278 .seealso: [](chapter_vectors), `ReductionType`, `MatGetColumnReductions()`, `REDUCTION_SUM_REALPART`, `REDUCTION_MEAN_IMAGINARYPART`, `REDUCTION_NORM_1`, 279 `REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY` 280 M*/ 281 282 /*MC 283 REDUCTION_MEAN_REALPART - arithmetic mean of real part of matrix column 284 285 Level: beginner 286 287 .seealso: [](chapter_vectors), `ReductionType`, `MatGetColumnReductions()`, `REDUCTION_MEAN_IMAGINARYPART`, `REDUCTION_SUM_REALPART`, `REDUCTION_NORM_1`, 288 `REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY` 289 M*/ 290 291 /*MC 292 REDUCTION_MEAN_IMAGINARYPART - arithmetic mean of imaginary part of matrix column 293 294 Level: beginner 295 296 .seealso: [](chapter_vectors), `ReductionType`, `MatGetColumnReductions()`, `REDUCTION_MEAN_REALPART`, `REDUCTION_SUM_IMAGINARYPART`, `REDUCTION_NORM_1`, 297 `REDUCTION_NORM_2`, `REDUCTION_NORM_FROBENIUS`, `REDUCTION_NORM_INFINITY` 298 M*/ 299 300 PETSC_EXTERN PetscErrorCode VecNorm(Vec, NormType, PetscReal *); 301 PETSC_EXTERN PetscErrorCode VecNormAvailable(Vec, NormType, PetscBool *, PetscReal *); 302 PETSC_EXTERN PetscErrorCode VecNormalize(Vec, PetscReal *); 303 PETSC_EXTERN PetscErrorCode VecSum(Vec, PetscScalar *); 304 PETSC_EXTERN PetscErrorCode VecMean(Vec, PetscScalar *); 305 PETSC_EXTERN PetscErrorCode VecMax(Vec, PetscInt *, PetscReal *); 306 PETSC_EXTERN PetscErrorCode VecMin(Vec, PetscInt *, PetscReal *); 307 PETSC_EXTERN PetscErrorCode VecScale(Vec, PetscScalar); 308 PETSC_EXTERN PetscErrorCode VecCopy(Vec, Vec); 309 PETSC_EXTERN PetscErrorCode VecSetRandom(Vec, PetscRandom); 310 PETSC_EXTERN PetscErrorCode VecSet(Vec, PetscScalar); 311 PETSC_EXTERN PetscErrorCode VecSetInf(Vec); 312 PETSC_EXTERN PetscErrorCode VecSwap(Vec, Vec); 313 PETSC_EXTERN PetscErrorCode VecAXPY(Vec, PetscScalar, Vec); 314 PETSC_EXTERN PetscErrorCode VecAXPBY(Vec, PetscScalar, PetscScalar, Vec); 315 PETSC_EXTERN PetscErrorCode VecMAXPY(Vec, PetscInt, const PetscScalar[], Vec[]); 316 PETSC_EXTERN PetscErrorCode VecAYPX(Vec, PetscScalar, Vec); 317 PETSC_EXTERN PetscErrorCode VecWAXPY(Vec, PetscScalar, Vec, Vec); 318 PETSC_EXTERN PetscErrorCode VecAXPBYPCZ(Vec, PetscScalar, PetscScalar, PetscScalar, Vec, Vec); 319 PETSC_EXTERN PetscErrorCode VecPointwiseMax(Vec, Vec, Vec); 320 PETSC_EXTERN PetscErrorCode VecPointwiseMaxAbs(Vec, Vec, Vec); 321 PETSC_EXTERN PetscErrorCode VecPointwiseMin(Vec, Vec, Vec); 322 PETSC_EXTERN PetscErrorCode VecPointwiseMult(Vec, Vec, Vec); 323 PETSC_EXTERN PetscErrorCode VecPointwiseDivide(Vec, Vec, Vec); 324 PETSC_EXTERN PetscErrorCode VecMaxPointwiseDivide(Vec, Vec, PetscReal *); 325 PETSC_EXTERN PetscErrorCode VecShift(Vec, PetscScalar); 326 PETSC_EXTERN PetscErrorCode VecReciprocal(Vec); 327 PETSC_EXTERN PetscErrorCode VecPermute(Vec, IS, PetscBool); 328 PETSC_EXTERN PetscErrorCode VecSqrtAbs(Vec); 329 PETSC_EXTERN PetscErrorCode VecLog(Vec); 330 PETSC_EXTERN PetscErrorCode VecExp(Vec); 331 PETSC_EXTERN PetscErrorCode VecAbs(Vec); 332 PETSC_EXTERN PetscErrorCode VecDuplicate(Vec, Vec *); 333 PETSC_EXTERN PetscErrorCode VecDuplicateVecs(Vec, PetscInt, Vec *[]); 334 PETSC_EXTERN PetscErrorCode VecDestroyVecs(PetscInt, Vec *[]); 335 PETSC_EXTERN PetscErrorCode VecStrideNormAll(Vec, NormType, PetscReal[]); 336 PETSC_EXTERN PetscErrorCode VecStrideMaxAll(Vec, PetscInt[], PetscReal[]); 337 PETSC_EXTERN PetscErrorCode VecStrideMinAll(Vec, PetscInt[], PetscReal[]); 338 PETSC_EXTERN PetscErrorCode VecStrideScaleAll(Vec, const PetscScalar[]); 339 PETSC_EXTERN PetscErrorCode VecStrideSumAll(Vec, PetscScalar *); 340 PETSC_EXTERN PetscErrorCode VecUniqueEntries(Vec, PetscInt *, PetscScalar **); 341 342 PETSC_EXTERN PetscErrorCode VecStrideNorm(Vec, PetscInt, NormType, PetscReal *); 343 PETSC_EXTERN PetscErrorCode VecStrideMax(Vec, PetscInt, PetscInt *, PetscReal *); 344 PETSC_EXTERN PetscErrorCode VecStrideMin(Vec, PetscInt, PetscInt *, PetscReal *); 345 PETSC_EXTERN PetscErrorCode VecStrideScale(Vec, PetscInt, PetscScalar); 346 PETSC_EXTERN PetscErrorCode VecStrideSum(Vec, PetscInt, PetscScalar *); 347 PETSC_EXTERN PetscErrorCode VecStrideSet(Vec, PetscInt, PetscScalar); 348 349 PETSC_EXTERN PetscErrorCode VecStrideGather(Vec, PetscInt, Vec, InsertMode); 350 PETSC_EXTERN PetscErrorCode VecStrideScatter(Vec, PetscInt, Vec, InsertMode); 351 PETSC_EXTERN PetscErrorCode VecStrideGatherAll(Vec, Vec[], InsertMode); 352 PETSC_EXTERN PetscErrorCode VecStrideScatterAll(Vec[], Vec, InsertMode); 353 354 PETSC_EXTERN PetscErrorCode VecStrideSubSetScatter(Vec, PetscInt, const PetscInt[], const PetscInt[], Vec, InsertMode); 355 PETSC_EXTERN PetscErrorCode VecStrideSubSetGather(Vec, PetscInt, const PetscInt[], const PetscInt[], Vec, InsertMode); 356 357 PETSC_EXTERN PetscErrorCode VecSetValues(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 358 PETSC_EXTERN PetscErrorCode VecGetValues(Vec, PetscInt, const PetscInt[], PetscScalar[]); 359 PETSC_EXTERN PetscErrorCode VecAssemblyBegin(Vec); 360 PETSC_EXTERN PetscErrorCode VecAssemblyEnd(Vec); 361 PETSC_EXTERN PetscErrorCode VecStashSetInitialSize(Vec, PetscInt, PetscInt); 362 PETSC_EXTERN PetscErrorCode VecStashView(Vec, PetscViewer); 363 PETSC_EXTERN PetscErrorCode VecStashViewFromOptions(Vec, PetscObject, const char[]); 364 PETSC_EXTERN PetscErrorCode VecStashGetInfo(Vec, PetscInt *, PetscInt *, PetscInt *, PetscInt *); 365 366 PETSC_EXTERN PetscErrorCode VecSetPreallocationCOO(Vec, PetscCount, const PetscInt[]); 367 PETSC_EXTERN PetscErrorCode VecSetPreallocationCOOLocal(Vec, PetscCount, PetscInt[]); 368 PETSC_EXTERN PetscErrorCode VecSetValuesCOO(Vec, const PetscScalar[], InsertMode); 369 370 /*MC 371 VecSetValue - Set a single entry into a vector. 372 373 Synopsis: 374 #include <petscvec.h> 375 PetscErrorCode VecSetValue(Vec v,PetscInt row,PetscScalar value, InsertMode mode); 376 377 Not Collective 378 379 Input Parameters: 380 + v - the vector 381 . row - the row location of the entry 382 . value - the value to insert 383 - mode - either `INSERT_VALUES` or `ADD_VALUES` 384 385 Level: beginner 386 387 Notes: 388 For efficiency one should use `VecSetValues()` and set several or 389 many values simultaneously if possible. 390 391 These values may be cached, so `VecAssemblyBegin()` and `VecAssemblyEnd()` 392 MUST be called after all calls to `VecSetValue()` have been completed. 393 394 `VecSetValue()` uses 0-based indices in Fortran as well as in C. 395 396 .seealso: [](chapter_vectors), `VecSetValues()`, `VecAssemblyBegin()`, `VecAssemblyEnd()`, `VecSetValuesBlockedLocal()`, `VecSetValueLocal()` 397 M*/ 398 static inline PetscErrorCode VecSetValue(Vec v, PetscInt i, PetscScalar va, InsertMode mode) 399 { 400 return VecSetValues(v, 1, &i, &va, mode); 401 } 402 403 PETSC_EXTERN PetscErrorCode VecSetBlockSize(Vec, PetscInt); 404 PETSC_EXTERN PetscErrorCode VecGetBlockSize(Vec, PetscInt *); 405 PETSC_EXTERN PetscErrorCode VecSetValuesBlocked(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 406 407 /* Dynamic creation and loading functions */ 408 PETSC_EXTERN PetscFunctionList VecList; 409 PETSC_EXTERN PetscErrorCode VecSetType(Vec, VecType); 410 PETSC_EXTERN PetscErrorCode VecGetType(Vec, VecType *); 411 PETSC_EXTERN PetscErrorCode VecRegister(const char[], PetscErrorCode (*)(Vec)); 412 413 PETSC_EXTERN PetscErrorCode VecScatterBegin(VecScatter, Vec, Vec, InsertMode, ScatterMode); 414 PETSC_EXTERN PetscErrorCode VecScatterEnd(VecScatter, Vec, Vec, InsertMode, ScatterMode); 415 PETSC_EXTERN PetscErrorCode VecScatterDestroy(VecScatter *); 416 PETSC_EXTERN PetscErrorCode VecScatterSetUp(VecScatter); 417 PETSC_EXTERN PetscErrorCode VecScatterCopy(VecScatter, VecScatter *); 418 PETSC_EXTERN PetscErrorCode VecScatterView(VecScatter, PetscViewer); 419 PETSC_EXTERN PetscErrorCode VecScatterViewFromOptions(VecScatter, PetscObject, const char[]); 420 PETSC_EXTERN PetscErrorCode VecScatterRemap(VecScatter, PetscInt[], PetscInt[]); 421 PETSC_EXTERN PetscErrorCode VecScatterGetMerged(VecScatter, PetscBool *); 422 423 PETSC_EXTERN PetscErrorCode VecGetArray4d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]); 424 PETSC_EXTERN PetscErrorCode VecRestoreArray4d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]); 425 PETSC_EXTERN PetscErrorCode VecGetArray3d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]); 426 PETSC_EXTERN PetscErrorCode VecRestoreArray3d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]); 427 PETSC_EXTERN PetscErrorCode VecGetArray2d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]); 428 PETSC_EXTERN PetscErrorCode VecRestoreArray2d(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]); 429 PETSC_EXTERN PetscErrorCode VecGetArray1d(Vec, PetscInt, PetscInt, PetscScalar *[]); 430 PETSC_EXTERN PetscErrorCode VecRestoreArray1d(Vec, PetscInt, PetscInt, PetscScalar *[]); 431 432 PETSC_EXTERN PetscErrorCode VecGetArray4dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]); 433 PETSC_EXTERN PetscErrorCode VecGetArray4dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]); 434 PETSC_EXTERN PetscErrorCode VecRestoreArray4dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]); 435 PETSC_EXTERN PetscErrorCode VecGetArray3dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]); 436 PETSC_EXTERN PetscErrorCode VecRestoreArray3dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]); 437 PETSC_EXTERN PetscErrorCode VecGetArray2dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]); 438 PETSC_EXTERN PetscErrorCode VecRestoreArray2dWrite(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]); 439 PETSC_EXTERN PetscErrorCode VecGetArray1dWrite(Vec, PetscInt, PetscInt, PetscScalar *[]); 440 PETSC_EXTERN PetscErrorCode VecRestoreArray1dWrite(Vec, PetscInt, PetscInt, PetscScalar *[]); 441 442 PETSC_EXTERN PetscErrorCode VecGetArray4dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]); 443 PETSC_EXTERN PetscErrorCode VecRestoreArray4dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ****[]); 444 PETSC_EXTERN PetscErrorCode VecGetArray3dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]); 445 PETSC_EXTERN PetscErrorCode VecRestoreArray3dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar ***[]); 446 PETSC_EXTERN PetscErrorCode VecGetArray2dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]); 447 PETSC_EXTERN PetscErrorCode VecRestoreArray2dRead(Vec, PetscInt, PetscInt, PetscInt, PetscInt, PetscScalar **[]); 448 PETSC_EXTERN PetscErrorCode VecGetArray1dRead(Vec, PetscInt, PetscInt, PetscScalar *[]); 449 PETSC_EXTERN PetscErrorCode VecRestoreArray1dRead(Vec, PetscInt, PetscInt, PetscScalar *[]); 450 451 PETSC_EXTERN PetscErrorCode VecPlaceArray(Vec, const PetscScalar[]); 452 PETSC_EXTERN PetscErrorCode VecResetArray(Vec); 453 PETSC_EXTERN PetscErrorCode VecReplaceArray(Vec, const PetscScalar[]); 454 455 PETSC_EXTERN PetscErrorCode VecGetArrays(const Vec[], PetscInt, PetscScalar **[]); 456 PETSC_EXTERN PetscErrorCode VecRestoreArrays(const Vec[], PetscInt, PetscScalar **[]); 457 458 PETSC_EXTERN PetscErrorCode VecView(Vec, PetscViewer); 459 PETSC_EXTERN PetscErrorCode VecViewNative(Vec, PetscViewer); 460 PETSC_EXTERN PetscErrorCode VecEqual(Vec, Vec, PetscBool *); 461 PETSC_EXTERN PetscErrorCode VecLoad(Vec, PetscViewer); 462 463 PETSC_EXTERN PetscErrorCode VecGetSize(Vec, PetscInt *); 464 PETSC_EXTERN PetscErrorCode VecGetLocalSize(Vec, PetscInt *); 465 PETSC_EXTERN PetscErrorCode VecGetOwnershipRange(Vec, PetscInt *, PetscInt *); 466 PETSC_EXTERN PetscErrorCode VecGetOwnershipRanges(Vec, const PetscInt *[]); 467 468 PETSC_EXTERN PetscErrorCode VecSetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping); 469 PETSC_EXTERN PetscErrorCode VecSetValuesLocal(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 470 471 PETSC_EXTERN PetscErrorCode VecViennaCLGetCLContext(Vec, PETSC_UINTPTR_T *); 472 PETSC_EXTERN PetscErrorCode VecViennaCLGetCLQueue(Vec, PETSC_UINTPTR_T *); 473 PETSC_EXTERN PetscErrorCode VecViennaCLGetCLMemRead(Vec, PETSC_UINTPTR_T *); 474 PETSC_EXTERN PetscErrorCode VecViennaCLGetCLMemWrite(Vec, PETSC_UINTPTR_T *); 475 PETSC_EXTERN PetscErrorCode VecViennaCLRestoreCLMemWrite(Vec); 476 PETSC_EXTERN PetscErrorCode VecViennaCLGetCLMem(Vec, PETSC_UINTPTR_T *); 477 PETSC_EXTERN PetscErrorCode VecViennaCLRestoreCLMem(Vec); 478 479 /*MC 480 VecSetValueLocal - Set a single entry into a vector using the local numbering, see `VecSetValuesLocal()` 481 482 Synopsis: 483 #include <petscvec.h> 484 PetscErrorCode VecSetValueLocal(Vec v,PetscInt row,PetscScalar value, InsertMode mode); 485 486 Not Collective 487 488 Input Parameters: 489 + v - the vector 490 . row - the row location of the entry 491 . value - the value to insert 492 - mode - either `INSERT_VALUES` or `ADD_VALUES` 493 494 Level: beginner 495 496 Notes: 497 For efficiency one should use `VecSetValuesLocal()` and set several or 498 many values simultaneously if possible. 499 500 These values may be cached, so `VecAssemblyBegin()` and `VecAssemblyEnd()` 501 MUST be called after all calls to `VecSetValueLocal()` have been completed. 502 503 `VecSetValues()` uses 0-based indices in Fortran as well as in C. 504 505 .seealso: [](chapter_vectors), `VecSetValuesLocal()`, `VecSetValues()`, `VecAssemblyBegin()`, `VecAssemblyEnd()`, `VecSetValuesBlockedLocal()`, `VecSetValue()` 506 M*/ 507 static inline PetscErrorCode VecSetValueLocal(Vec v, PetscInt i, PetscScalar va, InsertMode mode) 508 { 509 return VecSetValuesLocal(v, 1, &i, &va, mode); 510 } 511 512 /*MC 513 VecCheckAssembled - checks if values have been changed in the vector, by `VecSetValues()` or related routines, but it has not been assembled 514 515 Synopsis: 516 #include <petscvec.h> 517 VecCheckAssembled(Vec v); 518 519 Not Collective 520 521 Input Parameter: 522 . v - the vector to check 523 524 Level: developer 525 526 Note: 527 After calls to `VecSetValues()` and related routines on must call ``VecAssemblyBegin()` and `VecAssemblyEnd()` before using the vector 528 529 .seealso: [](chapter_vectors), `Vec`, `VecSetValues()`, `VecAssemblyBegin()`, `VecAssemblyEnd()`, `MatAssemblyBegin()`, `MatAssemblyEnd()` 530 M*/ 531 #define VecCheckAssembled(v) PetscCheck(v->stash.insertmode == NOT_SET_VALUES, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Not for unassembled vector, did you call VecAssemblyBegin()/VecAssemblyEnd()?"); 532 533 PETSC_EXTERN PetscErrorCode VecSetValuesBlockedLocal(Vec, PetscInt, const PetscInt[], const PetscScalar[], InsertMode); 534 PETSC_EXTERN PetscErrorCode VecGetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping *); 535 536 PETSC_EXTERN PetscErrorCode VecDotBegin(Vec, Vec, PetscScalar *); 537 PETSC_EXTERN PetscErrorCode VecDotEnd(Vec, Vec, PetscScalar *); 538 PETSC_EXTERN PetscErrorCode VecTDotBegin(Vec, Vec, PetscScalar *); 539 PETSC_EXTERN PetscErrorCode VecTDotEnd(Vec, Vec, PetscScalar *); 540 PETSC_EXTERN PetscErrorCode VecNormBegin(Vec, NormType, PetscReal *); 541 PETSC_EXTERN PetscErrorCode VecNormEnd(Vec, NormType, PetscReal *); 542 543 PETSC_EXTERN PetscErrorCode VecMDotBegin(Vec, PetscInt, const Vec[], PetscScalar[]); 544 PETSC_EXTERN PetscErrorCode VecMDotEnd(Vec, PetscInt, const Vec[], PetscScalar[]); 545 PETSC_EXTERN PetscErrorCode VecMTDotBegin(Vec, PetscInt, const Vec[], PetscScalar[]); 546 PETSC_EXTERN PetscErrorCode VecMTDotEnd(Vec, PetscInt, const Vec[], PetscScalar[]); 547 PETSC_EXTERN PetscErrorCode PetscCommSplitReductionBegin(MPI_Comm); 548 549 PETSC_EXTERN PetscErrorCode VecBindToCPU(Vec, PetscBool); 550 PETSC_DEPRECATED_FUNCTION("Use VecBindToCPU (since v3.13)") static inline PetscErrorCode VecPinToCPU(Vec v, PetscBool flg) 551 { 552 return VecBindToCPU(v, flg); 553 } 554 PETSC_EXTERN PetscErrorCode VecBoundToCPU(Vec, PetscBool *); 555 PETSC_EXTERN PetscErrorCode VecSetBindingPropagates(Vec, PetscBool); 556 PETSC_EXTERN PetscErrorCode VecGetBindingPropagates(Vec, PetscBool *); 557 PETSC_EXTERN PetscErrorCode VecSetPinnedMemoryMin(Vec, size_t); 558 PETSC_EXTERN PetscErrorCode VecGetPinnedMemoryMin(Vec, size_t *); 559 560 PETSC_EXTERN PetscErrorCode VecGetOffloadMask(Vec, PetscOffloadMask *); 561 562 typedef enum { 563 VEC_IGNORE_OFF_PROC_ENTRIES, 564 VEC_IGNORE_NEGATIVE_INDICES, 565 VEC_SUBSET_OFF_PROC_ENTRIES 566 } VecOption; 567 PETSC_EXTERN PetscErrorCode VecSetOption(Vec, VecOption, PetscBool); 568 569 PETSC_EXTERN PetscErrorCode VecGetArray(Vec, PetscScalar **); 570 PETSC_EXTERN PetscErrorCode VecGetArrayWrite(Vec, PetscScalar **); 571 PETSC_EXTERN PetscErrorCode VecGetArrayRead(Vec, const PetscScalar **); 572 PETSC_EXTERN PetscErrorCode VecRestoreArray(Vec, PetscScalar **); 573 PETSC_EXTERN PetscErrorCode VecRestoreArrayWrite(Vec, PetscScalar **); 574 PETSC_EXTERN PetscErrorCode VecRestoreArrayRead(Vec, const PetscScalar **); 575 PETSC_EXTERN PetscErrorCode VecCreateLocalVector(Vec, Vec *); 576 PETSC_EXTERN PetscErrorCode VecGetLocalVector(Vec, Vec); 577 PETSC_EXTERN PetscErrorCode VecRestoreLocalVector(Vec, Vec); 578 PETSC_EXTERN PetscErrorCode VecGetLocalVectorRead(Vec, Vec); 579 PETSC_EXTERN PetscErrorCode VecRestoreLocalVectorRead(Vec, Vec); 580 PETSC_EXTERN PetscErrorCode VecGetArrayAndMemType(Vec, PetscScalar **, PetscMemType *); 581 PETSC_EXTERN PetscErrorCode VecRestoreArrayAndMemType(Vec, PetscScalar **); 582 PETSC_EXTERN PetscErrorCode VecGetArrayReadAndMemType(Vec, const PetscScalar **, PetscMemType *); 583 PETSC_EXTERN PetscErrorCode VecRestoreArrayReadAndMemType(Vec, const PetscScalar **); 584 PETSC_EXTERN PetscErrorCode VecGetArrayWriteAndMemType(Vec, PetscScalar **, PetscMemType *); 585 PETSC_EXTERN PetscErrorCode VecRestoreArrayWriteAndMemType(Vec, PetscScalar **); 586 587 /*@C 588 VecGetArrayPair - Accesses a pair of pointers for two vectors that may be common. When not common the first pointer is read only 589 590 Logically Collective; No Fortran Support 591 592 Input Parameters: 593 + x - the vector 594 - y - the second vector 595 596 Output Parameters: 597 + xv - location to put pointer to the first array 598 - yv - location to put pointer to the second array 599 600 Level: developer 601 602 .seealso: [](chapter_vectors), `VecGetArray()`, `VecGetArrayRead()`, `VecRestoreArrayPair()` 603 @*/ 604 static inline PetscErrorCode VecGetArrayPair(Vec x, Vec y, PetscScalar **xv, PetscScalar **yv) 605 { 606 PetscFunctionBegin; 607 PetscCall(VecGetArray(y, yv)); 608 if (x == y) *xv = *yv; 609 else PetscCall(VecGetArrayRead(x, (const PetscScalar **)xv)); 610 PetscFunctionReturn(PETSC_SUCCESS); 611 } 612 613 /*@C 614 VecRestoreArrayPair - Returns a pair of pointers for two vectors that may be common obtained with `VecGetArrayPair()` 615 616 Logically Collective; No Fortran Support 617 618 Input Parameters: 619 + x - the vector 620 . y - the second vector 621 . xv - location to put pointer to the first array 622 - yv - location to put pointer to the second array 623 624 Level: developer 625 626 .seealso: [](chapter_vectors), `VecGetArray()`, `VecGetArrayRead()`, `VecGetArrayPair()` 627 @*/ 628 static inline PetscErrorCode VecRestoreArrayPair(Vec x, Vec y, PetscScalar **xv, PetscScalar **yv) 629 { 630 PetscFunctionBegin; 631 PetscCall(VecRestoreArray(y, yv)); 632 if (x != y) PetscCall(VecRestoreArrayRead(x, (const PetscScalar **)xv)); 633 PetscFunctionReturn(PETSC_SUCCESS); 634 } 635 636 #if defined(PETSC_USE_DEBUG) 637 PETSC_EXTERN PetscErrorCode VecLockReadPush(Vec); 638 PETSC_EXTERN PetscErrorCode VecLockReadPop(Vec); 639 PETSC_EXTERN PetscErrorCode VecLockWriteSet(Vec, PetscBool); 640 PETSC_EXTERN PetscErrorCode VecLockGet(Vec, PetscInt *); 641 PETSC_EXTERN PetscErrorCode VecLockGetLocation(Vec, const char *[], const char *[], int *); 642 static inline PetscErrorCode VecSetErrorIfLocked(Vec x, PetscInt arg) 643 { 644 PetscInt state; 645 646 PetscFunctionBegin; 647 PetscCall(VecLockGet(x, &state)); 648 if (PetscUnlikely(state != 0)) { 649 const char *file, *func, *name; 650 int line; 651 652 PetscCall(VecLockGetLocation(x, &file, &func, &line)); 653 PetscCall(PetscObjectGetName((PetscObject)x, &name)); 654 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Vector '%s' (argument #%" PetscInt_FMT ") was locked for %s access in %s() at %s:%d (line numbers only accurate to function begin)", name, arg, state > 0 ? "read-only" : "write-only", func ? func : "unknown_function", file ? file : "unknown file", line); 655 } 656 PetscFunctionReturn(PETSC_SUCCESS); 657 } 658 /* The three are deprecated */ 659 PETSC_EXTERN PETSC_DEPRECATED_FUNCTION("Use VecLockReadPush() (since version 3.11)") PetscErrorCode VecLockPush(Vec); 660 PETSC_EXTERN PETSC_DEPRECATED_FUNCTION("Use VecLockReadPop() (since version 3.11)") PetscErrorCode VecLockPop(Vec); 661 #define VecLocked(x, arg) VecSetErrorIfLocked(x, arg) PETSC_DEPRECATED_MACRO("GCC warning \"Use VecSetErrorIfLocked() (since version 3.11)\"") 662 #else 663 #define VecLockReadPush(x) PETSC_SUCCESS 664 #define VecLockReadPop(x) PETSC_SUCCESS 665 #define VecLockGet(x, s) (*(s) = 0, PETSC_SUCCESS) 666 #define VecSetErrorIfLocked(x, arg) PETSC_SUCCESS 667 #define VecLockWriteSet(x, flg) PETSC_SUCCESS 668 /* The three are deprecated */ 669 #define VecLockPush(x) PETSC_SUCCESS 670 #define VecLockPop(x) PETSC_SUCCESS 671 #define VecLocked(x, arg) PETSC_SUCCESS 672 #endif 673 674 /*E 675 VecOperation - Enumeration of overide-able methods in the `Vec` implementation function-table. 676 677 Values: 678 + `VECOP_DUPLICATE` - `VecDuplicate()` 679 . `VECOP_SET` - `VecSet()` 680 . `VECOP_VIEW` - `VecView()` 681 . `VECOP_LOAD` - `VecLoad()` 682 . `VECOP_VIEWNATIVE` - `VecViewNative()` 683 - `VECOP_LOADNATIVE` - `VecLoadNative()` 684 685 Level: advanced 686 687 Notes: 688 Some operations may serve as the implementation for other routines not listed above. For 689 example `VECOP_SET` can be used to simultaneously overriding the implementation used in 690 `VecSet()`, `VecSetInf()`, and `VecZeroEntries()`. 691 692 Entries to `VecOperation` are added as needed so if you do not see the operation listed which 693 you'd like to replace, please send mail to `petsc-maint@mcs.anl.gov`! 694 695 .seealso: [](chapter_vectors), `Vec`, `VecSetOperation()` 696 E*/ 697 typedef enum { 698 VECOP_DUPLICATE = 0, 699 VECOP_SET = 10, 700 VECOP_VIEW = 33, 701 VECOP_LOAD = 41, 702 VECOP_VIEWNATIVE = 68, 703 VECOP_LOADNATIVE = 69 704 } VecOperation; 705 PETSC_EXTERN PetscErrorCode VecSetOperation(Vec, VecOperation, void (*)(void)); 706 707 /* 708 Routines for dealing with ghosted vectors: 709 vectors with ghost elements at the end of the array. 710 */ 711 PETSC_EXTERN PetscErrorCode VecMPISetGhost(Vec, PetscInt, const PetscInt[]); 712 PETSC_EXTERN PetscErrorCode VecCreateGhost(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], Vec *); 713 PETSC_EXTERN PetscErrorCode VecCreateGhostWithArray(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscScalar[], Vec *); 714 PETSC_EXTERN PetscErrorCode VecCreateGhostBlock(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], Vec *); 715 PETSC_EXTERN PetscErrorCode VecCreateGhostBlockWithArray(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscInt, const PetscInt[], const PetscScalar[], Vec *); 716 PETSC_EXTERN PetscErrorCode VecGhostGetLocalForm(Vec, Vec *); 717 PETSC_EXTERN PetscErrorCode VecGhostRestoreLocalForm(Vec, Vec *); 718 PETSC_EXTERN PetscErrorCode VecGhostIsLocalForm(Vec, Vec, PetscBool *); 719 PETSC_EXTERN PetscErrorCode VecGhostUpdateBegin(Vec, InsertMode, ScatterMode); 720 PETSC_EXTERN PetscErrorCode VecGhostUpdateEnd(Vec, InsertMode, ScatterMode); 721 722 PETSC_EXTERN PetscErrorCode VecConjugate(Vec); 723 PETSC_EXTERN PetscErrorCode VecImaginaryPart(Vec); 724 PETSC_EXTERN PetscErrorCode VecRealPart(Vec); 725 726 PETSC_EXTERN PetscErrorCode VecScatterCreateToAll(Vec, VecScatter *, Vec *); 727 PETSC_EXTERN PetscErrorCode VecScatterCreateToZero(Vec, VecScatter *, Vec *); 728 729 PETSC_EXTERN PetscErrorCode ISComplementVec(IS, Vec, IS *); 730 PETSC_EXTERN PetscErrorCode VecPow(Vec, PetscScalar); 731 PETSC_EXTERN PetscErrorCode VecMedian(Vec, Vec, Vec, Vec); 732 PETSC_EXTERN PetscErrorCode VecWhichInactive(Vec, Vec, Vec, Vec, PetscBool, IS *); 733 PETSC_EXTERN PetscErrorCode VecWhichBetween(Vec, Vec, Vec, IS *); 734 PETSC_EXTERN PetscErrorCode VecWhichBetweenOrEqual(Vec, Vec, Vec, IS *); 735 PETSC_EXTERN PetscErrorCode VecWhichGreaterThan(Vec, Vec, IS *); 736 PETSC_EXTERN PetscErrorCode VecWhichLessThan(Vec, Vec, IS *); 737 PETSC_EXTERN PetscErrorCode VecWhichEqual(Vec, Vec, IS *); 738 PETSC_EXTERN PetscErrorCode VecISAXPY(Vec, IS, PetscScalar, Vec); 739 PETSC_EXTERN PetscErrorCode VecISCopy(Vec, IS, ScatterMode, Vec); 740 PETSC_EXTERN PetscErrorCode VecISSet(Vec, IS, PetscScalar); 741 PETSC_EXTERN PetscErrorCode VecBoundGradientProjection(Vec, Vec, Vec, Vec, Vec); 742 PETSC_EXTERN PetscErrorCode VecStepBoundInfo(Vec, Vec, Vec, Vec, PetscReal *, PetscReal *, PetscReal *); 743 PETSC_EXTERN PetscErrorCode VecStepMax(Vec, Vec, PetscReal *); 744 PETSC_EXTERN PetscErrorCode VecStepMaxBounded(Vec, Vec, Vec, Vec, PetscReal *); 745 746 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaGetVector(PetscViewer, Vec); 747 PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutVector(PetscViewer, Vec); 748 749 /*S 750 Vecs - Collection of vectors where the data for the vectors is stored in 751 one contiguous memory 752 753 Level: advanced 754 755 Notes: 756 Temporary construct for handling multiply right hand side solves 757 758 This is faked by storing a single vector that has enough array space for 759 n vectors 760 761 S*/ 762 struct _n_Vecs { 763 PetscInt n; 764 Vec v; 765 }; 766 typedef struct _n_Vecs *Vecs; 767 PETSC_EXTERN PetscErrorCode VecsDestroy(Vecs); 768 PETSC_EXTERN PetscErrorCode VecsCreateSeq(MPI_Comm, PetscInt, PetscInt, Vecs *); 769 PETSC_EXTERN PetscErrorCode VecsCreateSeqWithArray(MPI_Comm, PetscInt, PetscInt, PetscScalar *, Vecs *); 770 PETSC_EXTERN PetscErrorCode VecsDuplicate(Vecs, Vecs *); 771 772 #if defined(PETSC_HAVE_VIENNACL) 773 typedef struct _p_PetscViennaCLIndices *PetscViennaCLIndices; 774 PETSC_EXTERN PetscErrorCode PetscViennaCLIndicesCreate(PetscInt, PetscInt *, PetscInt, PetscInt *, PetscViennaCLIndices *); 775 PETSC_EXTERN PetscErrorCode PetscViennaCLIndicesDestroy(PetscViennaCLIndices *); 776 PETSC_EXTERN PetscErrorCode VecViennaCLCopyToGPUSome_Public(Vec, PetscViennaCLIndices); 777 PETSC_EXTERN PetscErrorCode VecViennaCLCopyFromGPUSome_Public(Vec, PetscViennaCLIndices); 778 PETSC_EXTERN PetscErrorCode VecCreateSeqViennaCL(MPI_Comm, PetscInt, Vec *); 779 PETSC_EXTERN PetscErrorCode VecCreateMPIViennaCL(MPI_Comm, PetscInt, PetscInt, Vec *); 780 #endif 781 #if defined(PETSC_HAVE_CUDA) || defined(PETSC_HAVE_HIP) 782 PETSC_EXTERN PetscErrorCode VecScatterInitializeForGPU(VecScatter, Vec); 783 PETSC_EXTERN PetscErrorCode VecScatterFinalizeForGPU(VecScatter); 784 #endif 785 #if defined(PETSC_HAVE_KOKKOS_KERNELS) 786 PETSC_EXTERN PetscErrorCode VecCreateSeqKokkos(MPI_Comm, PetscInt, Vec *); 787 PETSC_EXTERN PetscErrorCode VecCreateSeqKokkosWithArray(MPI_Comm, PetscInt, PetscInt, const PetscScalar *, Vec *); 788 PETSC_EXTERN PetscErrorCode VecCreateMPIKokkos(MPI_Comm, PetscInt, PetscInt, Vec *); 789 PETSC_EXTERN PetscErrorCode VecCreateMPIKokkosWithArray(MPI_Comm, PetscInt, PetscInt, PetscInt, const PetscScalar *, Vec *); 790 #endif 791 792 PETSC_EXTERN PetscErrorCode VecNestGetSubVecs(Vec, PetscInt *, Vec **); 793 PETSC_EXTERN PetscErrorCode VecNestGetSubVec(Vec, PetscInt, Vec *); 794 PETSC_EXTERN PetscErrorCode VecNestSetSubVecs(Vec, PetscInt, PetscInt *, Vec *); 795 PETSC_EXTERN PetscErrorCode VecNestSetSubVec(Vec, PetscInt, Vec); 796 PETSC_EXTERN PetscErrorCode VecCreateNest(MPI_Comm, PetscInt, IS *, Vec *, Vec *); 797 PETSC_EXTERN PetscErrorCode VecNestGetSize(Vec, PetscInt *); 798 799 PETSC_EXTERN PetscErrorCode PetscOptionsGetVec(PetscOptions, const char[], const char[], Vec, PetscBool *); 800 PETSC_EXTERN PetscErrorCode VecChop(Vec, PetscReal); 801 802 PETSC_EXTERN PetscErrorCode VecGetLayout(Vec, PetscLayout *); 803 PETSC_EXTERN PetscErrorCode VecSetLayout(Vec, PetscLayout); 804 805 PETSC_EXTERN PetscErrorCode PetscSectionVecView(PetscSection, Vec, PetscViewer); 806 PETSC_EXTERN PetscErrorCode VecGetValuesSection(Vec, PetscSection, PetscInt, PetscScalar **); 807 PETSC_EXTERN PetscErrorCode VecSetValuesSection(Vec, PetscSection, PetscInt, PetscScalar[], InsertMode); 808 PETSC_EXTERN PetscErrorCode PetscSectionVecNorm(PetscSection, PetscSection, Vec, NormType, PetscReal[]); 809 810 /*S 811 VecTagger - Object used to manage the tagging of a subset of indices based on the values of a vector. The 812 motivating application is the selection of cells for refinement or coarsening based on vector containing 813 the values in an error indicator metric. 814 815 Level: advanced 816 817 Values: 818 + `VECTAGGERABSOLUTE` - "absolute" values are in a box of explicitly defined values 819 . `VECTAGGERRELATIVE` - "relative" values are in a box of values relative to the set of all values in the vector 820 . `VECTAGGERCDF` - "cdf" values are in a relative range of the *cumulative distribution* of values in the vector 821 . `VECTAGGEROR` - "or" values are in the union of other tags 822 - `VECTAGGERAND` - "and" values are in the intersection of other tags 823 824 Developer Note: 825 Why not use a `DMLabel` or similar object 826 827 .seealso: [](chapter_vectors), `Vec`, `VecTaggerType`, `VecTaggerCreate()` 828 S*/ 829 typedef struct _p_VecTagger *VecTagger; 830 831 /*J 832 VecTaggerType - String with the name of a `VecTagger` type 833 834 Level: advanced 835 836 .seealso: [](chapter_vectors), `Vec`, `VecTagger`, `VecTaggerCreate()` 837 J*/ 838 typedef const char *VecTaggerType; 839 #define VECTAGGERABSOLUTE "absolute" 840 #define VECTAGGERRELATIVE "relative" 841 #define VECTAGGERCDF "cdf" 842 #define VECTAGGEROR "or" 843 #define VECTAGGERAND "and" 844 845 PETSC_EXTERN PetscClassId VEC_TAGGER_CLASSID; 846 PETSC_EXTERN PetscFunctionList VecTaggerList; 847 PETSC_EXTERN PetscErrorCode VecTaggerRegister(const char[], PetscErrorCode (*)(VecTagger)); 848 849 PETSC_EXTERN PetscErrorCode VecTaggerCreate(MPI_Comm, VecTagger *); 850 PETSC_EXTERN PetscErrorCode VecTaggerSetBlockSize(VecTagger, PetscInt); 851 PETSC_EXTERN PetscErrorCode VecTaggerGetBlockSize(VecTagger, PetscInt *); 852 PETSC_EXTERN PetscErrorCode VecTaggerSetType(VecTagger, VecTaggerType); 853 PETSC_EXTERN PetscErrorCode VecTaggerGetType(VecTagger, VecTaggerType *); 854 PETSC_EXTERN PetscErrorCode VecTaggerSetInvert(VecTagger, PetscBool); 855 PETSC_EXTERN PetscErrorCode VecTaggerGetInvert(VecTagger, PetscBool *); 856 PETSC_EXTERN PetscErrorCode VecTaggerSetFromOptions(VecTagger); 857 PETSC_EXTERN PetscErrorCode VecTaggerSetUp(VecTagger); 858 PETSC_EXTERN PetscErrorCode VecTaggerView(VecTagger, PetscViewer); 859 PETSC_EXTERN PetscErrorCode VecTaggerComputeIS(VecTagger, Vec, IS *, PetscBool *); 860 PETSC_EXTERN PetscErrorCode VecTaggerDestroy(VecTagger *); 861 862 /*S 863 VecTaggerBox - A box range used to tag values. For real scalars, this is just a closed interval; for complex scalars, the box is the closed region in the complex plane 864 such that real(min) <= real(z) <= real(max) and imag(min) <= imag(z) <= imag(max). `INF` is an acceptable endpoint. 865 866 Level: beginner 867 868 .seealso: [](chapter_vectors), `Vec`, `VecTagger`, `VecTaggerType`, `VecTaggerCreate()`, `VecTaggerComputeIntervals()` 869 S*/ 870 typedef struct { 871 PetscScalar min; 872 PetscScalar max; 873 } VecTaggerBox; 874 PETSC_EXTERN PetscErrorCode VecTaggerComputeBoxes(VecTagger, Vec, PetscInt *, VecTaggerBox **, PetscBool *); 875 876 PETSC_EXTERN PetscErrorCode VecTaggerAbsoluteSetBox(VecTagger, VecTaggerBox *); 877 PETSC_EXTERN PetscErrorCode VecTaggerAbsoluteGetBox(VecTagger, const VecTaggerBox **); 878 879 PETSC_EXTERN PetscErrorCode VecTaggerRelativeSetBox(VecTagger, VecTaggerBox *); 880 PETSC_EXTERN PetscErrorCode VecTaggerRelativeGetBox(VecTagger, const VecTaggerBox **); 881 882 PETSC_EXTERN PetscErrorCode VecTaggerCDFSetBox(VecTagger, VecTaggerBox *); 883 PETSC_EXTERN PetscErrorCode VecTaggerCDFGetBox(VecTagger, const VecTaggerBox **); 884 885 /*E 886 VecTaggerCDFMethod - Determines what method is used to compute absolute values from cumulative distribution values (e.g., what value is the preimage of .95 in the cdf). 887 888 Level: advanced 889 890 Values: 891 + `VECTAGGER_CDF_GATHER` - gather results to rank 0, perform the computation and broadcast the result 892 - `VECTAGGER_CDF_ITERATIVE` - compute the results on all ranks iteratively using `MPI_Allreduce()` 893 894 Note: 895 Relevant only in parallel: in serial it is directly computed. 896 897 .seealso: [](chapter_vectors), `Vec`, `VecTagger`, `VecTaggerType`, `VecTaggerCreate()`, `VecTaggerCDFSetMethod()`, `VecTaggerCDFMethods` 898 E*/ 899 typedef enum { 900 VECTAGGER_CDF_GATHER, 901 VECTAGGER_CDF_ITERATIVE, 902 VECTAGGER_CDF_NUM_METHODS 903 } VecTaggerCDFMethod; 904 PETSC_EXTERN const char *const VecTaggerCDFMethods[]; 905 906 PETSC_EXTERN PetscErrorCode VecTaggerCDFSetMethod(VecTagger, VecTaggerCDFMethod); 907 PETSC_EXTERN PetscErrorCode VecTaggerCDFGetMethod(VecTagger, VecTaggerCDFMethod *); 908 PETSC_EXTERN PetscErrorCode VecTaggerCDFIterativeSetTolerances(VecTagger, PetscInt, PetscReal, PetscReal); 909 PETSC_EXTERN PetscErrorCode VecTaggerCDFIterativeGetTolerances(VecTagger, PetscInt *, PetscReal *, PetscReal *); 910 911 PETSC_EXTERN PetscErrorCode VecTaggerOrSetSubs(VecTagger, PetscInt, VecTagger *, PetscCopyMode); 912 PETSC_EXTERN PetscErrorCode VecTaggerOrGetSubs(VecTagger, PetscInt *, VecTagger **); 913 914 PETSC_EXTERN PetscErrorCode VecTaggerAndSetSubs(VecTagger, PetscInt, VecTagger *, PetscCopyMode); 915 PETSC_EXTERN PetscErrorCode VecTaggerAndGetSubs(VecTagger, PetscInt *, VecTagger **); 916 917 PETSC_EXTERN PetscErrorCode VecTaggerInitializePackage(void); 918 PETSC_EXTERN PetscErrorCode VecTaggerFinalizePackage(void); 919 920 #if PetscDefined(USE_DEBUG) 921 /* This is an internal debug-only routine that should not be used by users */ 922 PETSC_SINGLE_LIBRARY_INTERN PetscErrorCode VecValidValues_Internal(Vec, PetscInt, PetscBool); 923 #else 924 #define VecValidValues_Internal(...) PETSC_SUCCESS 925 #endif /* PETSC_USE_DEBUG */ 926 927 #define VEC_CUPM_NOT_CONFIGURED(impl) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP_SYS, "Must configure PETSc with " PetscStringize(impl) " support to use %s", PETSC_FUNCTION_NAME) 928 929 #if PetscDefined(HAVE_CUDA) 930 #define VEC_CUDA_DECL_OR_STUB(__decl__, ...) PETSC_EXTERN __decl__; 931 #else 932 #define VEC_CUDA_DECL_OR_STUB(__decl__, ...) \ 933 static inline __decl__ \ 934 { \ 935 __VA_ARGS__; \ 936 VEC_CUPM_NOT_CONFIGURED(cuda); \ 937 } 938 #endif /* PETSC_HAVE_CUDA */ 939 940 /* extra underscore here to make it line up with the cuda versions */ 941 #if PetscDefined(HAVE_HIP) 942 #define VEC_HIP__DECL_OR_STUB(__decl__, ...) PETSC_EXTERN __decl__; 943 #else 944 #define VEC_HIP__DECL_OR_STUB(__decl__, ...) \ 945 static inline __decl__ \ 946 { \ 947 __VA_ARGS__; \ 948 VEC_CUPM_NOT_CONFIGURED(hip); \ 949 } 950 #endif /* PETSC_HAVE_HIP */ 951 952 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateSeqCUDA(MPI_Comm a, PetscInt b, Vec *c), (void)a, (void)b, (void)c) 953 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateSeqHIP(MPI_Comm a, PetscInt b, Vec *c), (void)a, (void)b, (void)c) 954 955 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateSeqCUDAWithArray(MPI_Comm a, PetscInt b, PetscInt c, const PetscScalar *d, Vec *e), (void)a, (void)b, (void)c, (void)d, (void)e) 956 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateSeqHIPWithArray(MPI_Comm a, PetscInt b, PetscInt c, const PetscScalar *d, Vec *e), (void)a, (void)b, (void)c, (void)d, (void)e) 957 958 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateSeqCUDAWithArrays(MPI_Comm a, PetscInt b, PetscInt c, const PetscScalar *d, const PetscScalar *e, Vec *f), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f) 959 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateSeqHIPWithArrays(MPI_Comm a, PetscInt b, PetscInt c, const PetscScalar *d, const PetscScalar *e, Vec *f), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f) 960 961 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateMPICUDA(MPI_Comm a, PetscInt b, PetscInt c, Vec *d), (void)a, (void)b, (void)c, (void)d) 962 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateMPIHIP(MPI_Comm a, PetscInt b, PetscInt c, Vec *d), (void)a, (void)b, (void)c, (void)d) 963 964 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateMPICUDAWithArray(MPI_Comm a, PetscInt b, PetscInt c, PetscInt d, const PetscScalar *e, Vec *f), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f) 965 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateMPIHIPWithArray(MPI_Comm a, PetscInt b, PetscInt c, PetscInt d, const PetscScalar *e, Vec *f), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f) 966 967 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCreateMPICUDAWithArrays(MPI_Comm a, PetscInt b, PetscInt c, PetscInt d, const PetscScalar *e, const PetscScalar *f, Vec *g), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f, (void)g) 968 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecCreateMPIHIPWithArrays(MPI_Comm a, PetscInt b, PetscInt c, PetscInt d, const PetscScalar *e, const PetscScalar *f, Vec *g), (void)a, (void)b, (void)c, (void)d, (void)e, (void)f, (void)g) 969 970 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAGetArray(Vec a, PetscScalar **b), (void)a, (void)b) 971 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPGetArray(Vec a, PetscScalar **b), (void)a, (void)b) 972 973 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDARestoreArray(Vec a, PetscScalar **b), (void)a, (void)b) 974 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPRestoreArray(Vec a, PetscScalar **b), (void)a, (void)b) 975 976 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAGetArrayRead(Vec a, const PetscScalar **b), (void)a, (void)b) 977 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPGetArrayRead(Vec a, const PetscScalar **b), (void)a, (void)b) 978 979 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDARestoreArrayRead(Vec a, const PetscScalar **b), (void)a, (void)b) 980 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPRestoreArrayRead(Vec a, const PetscScalar **b), (void)a, (void)b) 981 982 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAGetArrayWrite(Vec a, PetscScalar **b), (void)a, (void)b) 983 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPGetArrayWrite(Vec a, PetscScalar **b), (void)a, (void)b) 984 985 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDARestoreArrayWrite(Vec a, PetscScalar **b), (void)a, (void)b) 986 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPRestoreArrayWrite(Vec a, PetscScalar **b), (void)a, (void)b) 987 988 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAPlaceArray(Vec a, const PetscScalar b[]), (void)a, (void)b) 989 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPPlaceArray(Vec a, const PetscScalar b[]), (void)a, (void)b) 990 991 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAReplaceArray(Vec a, const PetscScalar b[]), (void)a, (void)b) 992 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPReplaceArray(Vec a, const PetscScalar b[]), (void)a, (void)b) 993 994 VEC_CUDA_DECL_OR_STUB(PetscErrorCode VecCUDAResetArray(Vec a), (void)a) 995 VEC_HIP__DECL_OR_STUB(PetscErrorCode VecHIPResetArray(Vec a), (void)a) 996 997 #undef VEC_CUPM_NOT_CONFIGURED 998 #undef VEC_CUDA_DECL_OR_STUB 999 #undef VEC_HIP__DECL_OR_STUB 1000 1001 #endif 1002