12eac72dbSBarry Smith /* 237f753daSBarry Smith Defines the vector component of PETSc. Vectors generally represent 337f753daSBarry Smith degrees of freedom for finite element/finite difference functions 484cb2905SBarry Smith on a grid. They have more mathematical structure then simple arrays. 52eac72dbSBarry Smith */ 62eac72dbSBarry Smith 70a835dfdSSatish Balay #ifndef __PETSCVEC_H 80a835dfdSSatish Balay #define __PETSCVEC_H 92c8e378dSBarry Smith #include <petscis.h> 105f5f199fSBarry Smith 112eac72dbSBarry Smith 1209321671SBarry Smith /*S 1309321671SBarry Smith Vec - Abstract PETSc vector object 1409321671SBarry Smith 1509321671SBarry Smith Level: beginner 1609321671SBarry Smith 1709321671SBarry Smith Concepts: field variables, unknowns, arrays 1809321671SBarry Smith 1909321671SBarry Smith .seealso: VecCreate(), VecType, VecSetType() 2009321671SBarry Smith S*/ 21f09e8eb9SSatish Balay typedef struct _p_Vec* Vec; 2209321671SBarry Smith 2309321671SBarry Smith /*S 2409321671SBarry Smith VecScatter - Object used to manage communication of data 2509321671SBarry Smith between vectors in parallel. Manages both scatters and gathers 2609321671SBarry Smith 2709321671SBarry Smith Level: beginner 2809321671SBarry Smith 2909321671SBarry Smith Concepts: scatter 3009321671SBarry Smith 3109321671SBarry Smith .seealso: VecScatterCreate(), VecScatterBegin(), VecScatterEnd() 3209321671SBarry Smith S*/ 33f09e8eb9SSatish Balay typedef struct _p_VecScatter* VecScatter; 3409321671SBarry Smith 3509321671SBarry Smith /*E 36398c84b2SBarry Smith ScatterMode - Determines the direction of a scatter 37398c84b2SBarry Smith 38398c84b2SBarry Smith Level: beginner 39398c84b2SBarry Smith 40398c84b2SBarry Smith .seealso: VecScatter, VecScatterBegin(), VecScatterEnd() 41398c84b2SBarry Smith E*/ 42398c84b2SBarry Smith typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode; 43398c84b2SBarry Smith 44398c84b2SBarry Smith /*MC 45398c84b2SBarry Smith SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call 46398c84b2SBarry Smith 47398c84b2SBarry Smith Level: beginner 48398c84b2SBarry Smith 49398c84b2SBarry Smith .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL, 50398c84b2SBarry Smith SCATTER_REVERSE_LOCAL 51398c84b2SBarry Smith 52398c84b2SBarry Smith M*/ 53398c84b2SBarry Smith 54398c84b2SBarry Smith /*MC 55398c84b2SBarry Smith SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in 56398c84b2SBarry Smith in the VecScatterCreate() 57398c84b2SBarry Smith 58398c84b2SBarry Smith Level: beginner 59398c84b2SBarry Smith 60398c84b2SBarry Smith .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL, 61398c84b2SBarry Smith SCATTER_REVERSE_LOCAL 62398c84b2SBarry Smith 63398c84b2SBarry Smith M*/ 64398c84b2SBarry Smith 65398c84b2SBarry Smith /*MC 66398c84b2SBarry Smith SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication 67398c84b2SBarry Smith is done. Any variables that have be moved between processes are ignored 68398c84b2SBarry Smith 69398c84b2SBarry Smith Level: developer 70398c84b2SBarry Smith 71398c84b2SBarry Smith .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD, 72398c84b2SBarry Smith SCATTER_REVERSE_LOCAL 73398c84b2SBarry Smith 74398c84b2SBarry Smith M*/ 75398c84b2SBarry Smith 76398c84b2SBarry Smith /*MC 77398c84b2SBarry Smith SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in 78398c84b2SBarry Smith in the VecScatterCreate() except NO parallel communication 79398c84b2SBarry Smith is done. Any variables that have be moved between processes are ignored 80398c84b2SBarry Smith 81398c84b2SBarry Smith Level: developer 82398c84b2SBarry Smith 83398c84b2SBarry Smith .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL, 84398c84b2SBarry Smith SCATTER_REVERSE 85398c84b2SBarry Smith 86398c84b2SBarry Smith M*/ 87398c84b2SBarry Smith 8876bdecfbSBarry Smith /*J 8909321671SBarry Smith VecType - String with the name of a PETSc vector or the creation function 9009321671SBarry Smith with an optional dynamic library name, for example 9109321671SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:myveccreate() 9209321671SBarry Smith 9309321671SBarry Smith Level: beginner 9409321671SBarry Smith 9509321671SBarry Smith .seealso: VecSetType(), Vec 9676bdecfbSBarry Smith J*/ 9719fd82e9SBarry Smith typedef const char* VecType; 980676abe4SMatthew Knepley #define VECSEQ "seq" 990676abe4SMatthew Knepley #define VECMPI "mpi" 100f48c50deSBarry Smith #define VECSTANDARD "standard" /* seq on one process and mpi on several */ 1010676abe4SMatthew Knepley #define VECSHARED "shared" 102765467adSMatthew Knepley #define VECSIEVE "sieve" 1038154be41SBarry Smith #define VECSEQCUSP "seqcusp" 1048154be41SBarry Smith #define VECMPICUSP "mpicusp" 1058154be41SBarry Smith #define VECCUSP "cusp" /* seqcusp on one process and mpicusp on several */ 1061aae2881SJed Brown #define VECNEST "nest" 1071bf2b38bSKerry Stevens #define VECSEQPTHREAD "seqpthread" 1084b71561bSShri Abhyankar #define VECMPIPTHREAD "mpipthread" 109bf2c1783SBarry Smith #define VECPTHREAD "pthread" /* seqpthread on one process and mpipthread on several */ 1102eac72dbSBarry Smith 1114b71561bSShri Abhyankar 112fd487807SMatthew Knepley /* Logging support */ 1130700a824SBarry Smith #define VEC_FILE_CLASSID 1211214 114014dd563SJed Brown PETSC_EXTERN PetscClassId VEC_CLASSID; 115014dd563SJed Brown PETSC_EXTERN PetscClassId VEC_SCATTER_CLASSID; 1168ba1e511SMatthew Knepley 11745b63f25SDmitry Karpeev 118014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecInitializePackage(const char[]); 119014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecFinalizePackage(void); 120fd487807SMatthew Knepley 121014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreate(MPI_Comm,Vec*); 122014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateSeq(MPI_Comm,PetscInt,Vec*); 123014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateMPI(MPI_Comm,PetscInt,PetscInt,Vec*); 124014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateSeqWithArray(MPI_Comm,PetscInt,PetscInt,const PetscScalar[],Vec*); 125014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateMPIWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscScalar[],Vec*); 126014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateShared(MPI_Comm,PetscInt,PetscInt,Vec*); 127014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetFromOptions(Vec); 1280d2bece7SBarry Smith PETSC_EXTERN PetscErrorCode VecViewFromOptions(Vec,const char[]); 1290d2bece7SBarry Smith 130014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetUp(Vec); 131014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecDestroy(Vec*); 132014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecZeroEntries(Vec); 133014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetOptionsPrefix(Vec,const char[]); 134014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecAppendOptionsPrefix(Vec,const char[]); 135014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetOptionsPrefix(Vec,const char*[]); 136f69a0ea3SMatthew Knepley 137014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetSizes(Vec,PetscInt,PetscInt); 138fd487807SMatthew Knepley 13952b6e47cSBarry Smith PETSC_EXTERN PetscErrorCode VecDotNorm2(Vec,Vec,PetscScalar*,PetscReal*); 140014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecDot(Vec,Vec,PetscScalar*); 14167392de3SBarry Smith PETSC_EXTERN PetscErrorCode VecDotRealPart(Vec,Vec,PetscReal*); 142014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecTDot(Vec,Vec,PetscScalar*); 143014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMDot(Vec,PetscInt,const Vec[],PetscScalar[]); 144014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMTDot(Vec,PetscInt,const Vec[],PetscScalar[]); 145014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetSubVector(Vec,IS,Vec*); 146014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRestoreSubVector(Vec,IS,Vec*); 147cddf8d76SBarry Smith 14809321671SBarry Smith /*E 14909321671SBarry Smith NormType - determines what type of norm to compute 15009321671SBarry Smith 15109321671SBarry Smith Level: beginner 15209321671SBarry Smith 15309321671SBarry Smith .seealso: VecNorm(), VecNormBegin(), VecNormEnd(), MatNorm() 15409321671SBarry Smith E*/ 1559dcbbd2bSBarry Smith typedef enum {NORM_1=0,NORM_2=1,NORM_FROBENIUS=2,NORM_INFINITY=3,NORM_1_AND_2=4} NormType; 1566a6fc655SJed Brown PETSC_EXTERN const char *const NormTypes[]; 157cddf8d76SBarry Smith #define NORM_MAX NORM_INFINITY 15809321671SBarry Smith 1599b250c83SBarry Smith /*MC 1609b250c83SBarry Smith NORM_1 - the one norm, ||v|| = sum_i | v_i |. ||A|| = max_j || v_*j ||, maximum column sum 1619b250c83SBarry Smith 1629b250c83SBarry Smith Level: beginner 1639b250c83SBarry Smith 1649b250c83SBarry Smith .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_2, NORM_FROBENIUS, 1659b250c83SBarry Smith NORM_INFINITY, NORM_1_AND_2 1669b250c83SBarry Smith 1679b250c83SBarry Smith M*/ 1689b250c83SBarry Smith 1699b250c83SBarry Smith /*MC 1709b250c83SBarry Smith NORM_2 - the two norm, ||v|| = sqrt(sum_i (v_i)^2) (vectors only) 1719b250c83SBarry Smith 1729b250c83SBarry Smith Level: beginner 1739b250c83SBarry Smith 1749b250c83SBarry Smith .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_FROBENIUS, 1759b250c83SBarry Smith NORM_INFINITY, NORM_1_AND_2 1769b250c83SBarry Smith 1779b250c83SBarry Smith M*/ 1789b250c83SBarry Smith 1799b250c83SBarry Smith /*MC 1809b250c83SBarry Smith NORM_FROBENIUS - ||A|| = sqrt(sum_ij (A_ij)^2), same as NORM_2 for vectors 1819b250c83SBarry Smith 1829b250c83SBarry Smith Level: beginner 1839b250c83SBarry Smith 1849b250c83SBarry Smith .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 1859b250c83SBarry Smith NORM_INFINITY, NORM_1_AND_2 1869b250c83SBarry Smith 1879b250c83SBarry Smith M*/ 1889b250c83SBarry Smith 1899b250c83SBarry Smith /*MC 1909b250c83SBarry Smith NORM_INFINITY - ||v|| = max_i |v_i|. ||A|| = max_i || v_i* ||, maximum row sum 1919b250c83SBarry Smith 1929b250c83SBarry Smith Level: beginner 1939b250c83SBarry Smith 1949b250c83SBarry Smith .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 1959b250c83SBarry Smith NORM_FROBINIUS, NORM_1_AND_2 1969b250c83SBarry Smith 1979b250c83SBarry Smith M*/ 1989b250c83SBarry Smith 1999b250c83SBarry Smith /*MC 2009b250c83SBarry Smith NORM_1_AND_2 - computes both the 1 and 2 norm of a vector 2019b250c83SBarry Smith 2029b250c83SBarry Smith Level: beginner 2039b250c83SBarry Smith 2049b250c83SBarry Smith .seealso: NormType, MatNorm(), VecNorm(), VecNormBegin(), VecNormEnd(), NORM_1, NORM_2, 2059b250c83SBarry Smith NORM_FROBINIUS, NORM_INFINITY 2069b250c83SBarry Smith 2079b250c83SBarry Smith M*/ 2089b250c83SBarry Smith 2099b250c83SBarry Smith /*MC 2109b250c83SBarry Smith NORM_MAX - see NORM_INFINITY 2119b250c83SBarry Smith 212d41222bbSBarry Smith Level: beginner 213d41222bbSBarry Smith 2149b250c83SBarry Smith M*/ 2159b250c83SBarry Smith 216014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNorm(Vec,NormType,PetscReal *); 217014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNormAvailable(Vec,NormType,PetscBool *,PetscReal *); 218014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNormalize(Vec,PetscReal *); 219014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSum(Vec,PetscScalar*); 220014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMax(Vec,PetscInt*,PetscReal *); 221014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMin(Vec,PetscInt*,PetscReal *); 222014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScale(Vec,PetscScalar); 223014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCopy(Vec,Vec); 224014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetRandom(Vec,PetscRandom); 225014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSet(Vec,PetscScalar); 226014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSwap(Vec,Vec); 227014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecAXPY(Vec,PetscScalar,Vec); 228014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecAXPBY(Vec,PetscScalar,PetscScalar,Vec); 229014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMAXPY(Vec,PetscInt,const PetscScalar[],Vec[]); 230014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecAYPX(Vec,PetscScalar,Vec); 231014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecWAXPY(Vec,PetscScalar,Vec,Vec); 232014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecAXPBYPCZ(Vec,PetscScalar,PetscScalar,PetscScalar,Vec,Vec); 233014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecPointwiseMax(Vec,Vec,Vec); 234014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecPointwiseMaxAbs(Vec,Vec,Vec); 235014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecPointwiseMin(Vec,Vec,Vec); 236014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecPointwiseMult(Vec,Vec,Vec); 237014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecPointwiseDivide(Vec,Vec,Vec); 238014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMaxPointwiseDivide(Vec,Vec,PetscReal*); 239014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecShift(Vec,PetscScalar); 240014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecReciprocal(Vec); 241014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecPermute(Vec, IS, PetscBool ); 242014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSqrtAbs(Vec); 243014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecLog(Vec); 244014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecExp(Vec); 245014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecAbs(Vec); 246014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecDuplicate(Vec,Vec*); 247014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecDuplicateVecs(Vec,PetscInt,Vec*[]); 248014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecDestroyVecs(PetscInt, Vec*[]); 249014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideNormAll(Vec,NormType,PetscReal[]); 250014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideMaxAll(Vec,PetscInt [],PetscReal []); 251014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideMinAll(Vec,PetscInt [],PetscReal []); 252014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideScaleAll(Vec,const PetscScalar[]); 2534a560884SBarry Smith 254014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideNorm(Vec,PetscInt,NormType,PetscReal*); 255014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideMax(Vec,PetscInt,PetscInt *,PetscReal *); 256014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideMin(Vec,PetscInt,PetscInt *,PetscReal *); 257014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideScale(Vec,PetscInt,PetscScalar); 258014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideSet(Vec,PetscInt,PetscScalar); 259954b3ec6SBarry Smith 260954b3ec6SBarry Smith 261014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideGather(Vec,PetscInt,Vec,InsertMode); 262014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideScatter(Vec,PetscInt,Vec,InsertMode); 263014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideGatherAll(Vec,Vec[],InsertMode); 264014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStrideScatterAll(Vec[],Vec,InsertMode); 265d2655a18SBarry Smith 266014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetValues(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 267014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetValues(Vec,PetscInt,const PetscInt[],PetscScalar[]); 268014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecAssemblyBegin(Vec); 269014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecAssemblyEnd(Vec); 270014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStashSetInitialSize(Vec,PetscInt,PetscInt); 271014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStashView(Vec,PetscViewer); 272014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecStashGetInfo(Vec,PetscInt*,PetscInt*,PetscInt*,PetscInt*); 27362dc5420SSatish Balay 27430de9b25SBarry Smith /*MC 27530de9b25SBarry Smith VecSetValue - Set a single entry into a vector. 27630de9b25SBarry Smith 27730de9b25SBarry Smith Synopsis: 278f2ba6396SBarry Smith #include "petscvec.h" 2798122439eSJed Brown PetscErrorCode VecSetValue(Vec v,PetscInt row,PetscScalar value, InsertMode mode); 28030de9b25SBarry Smith 28130de9b25SBarry Smith Not Collective 28230de9b25SBarry Smith 28330de9b25SBarry Smith Input Parameters: 28430de9b25SBarry Smith + v - the vector 28530de9b25SBarry Smith . row - the row location of the entry 28630de9b25SBarry Smith . value - the value to insert 28730de9b25SBarry Smith - mode - either INSERT_VALUES or ADD_VALUES 28830de9b25SBarry Smith 28930de9b25SBarry Smith Notes: 29030de9b25SBarry Smith For efficiency one should use VecSetValues() and set several or 29130de9b25SBarry Smith many values simultaneously if possible. 29230de9b25SBarry Smith 2931d73ed98SBarry Smith These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd() 2941d73ed98SBarry Smith MUST be called after all calls to VecSetValues() have been completed. 2951d73ed98SBarry Smith 2961d73ed98SBarry Smith VecSetValues() uses 0-based indices in Fortran as well as in C. 2971d73ed98SBarry Smith 2981d73ed98SBarry Smith Level: beginner 2991d73ed98SBarry Smith 3001d73ed98SBarry Smith .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValueLocal() 3011d73ed98SBarry Smith M*/ 30250755921SBarry Smith PETSC_STATIC_INLINE PetscErrorCode VecSetValue(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValues(v,1,&i,&va,mode);} 3031d73ed98SBarry Smith 30430de9b25SBarry Smith 305014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetBlockSize(Vec,PetscInt); 306014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetBlockSize(Vec,PetscInt*); 307014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetValuesBlocked(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 3088ed539a5SBarry Smith 309fd487807SMatthew Knepley /* Dynamic creation and loading functions */ 310140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList VecList; 311014dd563SJed Brown PETSC_EXTERN PetscBool VecRegisterAllCalled; 31219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode VecSetType(Vec, VecType); 31319fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode VecGetType(Vec, VecType *); 314014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRegister(const char[],const char[],const char[],PetscErrorCode (*)(Vec)); 315014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRegisterAll(const char []); 316014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRegisterDestroy(void); 31730de9b25SBarry Smith 31830de9b25SBarry Smith /*MC 31930de9b25SBarry Smith VecRegisterDynamic - Adds a new vector component implementation 32030de9b25SBarry Smith 32130de9b25SBarry Smith Synopsis: 322f2ba6396SBarry Smith #include "petscvec.h" 3231890ba74SBarry Smith PetscErrorCode VecRegisterDynamic(const char *name, const char *path, const char *func_name, PetscErrorCode (*create_func)(Vec)) 32430de9b25SBarry Smith 32530de9b25SBarry Smith Not Collective 32630de9b25SBarry Smith 32730de9b25SBarry Smith Input Parameters: 32830de9b25SBarry Smith + name - The name of a new user-defined creation routine 32930de9b25SBarry Smith . path - The path (either absolute or relative) of the library containing this routine 33030de9b25SBarry Smith . func_name - The name of routine to create method context 33130de9b25SBarry Smith - create_func - The creation routine itself 33230de9b25SBarry Smith 33330de9b25SBarry Smith Notes: 33430de9b25SBarry Smith VecRegisterDynamic() may be called multiple times to add several user-defined vectors 33530de9b25SBarry Smith 33630de9b25SBarry Smith If dynamic libraries are used, then the fourth input argument (routine_create) is ignored. 33730de9b25SBarry Smith 33830de9b25SBarry Smith Sample usage: 33930de9b25SBarry Smith .vb 34030de9b25SBarry Smith VecRegisterDynamic("my_vec","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyVectorCreate", MyVectorCreate); 34130de9b25SBarry Smith .ve 34230de9b25SBarry Smith 34330de9b25SBarry Smith Then, your vector type can be chosen with the procedural interface via 34430de9b25SBarry Smith .vb 34530de9b25SBarry Smith VecCreate(MPI_Comm, Vec *); 34630de9b25SBarry Smith VecSetType(Vec,"my_vector_name"); 34730de9b25SBarry Smith .ve 34830de9b25SBarry Smith or at runtime via the option 34930de9b25SBarry Smith .vb 35030de9b25SBarry Smith -vec_type my_vector_name 35130de9b25SBarry Smith .ve 35230de9b25SBarry Smith 353ab901514SBarry Smith Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 35430de9b25SBarry Smith If your function is not being put into a shared library then use VecRegister() instead 35530de9b25SBarry Smith 35630de9b25SBarry Smith Level: advanced 35730de9b25SBarry Smith 35830de9b25SBarry Smith .keywords: Vec, register 35930de9b25SBarry Smith .seealso: VecRegisterAll(), VecRegisterDestroy(), VecRegister() 36030de9b25SBarry Smith M*/ 361aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 362f1af5d2fSBarry Smith #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,0) 36388d459dfSBarry Smith #else 364f1af5d2fSBarry Smith #define VecRegisterDynamic(a,b,c,d) VecRegister(a,b,c,d) 36588d459dfSBarry Smith #endif 36688d459dfSBarry Smith 36709321671SBarry Smith 368014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterCreate(Vec,IS,Vec,IS,VecScatter *); 369014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterCreateEmpty(MPI_Comm,VecScatter *); 370014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterCreateLocal(VecScatter,PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],PetscInt,const PetscInt[],const PetscInt[],const PetscInt[],PetscInt); 371014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterBegin(VecScatter,Vec,Vec,InsertMode,ScatterMode); 372014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterEnd(VecScatter,Vec,Vec,InsertMode,ScatterMode); 373014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterDestroy(VecScatter*); 374014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterCopy(VecScatter,VecScatter *); 375014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterView(VecScatter,PetscViewer); 376014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterRemap(VecScatter,PetscInt *,PetscInt*); 377014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterGetMerged(VecScatter,PetscBool *); 3782195c698SBarry Smith 379014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]); 380014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRestoreArray4d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar****[]); 381014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]); 382014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRestoreArray3d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar***[]); 383014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]); 384014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRestoreArray2d(Vec,PetscInt,PetscInt,PetscInt,PetscInt,PetscScalar**[]); 385014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]); 386014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRestoreArray1d(Vec,PetscInt,PetscInt,PetscScalar *[]); 387ab360428SBarry Smith 388014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecPlaceArray(Vec,const PetscScalar[]); 389014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecResetArray(Vec); 390014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecReplaceArray(Vec,const PetscScalar[]); 391014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetArrays(const Vec[],PetscInt,PetscScalar**[]); 392014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecRestoreArrays(const Vec[],PetscInt,PetscScalar**[]); 39384cb2905SBarry Smith 394014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecView(Vec,PetscViewer); 395014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecEqual(Vec,Vec,PetscBool *); 396014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecLoad(Vec, PetscViewer); 3978ed539a5SBarry Smith 398014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetSize(Vec,PetscInt*); 399014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetLocalSize(Vec,PetscInt*); 400014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetOwnershipRange(Vec,PetscInt*,PetscInt*); 401014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetOwnershipRanges(Vec,const PetscInt *[]); 4028ed539a5SBarry Smith 403014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping); 404014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetValuesLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 40588b03592SBarry Smith 40688b03592SBarry Smith /*MC 40788b03592SBarry Smith VecSetValueLocal - Set a single entry into a vector using the local numbering 40888b03592SBarry Smith 40988b03592SBarry Smith Synopsis: 410f2ba6396SBarry Smith #include "petscvec.h" 4118122439eSJed Brown PetscErrorCode VecSetValueLocal(Vec v,PetscInt row,PetscScalar value, InsertMode mode); 41288b03592SBarry Smith 41388b03592SBarry Smith Not Collective 41488b03592SBarry Smith 41588b03592SBarry Smith Input Parameters: 41688b03592SBarry Smith + v - the vector 41788b03592SBarry Smith . row - the row location of the entry 41888b03592SBarry Smith . value - the value to insert 41988b03592SBarry Smith - mode - either INSERT_VALUES or ADD_VALUES 42088b03592SBarry Smith 42188b03592SBarry Smith Notes: 42288b03592SBarry Smith For efficiency one should use VecSetValues() and set several or 42388b03592SBarry Smith many values simultaneously if possible. 42488b03592SBarry Smith 42588b03592SBarry Smith These values may be cached, so VecAssemblyBegin() and VecAssemblyEnd() 42688b03592SBarry Smith MUST be called after all calls to VecSetValues() have been completed. 42788b03592SBarry Smith 42888b03592SBarry Smith VecSetValues() uses 0-based indices in Fortran as well as in C. 42988b03592SBarry Smith 43088b03592SBarry Smith Level: beginner 43188b03592SBarry Smith 43288b03592SBarry Smith .seealso: VecSetValues(), VecAssemblyBegin(), VecAssemblyEnd(), VecSetValuesBlockedLocal(), VecSetValue() 43388b03592SBarry Smith M*/ 43488b03592SBarry Smith PETSC_STATIC_INLINE PetscErrorCode VecSetValueLocal(Vec v,PetscInt i,PetscScalar va,InsertMode mode) {return VecSetValuesLocal(v,1,&i,&va,mode);} 43588b03592SBarry Smith 436014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetLocalToGlobalMappingBlock(Vec,ISLocalToGlobalMapping); 437014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetValuesBlockedLocal(Vec,PetscInt,const PetscInt[],const PetscScalar[],InsertMode); 438014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetLocalToGlobalMappingBlock(Vec,ISLocalToGlobalMapping*); 439014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGetLocalToGlobalMapping(Vec,ISLocalToGlobalMapping*); 44090f02eecSBarry Smith 441014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecDotBegin(Vec,Vec,PetscScalar *); 442014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecDotEnd(Vec,Vec,PetscScalar *); 443014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecTDotBegin(Vec,Vec,PetscScalar *); 444014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecTDotEnd(Vec,Vec,PetscScalar *); 445014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNormBegin(Vec,NormType,PetscReal *); 446014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNormEnd(Vec,NormType,PetscReal *); 447d3c178dbSBarry Smith 448014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]); 449014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]); 450014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMTDotBegin(Vec,PetscInt,const Vec[],PetscScalar[]); 451014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMTDotEnd(Vec,PetscInt,const Vec[],PetscScalar[]); 452014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommSplitReductionBegin(MPI_Comm); 453a751f32aSSatish Balay 454a751f32aSSatish Balay 4559533e83fSBarry Smith typedef enum {VEC_IGNORE_OFF_PROC_ENTRIES,VEC_IGNORE_NEGATIVE_INDICES} VecOption; 456014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetOption(Vec,VecOption,PetscBool ); 45790f02eecSBarry Smith 458*5c0c2446SJed Brown PETSC_EXTERN PetscErrorCode VecGetArray(Vec,PetscScalar**); 459*5c0c2446SJed Brown PETSC_EXTERN PetscErrorCode VecGetArrayRead(Vec,const PetscScalar**); 460*5c0c2446SJed Brown PETSC_EXTERN PetscErrorCode VecRestoreArray(Vec,PetscScalar**); 461*5c0c2446SJed Brown PETSC_EXTERN PetscErrorCode VecRestoreArrayRead(Vec,const PetscScalar**); 462*5c0c2446SJed Brown PETSC_EXTERN PetscErrorCode VecValidValues_Private(Vec,PetscInt,PetscBool); 463e1fa1e0fSSatish Balay 464f7ecc322SBarry Smith #if defined(PETSC_USE_DEBUG) 465*5c0c2446SJed Brown # define VecValidValues(x,argnum,begin) do { \ 466*5c0c2446SJed Brown PetscErrorCode _vecvalidvalues_ierr; \ 467*5c0c2446SJed Brown _vecvalidvalues_ierr = VecValidValues_Private((x),(argnum),(begin));CHKERRQ(_vecvalidvalues_ierr); \ 468*5c0c2446SJed Brown } while (0) 469f7ecc322SBarry Smith #else 470*5c0c2446SJed Brown # define VecValidValues(x,argnum,begin) do { } while (0) 471f7ecc322SBarry Smith #endif 472f7ecc322SBarry Smith 473014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecContourScale(Vec,PetscReal,PetscReal); 474522c5e43SBarry Smith 47515091d37SBarry Smith /* 47615091d37SBarry Smith These numbers need to match the entries in 4773c94ec11SBarry Smith the function table in vecimpl.h 47815091d37SBarry Smith */ 4792dcb2ebcSBarry Smith typedef enum { VECOP_VIEW = 33, VECOP_LOAD = 41, VECOP_DUPLICATE = 0} VecOperation; 480014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecSetOperation(Vec,VecOperation,void(*)(void)); 481b19c1e4cSBarry Smith 482e182c471SBarry Smith /* 483e182c471SBarry Smith Routines for dealing with ghosted vectors: 484e182c471SBarry Smith vectors with ghost elements at the end of the array. 485e182c471SBarry Smith */ 486014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecMPISetGhost(Vec,PetscInt,const PetscInt[]); 487014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateGhost(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*); 488014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateGhostWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*); 489014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateGhostBlock(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],Vec*); 490014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateGhostBlockWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscInt,const PetscInt[],const PetscScalar[],Vec*); 491014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGhostGetLocalForm(Vec,Vec*); 492014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGhostRestoreLocalForm(Vec,Vec*); 4933efe6655SBarry Smith PETSC_EXTERN PetscErrorCode VecGhostIsLocalForm(Vec,Vec,PetscBool*); 494014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGhostUpdateBegin(Vec,InsertMode,ScatterMode); 495014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecGhostUpdateEnd(Vec,InsertMode,ScatterMode); 496e182c471SBarry Smith 497014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecConjugate(Vec); 49834233285SBarry Smith 499014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterCreateToAll(Vec,VecScatter*,Vec*); 500014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterCreateToZero(Vec,VecScatter*,Vec*); 501bba1ac68SSatish Balay 502014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerMathematicaGetVector(PetscViewer, Vec); 503014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerMathematicaPutVector(PetscViewer, Vec); 5047dbadf16SMatthew Knepley 505d59c15a7SBarry Smith /*S 506d59c15a7SBarry Smith Vecs - Collection of vectors where the data for the vectors is stored in 507759e7b9cSHong Zhang one contiguous memory 508d59c15a7SBarry Smith 509d59c15a7SBarry Smith Level: advanced 510d59c15a7SBarry Smith 511d59c15a7SBarry Smith Notes: 512d59c15a7SBarry Smith Temporary construct for handling multiply right hand side solves 513d59c15a7SBarry Smith 514d59c15a7SBarry Smith This is faked by storing a single vector that has enough array space for 515d59c15a7SBarry Smith n vectors 516d59c15a7SBarry Smith 517d59c15a7SBarry Smith Concepts: parallel decomposition 518d59c15a7SBarry Smith 519d59c15a7SBarry Smith S*/ 52095fbd943SSatish Balay struct _n_Vecs {PetscInt n; Vec v;}; 52195fbd943SSatish Balay typedef struct _n_Vecs* Vecs; 522e1317eeeSBarry Smith PETSC_EXTERN PetscErrorCode VecsDestroy(Vecs); 523e1317eeeSBarry Smith PETSC_EXTERN PetscErrorCode VecsCreateSeq(MPI_Comm,PetscInt,PetscInt,Vecs*); 524e1317eeeSBarry Smith PETSC_EXTERN PetscErrorCode VecsCreateSeqWithArray(MPI_Comm,PetscInt,PetscInt,PetscScalar*,Vecs*); 525e1317eeeSBarry Smith PETSC_EXTERN PetscErrorCode VecsDuplicate(Vecs,Vecs*); 526e9fa29b7SSatish Balay 5278154be41SBarry Smith #if defined(PETSC_HAVE_CUSP) 528a5891931SBarry Smith typedef struct _p_PetscCUSPIndices* PetscCUSPIndices; 529014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCUSPIndicesCreate(PetscInt, PetscInt*,PetscInt, PetscInt*,PetscCUSPIndices*); 530014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCUSPIndicesDestroy(PetscCUSPIndices*); 531014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCUSPCopyToGPUSome_Public(Vec,PetscCUSPIndices); 532014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCUSPCopyFromGPUSome_Public(Vec,PetscCUSPIndices); 53390c53902SBarry Smith 534bd72cc96SPaul Mullowney #if defined(PETSC_HAVE_TXPETSCGPU) 535014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCUSPResetIndexBuffersFlagsGPU_Public(PetscCUSPIndices); 536014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCUSPCopySomeToContiguousBufferGPU_Public(Vec,PetscCUSPIndices); 537014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCUSPCopySomeFromContiguousBufferGPU_Public(Vec,PetscCUSPIndices); 538014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterInitializeForGPU(VecScatter,Vec,ScatterMode); 539014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecScatterFinalizeForGPU(VecScatter); 540bd72cc96SPaul Mullowney #endif 541bd72cc96SPaul Mullowney 542014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateSeqCUSP(MPI_Comm,PetscInt,Vec*); 543014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateMPICUSP(MPI_Comm,PetscInt,PetscInt,Vec*); 544a5891931SBarry Smith #endif 545e9fa29b7SSatish Balay 546014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNestGetSubVecs(Vec,PetscInt*,Vec**); 547014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNestGetSubVec(Vec,PetscInt,Vec*); 548014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNestSetSubVecs(Vec,PetscInt,PetscInt*,Vec*); 549014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNestSetSubVec(Vec,PetscInt,Vec); 550014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecCreateNest(MPI_Comm,PetscInt,IS*,Vec*,Vec*); 551014dd563SJed Brown PETSC_EXTERN PetscErrorCode VecNestGetSize(Vec,PetscInt*); 55245b63f25SDmitry Karpeev 553ab352700SBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsVec(const char[],const char[],const char[],Vec,PetscBool*); 5544325cce7SMatthew G Knepley PETSC_EXTERN PetscErrorCode VecChop(Vec,PetscReal); 555ab352700SBarry Smith 5569a6d0b0bSJed Brown /*S 5579a6d0b0bSJed Brown PetscLayout - defines layout of vectors and matrices across processes (which rows are owned by which processes) 5589a6d0b0bSJed Brown 5599a6d0b0bSJed Brown Level: developer 5609a6d0b0bSJed Brown 5619a6d0b0bSJed Brown 5629a6d0b0bSJed Brown .seealso: PetscLayoutCreate(), PetscLayoutDestroy() 5639a6d0b0bSJed Brown S*/ 5649a6d0b0bSJed Brown typedef struct _n_PetscLayout* PetscLayout; 5659a6d0b0bSJed Brown struct _n_PetscLayout{ 5669a6d0b0bSJed Brown MPI_Comm comm; 5679a6d0b0bSJed Brown PetscInt n,N; /* local, global vector size */ 5689a6d0b0bSJed Brown PetscInt rstart,rend; /* local start, local end + 1 */ 5699a6d0b0bSJed Brown PetscInt *range; /* the offset of each processor */ 5709a6d0b0bSJed Brown PetscInt bs; /* number of elements in each block (generally for multi-component problems) Do NOT multiply above numbers by bs */ 5719a6d0b0bSJed Brown PetscInt refcnt; /* MPI Vecs obtained with VecDuplicate() and from MatGetVecs() reuse map of input object */ 5729a6d0b0bSJed Brown ISLocalToGlobalMapping mapping; /* mapping used in Vec/MatSetValuesLocal() */ 5739a6d0b0bSJed Brown ISLocalToGlobalMapping bmapping; /* mapping used in Vec/MatSetValuesBlockedLocal() */ 5749a6d0b0bSJed Brown PetscInt *trstarts; /* local start for each thread */ 5759a6d0b0bSJed Brown }; 5769a6d0b0bSJed Brown 5779a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutCreate(MPI_Comm,PetscLayout*); 5789a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutSetUp(PetscLayout); 5799a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutDestroy(PetscLayout*); 5809a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutDuplicate(PetscLayout,PetscLayout*); 5819a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutReference(PetscLayout,PetscLayout*); 5829a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutSetLocalSize(PetscLayout,PetscInt); 5839a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutGetLocalSize(PetscLayout,PetscInt *); 5849a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutSetSize(PetscLayout,PetscInt); 5859a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutGetSize(PetscLayout,PetscInt *); 5869a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutSetBlockSize(PetscLayout,PetscInt); 5879a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutGetBlockSize(PetscLayout,PetscInt*); 5889a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutGetRange(PetscLayout,PetscInt *,PetscInt *); 5899a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutGetRanges(PetscLayout,const PetscInt *[]); 5909a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout,ISLocalToGlobalMapping); 5919a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMappingBlock(PetscLayout,ISLocalToGlobalMapping); 5929a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSFSetGraphLayout(PetscSF,PetscLayout,PetscInt,const PetscInt*,PetscCopyMode,const PetscInt*); 593077aedafSJed Brown PETSC_EXTERN PetscErrorCode VecGetLayout(Vec,PetscLayout*); 594077aedafSJed Brown PETSC_EXTERN PetscErrorCode VecSetLayout(Vec,PetscLayout); 5959a6d0b0bSJed Brown 5969a6d0b0bSJed Brown #undef __FUNCT__ 5979a6d0b0bSJed Brown #define __FUNCT__ "PetscLayoutFindOwner" 5989a6d0b0bSJed Brown /*@C 5999a6d0b0bSJed Brown PetscLayoutFindOwner - Find the owning rank for a global index 6009a6d0b0bSJed Brown 6019a6d0b0bSJed Brown Not Collective 6029a6d0b0bSJed Brown 6039a6d0b0bSJed Brown Input Parameters: 6049a6d0b0bSJed Brown + map - the layout 6059a6d0b0bSJed Brown - idx - global index to find the owner of 6069a6d0b0bSJed Brown 6079a6d0b0bSJed Brown Output Parameter: 6089a6d0b0bSJed Brown . owner - the owning rank 6099a6d0b0bSJed Brown 6109a6d0b0bSJed Brown Level: developer 6119a6d0b0bSJed Brown 6129a6d0b0bSJed Brown Fortran Notes: 6139a6d0b0bSJed Brown Not available from Fortran 6149a6d0b0bSJed Brown 6159a6d0b0bSJed Brown @*/ 6169a6d0b0bSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwner(PetscLayout map,PetscInt idx,PetscInt *owner) 6179a6d0b0bSJed Brown { 6189a6d0b0bSJed Brown PetscErrorCode ierr; 6199a6d0b0bSJed Brown PetscMPIInt lo = 0,hi,t; 6209a6d0b0bSJed Brown 6219a6d0b0bSJed Brown PetscFunctionBegin; 6229a6d0b0bSJed Brown *owner = -1; /* GCC erroneously issues warning about possibly uninitialized use when error condition */ 6239a6d0b0bSJed Brown if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first"); 6249a6d0b0bSJed Brown if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx); 6259a6d0b0bSJed Brown ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr); 6269a6d0b0bSJed Brown while (hi - lo > 1) { 6279a6d0b0bSJed Brown t = lo + (hi - lo) / 2; 6289a6d0b0bSJed Brown if (idx < map->range[t]) hi = t; 6299a6d0b0bSJed Brown else lo = t; 6309a6d0b0bSJed Brown } 6319a6d0b0bSJed Brown *owner = lo; 6329a6d0b0bSJed Brown PetscFunctionReturn(0); 6339a6d0b0bSJed Brown } 6349a6d0b0bSJed Brown 6359a6d0b0bSJed Brown #undef __FUNCT__ 6369a6d0b0bSJed Brown #define __FUNCT__ "PetscLayoutFindOwnerIndex" 6379a6d0b0bSJed Brown /*@C 6389a6d0b0bSJed Brown PetscLayoutFindOwnerIndex - Find the owning rank and the local index for a global index 6399a6d0b0bSJed Brown 6409a6d0b0bSJed Brown Not Collective 6419a6d0b0bSJed Brown 6429a6d0b0bSJed Brown Input Parameters: 6439a6d0b0bSJed Brown + map - the layout 6449a6d0b0bSJed Brown - idx - global index to find the owner of 6459a6d0b0bSJed Brown 6469a6d0b0bSJed Brown Output Parameter: 6479a6d0b0bSJed Brown + owner - the owning rank 6489a6d0b0bSJed Brown - lidx - local index used by the owner for idx 6499a6d0b0bSJed Brown 6509a6d0b0bSJed Brown Level: developer 6519a6d0b0bSJed Brown 6529a6d0b0bSJed Brown Fortran Notes: 6539a6d0b0bSJed Brown Not available from Fortran 6549a6d0b0bSJed Brown 6559a6d0b0bSJed Brown @*/ 6569a6d0b0bSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwnerIndex(PetscLayout map,PetscInt idx,PetscInt *owner, PetscInt *lidx) 6579a6d0b0bSJed Brown { 6589a6d0b0bSJed Brown PetscErrorCode ierr; 6599a6d0b0bSJed Brown PetscMPIInt lo = 0,hi,t; 6609a6d0b0bSJed Brown 6619a6d0b0bSJed Brown PetscFunctionBegin; 6629a6d0b0bSJed Brown if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first"); 6639a6d0b0bSJed Brown if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx); 6649a6d0b0bSJed Brown ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr); 6659a6d0b0bSJed Brown while (hi - lo > 1) { 6669a6d0b0bSJed Brown t = lo + (hi - lo) / 2; 6679a6d0b0bSJed Brown if (idx < map->range[t]) hi = t; 6689a6d0b0bSJed Brown else lo = t; 6699a6d0b0bSJed Brown } 6709a6d0b0bSJed Brown *owner = lo; 6719a6d0b0bSJed Brown *lidx = idx-map->range[lo]; 6729a6d0b0bSJed Brown PetscFunctionReturn(0); 6739a6d0b0bSJed Brown } 6749a6d0b0bSJed Brown 6759a6d0b0bSJed Brown /*S 6769a6d0b0bSJed Brown PetscSection - This is a mapping from DMMESH points to sets of values, which is 6779a6d0b0bSJed Brown our presentation of a fibre bundle. 6789a6d0b0bSJed Brown 6799a6d0b0bSJed Brown Level: developer 6809a6d0b0bSJed Brown 6819a6d0b0bSJed Brown .seealso: PetscSectionCreate(), PetscSectionDestroy() 6829a6d0b0bSJed Brown S*/ 6839a6d0b0bSJed Brown typedef struct _n_PetscSection *PetscSection; 6849a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionCreate(MPI_Comm,PetscSection*); 6859a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionClone(PetscSection, PetscSection*); 6869a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetNumFields(PetscSection, PetscInt *); 6879a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetNumFields(PetscSection, PetscInt); 6889a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetFieldName(PetscSection, PetscInt, const char *[]); 6899a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetFieldName(PetscSection, PetscInt, const char []); 6909a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetFieldComponents(PetscSection, PetscInt, PetscInt *); 6919a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetFieldComponents(PetscSection, PetscInt, PetscInt); 6929a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetChart(PetscSection, PetscInt *, PetscInt *); 6939a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetChart(PetscSection, PetscInt, PetscInt); 6949a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetDof(PetscSection, PetscInt, PetscInt*); 6959a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetDof(PetscSection, PetscInt, PetscInt); 6969a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionAddDof(PetscSection, PetscInt, PetscInt); 6979a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetFieldDof(PetscSection, PetscInt, PetscInt, PetscInt*); 6989a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetFieldDof(PetscSection, PetscInt, PetscInt, PetscInt); 6999a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionAddFieldDof(PetscSection, PetscInt, PetscInt, PetscInt); 7009a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetConstraintDof(PetscSection, PetscInt, PetscInt*); 7019a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetConstraintDof(PetscSection, PetscInt, PetscInt); 7029a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionAddConstraintDof(PetscSection, PetscInt, PetscInt); 7039a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt*); 7049a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt); 7059a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt); 7069a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetConstraintIndices(PetscSection, PetscInt, const PetscInt**); 7079a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetConstraintIndices(PetscSection, PetscInt, const PetscInt*); 7089a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection, PetscInt, PetscInt, const PetscInt**); 7099a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection, PetscInt, PetscInt, const PetscInt*); 7109a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetUpBC(PetscSection); 7119a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetUp(PetscSection); 7129a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetMaxDof(PetscSection, PetscInt*); 7139a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetStorageSize(PetscSection, PetscInt*); 7149a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection, PetscInt*); 7159a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetOffset(PetscSection, PetscInt, PetscInt*); 7169a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetOffset(PetscSection, PetscInt, PetscInt); 7179a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetFieldOffset(PetscSection, PetscInt, PetscInt, PetscInt*); 7189a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionSetFieldOffset(PetscSection, PetscInt, PetscInt, PetscInt); 7199a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetOffsetRange(PetscSection, PetscInt *, PetscInt *); 7209a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionView(PetscSection, PetscViewer); 7219a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionVecView(PetscSection, Vec, PetscViewer); 7229a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionReset(PetscSection); 7239a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionDestroy(PetscSection*); 7249a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionCreateGlobalSection(PetscSection, PetscSF, PetscBool, PetscSection *); 7259a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection, PetscSF, PetscBool, PetscInt, const PetscInt [], PetscSection *); 7269a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionCreateSubsection(PetscSection, PetscInt, PetscInt [], PetscSection *); 7279a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection, IS, PetscSection *); 7289a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetPointLayout(MPI_Comm, PetscSection, PetscLayout *); 7299a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode PetscSectionGetValueLayout(MPI_Comm, PetscSection, PetscLayout *); 7309a6d0b0bSJed Brown 7319a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode VecGetValuesSection(Vec, PetscSection, PetscInt, PetscScalar **); 7329a6d0b0bSJed Brown PETSC_EXTERN PetscErrorCode VecSetValuesSection(Vec, PetscSection, PetscInt, PetscScalar [], InsertMode); 7339a6d0b0bSJed Brown 7342eac72dbSBarry Smith #endif 7352b82984cSSatish Balay 736