Actual source code: petscvec.h

petsc-master 2018-10-20
Report Typos and Errors
  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:  VecScatterCreateWithData(), 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 VecScatterCreateWithData() call

 47:     Level: beginner

 49: .seealso: VecScatter, ScatterMode, VecScatterCreateWithData(), 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 VecScatterCreateWithData()

 58:     Level: beginner

 60: .seealso: VecScatter, ScatterMode, VecScatterCreateWithData(), 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 VecScatterCreateWithData() 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, VecScatterCreateWithData(), 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 VecScatterCreateWithData()  except NO parallel communication
 79:        is done. Any variables that have be moved between processes are ignored

 81:     Level: developer

 83: .seealso: VecScatter, ScatterMode, VecScatterCreateWithData(), 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 VECSEQVIENNACL "seqviennacl"
101: #define VECMPIVIENNACL "mpiviennacl"
102: #define VECVIENNACL    "viennacl"   /* seqviennacl on one process and mpiviennacl on several */
103: #define VECSEQCUDA     "seqcuda"
104: #define VECMPICUDA     "mpicuda"
105: #define VECCUDA        "cuda"       /* seqcuda on one process and mpicuda on several */
106: #define VECNEST        "nest"
107: #define VECNODE        "node"       /* use on-node shared memory */

109: /*J
110:     VecScatterType - String with the name of a PETSc vector scatter type

112:    Level: beginner

114: .seealso: VecScatterSetType(), VecScatter, VecScatterCreateWithData(), VecScatterDestroy()
115: J*/
116: typedef const char* VecScatterType;
117: #define VECSCATTERSEQ       "seq"
118: #define VECSCATTERMPI1      "mpi1"
119: #define VECSCATTERMPI3      "mpi3"     /* use MPI3 on-node shared memory */
120: #define VECSCATTERMPI3NODE  "mpi3node" /* use MPI3 on-node shared memory for vector type VECNODE */

122: /* Dynamic creation and loading functions */
123: PETSC_EXTERN PetscFunctionList VecScatterList;
124: PETSC_EXTERN PetscErrorCode VecScatterSetType(VecScatter, VecScatterType);
125: PETSC_EXTERN PetscErrorCode VecScatterGetType(VecScatter, VecScatterType *);
126: PETSC_EXTERN PetscErrorCode VecScatterSetFromOptions(VecScatter);
127: PETSC_EXTERN PetscErrorCode VecScatterRegister(const char[],PetscErrorCode (*)(VecScatter));
128: PETSC_EXTERN PetscErrorCode VecScatterCreateWithData(Vec,IS,Vec,IS,VecScatter*);
129: PETSC_EXTERN PetscErrorCode VecScatterInitializePackage(void);
130: PETSC_EXTERN PetscErrorCode VecScatterFinalizePackage(void);

132: /* Logging support */
133: #define    REAL_FILE_CLASSID 1211213
134: #define    VEC_FILE_CLASSID 1211214
135: PETSC_EXTERN PetscClassId VEC_CLASSID;
136: PETSC_EXTERN PetscClassId VEC_SCATTER_CLASSID;


139: PETSC_EXTERN PetscErrorCode VecInitializePackage(void);
140: PETSC_EXTERN PetscErrorCode VecFinalizePackage(void);

142: PETSC_EXTERN PetscErrorCode VecCreate(MPI_Comm,Vec*);
143: PETSC_EXTERN PetscErrorCode VecCreateSeq(MPI_Comm,PetscInt,Vec*);
144: PETSC_EXTERN PetscErrorCode VecCreateMPI(MPI_Comm,PetscInt,PetscInt,Vec*);
145: PETSC_EXTERN PetscErrorCode VecCreateSeqWithArray(MPI_Comm,PetscInt,PetscInt,const PetscScalar[],Vec*);
146: PETSC_EXTERN PetscErrorCode VecCreateMPIWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscScalar[],Vec*);
147: PETSC_EXTERN PetscErrorCode VecCreateShared(MPI_Comm,PetscInt,PetscInt,Vec*);
148: PETSC_EXTERN PetscErrorCode VecCreateNode(MPI_Comm,PetscInt,PetscInt,Vec*);

150: PETSC_EXTERN PetscErrorCode VecSetFromOptions(Vec);
151: PETSC_STATIC_INLINE PetscErrorCode VecViewFromOptions(Vec A,PetscObject B,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,B,name);}

153: PETSC_EXTERN PetscErrorCode VecSetUp(Vec);
154: PETSC_EXTERN PetscErrorCode VecDestroy(Vec*);
155: PETSC_EXTERN PetscErrorCode VecZeroEntries(Vec);
156: PETSC_EXTERN PetscErrorCode VecSetOptionsPrefix(Vec,const char[]);
157: PETSC_EXTERN PetscErrorCode VecAppendOptionsPrefix(Vec,const char[]);
158: PETSC_EXTERN PetscErrorCode VecGetOptionsPrefix(Vec,const char*[]);

160: PETSC_EXTERN PetscErrorCode VecSetSizes(Vec,PetscInt,PetscInt);

