1 /* $Id: vec.h,v 1.96 1999/05/12 03:35:01 bsmith Exp bsmith $ */ 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 */ 7 8 #ifndef __VEC_H 9 #define __VEC_H 10 #include "is.h" 11 #include "sys.h" 12 13 #define VEC_COOKIE PETSC_COOKIE+3 14 #define MAP_COOKIE PETSC_COOKIE+22 15 #define VEC_SCATTER_COOKIE PETSC_COOKIE+4 16 17 typedef struct _p_Map* Map; 18 typedef struct _p_Vec* Vec; 19 typedef struct _p_VecScatter* VecScatter; 20 #define VEC_SEQ "seq" 21 #define VEC_MPI "mpi" 22 #define VEC_SHARED "shared" 23 typedef char* VecType; 24 25 extern int VecCreateSeq(MPI_Comm,int,Vec*); 26 extern int MapCreateMPI(MPI_Comm,int,int,Map*); 27 extern int VecCreateMPI(MPI_Comm,int,int,Vec*); 28 extern int VecCreateSeqWithArray(MPI_Comm,int,const Scalar[],Vec*); 29 extern int VecCreateMPIWithArray(MPI_Comm,int,int,const Scalar[],Vec*); 30 extern int VecCreateShared(MPI_Comm,int,int,Vec*); 31 extern int VecCreate(MPI_Comm,int,int,Vec*); 32 extern int VecSetType(Vec,VecType); 33 extern int VecSetFromOptions(Vec); 34 35 extern int VecDestroy(Vec); 36 37 extern int MapDestroy(Map); 38 extern int MapGetLocalSize(Map,int *); 39 extern int MapGetSize(Map,int *); 40 extern int MapGetLocalRange(Map,int *,int *); 41 extern int MapGetGlobalRange(Map,int *[]); 42 43 extern int VecDot(Vec,Vec,Scalar*); 44 extern int VecTDot(Vec,Vec,Scalar*); 45 extern int VecMDot(int,Vec,const Vec[],Scalar*); 46 extern int VecMTDot(int,Vec,const Vec[],Scalar*); 47 48 typedef enum {NORM_1=1,NORM_2=2,NORM_FROBENIUS=3,NORM_INFINITY=4,NORM_1_AND_2=5} NormType; 49 #define NORM_MAX NORM_INFINITY 50 extern int VecNorm(Vec,NormType,double *); 51 extern int VecSum(Vec,Scalar*); 52 extern int VecMax(Vec,int*,double*); 53 extern int VecMin(Vec,int*,double*); 54 extern int VecScale(const Scalar*,Vec); 55 extern int VecCopy(Vec,Vec); 56 extern int VecSetRandom(PetscRandom,Vec); 57 extern int VecSet(const Scalar*,Vec); 58 extern int VecSwap(Vec,Vec); 59 extern int VecAXPY(const Scalar*,Vec,Vec); 60 extern int VecAXPBY(const Scalar*,const Scalar *,Vec,Vec); 61 extern int VecMAXPY(int,const Scalar*,Vec,Vec*); 62 extern int VecAYPX(const Scalar*,Vec,Vec); 63 extern int VecWAXPY(const Scalar*,Vec,Vec,Vec); 64 extern int VecPointwiseMult(Vec,Vec,Vec); 65 extern int VecPointwiseDivide(Vec,Vec,Vec); 66 extern int VecShift(const Scalar*,Vec); 67 extern int VecReciprocal(Vec); 68 extern int VecAbs(Vec); 69 extern int VecDuplicate(Vec,Vec*); 70 extern int VecDuplicateVecs(Vec,int,Vec*[]); 71 extern int VecDestroyVecs(const Vec[],int); 72 extern int VecGetMap(Vec,Map*); 73 74 typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode; 75 extern int VecStrideNorm(Vec,int,NormType,double*); 76 extern int VecStrideGather(Vec,int,Vec,InsertMode); 77 extern int VecStrideScatter(Vec,int,Vec,InsertMode); 78 extern int VecStrideMax(Vec,int,int *,double *); 79 extern int VecStrideMin(Vec,int,int *,double *); 80 81 extern int VecSetValues(Vec,int,const int[],const Scalar[],InsertMode); 82 extern int VecAssemblyBegin(Vec); 83 extern int VecAssemblyEnd(Vec); 84 extern int VecSetStashInitialSize(Vec,int, int); 85 86 #define VecSetValue(v,i,va,mode) \ 87 {int _ierr,_row = i; Scalar _va = va; \ 88 _ierr = VecSetValues(v,1,&_row,&_va,mode);CHKERRQ(_ierr); \ 89 } 90 extern int VecSetBlockSize(Vec,int); 91 extern int VecGetBlockSize(Vec,int*); 92 extern int VecSetValuesBlocked(Vec,int,const int[],const Scalar[],InsertMode); 93 94 extern int VecRegisterAllCalled; 95 extern int VecRegisterAll(const char []); 96 extern int VecRegister_Private(const char[],const char[],const char[],int(*)(Vec)); 97 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 98 #define VecRegister(a,b,c,d) VecRegister_Private(a,b,c,0) 99 #else 100 #define VecRegister(a,b,c,d) VecRegister_Private(a,b,c,d) 101 #endif 102 103 typedef enum {SCATTER_FORWARD=0,SCATTER_REVERSE=1,SCATTER_FORWARD_LOCAL=2, 104 SCATTER_REVERSE_LOCAL=3,SCATTER_LOCAL=2} ScatterMode; 105 extern int VecScatterCreate(Vec,IS,Vec,IS,VecScatter *); 106 extern int VecScatterPostRecvs(Vec,Vec,InsertMode,ScatterMode,VecScatter); 107 extern int VecScatterBegin(Vec,Vec,InsertMode,ScatterMode,VecScatter); 108 extern int VecScatterEnd(Vec,Vec,InsertMode,ScatterMode,VecScatter); 109 extern int VecScatterDestroy(VecScatter); 110 extern int VecScatterCopy(VecScatter,VecScatter *); 111 extern int VecScatterView(VecScatter,Viewer); 112 extern int VecScatterRemap(VecScatter,int *,int*); 113 114 typedef enum {PIPELINE_DOWN=0,PIPELINE_UP=1} PipelineDirection; 115 typedef enum {PIPELINE_NONE=1, PIPELINE_SEQUENTIAL=2, 116 PIPELINE_REDBLACK=3, PIPELINE_MULTICOLOR=4} PipelineType; 117 118 typedef struct _p_VecPipeline* VecPipeline; 119 120 extern int VecPipelineCreate(MPI_Comm,Vec,IS,Vec,IS,VecPipeline *); 121 extern int VecPipelineSetType(VecPipeline,PipelineType,PetscObject); 122 extern int VecPipelineSetup(VecPipeline); 123 extern int VecPipelineBegin(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline); 124 extern int VecPipelineEnd(Vec,Vec,InsertMode,ScatterMode,PipelineDirection,VecPipeline); 125 extern int VecPipelineView(VecPipeline,Viewer); 126 extern int VecPipelineDestroy(VecPipeline); 127 128 extern int VecGetArray(Vec,Scalar*[]); 129 extern int VecRestoreArray(Vec,Scalar*[]); 130 extern int VecPlaceArray(Vec,const Scalar[]); 131 extern int VecReplaceArray(Vec,const Scalar[]); 132 extern int VecGetArrays(const Vec[],int,Scalar**[]); 133 extern int VecRestoreArrays(const Vec[],int,Scalar**[]); 134 135 extern int VecValid(Vec,PetscTruth*); 136 extern int VecView(Vec,Viewer); 137 extern int VecEqual(Vec,Vec,PetscTruth*); 138 extern int VecLoad(Viewer,Vec*); 139 extern int VecLoadIntoVector(Viewer,Vec); 140 141 extern int VecGetSize(Vec,int*); 142 extern int VecGetType(Vec,VecType*); 143 extern int VecGetLocalSize(Vec,int*); 144 extern int VecGetOwnershipRange(Vec,int*,int*); 145 146 extern int VecSetLocalToGlobalMapping(Vec, ISLocalToGlobalMapping); 147 extern int VecSetValuesLocal(Vec,int,const int[],const Scalar[],InsertMode); 148 extern int VecSetLocalToGlobalMappingBlocked(Vec, ISLocalToGlobalMapping); 149 extern int VecSetValuesBlockedLocal(Vec,int,const int[],const Scalar[],InsertMode); 150 151 extern int VecDotBegin(Vec,Vec,Scalar *); 152 extern int VecDotEnd(Vec,Vec,Scalar *); 153 extern int VecTDotBegin(Vec,Vec,Scalar *); 154 extern int VecTDotEnd(Vec,Vec,Scalar *); 155 extern int VecNormBegin(Vec,NormType,double *); 156 extern int VecNormEnd(Vec,NormType,double *); 157 158 typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES} VecOption; 159 extern int VecSetOption(Vec,VecOption); 160 161 extern int VecContourScale(Vec,double,double); 162 163 /* 164 These numbers need to match the entries in 165 the function table in src/vec/vecimpl.h 166 */ 167 typedef enum { VECOP_VIEW = 32, 168 VECOP_LOADINTOVECTOR = 40 169 } VecOperation; 170 extern int VecSetOperation(Vec,VecOperation,void*); 171 172 /* 173 Routines for dealing with ghosted vectors: 174 vectors with ghost elements at the end of the array. 175 */ 176 extern int VecCreateGhost(MPI_Comm,int,int,int,const int[],Vec*); 177 extern int VecCreateGhostWithArray(MPI_Comm,int,int,int,const int[],const Scalar[],Vec*); 178 extern int VecCreateGhostBlock(MPI_Comm,int,int,int,int,const int[],Vec*); 179 extern int VecCreateGhostBlockWithArray(MPI_Comm,int,int,int,int,const int[],const Scalar[],Vec*); 180 extern int VecGhostGetLocalForm(Vec,Vec*); 181 extern int VecGhostRestoreLocalForm(Vec,Vec*); 182 extern int VecGhostUpdateBegin(Vec,InsertMode,ScatterMode); 183 extern int VecGhostUpdateEnd(Vec,InsertMode,ScatterMode); 184 185 186 187 #endif 188 189 190 191