Actual source code: petscvec.h
1: /* $Id: petscvec.h,v 1.127 2001/09/11 16:31:30 bsmith Exp $ */
2: /*
3: Defines the vector component of PETSc. Vectors generally represent
4: degrees of freedom for finite element/finite difference functions
5: on a grid. They have more mathematical structure then simple arrays.
6: */
8: #ifndef __PETSCVEC_H
10: #include petscis.h
11: #include petscsys.h
13: /*S
14: PetscMap - Abstract PETSc object that defines the layout of vector and
15: matrices across processors
17: Level: advanced
19: Notes:
20: Does not play a role in the PETSc design, can be ignored
22: Concepts: parallel decomposition
24: .seealso: PetscMapCreateMPI()
25: S*/
26: typedef struct _p_PetscMap* PetscMap;
28: #define MAP_SEQ "seq"
29: #define MAP_MPI "mpi"
30: typedef char *PetscMapType;
32: #define MAP_SER_MPI_BINARY "mpi_binary"
33: typedef char *PetscMapSerializeType;
35: /* Logging support */
36: extern int MAP_COOKIE;
38: EXTERN int PetscMapCreate(MPI_Comm,PetscMap*);
39: EXTERN int PetscMapCreateMPI(MPI_Comm,int,int,PetscMap*);
40: EXTERN int PetscMapSerialize(MPI_Comm,PetscMap *,PetscViewer,PetscTruth);
41: EXTERN int PetscMapSetFromOptions(PetscMap);
42: EXTERN int PetscMapPrintHelp(PetscMap);
43: EXTERN int PetscMapDestroy(PetscMap);
45: EXTERN int PetscMapSetLocalSize(PetscMap,int);
46: EXTERN int PetscMapGetLocalSize(PetscMap,int *);
47: EXTERN int PetscMapSetSize(PetscMap,int);
48: EXTERN int PetscMapGetSize(PetscMap,int *);
49: EXTERN int PetscMapGetLocalRange(PetscMap,int *,int *);
50: EXTERN int PetscMapGetGlobalRange(PetscMap,int *[]);
52: /* Dynamic creation and loading functions */
53: extern PetscFList PetscMapList;
54: extern PetscTruth PetscMapRegisterAllCalled;
55: EXTERN int PetscMapSetType(PetscMap, PetscMapType);
56: EXTERN int PetscMapGetType(PetscMap, PetscMapType *);
57: EXTERN int PetscMapRegister(const char[],const char[],const char[],int(*)(PetscMap));
58: EXTERN int PetscMapRegisterAll(const char []);
59: EXTERN int PetscMapRegisterDestroy(void);
60: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
61: #define PetscMapRegisterDynamic(a,b,c,d) PetscMapRegister(a,b,c,0)
62: #else
63: #define PetscMapRegisterDynamic(a,b,c,d) PetscMapRegister(a,b,c,d)
64: #endif
66: extern PetscFList PetscMapSerializeList;
67: extern PetscTruth PetscMapSerializeRegisterAllCalled;
68: EXTERN int PetscMapSetSerializeType(PetscMap, PetscMapSerializeType);
69: EXTERN int PetscMapGetSerializeType(PetscMap, PetscMapSerializeType *);
70: EXTERN int PetscMapSerializeRegister(const char [], const char [], const char [], int (*)(MPI_Comm, PetscMap *, PetscViewer, PetscTruth));
71: EXTERN int PetscMapSerializeRegisterAll(const char []);
72: EXTERN int PetscMapSerializeRegisterDestroy(void);
73: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
74: #define PetscMapSerializeRegisterDynamic(a,b,c,d) PetscMapSerializeRegister(a,b,c,0)
75: #else
76: #define PetscMapSerializeRegisterDynamic(a,b,c,d) PetscMapSerializeRegister(a,b,c,d)
77: #endif
79: /*S
80: Vec - Abstract PETSc vector object
82: Level: beginner
84: Concepts: field variables, unknowns, arrays
86: .seealso: VecCreate(), VecType, VecSetType()
87: S*/
88: typedef struct _p_Vec* Vec;
90: /*S
91: VecScatter - Object used to manage communication of data
92: between vectors in parallel. Manages both scatters and gathers
94: Level: beginner
96: Concepts: scatter
98: .seealso: VecScatterCreate(), VecScatterBegin(), VecScatterEnd()
99: S*/
100: typedef struct _p_VecScatter* VecScatter;
102: /*E
103: VecType - String with the name of a PETSc vector or the creation function
104: with an optional dynamic library name, for example
105: http://www.mcs.anl.gov/petsc/lib.a:myveccreate()
107: Level: beginner
109: .seealso: VecSetType(), Vec
110: E*/
111: #define VECSEQ "seq"
112: #define VECMPI "mpi"
113: #define VECFETI "feti"
114: #define VECSHARED "shared"
115: #define VECESI "esi"
116: #define VECPETSCESI "petscesi"
117: typedef char* VecType;
119: #define VEC_SER_SEQ_BINARY "seq_binary"
120: #define VEC_SER_MPI_BINARY "mpi_binary"
121: typedef char *VecSerializeType;
123: /* Logging support */
124: #define VEC_FILE_COOKIE 1211214
125: extern int VEC_COOKIE;
126: extern int VEC_SCATTER_COOKIE;
127: extern int VEC_View, VEC_Max, VEC_Min, VEC_DotBarrier, VEC_Dot, VEC_MDotBarrier, VEC_MDot, VEC_TDot, VEC_MTDot, VEC_NormBarrier;
128: extern int VEC_Norm, VEC_Normalize, VEC_Scale, VEC_Copy, VEC_Set, VEC_AXPY, VEC_AYPX, VEC_WAXPY, VEC_MAXPY, VEC_Swap, VEC_AssemblyBegin;
129: extern int VEC_AssemblyEnd, VEC_PointwiseMult, VEC_SetValues, VEC_Load, VEC_ScatterBarrier, VEC_ScatterBegin, VEC_ScatterEnd;
130: extern int VEC_SetRandom, VEC_ReduceArithmetic, VEC_ReduceBarrier, VEC_ReduceCommunication;
132: EXTERN int VecInitializePackage(char *);
134: EXTERN int VecCreate(MPI_Comm,Vec *);
135: EXTERN int VecCreateSeq(MPI_Comm,int,Vec*);
136: EXTERN int VecCreateMPI(MPI_Comm,int,int,Vec*);
137: EXTERN int VecCreateSeqWithArray(MPI_Comm,int,const PetscScalar[],Vec*);
138: EXTERN int VecCreateMPIWithArray(MPI_Comm,int,int,const PetscScalar[],Vec*);
139: EXTERN int VecCreateShared(MPI_Comm,int,int,Vec*);
140: EXTERN int VecSerialize(MPI_Comm,Vec *,PetscViewer,PetscTruth);
141: EXTERN int VecSetFromOptions(Vec);
142: EXTERN int VecPrintHelp(Vec);
143: EXTERN int VecDestroy(Vec);
145: EXTERN int VecSetSizes(Vec,int,int);
147: EXTERN int VecDot(Vec,Vec,PetscScalar*);
148: EXTERN int VecTDot(Vec,Vec,PetscScalar*);
149: EXTERN int VecMDot(int,Vec,const Vec[],PetscScalar*);
150: EXTERN int VecMTDot(int,Vec,const Vec[],PetscScalar*);
152: /*E
153: NormType - determines what type of norm to compute
155: Level: beginner
157: .seealso: VecNorm(), VecNormBegin(), VecNormEnd(), MatNorm()
158: E*/
159: typedef enum {NORM_1=1,NORM_2=2,NORM_FROBENIUS=3,NORM_INFINITY=4,NORM_1_AND_2=5} NormType;
160: #define NORM_MAX NORM_INFINITY
162: EXTERN int VecNorm(Vec,NormType,PetscReal *);
163: EXTERN int VecNormalize(Vec,PetscReal *);
164: EXTERN int VecSum(Vec,PetscScalar*);
165: EXTERN int VecMax(Vec,int*,PetscReal *);
166: EXTERN int VecMin(Vec,int*,PetscReal *);
167: EXTERN int VecScale(const PetscScalar *a,Vec v);
168: EXTERN int VecCopy(Vec,Vec);
169: EXTERN int VecSetRandom(PetscRandom,Vec);
170: EXTERN int VecSet(const PetscScalar*,Vec);
171: EXTERN int VecSwap(Vec,Vec);
172: EXTERN int VecAXPY(const PetscScalar*,Vec,Vec);
173: EXTERN int VecAXPBY(const PetscScalar*,const PetscScalar *,Vec,Vec);
174: EXTERN int VecMAXPY(int,const PetscScalar*,Vec,Vec*);
175: EXTERN int VecAYPX(const PetscScalar*,Vec,Vec);
176: EXTERN int VecWAXPY(const PetscScalar*,Vec,Vec,Vec);
177: EXTERN int VecPointwiseMult(Vec,Vec,Vec);
178: EXTERN int VecPointwiseDivide(Vec,Vec,Vec);
179: EXTERN int VecMaxPointwiseDivide(Vec,Vec,PetscReal*);
180: EXTERN int VecShift(const PetscScalar*,Vec);
181: EXTERN int VecReciprocal(Vec);
182: EXTERN int VecPermute(Vec, IS, PetscTruth);
183: EXTERN int VecSqrt(Vec);
184: EXTERN int VecAbs(Vec);
185: EXTERN int VecDuplicate(Vec,Vec*);
186: EXTERN int VecDuplicateVecs(Vec,int,Vec*[]);
187: EXTERN int VecDestroyVecs(const Vec[],int);
188: EXTERN int VecGetPetscMap(Vec,PetscMap*);
190: EXTERN int VecStrideNormAll(Vec,NormType,PetscReal*);
191: EXTERN int VecStrideMaxAll(Vec,int *,PetscReal *);
192: EXTERN int VecStrideMinAll(Vec,int *,PetscReal *);
193: EXTERN int VecStrideScaleAll(Vec,PetscScalar*);
195: EXTERN int VecStrideNorm(Vec,int,NormType,PetscReal*);
196: EXTERN int VecStrideMax(Vec,int,int *,PetscReal *);
197: EXTERN int VecStrideMin(Vec,int,int *,PetscReal *);
198: EXTERN int VecStrideScale(Vec,int,PetscScalar*);
199: EXTERN int VecStrideGather(Vec,int,Vec,InsertMode);
200: EXTERN int VecStrideScatter(Vec,int,Vec,InsertMode);
201: EXTERN int VecStrideGatherAll(Vec,Vec*,InsertMode);
202: EXTERN int VecStrideScatterAll(Vec*,Vec,InsertMode);
204: EXTERN int VecSetValues(Vec,int,const int[],const PetscScalar[],InsertMode);
205: EXTERN int VecAssemblyBegin(Vec);
206: EXTERN int VecAssemblyEnd(Vec);
207: EXTERN int VecSetStashInitialSize(Vec,int,int);
208: EXTERN int VecStashView(Vec,PetscViewer);
210: /*MC
211: VecSetValue - Set a single entry into a vector.
213: Synopsis:
214: int VecSetValue(Vec v,int row,PetscScalar value, InsertMode mode);
216: Not Collective
218: Input Parameters:
219: + v - the vector
220: . row - the row location of the entry
221: . value - the value to insert
222: - mode - either INSERT_VALUES or ADD_VALUES
224: Notes:
225: For efficiency one should use VecSetValues() and set several or
226: many values simultaneously if possible.
228: Note that VecSetValue() does NOT return an error code (since this
229: is checked internally).
231: These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd()
232: MUST be called after all calls to VecSetValues() have been completed.
234: VecSetValues() uses 0-based indices in Fortran as well as in C.
236: Level: beginner
238: .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal()
239: M*/
240: #define VecSetValue(v,i,va,mode) 0;\
241: {int _ierr,_row = i; PetscScalar _va = va; \
242: _VecSetValues(v,1,&_row,&_va,mode);CHKERRQ(_ierr); \
243: }
245: EXTERN int VecSetBlockSize(Vec,int);
246: EXTERN int VecGetBlockSize(Vec,int*);
247: EXTERN int VecSetValuesBlocked(Vec,int,const int[],const PetscScalar[],InsertMode);
249: /* Dynamic creation and loading functions */
250: extern PetscFList VecList;
251: extern PetscTruth VecRegisterAllCalled;
252: EXTERN int VecSetType(Vec, VecType);
253: EXTERN int VecGetType(Vec, VecType *);
254: EXTERN int VecRegister(const char[],const char[],const char[],int(*)(Vec));
255: EXTERN int VecRegisterAll(const char []);
256: EXTERN int VecRegisterDestroy(void);
258: /*MC
259: VecRegisterDynamic - Adds a new vector component implementation
261: Synopsis:
262: VecRegisterDynamic(char *name, char *path, char *func_name, int (*create_func)(Vec))
264: Not Collective
266: Input Parameters:
267: + name - The name of a new user-defined creation routine
268: . path - The path (either absolute or relative) of the library containing this routine
269: . func_name - The name of routine to create method context
270: - create_func - The creation routine itself
272: Notes:
273: VecRegisterDynamic() may be called multiple times to add several user-defined vectors
275: If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.
277: Sample usage:
278: .vb
279: VecRegisterDynamic("my_vec","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyVectorCreate", MyVectorCreate);
280: .ve
282: Then, your vector type can be chosen with the procedural interface via
283: .vb
284: VecCreate(MPI_Comm, Vec *);
285: VecSetType(Vec,"my_vector_name");
286: .ve
287: or at runtime via the option
288: .vb
289: -vec_type my_vector_name
290: .ve
292: Notes: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
293: If your function is not being put into a shared library then use VecRegister() instead
294:
295: Level: advanced
297: .keywords: Vec, register
298: .seealso: VecRegisterAll(), VecRegisterDestroy(), VecRegister()
299: M*/
300: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
301: #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,0)
302: #else
303: #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,d)
304: #endif
306: extern PetscFList VecSerializeList;
307: extern PetscTruth VecSerializeRegisterAllCalled;
308: EXTERN int VecSetSerializeType(Vec, VecSerializeType);
309: EXTERN int VecGetSerializeType(Vec, VecSerializeType *);
310: EXTERN int VecSerializeRegister(const char [], const char [], const char [], int (*)(MPI_Comm, Vec *, PetscViewer, PetscTruth));
311: EXTERN int VecSerializeRegisterAll(const char []);
312: EXTERN int VecSerializeRegisterDestroy(void);
314: /*MC
315: VecSerializeRegisterDynamic - Adds a serialization method to the vec package.
317: Synopsis:
319: VecSerializeRegisterDynamic(char *name, char *path, char *func_name,
320: int (*serialize_func)(MPI_Comm, Vec *, PetscViewer, PetscTruth))
322: Not Collective
324: Input Parameters:
325: + name - The name of a new user-defined serialization routine
326: . path - The path (either absolute or relative) of the library containing this routine
327: . func_name - The name of the serialization routine
328: - serialize_func - The serialization routine itself
330: Notes:
331: VecSerializeRegister() may be called multiple times to add several user-defined serializers.
333: If dynamic libraries are used, then the fourth input argument (serialize_func) is ignored.
335: Sample usage:
336: .vb
337: VecSerializeRegisterDynamic("my_store", "/home/username/my_lib/lib/libO/solaris/libmy.a", "MyStoreFunc", MyStoreFunc);
338: .ve
340: Then, your serialization can be chosen with the procedural interface via
341: .vb
342: VecSetSerializeType(vec, "my_store")
343: .ve
344: or at runtime via the option
345: .vb
346: -vec_serialize_type my_store
347: .ve
349: Note: $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values.
351: Level: advanced
353: .keywords: Vec, register
354: .seealso: VecSerializeRegisterAll(), VecSerializeRegisterDestroy()
355: M*/
356: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
357: #define VecSerializeRegisterDynamic(a,b,c,d) VecSerializeRegister(a,b,c,0)
358: #else
359: #define VecSerializeRegisterDynamic(a,b,c,d) VecSerializeRegister(a,b,c,d)
360: #endif
362: EXTERN int VecScatterCreate(Vec,IS,Vec,IS,VecScatter *);
363: EXTERN int VecScatterPostRecvs(Vec,Vec,InsertMode,ScatterMode,VecScatter);
364: EXTERN int VecScatterBegin(Vec,Vec,InsertMode,ScatterMode,VecScatter);
365: EXTERN int VecScatterEnd(Vec,Vec,InsertMode,ScatterMode,VecScatter);
366: EXTERN int VecScatterDestroy(VecScatter);
367: EXTERN int VecScatterCopy(VecScatter,VecScatter *);
368: EXTERN int VecScatterView(VecScatter,PetscViewer);
369: EXTERN int VecScatterRemap(VecScatter,int *,int*);
371: typedef enum {PIPELINE_DOWN=0,PIPELINE_UP=1} PipelineDirection;
372: typedef enum {PIPELINE_NONE=1,PIPELINE_SEQUENTIAL=2,
373: PIPELINE_REDBLACK=3,PIPELINE_MULTICOLOR=4} PipelineType;
375: typedef struct _p_VecPipeline* VecPipeline;
377: EXTERN int VecPipelineCreate(MPI_Comm,Vec,IS,Vec,IS,VecPipeline *);
378: EXTERN int VecPipelineSetType(VecPipeline,PipelineType,PetscObject);
379: EXTERN int VecPipelineSetup(VecPipeline);
380: EXTERN int VecPipelineBegin(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
381: EXTERN int VecPipelineEnd(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline);
382: EXTERN int VecPipelineView(VecPipeline,PetscViewer);
383: EXTERN int VecPipelineDestroy(VecPipeline);
385: EXTERN int VecGetArray(Vec,PetscScalar*[]);
386: EXTERN int VecRestoreArray(Vec,PetscScalar*[]);
387: EXTERN int VecGetArray4d(Vec,int,int,int,int,int,int,int,int,PetscScalar****[]);
388: EXTERN int VecRestoreArray4d(Vec,int,int,int,int,int,int,int,int,PetscScalar****[]);
389: EXTERN int VecGetArray3d(Vec,int,int,int,int,int,int,PetscScalar***[]);
390: EXTERN int VecRestoreArray3d(Vec,int,int,int,int,int,int,PetscScalar***[]);
391: EXTERN int VecGetArray2d(Vec,int,int,int,int,PetscScalar**[]);
392: EXTERN int VecRestoreArray2d(Vec,int,int,int,int,PetscScalar**[]);
393: EXTERN int VecGetArray1d(Vec,int,int,PetscScalar *[]);
394: EXTERN int VecRestoreArray1d(Vec,int,int,PetscScalar *[]);
396: EXTERN int VecPlaceArray(Vec,const PetscScalar[]);
397: EXTERN int VecResetArray(Vec);
398: EXTERN int VecReplaceArray(Vec,const PetscScalar[]);
399: EXTERN int VecGetArrays(const Vec[],int,PetscScalar**[]);
400: EXTERN int VecRestoreArrays(const Vec[],int,PetscScalar**[]);
402: EXTERN int VecValid(Vec,PetscTruth*);
403: EXTERN int VecView(Vec,PetscViewer);
404: EXTERN int VecViewFromOptions(Vec, char *);
405: EXTERN int VecEqual(Vec,Vec,PetscTruth*);
406: EXTERN int VecLoad(PetscViewer,Vec*);
407: EXTERN int VecLoadIntoVector(PetscViewer,Vec);
409: EXTERN int VecGetSize(Vec,int*);
410: EXTERN int VecGetLocalSize(Vec,int*);
411: EXTERN int VecGetOwnershipRange(Vec,int*,int*);
413: EXTERN int VecSetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping);
414: EXTERN int VecSetValuesLocal(Vec,int,const int[],const PetscScalar[],InsertMode);
415: EXTERN int VecSetLocalToGlobalMappingBlock(Vec,ISLocalToGlobalMapping);
416: EXTERN int VecSetValuesBlockedLocal(Vec,int,const int[],const PetscScalar[],InsertMode);
418: EXTERN int VecDotBegin(Vec,Vec,PetscScalar *);
419: EXTERN int VecDotEnd(Vec,Vec,PetscScalar *);
420: EXTERN int VecTDotBegin(Vec,Vec,PetscScalar *);
421: EXTERN int VecTDotEnd(Vec,Vec,PetscScalar *);
422: EXTERN int VecNormBegin(Vec,NormType,PetscReal *);
423: EXTERN int VecNormEnd(Vec,NormType,PetscReal *);
425: typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES,VEC_TREAT_OFF_PROC_ENTRIES} VecOption;
426: EXTERN int VecSetOption(Vec,VecOption);
428: EXTERN int VecContourScale(Vec,PetscReal,PetscReal);
430: /*
431: These numbers need to match the entries in
432: the function table in src/vec/vecimpl.h
433: */
434: typedef enum { VECOP_VIEW = 32,
435: VECOP_LOADINTOVECTOR = 38
436: } VecOperation;
437: EXTERN int VecSetOperation(Vec,VecOperation,void(*)(void));
439: /*
440: Routines for dealing with ghosted vectors:
441: vectors with ghost elements at the end of the array.
442: */
443: EXTERN int VecCreateGhost(MPI_Comm,int,int,int,const int[],Vec*);
444: EXTERN int VecCreateGhostWithArray(MPI_Comm,int,int,int,const int[],const PetscScalar[],Vec*);
445: EXTERN int VecCreateGhostBlock(MPI_Comm,int,int,int,int,const int[],Vec*);
446: EXTERN int VecCreateGhostBlockWithArray(MPI_Comm,int,int,int,int,const int[],const PetscScalar[],Vec*);
447: EXTERN int VecGhostGetLocalForm(Vec,Vec*);
448: EXTERN int VecGhostRestoreLocalForm(Vec,Vec*);
449: EXTERN int VecGhostUpdateBegin(Vec,InsertMode,ScatterMode);
450: EXTERN int VecGhostUpdateEnd(Vec,InsertMode,ScatterMode);
452: EXTERN int VecConjugate(Vec);
454: EXTERN int VecConvertMPIToSeqAll(Vec vin,Vec *vout);
455: EXTERN int VecConvertMPIToMPIZero(Vec vin,Vec *vout);
458: EXTERN int VecESISetType(Vec,char*);
459: EXTERN int VecESISetFromOptions(Vec);
461: EXTERN int PetscViewerMathematicaGetVector(PetscViewer, Vec);
462: EXTERN int PetscViewerMathematicaPutVector(PetscViewer, Vec);
464: /*S
465: Vecs - Collection of vectors where the data for the vectors is stored in
466: one continquous memory
468: Level: advanced
470: Notes:
471: Temporary construct for handling multiply right hand side solves
473: This is faked by storing a single vector that has enough array space for
474: n vectors
476: Concepts: parallel decomposition
478: S*/
479: struct _p_Vecs {int n; Vec v;};
480: typedef struct _p_Vecs* Vecs;
481: #define VecsDestroy(x) (VecDestroy((x)->v) || PetscFree(x))
482: #define VecsCreateSeq(comm,p,m,x) (PetscNew(struct _p_Vecs,x) || VecCreateSeq(comm,p*m,&(*(x))->v) || (-1 == ((*(x))->n = (m))))
483: #define VecsCreateSeqWithArray(comm,p,m,a,x) (PetscNew(struct _p_Vecs,x) || VecCreateSeqWithArray(comm,p*m,a,&(*(x))->v) || (-1 == ((*(x))->n = (m))))
484: #define VecsDuplicate(x,y) (PetscNew(struct _p_Vecs,y) || VecDuplicate(x->v,&(*(y))->v) || (-1 == ((*(y))->n = (x)->n)))
485: #endif