162: PETSC_EXTERN PetscErrorCode VecDotNorm2(Vec,Vec,PetscScalar*,PetscReal*);
163: PETSC_EXTERN PetscErrorCode VecDot(Vec,Vec,PetscScalar*);
164: PETSC_EXTERN PetscErrorCode VecDotRealPart(Vec,Vec,PetscReal*);
165: PETSC_EXTERN PetscErrorCode VecTDot(Vec,Vec,PetscScalar*);
166: PETSC_EXTERN PetscErrorCode VecMDot(Vec,PetscInt,const Vec[],PetscScalar[]);
167: PETSC_EXTERN PetscErrorCode VecMTDot(Vec,PetscInt,const Vec[],PetscScalar[]);
168: PETSC_EXTERN PetscErrorCode VecGetSubVector(Vec,IS,Vec*);
169: PETSC_EXTERN PetscErrorCode VecRestoreSubVector(Vec,IS,Vec*);

171: /*E
172:     NormType - determines what type of norm to compute

174:     Level: beginner

176: .seealso: VecNorm(), VecNormBegin(), VecNormEnd(), MatNorm()
177: E*/
178: typedef enum {NORM_1=0,NORM_2=1,NORM_FROBENIUS=2,NORM_INFINITY=3,NORM_1_AND_2=4} NormType;
179: PETSC_EXTERN const char *const NormTypes[];
180: #define NORM_MAX NORM_INFINITY

182: /*MC
183:      NORM_1 - the one norm, ||v|| = sum_i | v_i |. ||A|| = max_j || v_*j ||, maximum column sum

185:    Level: beginner

187: .seealso:  NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_2, NORM_FROBENIUS,
188:            NORM_INFINITY, NORM_1_AND_2

190: M*/

192: /*MC
193:      NORM_2 - the two norm, ||v|| = sqrt(sum_i |v_i|^2) (vectors only)

195:    Level: beginner

197: .seealso:  NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_FROBENIUS,
198:            NORM_INFINITY, NORM_1_AND_2

200: M*/

202: /*MC
203:      NORM_FROBENIUS - ||A|| = sqrt(sum_ij |A_ij|^2), same as NORM_2 for vectors

205:    Level: beginner

207: .seealso:  NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2,
208:            NORM_INFINITY, NORM_1_AND_2

210: M*/

212: /*MC
213:      NORM_INFINITY - ||v|| = max_i |v_i|. ||A|| = max_i || v_i* ||, maximum row sum

215:    Level: beginner

217: .seealso:  NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2,
218:            NORM_FROBINIUS, NORM_1_AND_2

220: M*/

222: /*MC
223:      NORM_1_AND_2 - computes both the 1 and 2 norm of a vector

225:    Level: beginner

227: .seealso:  NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2,
228:            NORM_FROBINIUS, NORM_INFINITY

230: M*/

232: /*MC
233:      NORM_MAX - see NORM_INFINITY

235:    Level: beginner

237: M*/

239: PETSC_EXTERN PetscErrorCode VecNorm(Vec,NormType,PetscReal *);
240: PETSC_EXTERN PetscErrorCode VecNormAvailable(Vec,NormType,PetscBool *,PetscReal *);
241: PETSC_EXTERN PetscErrorCode VecNormalize(Vec,PetscReal *);
242: PETSC_EXTERN PetscErrorCode VecSum(Vec,PetscScalar*);
243: PETSC_EXTERN PetscErrorCode VecMax(Vec,PetscInt*,PetscReal *);
244: PETSC_EXTERN PetscErrorCode VecMin(Vec,PetscInt*,PetscReal *);
245: PETSC_EXTERN PetscErrorCode VecScale(Vec,PetscScalar);
246: PETSC_EXTERN PetscErrorCode VecCopy(Vec,Vec);
247: PETSC_EXTERN PetscErrorCode VecSetRandom(Vec,PetscRandom);
248: PETSC_EXTERN PetscErrorCode VecSet(Vec,PetscScalar);
249: PETSC_EXTERN PetscErrorCode VecSetInf(Vec);
250: PETSC_EXTERN PetscErrorCode VecSwap(Vec,Vec);
251: PETSC_EXTERN PetscErrorCode VecAXPY(Vec,PetscScalar,Vec);
252: PETSC_EXTERN PetscErrorCode VecAXPBY(Vec,PetscScalar,PetscScalar,Vec);
253: PETSC_EXTERN PetscErrorCode VecMAXPY(Vec,PetscInt,const PetscScalar[],Vec[]);
254: PETSC_EXTERN PetscErrorCode VecAYPX(Vec,PetscScalar,Vec);
255: PETSC_EXTERN PetscErrorCode VecWAXPY(Vec,PetscScalar,Vec,Vec);
256: PETSC_EXTERN PetscErrorCode VecAXPBYPCZ(Vec,PetscScalar,PetscScalar,PetscScalar,Vec,Vec);
257: PETSC_EXTERN PetscErrorCode VecPointwiseMax(Vec,Vec,Vec);
258: PETSC_EXTERN PetscErrorCode VecPointwiseMaxAbs(Vec,Vec,Vec);
259: PETSC_EXTERN PetscErrorCode VecPointwiseMin(Vec,Vec,Vec);
260: PETSC_EXTERN PetscErrorCode VecPointwiseMult(Vec,Vec,Vec);
261: PETSC_EXTERN PetscErrorCode VecPointwiseDivide(Vec,Vec,Vec);
262: PETSC_EXTERN PetscErrorCode VecMaxPointwiseDivide(Vec,Vec,PetscReal*);
263: PETSC_EXTERN PetscErrorCode VecShift(Vec,PetscScalar);
264: PETSC_EXTERN PetscErrorCode VecReciprocal(Vec);
265: PETSC_EXTERN PetscErrorCode VecPermute(Vec, IS, PetscBool );
266: PETSC_EXTERN PetscErrorCode VecSqrtAbs(Vec);
267: PETSC_EXTERN PetscErrorCode VecLog(Vec);
268: PETSC_EXTERN PetscErrorCode VecExp(Vec);
269: PETSC_EXTERN PetscErrorCode VecAbs(Vec);
270: PETSC_EXTERN PetscErrorCode VecDuplicate(Vec,Vec*);
271: PETSC_EXTERN PetscErrorCode VecDuplicateVecs(Vec,PetscInt,Vec*[]);
272: PETSC_EXTERN PetscErrorCode VecDestroyVecs(PetscInt, Vec*[]);
273: PETSC_EXTERN PetscErrorCode VecStrideNormAll(Vec,NormType,PetscReal[]);
274: PETSC_EXTERN PetscErrorCode VecStrideMaxAll(Vec,PetscInt [],PetscReal []);
275: PETSC_EXTERN PetscErrorCode VecStrideMinAll(Vec,PetscInt [],PetscReal []);
276: PETSC_EXTERN PetscErrorCode VecStrideScaleAll(Vec,const PetscScalar[]);
277: PETSC_EXTERN PetscErrorCode VecUniqueEntries(Vec,PetscInt*,PetscScalar**);

