xref: /petsc/include/petscis.h (revision e37d522bb0b6b2e333f7f902c83cd8ffbf2c1c9a)
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 */
56524c165SJacob Faibussowitsch #ifndef PETSCIS_H
626bd1501SBarry Smith #define PETSCIS_H
7ac09b921SBarry Smith 
82c8e378dSBarry Smith #include <petscsys.h>
90c312b8eSJed Brown #include <petscsftypes.h>
10ea844a1aSMatthew Knepley #include <petscsectiontypes.h>
114914ba2bSBarry Smith #include <petscistypes.h> /*I  "petscis.h" I*/
122eac72dbSBarry Smith 
13ac09b921SBarry Smith /* SUBMANSEC = IS */
14ac09b921SBarry Smith 
1597b48c8fSBarry Smith #define IS_FILE_CLASSID 1211218
16014dd563SJed Brown PETSC_EXTERN PetscClassId IS_CLASSID;
17f0479e8cSBarry Smith 
18607a6623SBarry Smith PETSC_EXTERN PetscErrorCode ISInitializePackage(void);
192b6de112SBarry Smith 
2076bdecfbSBarry Smith /*J
218f6c3df8SBarry Smith     ISType - String with the name of a PETSc index set type
2227bdab1eSBarry Smith 
2327bdab1eSBarry Smith    Level: beginner
2427bdab1eSBarry Smith 
25db781477SPatrick Sanan .seealso: `ISSetType()`, `IS`, `ISCreate()`, `ISRegister()`
2676bdecfbSBarry Smith J*/
2719fd82e9SBarry Smith typedef const char *ISType;
2827bdab1eSBarry Smith #define ISGENERAL "general"
2927bdab1eSBarry Smith #define ISSTRIDE  "stride"
3027bdab1eSBarry Smith #define ISBLOCK   "block"
3127bdab1eSBarry Smith 
3227bdab1eSBarry Smith /* Dynamic creation and loading functions */
33140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList ISList;
3419fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode    ISSetType(IS, ISType);
3519fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode    ISGetType(IS, ISType *);
36bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode    ISRegister(const char[], PetscErrorCode (*)(IS));
37014dd563SJed Brown PETSC_EXTERN PetscErrorCode    ISCreate(MPI_Comm, IS *);
3827bdab1eSBarry Smith 
39014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDestroy(IS *);
40014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetPermutation(IS);
41014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPermutation(IS, PetscBool *);
42014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetIdentity(IS);
43014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISIdentity(IS, PetscBool *);
44014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISContiguousLocal(IS, PetscInt, PetscInt, PetscInt *, PetscBool *);
4508480c60SBarry Smith 
462a1da528SToby Isaac /*E
472a1da528SToby Isaac     ISInfo - Info that may either be computed or set as known for an index set
482a1da528SToby Isaac 
492a1da528SToby Isaac     Level: beginner
502a1da528SToby Isaac 
512a1da528SToby Isaac    Developer Notes:
522a1da528SToby Isaac    Entries that are negative need not be called collectively by all processes.
532a1da528SToby Isaac 
5487497f52SBarry Smith    Any additions/changes here MUST also be made in include/petsc/finclude/petscis.h
5587497f52SBarry Smith 
5687497f52SBarry Smith    Any additions/changes here must also be made in src/vec/vec/interface/dlregisvec.c in ISInfos[]
5787497f52SBarry Smith 
58db781477SPatrick Sanan .seealso: `ISSetInfo()`
592a1da528SToby Isaac E*/
609371c9d4SSatish Balay typedef enum {
619371c9d4SSatish Balay   IS_INFO_MIN    = -1,
622a1da528SToby Isaac   IS_SORTED      = 0,
632a1da528SToby Isaac   IS_UNIQUE      = 1,
642a1da528SToby Isaac   IS_PERMUTATION = 2,
652a1da528SToby Isaac   IS_INTERVAL    = 3,
662a1da528SToby Isaac   IS_IDENTITY    = 4,
679371c9d4SSatish Balay   IS_INFO_MAX    = 5
689371c9d4SSatish Balay } ISInfo;
692a1da528SToby Isaac 
709371c9d4SSatish Balay typedef enum {
719371c9d4SSatish Balay   IS_LOCAL,
729371c9d4SSatish Balay   IS_GLOBAL
739371c9d4SSatish Balay } ISInfoType;
742a1da528SToby Isaac 
752a1da528SToby Isaac PETSC_EXTERN PetscErrorCode ISSetInfo(IS, ISInfo, ISInfoType, PetscBool, PetscBool);
76657dc977SToby Isaac PETSC_EXTERN PetscErrorCode ISGetInfo(IS, ISInfo, ISInfoType, PetscBool, PetscBool *);
772a1da528SToby Isaac PETSC_EXTERN PetscErrorCode ISClearInfoCache(IS, PetscBool);
78014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetIndices(IS, const PetscInt *[]);
79014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreIndices(IS, const PetscInt *[]);
80014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetTotalIndices(IS, const PetscInt *[]);
81014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreTotalIndices(IS, const PetscInt *[]);
82014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIndices(IS, const PetscInt *[]);
83014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIndices(IS, const PetscInt *[]);
84d60670a5SStefano Zampini PETSC_EXTERN PetscErrorCode ISGetNonlocalIS(IS, IS *);
85d60670a5SStefano Zampini PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIS(IS, IS *);
86014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetSize(IS, PetscInt *);
87014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetLocalSize(IS, PetscInt *);
88014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISInvertPermutation(IS, PetscInt, IS *);
89014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISView(IS, PetscViewer);
90fe2efc57SMark PETSC_EXTERN PetscErrorCode ISViewFromOptions(IS, PetscObject, const char[]);
91235f7792SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISLoad(IS, PetscViewer);
92014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISEqual(IS, IS, PetscBool *);
93e8386968SVaclav Hapla PETSC_EXTERN PetscErrorCode ISEqualUnsorted(IS, IS, PetscBool *);
94014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSort(IS);
95b080c0f9SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISSortRemoveDups(IS);
96014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSorted(IS, PetscBool *);
97014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDifference(IS, IS, IS *);
98014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSum(IS, IS, IS *);
99014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpand(IS, IS, IS *);
1003daafeecSToby Isaac PETSC_EXTERN PetscErrorCode ISIntersect(IS, IS, IS *);
101132da990SBarry Smith PETSC_EXTERN PetscErrorCode ISGetMinMax(IS, PetscInt *, PetscInt *);
102612dd529SBarry Smith 
103c3c3c9f4SToby Isaac PETSC_EXTERN PetscErrorCode ISLocate(IS, PetscInt, PetscInt *);
1049305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISGetPointRange(IS, PetscInt *, PetscInt *, const PetscInt **);
1059305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISRestorePointRange(IS, PetscInt *, PetscInt *, const PetscInt **);
1069305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISGetPointSubrange(IS, PetscInt, PetscInt, const PetscInt *);
107c3c3c9f4SToby Isaac 
108014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS, PetscInt *);
109014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS, PetscInt);
110c16cb8f2SBarry Smith 
111014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISToGeneral(IS);
11238f40f24SLois Curfman McInnes 
113014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDuplicate(IS, IS *);
114014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCopy(IS, IS);
1159fdaf958SVaclav Hapla PETSC_EXTERN PetscErrorCode ISShift(IS, PetscInt, IS);
116014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGather(IS, IS *);
117014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISComplement(IS, PetscInt, PetscInt, IS *);
118014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm, PetscInt, const IS[], IS *);
119bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm, PetscInt, IS[], IS *, IS *);
120bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISPairToList(IS, IS, PetscInt *, IS *[]);
121bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISEmbed(IS, IS, PetscBool, IS *);
1225ea6c424SDmitry Karpeev PETSC_EXTERN PetscErrorCode ISSortPermutation(IS, PetscBool, IS *);
123014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISOnComm(IS, MPI_Comm, PetscCopyMode, IS *);
1246583bcc1SStefano Zampini PETSC_EXTERN PetscErrorCode ISRenumber(IS, IS, PetscInt *, IS *);
1256c04a3c5SFande Kong PETSC_EXTERN PetscErrorCode ISCreateSubIS(IS, IS, IS *);
126d64ed03dSBarry Smith 
12784933e40SVaclav Hapla /* ISGENERAL specific */
12884933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateGeneral(MPI_Comm, PetscInt, const PetscInt[], PetscCopyMode, IS *);
12984933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralSetIndices(IS, PetscInt, const PetscInt[], PetscCopyMode);
1309bc6f2f1SVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralSetIndicesFromMask(IS, PetscInt, PetscInt, const PetscBool[]);
13153bb9c4cSVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralFilter(IS, PetscInt, PetscInt);
13253bb9c4cSVaclav Hapla 
13384933e40SVaclav Hapla /* ISBLOCK specific */
13484933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateBlock(MPI_Comm, PetscInt, PetscInt, const PetscInt[], PetscCopyMode, IS *);
13584933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockSetIndices(IS, PetscInt, PetscInt, const PetscInt[], PetscCopyMode);
13684933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS, const PetscInt *[]);
13784933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS, const PetscInt *[]);
13884933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS, PetscInt *);
13984933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS, PetscInt *);
14084933e40SVaclav Hapla 
14184933e40SVaclav Hapla /* ISSTRIDE specific */
14284933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateStride(MPI_Comm, PetscInt, PetscInt, PetscInt, IS *);
14384933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISStrideSetStride(IS, PetscInt, PetscInt, PetscInt);
14484933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS, PetscInt *, PetscInt *);
14584933e40SVaclav Hapla 
14656cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
147014dd563SJed Brown PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID;
14856cd22aeSBarry Smith 
1495c20da3cSBarry Smith /*E
1500040bde1SJunchao Zhang     ISGlobalToLocalMappingMode - Indicates mapping behavior if global indices are missing
1515c20da3cSBarry Smith 
15287497f52SBarry Smith    `IS_GTOLM_MASK` - missing global indices are masked by mapping them to a local index of -1
15387497f52SBarry Smith    `IS_GTOLM_DROP` - missing global indices are dropped
1545c20da3cSBarry Smith 
1555c20da3cSBarry Smith    Level: beginner
1565c20da3cSBarry Smith 
157db781477SPatrick Sanan .seealso: `ISGlobalToLocalMappingApplyBlock()`, `ISGlobalToLocalMappingApply()`
1585c20da3cSBarry Smith 
1595c20da3cSBarry Smith E*/
1609371c9d4SSatish Balay typedef enum {
1619371c9d4SSatish Balay   IS_GTOLM_MASK,
1629371c9d4SSatish Balay   IS_GTOLM_DROP
1639371c9d4SSatish Balay } ISGlobalToLocalMappingMode;
16490f02eecSBarry Smith 
165413f72f0SBarry Smith /*J
166413f72f0SBarry Smith     ISLocalToGlobalMappingType - String with the name of a mapping method
167413f72f0SBarry Smith 
168413f72f0SBarry Smith    Level: beginner
169413f72f0SBarry Smith 
170db781477SPatrick Sanan .seealso: `ISLocalToGlobalMappingSetType()`, `ISLocalToGlobalSetFromOptions()`
171413f72f0SBarry Smith J*/
172413f72f0SBarry Smith typedef const char *ISLocalToGlobalMappingType;
173413f72f0SBarry Smith #define ISLOCALTOGLOBALMAPPINGBASIC "basic"
174413f72f0SBarry Smith #define ISLOCALTOGLOBALMAPPINGHASH  "hash"
175413f72f0SBarry Smith 
176413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetType(ISLocalToGlobalMapping, ISLocalToGlobalMappingType);
177a0d79125SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetType(ISLocalToGlobalMapping, ISLocalToGlobalMappingType *);
1781d36bdfdSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRegister(const char[], PetscErrorCode (*)(ISLocalToGlobalMapping));
179413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRegisterAll(void);
180f0413b6fSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm, PetscInt, PetscInt, const PetscInt[], PetscCopyMode, ISLocalToGlobalMapping *);
181014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS, ISLocalToGlobalMapping *);
182014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF, PetscInt, ISLocalToGlobalMapping *);
1837e99dc12SLawrence Mitchell PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetFromOptions(ISLocalToGlobalMapping);
184413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetUp(ISLocalToGlobalMapping);
185014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping, PetscViewer);
186fe2efc57SMark PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingViewFromOptions(ISLocalToGlobalMapping, PetscObject, const char[]);
187662df134SStefano Zampini 
188014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping *);
18904a59952SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping, PetscInt, const PetscInt[], PetscInt[]);
19045b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyBlock(ISLocalToGlobalMapping, PetscInt, const PetscInt[], PetscInt[]);
191014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping, IS, IS *);
192413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, PetscInt, const PetscInt[], PetscInt *, PetscInt[]);
193413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyBlock(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, PetscInt, const PetscInt[], PetscInt *, PetscInt[]);
194413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyIS(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, IS, IS *);
195014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping, PetscInt *);
1961bd0b88eSStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]);
1971bd0b88eSStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]);
198014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]);
199014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]);
2006a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]);
2016a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]);
202014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping, const PetscInt **);
203014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping, const PetscInt **);
20445b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockIndices(ISLocalToGlobalMapping, const PetscInt **);
20545b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockIndices(ISLocalToGlobalMapping, const PetscInt **);
206014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm, PetscInt, const ISLocalToGlobalMapping[], ISLocalToGlobalMapping *);
20745b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockSize(ISLocalToGlobalMapping, PetscInt *);
20863fa5c83Sstefano_zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetBlockSize(ISLocalToGlobalMapping, PetscInt);
2096658fb44Sstefano_zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDuplicate(ISLocalToGlobalMapping, ISLocalToGlobalMapping *);
21045b6f7e9SBarry Smith 
21156cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
212b9617806SBarry Smith /*E
213b9617806SBarry Smith     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
214b9617806SBarry Smith                      or for just the local ghosted portion
215b9617806SBarry Smith 
216b9617806SBarry Smith     Level: beginner
217b9617806SBarry Smith 
21887497f52SBarry Smith $   `IS_COLORING_GLOBAL` - does not include the colors for ghost points, this is used when the function
2198ee2e534SBarry Smith $                        is called synchronously in parallel. This requires generating a "parallel coloring".
22087497f52SBarry Smith $   `IS_COLORING_LOCAL` - includes colors for ghost points, this is used when the function can be called
221bebe2cf6SSatish Balay $                         separately on individual processes with the ghost points already filled in. Does not
2228ee2e534SBarry Smith $                         require a "parallel coloring", rather each process colors its local + ghost part.
2235bdb020cSBarry Smith $                         Using this can result in much less parallel communication. Currently only works
2245bdb020cSBarry Smith $                         with DMDA and if you call MatFDColoringSetFunction() with the local function.
22573d7d85fSBarry Smith 
226db781477SPatrick Sanan .seealso: `DMCreateColoring()`
227b9617806SBarry Smith E*/
2289371c9d4SSatish Balay typedef enum {
2299371c9d4SSatish Balay   IS_COLORING_GLOBAL,
2309371c9d4SSatish Balay   IS_COLORING_LOCAL
2319371c9d4SSatish Balay } ISColoringType;
2326a6fc655SJed Brown PETSC_EXTERN const char *const                ISColoringTypes[];
233569ea7c4SPierre Jolivet typedef unsigned PETSC_IS_COLORING_VALUE_TYPE ISColoringValue;
234569ea7c4SPierre Jolivet #define IS_COLORING_MAX     PETSC_IS_COLORING_MAX
235569ea7c4SPierre Jolivet #define MPIU_COLORING_VALUE PETSC_MPIU_IS_COLORING_VALUE_TYPE
236014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm, PetscInt, ISColoringValue *, PetscInt *, ISColoringValue *[]);
237dde82324SBarry Smith 
238aaf3ff59SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm, PetscInt, PetscInt, const ISColoringValue[], PetscCopyMode, ISColoring *);
239014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring *);
240014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring, PetscViewer);
2418aec7d55SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringViewFromOptions(ISColoring, PetscObject, const char[]);
242071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring, PetscCopyMode, PetscInt *, IS *[]);
243071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring, PetscCopyMode, IS *[]);
24449b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring);
24549b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring, ISColoringType);
246bdaf1daeSBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetType(ISColoring, ISColoringType *);
247bdaf1daeSBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetColors(ISColoring, PetscInt *, PetscInt *, const ISColoringValue **);
2483a7fca6bSBarry Smith 
249dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/
25094f0491fSFande Kong PETSC_EXTERN PetscErrorCode ISBuildTwoSided(IS, IS, IS *);
251014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS, IS *);
252014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS, PetscInt, PetscInt[]);
253dbef8a1cSBarry Smith 
254014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt, PetscInt, PetscInt, PetscInt, const IS[], IS[]);
255*e37d522bSPierre Jolivet PETSC_DEPRECATED_FUNCTION("Use ISCompressIndicesGeneral() (since version 3.19)") static inline PetscErrorCode ISCompressIndicesSorted(PetscInt n, PetscInt bs, PetscInt imax, const IS is_in[], IS is_out[])
256*e37d522bSPierre Jolivet {
257*e37d522bSPierre Jolivet   return ISCompressIndicesGeneral(n, bs, n, imax, is_in, is_out);
258*e37d522bSPierre Jolivet }
259014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt, PetscInt, PetscInt, PetscInt, const IS[], IS[]);
260d9489beaSHong Zhang 
26169ce434fSBarry Smith struct _n_PetscLayout {
26269ce434fSBarry Smith   MPI_Comm               comm;
26338a25198SStefano Zampini   PetscMPIInt            size;
26469ce434fSBarry Smith   PetscInt               n, N;         /* local, global vector size */
26569ce434fSBarry Smith   PetscInt               rstart, rend; /* local start, local end + 1 */
26669ce434fSBarry Smith   PetscInt              *range;        /* the offset of each processor */
2679621ec18SVaclav Hapla   PetscBool              range_alloc;  /* should range be freed in Destroy? */
26833d57670SJed Brown   PetscInt               bs;           /* number of elements in each block (generally for multi-component
26933d57670SJed Brown                                        * problems). Defaults to -1 and can be arbitrarily lazy so always use
27033d57670SJed Brown                                        * PetscAbs(map->bs) when accessing directly and expecting result to be
27133d57670SJed Brown                                        * positive. Do NOT multiply above numbers by bs */
2722a7a6963SBarry Smith   PetscInt               refcnt;       /* MPI Vecs obtained with VecDuplicate() and from MatCreateVecs() reuse map of input object */
27369ce434fSBarry Smith   ISLocalToGlobalMapping mapping;      /* mapping used in Vec/MatSetValuesLocal() */
274ca5434daSLawrence Mitchell   PetscBool              setupcalled;  /* Forbid setup more than once */
275ca5434daSLawrence Mitchell   PetscInt               oldn, oldN;   /* Checking if setup is allowed */
276ca5434daSLawrence Mitchell   PetscInt               oldbs;        /* And again */
27769ce434fSBarry Smith };
27869ce434fSBarry Smith 
2797e3c27c9SBarry Smith /*@C
28069ce434fSBarry Smith      PetscLayoutFindOwner - Find the owning rank for a global index
28169ce434fSBarry Smith 
28220f4b53cSBarry Smith     Not Collective; No Fortran Support
28369ce434fSBarry Smith 
28469ce434fSBarry Smith    Input Parameters:
28569ce434fSBarry Smith +    map - the layout
28669ce434fSBarry Smith -    idx - global index to find the owner of
28769ce434fSBarry Smith 
28869ce434fSBarry Smith    Output Parameter:
28969ce434fSBarry Smith .    owner - the owning rank
29069ce434fSBarry Smith 
29169ce434fSBarry Smith    Level: developer
29269ce434fSBarry Smith 
29387497f52SBarry Smith .seealso: `PetscLayoutFindOwnerIndex()`
29469ce434fSBarry Smith @*/
295d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscLayoutFindOwner(PetscLayout map, PetscInt idx, PetscMPIInt *owner)
296d71ae5a4SJacob Faibussowitsch {
29769ce434fSBarry Smith   PetscMPIInt lo = 0, hi, t;
29869ce434fSBarry Smith 
29969ce434fSBarry Smith   PetscFunctionBegin;
30069ce434fSBarry Smith   *owner = -1; /* GCC erroneously issues warning about possibly uninitialized use when error condition */
30138a25198SStefano Zampini #if defined(PETSC_USE_DEBUG)
3022c71b3e2SJacob Faibussowitsch   PetscCheck((map->n >= 0) && (map->N >= 0) && (map->range), PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "PetscLayoutSetUp() must be called first");
3032c71b3e2SJacob Faibussowitsch   PetscCheck(idx >= 0 && idx <= map->N, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Index %" PetscInt_FMT " is out of range", idx);
30438a25198SStefano Zampini #endif
30538a25198SStefano Zampini   hi = map->size;
30669ce434fSBarry Smith   while (hi - lo > 1) {
30769ce434fSBarry Smith     t = lo + (hi - lo) / 2;
30869ce434fSBarry Smith     if (idx < map->range[t]) hi = t;
30969ce434fSBarry Smith     else lo = t;
31069ce434fSBarry Smith   }
31169ce434fSBarry Smith   *owner = lo;
3123ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
31369ce434fSBarry Smith }
31469ce434fSBarry Smith 
31569ce434fSBarry Smith /*@C
31669ce434fSBarry Smith      PetscLayoutFindOwnerIndex - Find the owning rank and the local index for a global index
31769ce434fSBarry Smith 
31820f4b53cSBarry Smith     Not Collective; No Fortran Support
31969ce434fSBarry Smith 
32069ce434fSBarry Smith    Input Parameters:
32169ce434fSBarry Smith +    map   - the layout
32269ce434fSBarry Smith -    idx   - global index to find the owner of
32369ce434fSBarry Smith 
324d8d19677SJose E. Roman    Output Parameters:
32569ce434fSBarry Smith +    owner - the owning rank
32669ce434fSBarry Smith -    lidx  - local index used by the owner for idx
32769ce434fSBarry Smith 
32869ce434fSBarry Smith    Level: developer
32969ce434fSBarry Smith 
33087497f52SBarry Smith .seealso: `PetscLayoutFindOwner()`
33187497f52SBarry Smith 
33269ce434fSBarry Smith @*/
333d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscLayoutFindOwnerIndex(PetscLayout map, PetscInt idx, PetscMPIInt *owner, PetscInt *lidx)
334d71ae5a4SJacob Faibussowitsch {
33569ce434fSBarry Smith   PetscMPIInt lo = 0, hi, t;
33669ce434fSBarry Smith 
33769ce434fSBarry Smith   PetscFunctionBegin;
33838a25198SStefano Zampini #if defined(PETSC_USE_DEBUG)
3392c71b3e2SJacob Faibussowitsch   PetscCheck((map->n >= 0) && (map->N >= 0) && (map->range), PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "PetscLayoutSetUp() must be called first");
3402c71b3e2SJacob Faibussowitsch   PetscCheck(idx >= 0 && idx <= map->N, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Index %" PetscInt_FMT " is out of range", idx);
34138a25198SStefano Zampini #endif
34238a25198SStefano Zampini   hi = map->size;
34369ce434fSBarry Smith   while (hi - lo > 1) {
34469ce434fSBarry Smith     t = lo + (hi - lo) / 2;
34569ce434fSBarry Smith     if (idx < map->range[t]) hi = t;
34669ce434fSBarry Smith     else lo = t;
34769ce434fSBarry Smith   }
34804799504SMark Adams   if (owner) *owner = lo;
34904799504SMark Adams   if (lidx) *lidx = idx - map->range[lo];
3503ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
35169ce434fSBarry Smith }
3529e03d832SJed Brown 
35301e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutCreate(MPI_Comm, PetscLayout *);
3549621ec18SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscLayoutCreateFromSizes(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscLayout *);
3559621ec18SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscLayoutCreateFromRanges(MPI_Comm, const PetscInt[], PetscCopyMode, PetscInt, PetscLayout *);
35601e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetUp(PetscLayout);
35701e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDestroy(PetscLayout *);
35801e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDuplicate(PetscLayout, PetscLayout *);
35901e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutReference(PetscLayout, PetscLayout *);
36001e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetLocalSize(PetscLayout, PetscInt);
36101e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetLocalSize(PetscLayout, PetscInt *);
36201e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetSize(PetscLayout, PetscInt);
36301e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetSize(PetscLayout, PetscInt *);
36401e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetBlockSize(PetscLayout, PetscInt);
36501e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetBlockSize(PetscLayout, PetscInt *);
36601e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRange(PetscLayout, PetscInt *, PetscInt *);
36701e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRanges(PetscLayout, const PetscInt *[]);
368f92d6284SStefano Zampini PETSC_EXTERN PetscErrorCode PetscLayoutCompare(PetscLayout, PetscLayout, PetscBool *);
36901e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout, ISLocalToGlobalMapping);
37007acc2aeSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutMapLocal(PetscLayout, PetscInt, const PetscInt[], PetscInt *, PetscInt **, PetscInt **);
37101e13f73SMatthew G. Knepley 
372ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortInt(PetscLayout, PetscLayout, PetscInt *, PetscInt *);
373ce605777SToby Isaac 
374ce605777SToby Isaac PETSC_EXTERN PetscErrorCode ISGetLayout(IS, PetscLayout *);
3754e1d6e84SVaclav Hapla PETSC_EXTERN PetscErrorCode ISSetLayout(IS, PetscLayout);
376ce605777SToby Isaac 
377a2ce50c7SBarry Smith #endif
378