Actual source code: petscvec.h
petsc-3.8.4 2018-03-24
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: */
7: #ifndef __PETSCVEC_H
9: #include <petscis.h>
10: #include <petscviewer.h>
12: /*S
13: Vec - Abstract PETSc vector object
15: Level: beginner
17: Concepts: field variables, unknowns, arrays
19: .seealso: VecCreate(), VecType, VecSetType()
20: S*/
21: typedef struct _p_Vec* Vec;
23: /*S
24: VecScatter - Object used to manage communication of data
25: between vectors in parallel. Manages both scatters and gathers
27: Level: beginner
29: Concepts: scatter
31: .seealso: VecScatterCreate(), VecScatterBegin(), VecScatterEnd()
32: S*/
33: typedef struct _p_VecScatter* VecScatter;
35: /*E
36: ScatterMode - Determines the direction of a scatter
38: Level: beginner
40: .seealso: VecScatter, VecScatterBegin(), VecScatterEnd()
41: E*/
42: typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode;
44: /*MC
45: SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call
47: Level: beginner
49: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL,
50: SCATTER_REVERSE_LOCAL
52: M*/
54: /*MC
55: SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in
56: in the VecScatterCreate()
58: Level: beginner
60: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
61: SCATTER_REVERSE_LOCAL
63: M*/
65: /*MC
66: SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication
67: is done. Any variables that have be moved between processes are ignored
69: Level: developer
71: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD,
72: SCATTER_REVERSE_LOCAL
74: M*/
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
81: Level: developer
83: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
84: SCATTER_REVERSE
86: M*/
88: /*J
89: VecType - String with the name of a PETSc vector
91: Level: beginner
93: .seealso: VecSetType(), Vec, VecCreate(), VecDestroy()
94: J*/
95: typedef const char* VecType;
96: #define VECSEQ "seq"
97: #define VECMPI "mpi"
98: #define VECSTANDARD "standard" /* seq on one process and mpi on several */
99: #define VECSHARED "shared"
100: #define VECSEQCUSP "seqcusp"
101: #define VECMPICUSP "mpicusp"
102: #define VECCUSP "cusp" /* seqcusp on one process and mpicusp on several */
103: #define VECSEQVIENNACL "seqviennacl"
104: #define VECMPIVIENNACL "mpiviennacl"
105: #define VECVIENNACL "viennacl" /* seqviennacl on one process and mpiviennacl on several */
106: #define VECSEQCUDA "seqcuda"
107: #define VECMPICUDA "mpicuda"
108: #define VECCUDA "cuda" /* seqcuda on one process and mpicuda on several */
109: #define VECNEST "nest"
112: /* Logging support */
113: #define REAL_FILE_CLASSID 1211213
114: #define VEC_FILE_CLASSID 1211214
115: PETSC_EXTERN PetscClassId VEC_CLASSID;
116: PETSC_EXTERN PetscClassId VEC_SCATTER_CLASSID;
119: PETSC_EXTERN PetscErrorCode VecInitializePackage(void);
120: PETSC_EXTERN PetscErrorCode VecFinalizePackage(void);
122: PETSC_EXTERN PetscErrorCode VecCreate(MPI_Comm,Vec*);
123: PETSC_EXTERN PetscErrorCode VecCreateSeq(MPI_Comm,PetscInt,Vec*);
124: PETSC_EXTERN PetscErrorCode VecCreateMPI(MPI_Comm,PetscInt,PetscInt,Vec*);
125: PETSC_EXTERN PetscErrorCode VecCreateSeqWithArray(MPI_Comm,PetscInt,PetscInt,const PetscScalar[],Vec*);
126: PETSC_EXTERN PetscErrorCode VecCreateMPIWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscScalar[],Vec*);
127: PETSC_EXTERN PetscErrorCode VecCreateShared(MPI_Comm,PetscInt,PetscInt,Vec*);
128: PETSC_EXTERN PetscErrorCode VecSetFromOptions(Vec);
129: PETSC_STATIC_INLINE PetscErrorCode VecViewFromOptions(Vec A,PetscObject B,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,B,name);}
131: PETSC_EXTERN PetscErrorCode VecSetUp(Vec);
132: PETSC_EXTERN PetscErrorCode VecDestroy(Vec*);
133: PETSC_EXTERN PetscErrorCode VecZeroEntries(Vec);
134: PETSC_EXTERN PetscErrorCode VecSetOptionsPrefix(Vec,const char[]);
135: PETSC_EXTERN PetscErrorCode VecAppendOptionsPrefix(Vec,const char[]);
136: PETSC_EXTERN PetscErrorCode VecGetOptionsPrefix(Vec,const char*[]);
138: PETSC_EXTERN PetscErrorCode VecSetSizes(Vec,PetscInt,PetscInt);
140: PETSC_EXTERN PetscErrorCode VecDotNorm2(Vec,Vec,PetscScalar*,PetscReal*);
141: PETSC_EXTERN PetscErrorCode VecDot(Vec,Vec,PetscScalar*);
142: PETSC_EXTERN PetscErrorCode VecDotRealPart(Vec,Vec,PetscReal*);
143: PETSC_EXTERN PetscErrorCode VecTDot(Vec,Vec,PetscScalar*);
144: PETSC_EXTERN PetscErrorCode VecMDot(Vec,PetscInt,const Vec[],PetscScalar[]);
145: PETSC_EXTERN PetscErrorCode VecMTDot(Vec,PetscInt,const Vec[],PetscScalar[]);
146: PETSC_EXTERN PetscErrorCode VecGetSubVector(Vec,IS,Vec*);
147: PETSC_EXTERN PetscErrorCode VecRestoreSubVector(Vec,IS,Vec*);
149: /*E
150: NormType - determines what type of norm to compute
152: Level: beginner
154: .seealso: VecNorm(), VecNormBegin(), VecNormEnd(), MatNorm()
155: E*/
156: typedef enum {NORM_1=0,NORM_2=1,NORM_FROBENIUS=2,NORM_INFINITY=3,NORM_1_AND_2=4} NormType;
157: PETSC_EXTERN const char *const NormTypes[];
158: #define NORM_MAX NORM_INFINITY
160: /*MC
161: NORM_1 - the one norm, ||v|| = sum_i | v_i |. ||A|| = max_j || v_*j ||, maximum column sum
163: Level: beginner
165: .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_2, NORM_FROBENIUS,
166: NORM_INFINITY, NORM_1_AND_2
168: M*/
170: /*MC
171: NORM_2 - the two norm, ||v|| = sqrt(sum_i |v_i|^2) (vectors only)
173: Level: beginner
175: .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_FROBENIUS,
176: NORM_INFINITY, NORM_1_AND_2
178: M*/
180: /*MC
181: NORM_FROBENIUS - ||A|| = sqrt(sum_ij |A_ij|^2), same as NORM_2 for vectors
183: Level: beginner
185: .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2,
186: NORM_INFINITY, NORM_1_AND_2
188: M*/
190: /*MC
191: NORM_INFINITY - ||v|| = max_i |v_i|. ||A|| = max_i || v_i* ||, maximum row sum
193: Level: beginner
195: .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2,
196: NORM_FROBINIUS, NORM_1_AND_2
198: M*/
200: /*MC
201: NORM_1_AND_2 - computes both the 1 and 2 norm of a vector
203: Level: beginner
205: .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2,
206: NORM_FROBINIUS, NORM_INFINITY
208: M*/
210: /*MC
211: NORM_MAX - see NORM_INFINITY
213: Level: beginner
215: M*/
217: PETSC_EXTERN PetscErrorCode VecNorm(Vec,NormType,PetscReal *);
218: PETSC_EXTERN PetscErrorCode VecNormAvailable(Vec,NormType,PetscBool *,PetscReal *);
219: PETSC_EXTERN PetscErrorCode VecNormalize(Vec,PetscReal *);
220: PETSC_EXTERN PetscErrorCode VecSum(Vec,PetscScalar*);
221: PETSC_EXTERN PetscErrorCode VecMax(Vec,PetscInt*,PetscReal *);
222: PETSC_EXTERN PetscErrorCode VecMin(Vec,PetscInt*,PetscReal *);
223: PETSC_EXTERN PetscErrorCode VecScale(Vec,PetscScalar);
224: PETSC_EXTERN PetscErrorCode VecCopy(Vec,Vec);
225: PETSC_EXTERN PetscErrorCode VecSetRandom(Vec,PetscRandom);
226: PETSC_EXTERN PetscErrorCode VecSet(Vec,PetscScalar);
227: PETSC_EXTERN PetscErrorCode VecSetInf(Vec);
228: PETSC_EXTERN PetscErrorCode VecSwap(Vec,Vec);
229: PETSC_EXTERN PetscErrorCode VecAXPY(Vec,PetscScalar,Vec);
230: PETSC_EXTERN PetscErrorCode VecAXPBY(Vec,PetscScalar,PetscScalar,Vec);
231: PETSC_EXTERN PetscErrorCode VecMAXPY(Vec,PetscInt,const PetscScalar[],Vec[]);
232: PETSC_EXTERN PetscErrorCode VecAYPX(Vec,PetscScalar,Vec);
233: PETSC_EXTERN PetscErrorCode VecWAXPY(Vec,PetscScalar,Vec,Vec);
234: PETSC_EXTERN PetscErrorCode VecAXPBYPCZ(Vec,PetscScalar,PetscScalar,PetscScalar,Vec,Vec);
235: PETSC_EXTERN PetscErrorCode VecPointwiseMax(Vec,Vec,Vec);
236: PETSC_EXTERN PetscErrorCode VecPointwiseMaxAbs(Vec,Vec,Vec);
237: PETSC_EXTERN PetscErrorCode VecPointwiseMin(Vec,Vec,Vec);
238: PETSC_EXTERN PetscErrorCode VecPointwiseMult(Vec,Vec,Vec);
239: PETSC_EXTERN PetscErrorCode VecPointwiseDivide(Vec,Vec,Vec);
240: PETSC_EXTERN PetscErrorCode VecMaxPointwiseDivide(Vec,Vec,PetscReal*);
241: PETSC_EXTERN PetscErrorCode VecShift(Vec,PetscScalar);
242: PETSC_EXTERN PetscErrorCode VecReciprocal(Vec);
243: PETSC_EXTERN PetscErrorCode VecPermute(Vec, IS, PetscBool );
244: PETSC_EXTERN PetscErrorCode VecSqrtAbs(Vec);
245: PETSC_EXTERN PetscErrorCode VecLog(Vec);
246: PETSC_EXTERN PetscErrorCode VecExp(Vec);
247: PETSC_EXTERN PetscErrorCode VecAbs(Vec);
248: PETSC_EXTERN PetscErrorCode VecDuplicate(Vec,Vec*);
249: PETSC_EXTERN PetscErrorCode VecDuplicateVecs(Vec,PetscInt,Vec*[]);
250: PETSC_EXTERN PetscErrorCode VecDestroyVecs(PetscInt, Vec*[]);
251: PETSC_EXTERN PetscErrorCode VecStrideNormAll(Vec,NormType,PetscReal[]);
252: PETSC_EXTERN PetscErrorCode VecStrideMaxAll(Vec,PetscInt [],PetscReal []);
253: PETSC_EXTERN PetscErrorCode VecStrideMinAll(Vec,PetscInt [],PetscReal []);
254: PETSC_EXTERN PetscErrorCode VecStrideScaleAll(Vec,const PetscScalar[]);
255: PETSC_EXTERN PetscErrorCode VecUniqueEntries(Vec,PetscInt*,PetscScalar**);
257: PETSC_EXTERN PetscErrorCode VecStrideNorm(Vec,PetscInt,NormType,PetscReal*);
258: PETSC_EXTERN PetscErrorCode VecStrideMax(Vec,PetscInt,PetscInt *,PetscReal *);
259: PETSC_EXTERN PetscErrorCode VecStrideMin(Vec,PetscInt,PetscInt *,PetscReal *);
260: PETSC_EXTERN PetscErrorCode VecStrideScale(Vec,PetscInt,PetscScalar);
261: PETSC_EXTERN PetscErrorCode VecStrideSet(Vec,PetscInt,PetscScalar);
264: PETSC_EXTERN PetscErrorCode VecStrideGather(Vec,PetscInt,Vec,InsertMode);
265: PETSC_EXTERN PetscErrorCode VecStrideScatter(Vec,PetscInt,Vec,InsertMode);
266: PETSC_EXTERN PetscErrorCode VecStrideGatherAll(Vec,Vec[],InsertMode);
267: PETSC_EXTERN PetscErrorCode VecStrideScatterAll(Vec[],Vec,InsertMode);
269: PETSC_EXTERN PetscErrorCode VecStrideSubSetScatter(Vec,PetscInt,const PetscInt[],const PetscInt[],Vec,InsertMode);
270: PETSC_EXTERN PetscErrorCode VecStrideSubSetGather(Vec,PetscInt,const PetscInt[],const PetscInt[],Vec,InsertMode);
272: PETSC_EXTERN PetscErrorCode VecSetValues(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
273: PETSC_EXTERN PetscErrorCode VecGetValues(Vec,PetscInt,const PetscInt[],PetscScalar[]);
274: PETSC_EXTERN PetscErrorCode VecAssemblyBegin(Vec);
275: PETSC_EXTERN PetscErrorCode VecAssemblyEnd(Vec);
276: PETSC_EXTERN PetscErrorCode VecStashSetInitialSize(Vec,PetscInt,PetscInt);
277: PETSC_EXTERN PetscErrorCode VecStashView(Vec,PetscViewer);
278: PETSC_EXTERN PetscErrorCode VecStashViewFromOptions(Vec,PetscObject,const char[]);
279: PETSC_EXTERN PetscErrorCode VecStashGetInfo(Vec,PetscInt*,PetscInt*,PetscInt*,PetscInt*);
281: /*MC
282: VecSetValue - Set a single entry into a vector.
284: Synopsis:
285: #include <petscvec.h>
286: PetscErrorCode VecSetValue(Vec v,PetscInt row,PetscScalar value, InsertMode mode);
288: Not Collective
290: Input Parameters:
291: + v - the vector
292: . row - the row location of the entry
293: . value - the value to insert
294: - mode - either INSERT_VALUES or ADD_VALUES
296: Notes:
297: For efficiency one should use VecSetValues() and set several or
298: many values simultaneously if possible.
300: These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd()
301: MUST be called after all calls to VecSetValues() have been completed.
303: VecSetValues() uses 0-based indices in Fortran as well as in C.
305: Level: beginner
307: .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValueLocal()
308: M*/
309: PETSC_STATIC_INLINE PetscErrorCode VecSetValue(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValues(v,1,&i,&va,mode);}
312: PETSC_EXTERN PetscErrorCode VecSetBlockSize(Vec,PetscInt);
313: PETSC_EXTERN PetscErrorCode VecGetBlockSize(Vec,PetscInt*);
314: PETSC_EXTERN PetscErrorCode VecSetValuesBlocked(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
316: /* Dynamic creation and loading functions */
317: PETSC_EXTERN PetscFunctionList VecList;
318: PETSC_EXTERN PetscErrorCode VecSetType(Vec, VecType);
319: PETSC_EXTERN PetscErrorCode VecGetType(Vec, VecType *);
320: PETSC_EXTERN PetscErrorCode VecRegister(const char[],PetscErrorCode (*)(Vec));
322: PETSC_EXTERN PetscErrorCode VecScatterCreate(Vec,IS,Vec,IS,VecScatter *);
323: PETSC_EXTERN PetscErrorCode VecScatterCreateEmpty(MPI_Comm,VecScatter *);
324: PETSC_EXTERN PetscErrorCode VecScatterCreateLocal(VecScatter,PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],PetscInt);
325: PETSC_EXTERN PetscErrorCode VecScatterBegin(VecScatter,Vec,Vec,InsertMode,ScatterMode);
326: PETSC_EXTERN PetscErrorCode VecScatterEnd(VecScatter,Vec,Vec,InsertMode,ScatterMode);
327: PETSC_EXTERN PetscErrorCode VecScatterDestroy(VecScatter*);
328: PETSC_EXTERN PetscErrorCode VecScatterCopy(VecScatter,VecScatter *);
329: PETSC_EXTERN PetscErrorCode VecScatterView(VecScatter,PetscViewer);
330: PETSC_STATIC_INLINE PetscErrorCode VecScatterViewFromOptions(VecScatter A,PetscObject obj,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,obj,name);}
331: PETSC_EXTERN PetscErrorCode VecScatterRemap(VecScatter,PetscInt *,PetscInt*);
332: PETSC_EXTERN PetscErrorCode VecScatterGetMerged(VecScatter,PetscBool *);
334: PETSC_EXTERN PetscErrorCode VecGetArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]);
335: PETSC_EXTERN PetscErrorCode VecRestoreArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]);
336: PETSC_EXTERN PetscErrorCode VecGetArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]);
337: PETSC_EXTERN PetscErrorCode VecRestoreArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]);
338: PETSC_EXTERN PetscErrorCode VecGetArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]);
339: PETSC_EXTERN PetscErrorCode VecRestoreArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]);
340: PETSC_EXTERN PetscErrorCode VecGetArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]);
341: PETSC_EXTERN PetscErrorCode VecRestoreArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]);
343: PETSC_EXTERN PetscErrorCode VecGetArray4dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]);
344: PETSC_EXTERN PetscErrorCode VecRestoreArray4dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]);
345: PETSC_EXTERN PetscErrorCode VecGetArray3dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]);
346: PETSC_EXTERN PetscErrorCode VecRestoreArray3dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]);
347: PETSC_EXTERN PetscErrorCode VecGetArray2dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]);
348: PETSC_EXTERN PetscErrorCode VecRestoreArray2dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]);
349: PETSC_EXTERN PetscErrorCode VecGetArray1dRead(Vec,PetscInt,PetscInt,PetscScalar *[]);
350: PETSC_EXTERN PetscErrorCode VecRestoreArray1dRead(Vec,PetscInt,PetscInt,PetscScalar *[]);
352: PETSC_EXTERN PetscErrorCode VecPlaceArray(Vec,const PetscScalar[]);
353: PETSC_EXTERN PetscErrorCode VecResetArray(Vec);
354: PETSC_EXTERN PetscErrorCode VecReplaceArray(Vec,const PetscScalar[]);
355: PETSC_EXTERN PetscErrorCode VecGetArrays(const Vec[],PetscInt,PetscScalar**[]);
356: PETSC_EXTERN PetscErrorCode VecRestoreArrays(const Vec[],PetscInt,PetscScalar**[]);
358: PETSC_EXTERN PetscErrorCode VecView(Vec,PetscViewer);
359: PETSC_EXTERN PetscErrorCode VecEqual(Vec,Vec,PetscBool *);
360: PETSC_EXTERN PetscErrorCode VecLoad(Vec, PetscViewer);
362: PETSC_EXTERN PetscErrorCode VecGetSize(Vec,PetscInt*);
363: PETSC_EXTERN PetscErrorCode VecGetLocalSize(Vec,PetscInt*);
364: PETSC_EXTERN PetscErrorCode VecGetOwnershipRange(Vec,PetscInt*,PetscInt*);
365: PETSC_EXTERN PetscErrorCode VecGetOwnershipRanges(Vec,const PetscInt *[]);
367: PETSC_EXTERN PetscErrorCode VecSetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping);
368: PETSC_EXTERN PetscErrorCode VecSetValuesLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
370: /*MC
371: VecSetValueLocal - Set a single entry into a vector using the local numbering
373: Synopsis:
374: #include <petscvec.h>
375: PetscErrorCode VecSetValueLocal(Vec v,PetscInt row,PetscScalar value, InsertMode mode);
377: Not Collective
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
385: Notes:
386: For efficiency one should use VecSetValues() and set several or
387: many values simultaneously if possible.
389: These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd()
390: MUST be called after all calls to VecSetValues() have been completed.
392: VecSetValues() uses 0-based indices in Fortran as well as in C.
394: Level: beginner
396: .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValue()
397: M*/
398: PETSC_STATIC_INLINE PetscErrorCode VecSetValueLocal(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValuesLocal(v,1,&i,&va,mode);}
400: PETSC_EXTERN PetscErrorCode VecSetValuesBlockedLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
401: PETSC_EXTERN PetscErrorCode VecGetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping*);
403: PETSC_EXTERN PetscErrorCode VecDotBegin(Vec,Vec,PetscScalar *);
404: PETSC_EXTERN PetscErrorCode VecDotEnd(Vec,Vec,PetscScalar *);
405: PETSC_EXTERN PetscErrorCode VecTDotBegin(Vec,Vec,PetscScalar *);
406: PETSC_EXTERN PetscErrorCode VecTDotEnd(Vec,Vec,PetscScalar *);
407: PETSC_EXTERN PetscErrorCode VecNormBegin(Vec,NormType,PetscReal *);
408: PETSC_EXTERN PetscErrorCode VecNormEnd(Vec,NormType,PetscReal *);
410: PETSC_EXTERN PetscErrorCode VecMDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]);
411: PETSC_EXTERN PetscErrorCode VecMDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]);
412: PETSC_EXTERN PetscErrorCode VecMTDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]);
413: PETSC_EXTERN PetscErrorCode VecMTDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]);
414: PETSC_EXTERN PetscErrorCode PetscCommSplitReductionBegin(MPI_Comm);
417: typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES,VEC_IGNORE_NEGATIVE_INDICES,VEC_SUBSET_OFF_PROC_ENTRIES} VecOption;
418: PETSC_EXTERN PetscErrorCode VecSetOption(Vec,VecOption,PetscBool );
420: PETSC_EXTERN PetscErrorCode VecGetArray(Vec,PetscScalar**);
421: PETSC_EXTERN PetscErrorCode VecGetArrayRead(Vec,const PetscScalar**);
422: PETSC_EXTERN PetscErrorCode VecRestoreArray(Vec,PetscScalar**);
423: PETSC_EXTERN PetscErrorCode VecRestoreArrayRead(Vec,const PetscScalar**);
424: PETSC_EXTERN PetscErrorCode VecGetLocalVector(Vec,Vec);
425: PETSC_EXTERN PetscErrorCode VecRestoreLocalVector(Vec,Vec);
426: PETSC_EXTERN PetscErrorCode VecGetLocalVectorRead(Vec,Vec);
427: PETSC_EXTERN PetscErrorCode VecRestoreLocalVectorRead(Vec,Vec);
429: /*@C
430: VecGetArrayPair - Accesses a pair of pointers for two vectors that may be common. When not common the first is read only
432: Logically Collective on Vec
434: Input Parameter:
435: + x - the vector
436: - y - the second vector
438: Output Parameter:
439: + xv - location to put pointer to the first array
440: - yv - location to put pointer to the second array
442: Level: developer
444: .seealso: VecGetArray(), VecGetArrayRead(), VecRestoreArrayPair()
446: @*/
447: PETSC_STATIC_INLINE PetscErrorCode VecGetArrayPair(Vec x,Vec y,PetscScalar **xv,PetscScalar **yv)
448: {
452: VecGetArray(y,yv);
453: if (x != y) {
454: VecGetArrayRead(x,(const PetscScalar **)xv);
455: } else {
456: *xv = *yv;
457: }
458: return(0);
459: }
461: /*@C
462: VecRestoreArrayPair - Returns a pair of pointers for two vectors that may be common. When not common the first is read only
464: Logically Collective on Vec
466: Input Parameter:
467: + x - the vector
468: - y - the second vector
470: Output Parameter:
471: + xv - location to put pointer to the first array
472: - yv - location to put pointer to the second array
474: Level: developer
476: .seealso: VecGetArray(), VecGetArrayRead(), VecGetArrayPair()
478: @*/
479: PETSC_STATIC_INLINE PetscErrorCode VecRestoreArrayPair(Vec x,Vec y,PetscScalar **xv,PetscScalar **yv)
480: {
484: VecRestoreArray(y,yv);
485: if (x != y) {
486: VecRestoreArrayRead(x,(const PetscScalar **)xv);
487: }
488: return(0);
489: }
491: #if defined(PETSC_USE_DEBUG)
492: PETSC_EXTERN PetscErrorCode VecLockGet(Vec,PetscInt*);
493: PETSC_EXTERN PetscErrorCode VecLockPush(Vec);
494: PETSC_EXTERN PetscErrorCode VecLockPop(Vec);
495: #define VecLocked(x,arg) do {PetscInt _st; PetscErrorCode __VecLockGet(x,&_st); CHKERRQ(__ierr); if (_st > 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE," Vec is locked read only, argument # %d",arg);} while (0)
496: #else
497: #define VecLockGet(x,arg) *(arg) = 0
498: #define VecLockPush(x) 0
499: #define VecLockPop(x) 0
500: #define VecLocked(x,arg)
501: #endif
503: PETSC_EXTERN PetscErrorCode VecValidValues(Vec,PetscInt,PetscBool);
505: /*
506: These numbers need to match the entries in
507: the function table in vecimpl.h
508: */
509: typedef enum { VECOP_DUPLICATE = 0, VECOP_VIEW = 33, VECOP_LOAD = 41, VECOP_VIEWNATIVE = 68, VECOP_LOADNATIVE = 69 } VecOperation;
510: PETSC_EXTERN PetscErrorCode VecSetOperation(Vec,VecOperation,void(*)(void));
512: /*
513: Routines for dealing with ghosted vectors:
514: vectors with ghost elements at the end of the array.
515: */
516: PETSC_EXTERN PetscErrorCode VecMPISetGhost(Vec,PetscInt,const PetscInt[]);
517: PETSC_EXTERN PetscErrorCode VecCreateGhost(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*);
518: PETSC_EXTERN PetscErrorCode VecCreateGhostWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*);
519: PETSC_EXTERN PetscErrorCode VecCreateGhostBlock(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*);
520: PETSC_EXTERN PetscErrorCode VecCreateGhostBlockWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*);
521: PETSC_EXTERN PetscErrorCode VecGhostGetLocalForm(Vec,Vec*);
522: PETSC_EXTERN PetscErrorCode VecGhostRestoreLocalForm(Vec,Vec*);
523: PETSC_EXTERN PetscErrorCode VecGhostIsLocalForm(Vec,Vec,PetscBool*);
524: PETSC_EXTERN PetscErrorCode VecGhostUpdateBegin(Vec,InsertMode,ScatterMode);
525: PETSC_EXTERN PetscErrorCode VecGhostUpdateEnd(Vec,InsertMode,ScatterMode);
527: PETSC_EXTERN PetscErrorCode VecConjugate(Vec);
529: PETSC_EXTERN PetscErrorCode VecScatterCreateToAll(Vec,VecScatter*,Vec*);
530: PETSC_EXTERN PetscErrorCode VecScatterCreateToZero(Vec,VecScatter*,Vec*);
532: PETSC_EXTERN PetscErrorCode ISComplementVec(IS,Vec,IS*);
533: PETSC_EXTERN PetscErrorCode VecPow(Vec, PetscScalar);
534: PETSC_EXTERN PetscErrorCode VecMedian(Vec, Vec, Vec, Vec);
535: PETSC_EXTERN PetscErrorCode VecWhichBetween(Vec, Vec, Vec, IS *);
536: PETSC_EXTERN PetscErrorCode VecWhichBetweenOrEqual(Vec, Vec, Vec, IS *);
537: PETSC_EXTERN PetscErrorCode VecWhichGreaterThan(Vec, Vec, IS * );
538: PETSC_EXTERN PetscErrorCode VecWhichLessThan(Vec, Vec, IS *);
539: PETSC_EXTERN PetscErrorCode VecWhichEqual(Vec, Vec, IS *);
540: PETSC_EXTERN PetscErrorCode VecISAXPY(Vec, IS, PetscScalar,Vec);
541: PETSC_EXTERN PetscErrorCode VecISSet(Vec,IS, PetscScalar);
542: PETSC_EXTERN PetscErrorCode VecBoundGradientProjection(Vec, Vec, Vec, Vec, Vec);
543: PETSC_EXTERN PetscErrorCode VecStepBoundInfo(Vec,Vec,Vec,Vec,PetscReal*, PetscReal*,PetscReal*);
544: PETSC_EXTERN PetscErrorCode VecStepMax(Vec, Vec, PetscReal *);
545: PETSC_EXTERN PetscErrorCode VecStepMaxBounded(Vec,Vec,Vec,Vec,PetscReal*);
547: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaGetVector(PetscViewer, Vec);
548: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutVector(PetscViewer, Vec);
550: /*S
551: Vecs - Collection of vectors where the data for the vectors is stored in
552: one contiguous memory
554: Level: advanced
556: Notes:
557: Temporary construct for handling multiply right hand side solves
559: This is faked by storing a single vector that has enough array space for
560: n vectors
562: Concepts: parallel decomposition
564: S*/
565: struct _n_Vecs {PetscInt n; Vec v;};
566: typedef struct _n_Vecs* Vecs;
567: PETSC_EXTERN PetscErrorCode VecsDestroy(Vecs);
568: PETSC_EXTERN PetscErrorCode VecsCreateSeq(MPI_Comm,PetscInt,PetscInt,Vecs*);
569: PETSC_EXTERN PetscErrorCode VecsCreateSeqWithArray(MPI_Comm,PetscInt,PetscInt,PetscScalar*,Vecs*);
570: PETSC_EXTERN PetscErrorCode VecsDuplicate(Vecs,Vecs*);
572: #if defined(PETSC_HAVE_CUSP)
573: typedef struct _p_PetscCUSPIndices* PetscCUSPIndices;
574: typedef struct _p_VecScatterCUSPIndices_StoS* VecScatterCUSPIndices_StoS;
575: typedef struct _p_VecScatterCUSPIndices_PtoP* VecScatterCUSPIndices_PtoP;
576: PETSC_EXTERN PetscErrorCode VecCUSPCopyToGPUSome_Public(Vec,PetscCUSPIndices);
577: PETSC_EXTERN PetscErrorCode VecCUSPCopyFromGPUSome_Public(Vec,PetscCUSPIndices);
578: PETSC_EXTERN PetscErrorCode VecScatterInitializeForGPU(VecScatter,Vec,ScatterMode);
579: PETSC_EXTERN PetscErrorCode VecScatterFinalizeForGPU(VecScatter);
580: PETSC_EXTERN PetscErrorCode VecCreateSeqCUSP(MPI_Comm,PetscInt,Vec*);
581: PETSC_EXTERN PetscErrorCode VecCreateMPICUSP(MPI_Comm,PetscInt,PetscInt,Vec*);
582: #elif defined(PETSC_HAVE_VIENNACL)
583: typedef struct _p_PetscViennaCLIndices* PetscViennaCLIndices;
584: PETSC_EXTERN PetscErrorCode PetscViennaCLIndicesCreate(PetscInt, PetscInt*,PetscInt, PetscInt*,PetscViennaCLIndices*);
585: PETSC_EXTERN PetscErrorCode PetscViennaCLIndicesDestroy(PetscViennaCLIndices*);
586: PETSC_EXTERN PetscErrorCode VecViennaCLCopyToGPUSome_Public(Vec,PetscViennaCLIndices);
587: PETSC_EXTERN PetscErrorCode VecViennaCLCopyFromGPUSome_Public(Vec,PetscViennaCLIndices);
588: PETSC_EXTERN PetscErrorCode VecCreateSeqViennaCL(MPI_Comm,PetscInt,Vec*);
589: PETSC_EXTERN PetscErrorCode VecCreateMPIViennaCL(MPI_Comm,PetscInt,PetscInt,Vec*);
590: #elif defined(PETSC_HAVE_VECCUDA)
591: typedef struct _p_PetscCUDAIndices* PetscCUDAIndices;
592: typedef struct _p_VecScatterCUDAIndices_StoS* VecScatterCUDAIndices_StoS;
593: typedef struct _p_VecScatterCUDAIndices_PtoP* VecScatterCUDAIndices_PtoP;
594: PETSC_EXTERN PetscErrorCode VecCUDACopyToGPUSome_Public(Vec,PetscCUDAIndices);
595: PETSC_EXTERN PetscErrorCode VecCUDACopyFromGPUSome_Public(Vec,PetscCUDAIndices);
596: PETSC_EXTERN PetscErrorCode VecScatterInitializeForGPU(VecScatter,Vec,ScatterMode);
597: PETSC_EXTERN PetscErrorCode VecScatterFinalizeForGPU(VecScatter);
598: PETSC_EXTERN PetscErrorCode VecCreateSeqCUDA(MPI_Comm,PetscInt,Vec*);
599: PETSC_EXTERN PetscErrorCode VecCreateSeqCUDAWithArray(MPI_Comm,PetscInt,PetscInt,const PetscScalar*,Vec*);
600: PETSC_EXTERN PetscErrorCode VecCreateMPICUDA(MPI_Comm,PetscInt,PetscInt,Vec*);
601: PETSC_EXTERN PetscErrorCode VecCreateMPICUDAWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscScalar*,Vec*);
602: #endif
604: PETSC_EXTERN PetscErrorCode VecNestGetSubVecs(Vec,PetscInt*,Vec**);
605: PETSC_EXTERN PetscErrorCode VecNestGetSubVec(Vec,PetscInt,Vec*);
606: PETSC_EXTERN PetscErrorCode VecNestSetSubVecs(Vec,PetscInt,PetscInt*,Vec*);
607: PETSC_EXTERN PetscErrorCode VecNestSetSubVec(Vec,PetscInt,Vec);
608: PETSC_EXTERN PetscErrorCode VecCreateNest(MPI_Comm,PetscInt,IS*,Vec*,Vec*);
609: PETSC_EXTERN PetscErrorCode VecNestGetSize(Vec,PetscInt*);
611: PETSC_EXTERN PetscErrorCode PetscOptionsGetVec(PetscOptions,const char[],const char[],Vec,PetscBool*);
612: PETSC_EXTERN PetscErrorCode VecChop(Vec,PetscReal);
614: PETSC_EXTERN PetscErrorCode VecGetLayout(Vec,PetscLayout*);
615: PETSC_EXTERN PetscErrorCode VecSetLayout(Vec,PetscLayout);
617: PETSC_EXTERN PetscErrorCode PetscSectionVecView(PetscSection, Vec, PetscViewer);
618: PETSC_EXTERN PetscErrorCode VecGetValuesSection(Vec, PetscSection, PetscInt, PetscScalar **);
619: PETSC_EXTERN PetscErrorCode VecSetValuesSection(Vec, PetscSection, PetscInt, PetscScalar [], InsertMode);
620: PETSC_EXTERN PetscErrorCode PetscSectionVecNorm(PetscSection, PetscSection, Vec, NormType, PetscReal []);
622: PETSC_EXTERN PetscErrorCode PetscSFCreateFromZero(MPI_Comm,Vec,PetscSF*);
624: /*S
625: VecTagger - Object used to manage the tagging of a subset of indices based on the values of a vector. The
626: motivating application is the selection of cells for refinement or coarsening based on vector containing
627: the values in an error indicator metric.
629: Level: advanced
630: S*/
631: typedef struct _p_VecTagger *VecTagger;
633: /*J
634: VecTaggerType - String with the name of a VecTagger type
636: Level: advanced
637: J*/
638: typedef const char* VecTaggerType;
639: /* tag where the vector values are in a box of explicitly defined values */
640: #define VECTAGGERABSOLUTE "absolute"
641: /* tag where the vector values are in a box of values relative to the set of all values in the vector */
642: #define VECTAGGERRELATIVE "relative"
643: /* tag where the vector values are in a relative range of the *cumulative distribution* of values in the vector */
644: #define VECTAGGERCDF "cdf"
645: /* tag a vector as the union of other tags */
646: #define VECTAGGEROR "or"
647: /* tag a vector as the intersection of other tags */
648: #define VECTAGGERAND "and"
650: PETSC_EXTERN PetscClassId VEC_TAGGER_CLASSID;
651: PETSC_EXTERN PetscFunctionList VecTaggerList;
652: PETSC_EXTERN PetscErrorCode VecTaggerRegister(const char[],PetscErrorCode (*) (VecTagger));
654: PETSC_EXTERN PetscErrorCode VecTaggerCreate(MPI_Comm,VecTagger *);
655: PETSC_EXTERN PetscErrorCode VecTaggerSetBlockSize(VecTagger,PetscInt);
656: PETSC_EXTERN PetscErrorCode VecTaggerGetBlockSize(VecTagger,PetscInt*);
657: PETSC_EXTERN PetscErrorCode VecTaggerSetType(VecTagger,VecTaggerType);
658: PETSC_EXTERN PetscErrorCode VecTaggerGetType(VecTagger,VecTaggerType *);
659: PETSC_EXTERN PetscErrorCode VecTaggerSetInvert(VecTagger,PetscBool);
660: PETSC_EXTERN PetscErrorCode VecTaggerGetInvert(VecTagger,PetscBool*);
661: PETSC_EXTERN PetscErrorCode VecTaggerSetFromOptions(VecTagger);
662: PETSC_EXTERN PetscErrorCode VecTaggerSetUp(VecTagger);
663: PETSC_EXTERN PetscErrorCode VecTaggerView(VecTagger,PetscViewer);
664: PETSC_EXTERN PetscErrorCode VecTaggerComputeIS(VecTagger,Vec,IS *);
665: PETSC_EXTERN PetscErrorCode VecTaggerDestroy(VecTagger *);
667: /*S
668: 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
669: such that real(min) <= real(z) <= real(max) and imag(min) <= imag(z) <= imag(max). INF is an acceptable endpoint.
671: Level: beginner
673: .seealso: VecTaggerComputeIntervals()
674: S*/
675: typedef struct {
676: PetscScalar min;
677: PetscScalar max;
678: } VecTaggerBox;
679: PETSC_EXTERN PetscErrorCode VecTaggerComputeBoxes(VecTagger,Vec,PetscInt *,VecTaggerBox **);
682: PETSC_EXTERN PetscErrorCode VecTaggerAbsoluteSetBox(VecTagger,VecTaggerBox *);
683: PETSC_EXTERN PetscErrorCode VecTaggerAbsoluteGetBox(VecTagger,const VecTaggerBox **);
685: PETSC_EXTERN PetscErrorCode VecTaggerRelativeSetBox(VecTagger,VecTaggerBox *);
686: PETSC_EXTERN PetscErrorCode VecTaggerRelativeGetBox(VecTagger,const VecTaggerBox **);
688: PETSC_EXTERN PetscErrorCode VecTaggerCDFSetBox(VecTagger,VecTaggerBox *);
689: PETSC_EXTERN PetscErrorCode VecTaggerCDFGetBox(VecTagger,const VecTaggerBox **);
691: /*E
692: 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). Relevant only in parallel: in serial it is directly computed.
694: Level: advanced
695: .seealso: VecTaggerCDFSetMethod(), VecTaggerCDFMethods
696: E*/
697: typedef enum {VECTAGGER_CDF_GATHER,VECTAGGER_CDF_ITERATIVE,VECTAGGER_CDF_NUM_METHODS} VecTaggerCDFMethod;
698: PETSC_EXTERN const char *const VecTaggerCDFMethods[];
700: PETSC_EXTERN PetscErrorCode VecTaggerCDFSetMethod(VecTagger,VecTaggerCDFMethod);
701: PETSC_EXTERN PetscErrorCode VecTaggerCDFGetMethod(VecTagger,VecTaggerCDFMethod*);
702: PETSC_EXTERN PetscErrorCode VecTaggerCDFIterativeSetTolerances(VecTagger,PetscInt,PetscReal,PetscReal);
703: PETSC_EXTERN PetscErrorCode VecTaggerCDFIterativeGetTolerances(VecTagger,PetscInt*,PetscReal*,PetscReal*);
705: PETSC_EXTERN PetscErrorCode VecTaggerOrSetSubs(VecTagger,PetscInt,VecTagger*,PetscCopyMode);
706: PETSC_EXTERN PetscErrorCode VecTaggerOrGetSubs(VecTagger,PetscInt*,VecTagger**);
708: PETSC_EXTERN PetscErrorCode VecTaggerAndSetSubs(VecTagger,PetscInt,VecTagger*,PetscCopyMode);
709: PETSC_EXTERN PetscErrorCode VecTaggerAndGetSubs(VecTagger,PetscInt*,VecTagger**);
711: PETSC_EXTERN PetscErrorCode VecTaggerInitializePackage(void);
712: PETSC_EXTERN PetscErrorCode VecTaggerFinalizePackage(void);
714: #endif