279: PETSC_EXTERN PetscErrorCode VecStrideNorm(Vec,PetscInt,NormType,PetscReal*);
280: PETSC_EXTERN PetscErrorCode VecStrideMax(Vec,PetscInt,PetscInt *,PetscReal *);
281: PETSC_EXTERN PetscErrorCode VecStrideMin(Vec,PetscInt,PetscInt *,PetscReal *);
282: PETSC_EXTERN PetscErrorCode VecStrideScale(Vec,PetscInt,PetscScalar);
283: PETSC_EXTERN PetscErrorCode VecStrideSet(Vec,PetscInt,PetscScalar);


286: PETSC_EXTERN PetscErrorCode VecStrideGather(Vec,PetscInt,Vec,InsertMode);
287: PETSC_EXTERN PetscErrorCode VecStrideScatter(Vec,PetscInt,Vec,InsertMode);
288: PETSC_EXTERN PetscErrorCode VecStrideGatherAll(Vec,Vec[],InsertMode);
289: PETSC_EXTERN PetscErrorCode VecStrideScatterAll(Vec[],Vec,InsertMode);

291: PETSC_EXTERN PetscErrorCode VecStrideSubSetScatter(Vec,PetscInt,const PetscInt[],const PetscInt[],Vec,InsertMode);
292: PETSC_EXTERN PetscErrorCode VecStrideSubSetGather(Vec,PetscInt,const PetscInt[],const PetscInt[],Vec,InsertMode);

