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