xref: /petsc/include/petscis.h (revision 6a8182857e2a1ca168ce28a153335aa68f3e4e3d)
12eac72dbSBarry Smith /*
2f8256253SLois Curfman McInnes    An index set is a generalization of a subset of integers.  Index sets
3f8256253SLois Curfman McInnes    are used for defining scatters and gathers.
42eac72dbSBarry Smith */
50a835dfdSSatish Balay #if !defined(__PETSCIS_H)
60a835dfdSSatish Balay #define __PETSCIS_H
72c8e378dSBarry Smith #include <petscsys.h>
80c312b8eSJed Brown #include <petscsftypes.h>
92eac72dbSBarry Smith 
1097b48c8fSBarry Smith #define IS_FILE_CLASSID 1211218
11014dd563SJed Brown PETSC_EXTERN PetscClassId IS_CLASSID;
12f0479e8cSBarry Smith 
13607a6623SBarry Smith PETSC_EXTERN PetscErrorCode ISInitializePackage(void);
142b6de112SBarry Smith 
155c20da3cSBarry Smith /*S
16f22f69f0SBarry Smith      IS - Abstract PETSc object that allows indexing.
175c20da3cSBarry Smith 
185c20da3cSBarry Smith    Level: beginner
195c20da3cSBarry Smith 
205c20da3cSBarry Smith   Concepts: indexing, stride
215c20da3cSBarry Smith 
225c20da3cSBarry Smith .seealso:  ISCreateGeneral(), ISCreateBlock(), ISCreateStride(), ISGetIndices(), ISDestroy()
235c20da3cSBarry Smith S*/
24f09e8eb9SSatish Balay typedef struct _p_IS* IS;
252eac72dbSBarry Smith 
2676bdecfbSBarry Smith /*J
278f6c3df8SBarry Smith     ISType - String with the name of a PETSc index set type
2827bdab1eSBarry Smith 
2927bdab1eSBarry Smith    Level: beginner
3027bdab1eSBarry Smith 
318f6c3df8SBarry Smith .seealso: ISSetType(), IS, ISCreate(), ISRegister()
3276bdecfbSBarry Smith J*/
3319fd82e9SBarry Smith typedef const char* ISType;
3427bdab1eSBarry Smith #define ISGENERAL      "general"
3527bdab1eSBarry Smith #define ISSTRIDE       "stride"
3627bdab1eSBarry Smith #define ISBLOCK        "block"
3727bdab1eSBarry Smith 
3827bdab1eSBarry Smith /* Dynamic creation and loading functions */
39140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList ISList;
40014dd563SJed Brown PETSC_EXTERN PetscBool         ISRegisterAllCalled;
4119fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode ISSetType(IS, ISType);
4219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode ISGetType(IS, ISType *);
43bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode ISRegister(const char[],PetscErrorCode (*)(IS));
44607a6623SBarry Smith PETSC_EXTERN PetscErrorCode ISRegisterAll(void);
45014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreate(MPI_Comm,IS*);
4627bdab1eSBarry Smith 
47639f9d9dSBarry Smith /*
48639f9d9dSBarry Smith     Default index set data structures that PETSc provides.
49639f9d9dSBarry Smith */
50014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,IS *);
51014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGeneralSetIndices(IS,PetscInt,const PetscInt[],PetscCopyMode);
52014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,IS *);
53014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockSetIndices(IS,PetscInt,PetscInt,const PetscInt[],PetscCopyMode);
54014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
55014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISStrideSetStride(IS,PetscInt,PetscInt,PetscInt);
564b0e389bSBarry Smith 
57014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDestroy(IS*);
58014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetPermutation(IS);
59014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPermutation(IS,PetscBool *);
60014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetIdentity(IS);
61014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISIdentity(IS,PetscBool *);
62014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISContiguousLocal(IS,PetscInt,PetscInt,PetscInt*,PetscBool*);
6308480c60SBarry Smith 
64014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetIndices(IS,const PetscInt *[]);
65014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreIndices(IS,const PetscInt *[]);
66014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetTotalIndices(IS,const PetscInt *[]);
67014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreTotalIndices(IS,const PetscInt *[]);
68014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIndices(IS,const PetscInt *[]);
69014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIndices(IS,const PetscInt *[]);
70014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIS(IS, IS *is);
71014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIS(IS, IS *is);
72014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetSize(IS,PetscInt *);
73014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetLocalSize(IS,PetscInt *);
74014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISInvertPermutation(IS,PetscInt,IS*);
75014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISView(IS,PetscViewer);
76ce1779c8SBarry Smith PETSC_STATIC_INLINE PetscErrorCode ISViewFromOptions(IS A,const char prefix[],const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,prefix,name);}
77235f7792SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISLoad(IS,PetscViewer);
78014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISEqual(IS,IS,PetscBool  *);
79014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSort(IS);
80b080c0f9SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISSortRemoveDups(IS);
81014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSorted(IS,PetscBool  *);
82014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDifference(IS,IS,IS*);
83014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSum(IS,IS,IS*);
84014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpand(IS,IS,IS*);
85132da990SBarry Smith PETSC_EXTERN PetscErrorCode ISGetMinMax(IS,PetscInt*,PetscInt*);
86612dd529SBarry Smith 
87014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS,const PetscInt *[]);
88014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS,const PetscInt *[]);
89014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS,PetscInt *);
90014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS,PetscInt *);
91014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS,PetscInt*);
92014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS,PetscInt);
93c16cb8f2SBarry Smith 
94014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*);
95c16cb8f2SBarry Smith 
96014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISToGeneral(IS);
9738f40f24SLois Curfman McInnes 
98014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDuplicate(IS,IS*);
99014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCopy(IS,IS);
100014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGather(IS,IS*);
101014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISComplement(IS,PetscInt,PetscInt,IS*);
102014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm,PetscInt,const IS[],IS*);
103bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm,PetscInt, IS[],IS*,IS*);
104bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISPairToList(IS,IS,PetscInt*, IS *[]);
105bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISEmbed(IS,IS,PetscBool,IS*);
106014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISOnComm(IS,MPI_Comm,PetscCopyMode,IS*);
107d64ed03dSBarry Smith 
10856cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
109014dd563SJed Brown PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID;
11056cd22aeSBarry Smith 
1115c20da3cSBarry Smith /*S
112d9ffb7b8SBarry Smith    ISLocalToGlobalMapping - mappings from an arbitrary
11390f02eecSBarry Smith       local ordering from 0 to n-1 to a global PETSc ordering
114d4bb536fSBarry Smith       used by a vector or matrix.
115d4bb536fSBarry Smith 
1165c20da3cSBarry Smith    Level: intermediate
1175c20da3cSBarry Smith 
118d4bb536fSBarry Smith    Note: mapping from Local to Global is scalable; but Global
119eec0b4cfSBarry Smith   to Local may not be if the range of global values represented locally
120d4bb536fSBarry Smith   is very large.
12174637425SBarry Smith 
12274637425SBarry Smith    Note: the ISLocalToGlobalMapping is actually a private object; it is included
123992144d0SBarry Smith   here for the inline function ISLocalToGlobalMappingApply() to allow it to be inlined since
12474637425SBarry Smith   it is used so often.
12574637425SBarry Smith 
1265c20da3cSBarry Smith .seealso:  ISLocalToGlobalMappingCreate()
1275c20da3cSBarry Smith S*/
128f09e8eb9SSatish Balay typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
1295c20da3cSBarry Smith 
1305c20da3cSBarry Smith /*E
1315c20da3cSBarry Smith     ISGlobalToLocalMappingType - Indicates if missing global indices are
1325c20da3cSBarry Smith 
1335c20da3cSBarry Smith    IS_GTOLM_MASK - missing global indices are replaced with -1
1345c20da3cSBarry Smith    IS_GTOLM_DROP - missing global indices are dropped
1355c20da3cSBarry Smith 
1365c20da3cSBarry Smith    Level: beginner
1375c20da3cSBarry Smith 
1389d90f715SBarry Smith .seealso: ISGlobalToLocalMappingApplyBlock()
1395c20da3cSBarry Smith 
1405c20da3cSBarry Smith E*/
141987e4450SSatish Balay typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
14290f02eecSBarry Smith 
143f0413b6fSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,ISLocalToGlobalMapping*);
144014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
145014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF,PetscInt,ISLocalToGlobalMapping*);
146014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
147014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping*);
14804a59952SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
14945b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyBlock(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
150014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
151014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
1529d90f715SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyBlock(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
153014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
154014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
155014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
156*6a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
157*6a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
158014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping,const PetscInt**);
159014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping,const PetscInt**);
16045b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockIndices(ISLocalToGlobalMapping,const PetscInt**);
16145b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockIndices(ISLocalToGlobalMapping,const PetscInt**);
162014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm,PetscInt,const ISLocalToGlobalMapping[],ISLocalToGlobalMapping*);
163186d4ecdSBarry Smith PETSC_EXTERN PetscErrorCode ISG2LMapApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
16445b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockSize(ISLocalToGlobalMapping,PetscInt*);
16545b6f7e9SBarry Smith 
16674637425SBarry Smith 
16756cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
168b9617806SBarry Smith /*E
169b9617806SBarry Smith     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
170b9617806SBarry Smith                      or for just the local ghosted portion
171b9617806SBarry Smith 
172b9617806SBarry Smith     Level: beginner
173b9617806SBarry Smith 
1748ee2e534SBarry Smith $   IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function
1758ee2e534SBarry Smith $                        is called synchronously in parallel. This requires generating a "parallel coloring".
1768ee2e534SBarry Smith $   IS_COLORING_GHOSTED - includes colors for ghost points, this is used when the function can be called
1778ee2e534SBarry Smith $                         seperately on individual processes with the ghost points already filled in. Does not
1788ee2e534SBarry Smith $                         require a "parallel coloring", rather each process colors its local + ghost part.
1798ee2e534SBarry Smith $                         Using this can result in much less parallel communication. In the paradigm of
1809a42bb27SBarry Smith $                         DMGetLocalVector() and DMGetGlobalVector() this could be called IS_COLORING_LOCAL
18173d7d85fSBarry Smith 
182e727c939SJed Brown .seealso: DMCreateColoring()
183b9617806SBarry Smith E*/
1848ee2e534SBarry Smith typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType;
1856a6fc655SJed Brown PETSC_EXTERN const char *const ISColoringTypes[];
1866c09f170SSatish Balay typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue;
187014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
188dde82324SBarry Smith 
1895c20da3cSBarry Smith /*S
190dde82324SBarry Smith      ISColoring - sets of IS's that define a coloring
191639f9d9dSBarry Smith               of the underlying indices
1925c20da3cSBarry Smith 
1935c20da3cSBarry Smith    Level: intermediate
1945c20da3cSBarry Smith 
1955c20da3cSBarry Smith     Notes:
196b9617806SBarry Smith         One should not access the *is records below directly because they may not yet
1975c20da3cSBarry Smith     have been created. One should use ISColoringGetIS() to make sure they are
1985c20da3cSBarry Smith     created when needed.
1995c20da3cSBarry Smith 
200a5057860SBarry Smith     Developer Note: this is not a PetscObject
201a5057860SBarry Smith 
2025c20da3cSBarry Smith .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
2035c20da3cSBarry Smith S*/
20495fbd943SSatish Balay struct _n_ISColoring {
205a7cc72afSBarry Smith   PetscInt        refct;
206a7cc72afSBarry Smith   PetscInt        n;                /* number of colors */
2075c20da3cSBarry Smith   IS              *is;              /* for each color indicates columns */
208639f9d9dSBarry Smith   MPI_Comm        comm;
20908b6dcc0SBarry Smith   ISColoringValue *colors;          /* for each column indicates color */
21032dcc486SBarry Smith   PetscInt        N;                /* number of columns */
211b9617806SBarry Smith   ISColoringType  ctype;
212639f9d9dSBarry Smith };
21395fbd943SSatish Balay typedef struct _n_ISColoring* ISColoring;
214639f9d9dSBarry Smith 
215014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*);
216014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring*);
217014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
218ce1779c8SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringViewFromOptions(ISColoring,const char[],const char[]);
219014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
220014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]);
22149b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring);
22249b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring,ISColoringType);
22349b734d2SBarry Smith 
2243a7fca6bSBarry Smith 
225dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/
226dbef8a1cSBarry Smith 
227014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
228014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt,PetscInt[]);
229dbef8a1cSBarry Smith 
230014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
231014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
232014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
233d9489beaSHong Zhang 
23469ce434fSBarry Smith /*S
23569ce434fSBarry Smith      PetscLayout - defines layout of vectors and matrices across processes (which rows are owned by which processes)
23669ce434fSBarry Smith 
23769ce434fSBarry Smith    Level: developer
23869ce434fSBarry Smith 
23969ce434fSBarry Smith 
24069ce434fSBarry Smith .seealso:  PetscLayoutCreate(), PetscLayoutDestroy()
24169ce434fSBarry Smith S*/
24269ce434fSBarry Smith typedef struct _n_PetscLayout* PetscLayout;
24369ce434fSBarry Smith struct _n_PetscLayout{
24469ce434fSBarry Smith   MPI_Comm               comm;
24569ce434fSBarry Smith   PetscInt               n,N;         /* local, global vector size */
24669ce434fSBarry Smith   PetscInt               rstart,rend; /* local start, local end + 1 */
24769ce434fSBarry Smith   PetscInt               *range;      /* the offset of each processor */
24833d57670SJed Brown   PetscInt               bs;          /* number of elements in each block (generally for multi-component
24933d57670SJed Brown                                        * problems). Defaults to -1 and can be arbitrarily lazy so always use
25033d57670SJed Brown                                        * PetscAbs(map->bs) when accessing directly and expecting result to be
25133d57670SJed Brown                                        * positive. Do NOT multiply above numbers by bs */
25269ce434fSBarry Smith   PetscInt               refcnt;      /* MPI Vecs obtained with VecDuplicate() and from MatGetVecs() reuse map of input object */
25369ce434fSBarry Smith   ISLocalToGlobalMapping mapping;     /* mapping used in Vec/MatSetValuesLocal() */
25469ce434fSBarry Smith   PetscInt               *trstarts;   /* local start for each thread */
25569ce434fSBarry Smith };
25669ce434fSBarry Smith 
25769ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutCreate(MPI_Comm,PetscLayout*);
25869ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetUp(PetscLayout);
25969ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutDestroy(PetscLayout*);
26069ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutDuplicate(PetscLayout,PetscLayout*);
26169ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutReference(PetscLayout,PetscLayout*);
26269ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetLocalSize(PetscLayout,PetscInt);
26369ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetLocalSize(PetscLayout,PetscInt *);
26469ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetSize(PetscLayout,PetscInt);
26569ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetSize(PetscLayout,PetscInt *);
26669ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetBlockSize(PetscLayout,PetscInt);
26769ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetBlockSize(PetscLayout,PetscInt*);
26869ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetRange(PetscLayout,PetscInt *,PetscInt *);
26969ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetRanges(PetscLayout,const PetscInt *[]);
27069ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout,ISLocalToGlobalMapping);
27169ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFSetGraphLayout(PetscSF,PetscLayout,PetscInt,const PetscInt*,PetscCopyMode,const PetscInt*);
27269ce434fSBarry Smith 
27369ce434fSBarry Smith #undef __FUNCT__
27469ce434fSBarry Smith #define __FUNCT__ "PetscLayoutFindOwner"
27569ce434fSBarry Smith /*@C
27669ce434fSBarry Smith      PetscLayoutFindOwner - Find the owning rank for a global index
27769ce434fSBarry Smith 
27869ce434fSBarry Smith     Not Collective
27969ce434fSBarry Smith 
28069ce434fSBarry Smith    Input Parameters:
28169ce434fSBarry Smith +    map - the layout
28269ce434fSBarry Smith -    idx - global index to find the owner of
28369ce434fSBarry Smith 
28469ce434fSBarry Smith    Output Parameter:
28569ce434fSBarry Smith .    owner - the owning rank
28669ce434fSBarry Smith 
28769ce434fSBarry Smith    Level: developer
28869ce434fSBarry Smith 
28969ce434fSBarry Smith     Fortran Notes:
29069ce434fSBarry Smith       Not available from Fortran
29169ce434fSBarry Smith 
29269ce434fSBarry Smith @*/
29369ce434fSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwner(PetscLayout map,PetscInt idx,PetscInt *owner)
29469ce434fSBarry Smith {
29569ce434fSBarry Smith   PetscErrorCode ierr;
29669ce434fSBarry Smith   PetscMPIInt    lo = 0,hi,t;
29769ce434fSBarry Smith 
29869ce434fSBarry Smith   PetscFunctionBegin;
29969ce434fSBarry Smith   *owner = -1;                  /* GCC erroneously issues warning about possibly uninitialized use when error condition */
30069ce434fSBarry Smith   if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first");
30169ce434fSBarry Smith   if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx);
30269ce434fSBarry Smith   ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr);
30369ce434fSBarry Smith   while (hi - lo > 1) {
30469ce434fSBarry Smith     t = lo + (hi - lo) / 2;
30569ce434fSBarry Smith     if (idx < map->range[t]) hi = t;
30669ce434fSBarry Smith     else                     lo = t;
30769ce434fSBarry Smith   }
30869ce434fSBarry Smith   *owner = lo;
30969ce434fSBarry Smith   PetscFunctionReturn(0);
31069ce434fSBarry Smith }
31169ce434fSBarry Smith 
31269ce434fSBarry Smith #undef __FUNCT__
31369ce434fSBarry Smith #define __FUNCT__ "PetscLayoutFindOwnerIndex"
31469ce434fSBarry Smith /*@C
31569ce434fSBarry Smith      PetscLayoutFindOwnerIndex - Find the owning rank and the local index for a global index
31669ce434fSBarry Smith 
31769ce434fSBarry Smith     Not Collective
31869ce434fSBarry Smith 
31969ce434fSBarry Smith    Input Parameters:
32069ce434fSBarry Smith +    map   - the layout
32169ce434fSBarry Smith -    idx   - global index to find the owner of
32269ce434fSBarry Smith 
32369ce434fSBarry Smith    Output Parameter:
32469ce434fSBarry Smith +    owner - the owning rank
32569ce434fSBarry Smith -    lidx  - local index used by the owner for idx
32669ce434fSBarry Smith 
32769ce434fSBarry Smith    Level: developer
32869ce434fSBarry Smith 
32969ce434fSBarry Smith     Fortran Notes:
33069ce434fSBarry Smith       Not available from Fortran
33169ce434fSBarry Smith 
33269ce434fSBarry Smith @*/
33369ce434fSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwnerIndex(PetscLayout map,PetscInt idx,PetscInt *owner, PetscInt *lidx)
33469ce434fSBarry Smith {
33569ce434fSBarry Smith   PetscErrorCode ierr;
33669ce434fSBarry Smith   PetscMPIInt    lo = 0,hi,t;
33769ce434fSBarry Smith 
33869ce434fSBarry Smith   PetscFunctionBegin;
33969ce434fSBarry Smith   if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first");
34069ce434fSBarry Smith   if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx);
34169ce434fSBarry Smith   ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr);
34269ce434fSBarry Smith   while (hi - lo > 1) {
34369ce434fSBarry Smith     t = lo + (hi - lo) / 2;
34469ce434fSBarry Smith     if (idx < map->range[t]) hi = t;
34569ce434fSBarry Smith     else                     lo = t;
34669ce434fSBarry Smith   }
34769ce434fSBarry Smith   *owner = lo;
34869ce434fSBarry Smith   *lidx  = idx-map->range[lo];
34969ce434fSBarry Smith   PetscFunctionReturn(0);
35069ce434fSBarry Smith }
3519e03d832SJed Brown 
3521d799100SJed Brown PETSC_EXTERN PetscClassId PETSC_SECTION_CLASSID;
3531d799100SJed Brown 
354d53a3d6fSBarry Smith /*S
35586ae641aSJed Brown   PetscSection - Mapping from integers in a designated range to contiguous sets of integers.
35686ae641aSJed Brown 
35786ae641aSJed Brown   In contrast to IS, which maps from integers to single integers, the range of a PetscSection is in the space of
35886ae641aSJed Brown   contiguous sets of integers. These ranges are frequently interpreted as domains of other array-like objects,
35986ae641aSJed Brown   especially other PetscSections, Vecs, and ISs. The domain is set with PetscSectionSetChart() and does not need to
36086ae641aSJed Brown   start at 0. For each point in the domain of a PetscSection, the output set is represented through an offset and a
36186ae641aSJed Brown   count, which are set using PetscSectionSetOffset() and PetscSectionSetDof() respectively. Lookup is typically using
36286ae641aSJed Brown   accessors or routines like VecGetValuesSection().
363d53a3d6fSBarry Smith 
364d53a3d6fSBarry Smith   Level: developer
365d53a3d6fSBarry Smith 
366d53a3d6fSBarry Smith .seealso:  PetscSectionCreate(), PetscSectionDestroy()
367d53a3d6fSBarry Smith S*/
3681d799100SJed Brown typedef struct _p_PetscSection *PetscSection;
369d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreate(MPI_Comm,PetscSection*);
370d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionClone(PetscSection, PetscSection*);
371d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetNumFields(PetscSection, PetscInt *);
372d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetNumFields(PetscSection, PetscInt);
373d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldName(PetscSection, PetscInt, const char *[]);
374d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldName(PetscSection, PetscInt, const char []);
375d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldComponents(PetscSection, PetscInt, PetscInt *);
376d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldComponents(PetscSection, PetscInt, PetscInt);
377d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetChart(PetscSection, PetscInt *, PetscInt *);
378d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetChart(PetscSection, PetscInt, PetscInt);
3794c0d72c2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionGetPermutation(PetscSection, IS *);
3804c0d72c2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionSetPermutation(PetscSection, IS);
381d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetDof(PetscSection, PetscInt, PetscInt*);
382d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetDof(PetscSection, PetscInt, PetscInt);
383d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddDof(PetscSection, PetscInt, PetscInt);
384d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldDof(PetscSection, PetscInt, PetscInt, PetscInt*);
385d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldDof(PetscSection, PetscInt, PetscInt, PetscInt);
386d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddFieldDof(PetscSection, PetscInt, PetscInt, PetscInt);
3877ba4506dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionHasConstraints(PetscSection, PetscBool *);
388d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstraintDof(PetscSection, PetscInt, PetscInt*);
389d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetConstraintDof(PetscSection, PetscInt, PetscInt);
390d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddConstraintDof(PetscSection, PetscInt, PetscInt);
391d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt*);
392d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt);
393d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt);
394d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstraintIndices(PetscSection, PetscInt, const PetscInt**);
395d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetConstraintIndices(PetscSection, PetscInt, const PetscInt*);
396d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection, PetscInt, PetscInt, const PetscInt**);
397d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection, PetscInt, PetscInt, const PetscInt*);
398d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetUpBC(PetscSection);
399d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetUp(PetscSection);
400d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetMaxDof(PetscSection, PetscInt*);
401d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetStorageSize(PetscSection, PetscInt*);
402d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection, PetscInt*);
403d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetOffset(PetscSection, PetscInt, PetscInt*);
404d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetOffset(PetscSection, PetscInt, PetscInt);
405d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldOffset(PetscSection, PetscInt, PetscInt, PetscInt*);
406d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldOffset(PetscSection, PetscInt, PetscInt, PetscInt);
407d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetOffsetRange(PetscSection, PetscInt *, PetscInt *);
408d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionView(PetscSection, PetscViewer);
409ce1779c8SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscSectionViewFromOptions(PetscSection A,const char prefix[],const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,prefix,name);}
410d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionReset(PetscSection);
411d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionDestroy(PetscSection*);
412d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateGlobalSection(PetscSection, PetscSF, PetscBool, PetscSection *);
413d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection, PetscSF, PetscBool, PetscInt, const PetscInt [], PetscSection *);
414d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateSubsection(PetscSection, PetscInt, PetscInt [], PetscSection *);
415d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection, IS, PetscSection *);
416d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetPointLayout(MPI_Comm, PetscSection, PetscLayout *);
417d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetValueLayout(MPI_Comm, PetscSection, PetscLayout *);
418b348688eSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionPermute(PetscSection, IS, PetscSection *);
419a7c23f90SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionGetField(PetscSection, PetscInt, PetscSection *);
420d53a3d6fSBarry Smith 
42105eca2e3SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionSetClosureIndex(PetscSection, PetscObject, PetscSection, IS);
42205eca2e3SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionGetClosureIndex(PetscSection, PetscObject, PetscSection *, IS *);
423d53a3d6fSBarry Smith 
424d53a3d6fSBarry Smith /* PetscSF support */
425d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFConvertPartition(PetscSF, PetscSection, IS, ISLocalToGlobalMapping *, PetscSF *);
426d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFCreateRemoteOffsets(PetscSF, PetscSection, PetscSection, PetscInt **);
427d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFDistributeSection(PetscSF, PetscSection, PetscInt **, PetscSection);
428d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFCreateSectionSF(PetscSF, PetscSection, PetscInt [], PetscSection, PetscSF *);
429d53a3d6fSBarry Smith 
4309e03d832SJed Brown /* Reset __FUNCT__ in case the user does not define it themselves */
4319e03d832SJed Brown #undef __FUNCT__
4329e03d832SJed Brown #define __FUNCT__ "User provided function"
4339e03d832SJed Brown 
434a2ce50c7SBarry Smith #endif
435