294: PETSC_EXTERN PetscErrorCode VecSetValues(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
295: PETSC_EXTERN PetscErrorCode VecGetValues(Vec,PetscInt,const PetscInt[],PetscScalar[]);
296: PETSC_EXTERN PetscErrorCode VecAssemblyBegin(Vec);
297: PETSC_EXTERN PetscErrorCode VecAssemblyEnd(Vec);
298: PETSC_EXTERN PetscErrorCode VecStashSetInitialSize(Vec,PetscInt,PetscInt);
299: PETSC_EXTERN PetscErrorCode VecStashView(Vec,PetscViewer);
300: PETSC_EXTERN PetscErrorCode VecStashViewFromOptions(Vec,PetscObject,const char[]);
301: PETSC_EXTERN PetscErrorCode VecStashGetInfo(Vec,PetscInt*,PetscInt*,PetscInt*,PetscInt*);

303: /*MC
304:    VecSetValue - Set a single entry into a vector.

306:    Synopsis:
307:    #include <petscvec.h>
308:    PetscErrorCode VecSetValue(Vec v,PetscInt row,PetscScalar value, InsertMode mode);

310:    Not Collective

312:    Input Parameters:
313: +  v - the vector
314: .  row - the row location of the entry
315: .  value - the value to insert
316: -  mode - either INSERT_VALUES or ADD_VALUES

318:    Notes:
319:    For efficiency one should use VecSetValues() and set several or
320:    many values simultaneously if possible.

322:    These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd()
323:    MUST be called after all calls to VecSetValue() have been completed.

325:    VecSetValue() uses 0-based indices in Fortran as well as in C.

327:    Level: beginner

329: .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValueLocal()
330: M*/
331: PETSC_STATIC_INLINE PetscErrorCode VecSetValue(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValues(v,1,&i,&va,mode);}


334: PETSC_EXTERN PetscErrorCode VecSetBlockSize(Vec,PetscInt);
335: PETSC_EXTERN PetscErrorCode VecGetBlockSize(Vec,PetscInt*);
336: PETSC_EXTERN PetscErrorCode VecSetValuesBlocked(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode);

338: /* Dynamic creation and loading functions */
339: PETSC_EXTERN PetscFunctionList VecList;
340: PETSC_EXTERN PetscErrorCode VecSetType(Vec, VecType);
341: PETSC_EXTERN PetscErrorCode VecGetType(Vec, VecType *);
342: PETSC_EXTERN PetscErrorCode VecRegister(const char[],PetscErrorCode (*)(Vec));

344: PETSC_EXTERN PetscErrorCode VecScatterSetData(VecScatter,Vec,IS,Vec,IS);
345: PETSC_EXTERN PetscErrorCode VecScatterCreate(MPI_Comm,VecScatter *);
346: PETSC_EXTERN PetscErrorCode VecScatterBegin(VecScatter,Vec,Vec,InsertMode,ScatterMode);
347: PETSC_EXTERN PetscErrorCode VecScatterEnd(VecScatter,Vec,Vec,InsertMode,ScatterMode);
348: PETSC_EXTERN PetscErrorCode VecScatterDestroy(VecScatter*);
349: PETSC_EXTERN PetscErrorCode VecScatterSetUp(VecScatter);
350: PETSC_EXTERN PetscErrorCode VecScatterCopy(VecScatter,VecScatter *);
351: PETSC_EXTERN PetscErrorCode VecScatterView(VecScatter,PetscViewer);
352: PETSC_STATIC_INLINE PetscErrorCode VecScatterViewFromOptions(VecScatter A,PetscObject obj,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,obj,name);}
353: PETSC_EXTERN PetscErrorCode VecScatterRemap(VecScatter,PetscInt[],PetscInt[]);
354: PETSC_EXTERN PetscErrorCode VecScatterGetMerged(VecScatter,PetscBool *);

356: PETSC_EXTERN PetscErrorCode VecGetArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]);
357: PETSC_EXTERN PetscErrorCode VecRestoreArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]);
358: PETSC_EXTERN PetscErrorCode VecGetArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]);
359: PETSC_EXTERN PetscErrorCode VecRestoreArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]);
360: PETSC_EXTERN PetscErrorCode VecGetArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]);
361: PETSC_EXTERN PetscErrorCode VecRestoreArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]);
362: PETSC_EXTERN PetscErrorCode VecGetArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]);
363: PETSC_EXTERN PetscErrorCode VecRestoreArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]);

365: PETSC_EXTERN PetscErrorCode VecGetArray4dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]);
366: PETSC_EXTERN PetscErrorCode VecRestoreArray4dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]);
367: PETSC_EXTERN PetscErrorCode VecGetArray3dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]);
368: PETSC_EXTERN PetscErrorCode VecRestoreArray3dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]);
369: PETSC_EXTERN PetscErrorCode VecGetArray2dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]);
370: PETSC_EXTERN PetscErrorCode VecRestoreArray2dRead(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]);
371: PETSC_EXTERN PetscErrorCode VecGetArray1dRead(Vec,PetscInt,PetscInt,PetscScalar *[]);
372: PETSC_EXTERN PetscErrorCode VecRestoreArray1dRead(Vec,PetscInt,PetscInt,PetscScalar *[]);

374: PETSC_EXTERN PetscErrorCode VecPlaceArray(Vec,const PetscScalar[]);
375: PETSC_EXTERN PetscErrorCode VecResetArray(Vec);
376: PETSC_EXTERN PetscErrorCode VecReplaceArray(Vec,const PetscScalar[]);
377: PETSC_EXTERN PetscErrorCode VecGetArrays(const Vec[],PetscInt,PetscScalar**[]);
378: PETSC_EXTERN PetscErrorCode VecRestoreArrays(const Vec[],PetscInt,PetscScalar**[]);

380: PETSC_EXTERN PetscErrorCode VecView(Vec,PetscViewer);
381: PETSC_EXTERN PetscErrorCode VecEqual(Vec,Vec,PetscBool *);
382: PETSC_EXTERN PetscErrorCode VecLoad(Vec, PetscViewer);

384: PETSC_EXTERN PetscErrorCode VecGetSize(Vec,PetscInt*);
385: PETSC_EXTERN PetscErrorCode VecGetLocalSize(Vec,PetscInt*);
386: PETSC_EXTERN PetscErrorCode VecGetOwnershipRange(Vec,PetscInt*,PetscInt*);
387: PETSC_EXTERN PetscErrorCode VecGetOwnershipRanges(Vec,const PetscInt *[]);

389: PETSC_EXTERN PetscErrorCode VecSetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping);
390: PETSC_EXTERN PetscErrorCode VecSetValuesLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode);

392: /*MC
393:    VecSetValueLocal - Set a single entry into a vector using the local numbering

395:    Synopsis:
396:    #include <petscvec.h>
397:    PetscErrorCode VecSetValueLocal(Vec v,PetscInt row,PetscScalar value, InsertMode mode);

399:    Not Collective

401:    Input Parameters:
402: +  v - the vector
403: .  row - the row location of the entry
404: .  value - the value to insert
405: -  mode - either INSERT_VALUES or ADD_VALUES

407:    Notes:
408:    For efficiency one should use VecSetValues() and set several or
409:    many values simultaneously if possible.

411:    These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd()
412:    MUST be called after all calls to VecSetValues() have been completed.

414:    VecSetValues() uses 0-based indices in Fortran as well as in C.

416:    Level: beginner

418: .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValue()
419: M*/
420: PETSC_STATIC_INLINE PetscErrorCode VecSetValueLocal(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValuesLocal(v,1,&i,&va,mode);}

422: PETSC_EXTERN PetscErrorCode VecSetValuesBlockedLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
423: PETSC_EXTERN PetscErrorCode VecGetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping*);

425: PETSC_EXTERN PetscErrorCode VecDotBegin(Vec,Vec,PetscScalar *);
426: PETSC_EXTERN PetscErrorCode VecDotEnd(Vec,Vec,PetscScalar *);
427: PETSC_EXTERN PetscErrorCode VecTDotBegin(Vec,Vec,PetscScalar *);
428: PETSC_EXTERN PetscErrorCode VecTDotEnd(Vec,Vec,PetscScalar *);
429: PETSC_EXTERN PetscErrorCode VecNormBegin(Vec,NormType,PetscReal *);
430: PETSC_EXTERN PetscErrorCode VecNormEnd(Vec,NormType,PetscReal *);

432: PETSC_EXTERN PetscErrorCode VecMDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]);
433: PETSC_EXTERN PetscErrorCode VecMDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]);
434: PETSC_EXTERN PetscErrorCode VecMTDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]);
435: PETSC_EXTERN PetscErrorCode VecMTDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]);
436: PETSC_EXTERN PetscErrorCode PetscCommSplitReductionBegin(MPI_Comm);


439: typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES,VEC_IGNORE_NEGATIVE_INDICES,VEC_SUBSET_OFF_PROC_ENTRIES} VecOption;
440: PETSC_EXTERN PetscErrorCode VecSetOption(Vec,VecOption,PetscBool );

442: PETSC_EXTERN PetscErrorCode VecGetArray(Vec,PetscScalar**);
443: PETSC_EXTERN PetscErrorCode VecGetArrayRead(Vec,const PetscScalar**);
444: PETSC_EXTERN PetscErrorCode VecRestoreArray(Vec,PetscScalar**);
445: PETSC_EXTERN PetscErrorCode VecRestoreArrayRead(Vec,const PetscScalar**);
446: PETSC_EXTERN PetscErrorCode VecGetLocalVector(Vec,Vec);
447: PETSC_EXTERN PetscErrorCode VecRestoreLocalVector(Vec,Vec);
448: PETSC_EXTERN PetscErrorCode VecGetLocalVectorRead(Vec,Vec);
449: PETSC_EXTERN PetscErrorCode VecRestoreLocalVectorRead(Vec,Vec);

451: /*@C
452:    VecGetArrayPair - Accesses a pair of pointers for two vectors that may be common. When not common the first is read only

454:    Logically Collective on Vec

456:    Input Parameters:
457: +  x - the vector
458: -  y - the second vector

460:    Output Parameters:
461: +  xv - location to put pointer to the first array
462: -  yv - location to put pointer to the second array

464:    Level: developer

466:    Not available from Fortran

468: .seealso: VecGetArray(), VecGetArrayRead(), VecRestoreArrayPair()

470: @*/
471: PETSC_STATIC_INLINE PetscErrorCode VecGetArrayPair(Vec x,Vec y,PetscScalar **xv,PetscScalar **yv)
472: {

476:   VecGetArray(y,yv);
477:   if (x != y) {
478:     VecGetArrayRead(x,(const PetscScalar **)xv);
479:   } else {
480:     *xv = *yv;
481:   }
482:   return(0);
483: }

485: /*@C
486:    VecRestoreArrayPair - Returns a pair of pointers for two vectors that may be common. When not common the first is read only

488:    Logically Collective on Vec

490:    Input Parameters:
491: +  x - the vector
492: -  y - the second vector

494:    Output Parameters:
495: +  xv - location to put pointer to the first array
496: -  yv - location to put pointer to the second array

498:    Level: developer

500:    Not available from Fortran

502: .seealso: VecGetArray(), VecGetArrayRead(), VecGetArrayPair()

504: @*/
505: PETSC_STATIC_INLINE PetscErrorCode VecRestoreArrayPair(Vec x,Vec y,PetscScalar **xv,PetscScalar **yv)
506: {

510:   VecRestoreArray(y,yv);
511:   if (x != y) {
512:     VecRestoreArrayRead(x,(const PetscScalar **)xv);
513:   }
514:   return(0);
515: }

517: #if defined(PETSC_USE_DEBUG)
518: PETSC_EXTERN PetscErrorCode VecLockGet(Vec,PetscInt*);
519: PETSC_EXTERN PetscErrorCode VecLockPush(Vec);
520: PETSC_EXTERN PetscErrorCode VecLockPop(Vec);
521: #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)
522: #else
523: #define VecLockGet(x,arg)     *(arg) = 0
524: #define VecLockPush(x)        0
525: #define VecLockPop(x)         0
526: #define VecLocked(x,arg)
527: #endif

529: PETSC_EXTERN PetscErrorCode VecValidValues(Vec,PetscInt,PetscBool);

531: /*
532:     These numbers need to match the entries in
533:   the function table in vecimpl.h
534: */
535: typedef enum { VECOP_DUPLICATE = 0, VECOP_VIEW = 33, VECOP_LOAD = 41, VECOP_VIEWNATIVE = 68, VECOP_LOADNATIVE = 69 } VecOperation;
536: PETSC_EXTERN PetscErrorCode VecSetOperation(Vec,VecOperation,void(*)(void));

538: /*
539:      Routines for dealing with ghosted vectors:
540:   vectors with ghost elements at the end of the array.
541: */
542: PETSC_EXTERN PetscErrorCode VecMPISetGhost(Vec,PetscInt,const PetscInt[]);
543: PETSC_EXTERN PetscErrorCode VecCreateGhost(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*);
544: PETSC_EXTERN PetscErrorCode VecCreateGhostWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*);
545: PETSC_EXTERN PetscErrorCode VecCreateGhostBlock(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*);
546: PETSC_EXTERN PetscErrorCode VecCreateGhostBlockWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*);
547: PETSC_EXTERN PetscErrorCode VecGhostGetLocalForm(Vec,Vec*);
548: PETSC_EXTERN PetscErrorCode VecGhostRestoreLocalForm(Vec,Vec*);
549: PETSC_EXTERN PetscErrorCode VecGhostIsLocalForm(Vec,Vec,PetscBool*);
550: PETSC_EXTERN PetscErrorCode VecGhostUpdateBegin(Vec,InsertMode,ScatterMode);
551: PETSC_EXTERN PetscErrorCode VecGhostUpdateEnd(Vec,InsertMode,ScatterMode);

553: PETSC_EXTERN PetscErrorCode VecConjugate(Vec);

555: PETSC_EXTERN PetscErrorCode VecScatterCreateToAll(Vec,VecScatter*,Vec*);
556: PETSC_EXTERN PetscErrorCode VecScatterCreateToZero(Vec,VecScatter*,Vec*);

558: PETSC_EXTERN PetscErrorCode ISComplementVec(IS,Vec,IS*);
559: PETSC_EXTERN PetscErrorCode VecPow(Vec, PetscScalar);
560: PETSC_EXTERN PetscErrorCode VecMedian(Vec, Vec, Vec, Vec);
561: PETSC_EXTERN PetscErrorCode VecWhichInactive(Vec, Vec, Vec, Vec, PetscBool, IS *);
562: PETSC_EXTERN PetscErrorCode VecWhichBetween(Vec, Vec, Vec, IS *);
563: PETSC_EXTERN PetscErrorCode VecWhichBetweenOrEqual(Vec, Vec, Vec, IS *);
564: PETSC_EXTERN PetscErrorCode VecWhichGreaterThan(Vec, Vec, IS * );
565: PETSC_EXTERN PetscErrorCode VecWhichLessThan(Vec, Vec, IS *);
566: PETSC_EXTERN PetscErrorCode VecWhichEqual(Vec, Vec, IS *);
567: PETSC_EXTERN PetscErrorCode VecISAXPY(Vec, IS, PetscScalar,Vec);
568: PETSC_EXTERN PetscErrorCode VecISCopy(Vec, IS, ScatterMode, Vec);
569: PETSC_EXTERN PetscErrorCode VecISSet(Vec,IS, PetscScalar);
570: PETSC_EXTERN PetscErrorCode VecBoundGradientProjection(Vec, Vec, Vec, Vec, Vec);
571: PETSC_EXTERN PetscErrorCode VecStepBoundInfo(Vec,Vec,Vec,Vec,PetscReal*, PetscReal*,PetscReal*);
572: PETSC_EXTERN PetscErrorCode VecStepMax(Vec, Vec, PetscReal *);
573: PETSC_EXTERN PetscErrorCode VecStepMaxBounded(Vec,Vec,Vec,Vec,PetscReal*);

575: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaGetVector(PetscViewer, Vec);
576: PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutVector(PetscViewer, Vec);

578: /*S
579:      Vecs - Collection of vectors where the data for the vectors is stored in
580:             one contiguous memory

582:    Level: advanced

584:    Notes:
585:     Temporary construct for handling multiply right hand side solves

587:     This is faked by storing a single vector that has enough array space for
588:     n vectors

590:   Concepts: parallel decomposition

592: S*/
593:         struct _n_Vecs  {PetscInt n; Vec v;};
594: typedef struct _n_Vecs* Vecs;
595: PETSC_EXTERN PetscErrorCode VecsDestroy(Vecs);
596: PETSC_EXTERN PetscErrorCode VecsCreateSeq(MPI_Comm,PetscInt,PetscInt,Vecs*);
597: PETSC_EXTERN PetscErrorCode VecsCreateSeqWithArray(MPI_Comm,PetscInt,PetscInt,PetscScalar*,Vecs*);
598: PETSC_EXTERN PetscErrorCode VecsDuplicate(Vecs,Vecs*);

600: #if defined(PETSC_HAVE_VIENNACL)
601: typedef struct _p_PetscViennaCLIndices* PetscViennaCLIndices;
602: PETSC_EXTERN PetscErrorCode PetscViennaCLIndicesCreate(PetscInt, PetscInt*,PetscInt, PetscInt*,PetscViennaCLIndices*);
603: PETSC_EXTERN PetscErrorCode PetscViennaCLIndicesDestroy(PetscViennaCLIndices*);
604: PETSC_EXTERN PetscErrorCode VecViennaCLCopyToGPUSome_Public(Vec,PetscViennaCLIndices);
605: PETSC_EXTERN PetscErrorCode VecViennaCLCopyFromGPUSome_Public(Vec,PetscViennaCLIndices);
606: PETSC_EXTERN PetscErrorCode VecCreateSeqViennaCL(MPI_Comm,PetscInt,Vec*);
607: PETSC_EXTERN PetscErrorCode VecCreateMPIViennaCL(MPI_Comm,PetscInt,PetscInt,Vec*);
608: #endif
609: #if defined(PETSC_HAVE_CUDA)
610: typedef struct _p_PetscCUDAIndices* PetscCUDAIndices;
611: typedef struct _p_VecScatterCUDAIndices_StoS* VecScatterCUDAIndices_StoS;
612: typedef struct _p_VecScatterCUDAIndices_PtoP* VecScatterCUDAIndices_PtoP;
613: PETSC_EXTERN PetscErrorCode VecCUDACopyToGPUSome_Public(Vec,PetscCUDAIndices);
614: PETSC_EXTERN PetscErrorCode VecCUDACopyFromGPUSome_Public(Vec,PetscCUDAIndices);
615: PETSC_EXTERN PetscErrorCode VecScatterInitializeForGPU(VecScatter,Vec,ScatterMode);
616: PETSC_EXTERN PetscErrorCode VecScatterFinalizeForGPU(VecScatter);
617: PETSC_EXTERN PetscErrorCode VecCreateSeqCUDA(MPI_Comm,PetscInt,Vec*);
618: PETSC_EXTERN PetscErrorCode VecCreateSeqCUDAWithArray(MPI_Comm,PetscInt,PetscInt,const PetscScalar*,Vec*);
619: PETSC_EXTERN PetscErrorCode VecCreateMPICUDA(MPI_Comm,PetscInt,PetscInt,Vec*);
620: PETSC_EXTERN PetscErrorCode VecCreateMPICUDAWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscScalar*,Vec*);
621: #endif

623: PETSC_EXTERN PetscErrorCode VecNestGetSubVecs(Vec,PetscInt*,Vec**);
624: PETSC_EXTERN PetscErrorCode VecNestGetSubVec(Vec,PetscInt,Vec*);
625: PETSC_EXTERN PetscErrorCode VecNestSetSubVecs(Vec,PetscInt,PetscInt*,Vec*);
626: PETSC_EXTERN PetscErrorCode VecNestSetSubVec(Vec,PetscInt,Vec);
627: PETSC_EXTERN PetscErrorCode VecCreateNest(MPI_Comm,PetscInt,IS*,Vec*,Vec*);
628: PETSC_EXTERN PetscErrorCode VecNestGetSize(Vec,PetscInt*);

630: PETSC_EXTERN PetscErrorCode PetscOptionsGetVec(PetscOptions,const char[],const char[],Vec,PetscBool*);
631: PETSC_EXTERN PetscErrorCode VecChop(Vec,PetscReal);

633: PETSC_EXTERN PetscErrorCode VecGetLayout(Vec,PetscLayout*);
634: PETSC_EXTERN PetscErrorCode VecSetLayout(Vec,PetscLayout);

636: PETSC_EXTERN PetscErrorCode PetscSectionVecView(PetscSection, Vec, PetscViewer);
637: PETSC_EXTERN PetscErrorCode VecGetValuesSection(Vec, PetscSection, PetscInt, PetscScalar **);
638: PETSC_EXTERN PetscErrorCode VecSetValuesSection(Vec, PetscSection, PetscInt, PetscScalar [], InsertMode);
639: PETSC_EXTERN PetscErrorCode PetscSectionVecNorm(PetscSection, PetscSection, Vec, NormType, PetscReal []);

641: PETSC_EXTERN PetscErrorCode PetscSFCreateFromZero(MPI_Comm,Vec,PetscSF*);

643: /*S
644:   VecTagger - Object used to manage the tagging of a subset of indices based on the values of a vector.  The
645:               motivating application is the selection of cells for refinement or coarsening based on vector containing
646:               the values in an error indicator metric.

648:   Level: advanced
649: S*/
650: typedef struct _p_VecTagger *VecTagger;

652: /*J
653:   VecTaggerType - String with the name of a VecTagger type

655:   Level: advanced
656: J*/
657: typedef const char* VecTaggerType;
658: /* tag where the vector values are in a box of explicitly defined values */
659: #define VECTAGGERABSOLUTE   "absolute"
660: /* tag where the vector values are in a box of values relative to the set of all values in the vector */
661: #define VECTAGGERRELATIVE   "relative"
662: /* tag where the vector values are in a relative range of the *cumulative distribution* of values in the vector */
663: #define VECTAGGERCDF        "cdf"
664: /* tag a vector as the union of other tags */
665: #define VECTAGGEROR         "or"
666: /* tag a vector as the intersection of other tags */
667: #define VECTAGGERAND        "and"

669: PETSC_EXTERN PetscClassId VEC_TAGGER_CLASSID;
670: PETSC_EXTERN PetscFunctionList VecTaggerList;
671: PETSC_EXTERN PetscErrorCode VecTaggerRegister(const char[],PetscErrorCode (*) (VecTagger));

673: PETSC_EXTERN PetscErrorCode VecTaggerCreate(MPI_Comm,VecTagger *);
674: PETSC_EXTERN PetscErrorCode VecTaggerSetBlockSize(VecTagger,PetscInt);
675: PETSC_EXTERN PetscErrorCode VecTaggerGetBlockSize(VecTagger,PetscInt*);
676: PETSC_EXTERN PetscErrorCode VecTaggerSetType(VecTagger,VecTaggerType);
677: PETSC_EXTERN PetscErrorCode VecTaggerGetType(VecTagger,VecTaggerType *);
678: PETSC_EXTERN PetscErrorCode VecTaggerSetInvert(VecTagger,PetscBool);
679: PETSC_EXTERN PetscErrorCode VecTaggerGetInvert(VecTagger,PetscBool*);
680: PETSC_EXTERN PetscErrorCode VecTaggerSetFromOptions(VecTagger);
681: PETSC_EXTERN PetscErrorCode VecTaggerSetUp(VecTagger);
682: PETSC_EXTERN PetscErrorCode VecTaggerView(VecTagger,PetscViewer);
683: PETSC_EXTERN PetscErrorCode VecTaggerComputeIS(VecTagger,Vec,IS *);
684: PETSC_EXTERN PetscErrorCode VecTaggerDestroy(VecTagger *);

686: /*S
687:    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
688:    such that real(min) <= real(z) <= real(max) and imag(min) <= imag(z) <= imag(max).  INF is an acceptable endpoint.

690:    Level: beginner

692: .seealso: VecTaggerComputeIntervals()
693: S*/
694: typedef struct {
695:   PetscScalar min;
696:   PetscScalar max;
697: } VecTaggerBox;
698: PETSC_EXTERN PetscErrorCode VecTaggerComputeBoxes(VecTagger,Vec,PetscInt *,VecTaggerBox **);


701: PETSC_EXTERN PetscErrorCode VecTaggerAbsoluteSetBox(VecTagger,VecTaggerBox *);
702: PETSC_EXTERN PetscErrorCode VecTaggerAbsoluteGetBox(VecTagger,const VecTaggerBox **);

704: PETSC_EXTERN PetscErrorCode VecTaggerRelativeSetBox(VecTagger,VecTaggerBox *);
705: PETSC_EXTERN PetscErrorCode VecTaggerRelativeGetBox(VecTagger,const VecTaggerBox **);

707: PETSC_EXTERN PetscErrorCode VecTaggerCDFSetBox(VecTagger,VecTaggerBox *);
708: PETSC_EXTERN PetscErrorCode VecTaggerCDFGetBox(VecTagger,const VecTaggerBox **);

710: /*E
711:   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.

713:   Level: advanced
714: .seealso: VecTaggerCDFSetMethod(), VecTaggerCDFMethods
715: E*/
716: typedef enum {VECTAGGER_CDF_GATHER,VECTAGGER_CDF_ITERATIVE,VECTAGGER_CDF_NUM_METHODS} VecTaggerCDFMethod;
717: PETSC_EXTERN const char *const VecTaggerCDFMethods[];

719: PETSC_EXTERN PetscErrorCode VecTaggerCDFSetMethod(VecTagger,VecTaggerCDFMethod);
720: PETSC_EXTERN PetscErrorCode VecTaggerCDFGetMethod(VecTagger,VecTaggerCDFMethod*);
721: PETSC_EXTERN PetscErrorCode VecTaggerCDFIterativeSetTolerances(VecTagger,PetscInt,PetscReal,PetscReal);
722: PETSC_EXTERN PetscErrorCode VecTaggerCDFIterativeGetTolerances(VecTagger,PetscInt*,PetscReal*,PetscReal*);

724: PETSC_EXTERN PetscErrorCode VecTaggerOrSetSubs(VecTagger,PetscInt,VecTagger*,PetscCopyMode);
725: PETSC_EXTERN PetscErrorCode VecTaggerOrGetSubs(VecTagger,PetscInt*,VecTagger**);

727: PETSC_EXTERN PetscErrorCode VecTaggerAndSetSubs(VecTagger,PetscInt,VecTagger*,PetscCopyMode);
728: PETSC_EXTERN PetscErrorCode VecTaggerAndGetSubs(VecTagger,PetscInt*,VecTagger**);

730: PETSC_EXTERN PetscErrorCode VecTaggerInitializePackage(void);
731: PETSC_EXTERN PetscErrorCode VecTaggerFinalizePackage(void);

733: #endif