xref: /petsc/include/petscis.h (revision 4f037aad63b0dd02ec302d96e63d16a2808e7a1f)
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 */
5a4963045SJacob Faibussowitsch #pragma once
6ac09b921SBarry Smith 
755502333SMatthew G. Knepley #include "petscsystypes.h"
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 
13ce78bad3SBarry Smith /* MANSEC = Vec */
14ac09b921SBarry Smith /* SUBMANSEC = IS */
15ac09b921SBarry Smith 
1697b48c8fSBarry Smith #define IS_FILE_CLASSID 1211218
17014dd563SJed Brown PETSC_EXTERN PetscClassId IS_CLASSID;
18f0479e8cSBarry Smith 
19607a6623SBarry Smith PETSC_EXTERN PetscErrorCode ISInitializePackage(void);
204bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode ISFinalizePackage(void);
212b6de112SBarry Smith 
2276bdecfbSBarry Smith /*J
238f6c3df8SBarry Smith     ISType - String with the name of a PETSc index set type
2427bdab1eSBarry Smith 
2516a05f60SBarry Smith    Values:
269c89aa79SPierre Jolivet +  `ISGENERAL` - the values are stored with an array of indices and generally have no structure
2716a05f60SBarry Smith .  `ISSTRIDE`  - the values have a simple structure of an initial offset and then a step size between values
28af27ebaaSBarry Smith -  `ISBLOCK`   - values are an array of indices, each representing a block (of the same common length) of values
2916a05f60SBarry Smith 
3027bdab1eSBarry Smith    Level: beginner
3127bdab1eSBarry Smith 
3216a05f60SBarry Smith .seealso: `ISSetType()`, `IS`, `ISCreateGeneral()`, `ISCreateStride()`, `ISCreateBlock()`, `ISCreate()`, `ISRegister()`,
3316a05f60SBarry Smith           `VecScatterCreate()`, `MatGetSubMatrices()`
3476bdecfbSBarry Smith J*/
3519fd82e9SBarry Smith typedef const char *ISType;
3627bdab1eSBarry Smith #define ISGENERAL "general"
3727bdab1eSBarry Smith #define ISSTRIDE  "stride"
3827bdab1eSBarry Smith #define ISBLOCK   "block"
3927bdab1eSBarry Smith 
4027bdab1eSBarry Smith /* Dynamic creation and loading functions */
41140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList ISList;
4219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode    ISSetType(IS, ISType);
4319fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode    ISGetType(IS, ISType *);
44bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode    ISRegister(const char[], PetscErrorCode (*)(IS));
45da8c939bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode    ISRegisterAll(void);
46014dd563SJed Brown PETSC_EXTERN PetscErrorCode    ISCreate(MPI_Comm, IS *);
4727bdab1eSBarry Smith 
48014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDestroy(IS *);
49014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetPermutation(IS);
50014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPermutation(IS, PetscBool *);
51014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetIdentity(IS);
52014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISIdentity(IS, PetscBool *);
53014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISContiguousLocal(IS, PetscInt, PetscInt, PetscInt *, PetscBool *);
5408480c60SBarry Smith 
552a1da528SToby Isaac /*E
562a1da528SToby Isaac    ISInfo - Info that may either be computed or set as known for an index set
572a1da528SToby Isaac 
5816a05f60SBarry Smith    Level: intermediate
592a1da528SToby Isaac 
6095bd0b28SBarry Smith    Developer Note:
612a1da528SToby Isaac    Entries that are negative need not be called collectively by all processes.
622a1da528SToby Isaac 
6316a05f60SBarry Smith .seealso: `IS`, `ISType`, `ISSetInfo()`
642a1da528SToby Isaac E*/
659371c9d4SSatish Balay typedef enum {
669371c9d4SSatish Balay   IS_INFO_MIN    = -1,
672a1da528SToby Isaac   IS_SORTED      = 0,
682a1da528SToby Isaac   IS_UNIQUE      = 1,
692a1da528SToby Isaac   IS_PERMUTATION = 2,
702a1da528SToby Isaac   IS_INTERVAL    = 3,
712a1da528SToby Isaac   IS_IDENTITY    = 4,
729371c9d4SSatish Balay   IS_INFO_MAX    = 5
739371c9d4SSatish Balay } ISInfo;
742a1da528SToby Isaac 
759371c9d4SSatish Balay typedef enum {
769371c9d4SSatish Balay   IS_LOCAL,
779371c9d4SSatish Balay   IS_GLOBAL
789371c9d4SSatish Balay } ISInfoType;
792a1da528SToby Isaac 
802a1da528SToby Isaac PETSC_EXTERN PetscErrorCode ISSetInfo(IS, ISInfo, ISInfoType, PetscBool, PetscBool);
81657dc977SToby Isaac PETSC_EXTERN PetscErrorCode ISGetInfo(IS, ISInfo, ISInfoType, PetscBool, PetscBool *);
822a1da528SToby Isaac PETSC_EXTERN PetscErrorCode ISClearInfoCache(IS, PetscBool);
83014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetIndices(IS, const PetscInt *[]);
84014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreIndices(IS, const PetscInt *[]);
85014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetTotalIndices(IS, const PetscInt *[]);
86014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreTotalIndices(IS, const PetscInt *[]);
87014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIndices(IS, const PetscInt *[]);
88014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIndices(IS, const PetscInt *[]);
89d60670a5SStefano Zampini PETSC_EXTERN PetscErrorCode ISGetNonlocalIS(IS, IS *);
90d60670a5SStefano Zampini PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIS(IS, IS *);
91014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetSize(IS, PetscInt *);
92014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetLocalSize(IS, PetscInt *);
93014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISInvertPermutation(IS, PetscInt, IS *);
94014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISView(IS, PetscViewer);
95fe2efc57SMark PETSC_EXTERN PetscErrorCode ISViewFromOptions(IS, PetscObject, const char[]);
96235f7792SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISLoad(IS, PetscViewer);
97014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISEqual(IS, IS, PetscBool *);
98e8386968SVaclav Hapla PETSC_EXTERN PetscErrorCode ISEqualUnsorted(IS, IS, PetscBool *);
99014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSort(IS);
100b080c0f9SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISSortRemoveDups(IS);
101014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSorted(IS, PetscBool *);
102014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDifference(IS, IS, IS *);
103014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSum(IS, IS, IS *);
104014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpand(IS, IS, IS *);
1053daafeecSToby Isaac PETSC_EXTERN PetscErrorCode ISIntersect(IS, IS, IS *);
106132da990SBarry Smith PETSC_EXTERN PetscErrorCode ISGetMinMax(IS, PetscInt *, PetscInt *);
107612dd529SBarry Smith 
108c3c3c9f4SToby Isaac PETSC_EXTERN PetscErrorCode ISLocate(IS, PetscInt, PetscInt *);
109ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode ISGetPointRange(IS, PetscInt *, PetscInt *, const PetscInt *[]);
110ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode ISRestorePointRange(IS, PetscInt *, PetscInt *, const PetscInt *[]);
1119305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISGetPointSubrange(IS, PetscInt, PetscInt, const PetscInt *);
112c3c3c9f4SToby Isaac 
113014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS, PetscInt *);
114014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS, PetscInt);
11555502333SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISGetCompressOutput(IS, PetscBool *);
11655502333SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISSetCompressOutput(IS, PetscBool);
117c16cb8f2SBarry Smith 
118014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISToGeneral(IS);
11938f40f24SLois Curfman McInnes 
120014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDuplicate(IS, IS *);
121014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCopy(IS, IS);
1229fdaf958SVaclav Hapla PETSC_EXTERN PetscErrorCode ISShift(IS, PetscInt, IS);
123014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGather(IS, IS *);
124014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISComplement(IS, PetscInt, PetscInt, IS *);
125014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm, PetscInt, const IS[], IS *);
126bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm, PetscInt, IS[], IS *, IS *);
127bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISPairToList(IS, IS, PetscInt *, IS *[]);
128bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISEmbed(IS, IS, PetscBool, IS *);
1295ea6c424SDmitry Karpeev PETSC_EXTERN PetscErrorCode ISSortPermutation(IS, PetscBool, IS *);
130014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISOnComm(IS, MPI_Comm, PetscCopyMode, IS *);
1316583bcc1SStefano Zampini PETSC_EXTERN PetscErrorCode ISRenumber(IS, IS, PetscInt *, IS *);
1326c04a3c5SFande Kong PETSC_EXTERN PetscErrorCode ISCreateSubIS(IS, IS, IS *);
133d64ed03dSBarry Smith 
13484933e40SVaclav Hapla /* ISGENERAL specific */
13584933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateGeneral(MPI_Comm, PetscInt, const PetscInt[], PetscCopyMode, IS *);
13684933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralSetIndices(IS, PetscInt, const PetscInt[], PetscCopyMode);
1379bc6f2f1SVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralSetIndicesFromMask(IS, PetscInt, PetscInt, const PetscBool[]);
13853bb9c4cSVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralFilter(IS, PetscInt, PetscInt);
13953bb9c4cSVaclav Hapla 
14084933e40SVaclav Hapla /* ISBLOCK specific */
14184933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateBlock(MPI_Comm, PetscInt, PetscInt, const PetscInt[], PetscCopyMode, IS *);
14284933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockSetIndices(IS, PetscInt, PetscInt, const PetscInt[], PetscCopyMode);
14384933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS, const PetscInt *[]);
14484933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS, const PetscInt *[]);
14584933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS, PetscInt *);
14684933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS, PetscInt *);
14784933e40SVaclav Hapla 
14884933e40SVaclav Hapla /* ISSTRIDE specific */
14984933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateStride(MPI_Comm, PetscInt, PetscInt, PetscInt, IS *);
15084933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISStrideSetStride(IS, PetscInt, PetscInt, PetscInt);
15184933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS, PetscInt *, PetscInt *);
15284933e40SVaclav Hapla 
1537de13914SStefano Zampini #define IS_LTOGM_FILE_CLASSID 1211217
154014dd563SJed Brown PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID;
15556cd22aeSBarry Smith 
1565c20da3cSBarry Smith /*E
1570040bde1SJunchao Zhang    ISGlobalToLocalMappingMode - Indicates mapping behavior if global indices are missing
1585c20da3cSBarry Smith 
15916a05f60SBarry Smith    Values:
16016a05f60SBarry Smith +  `IS_GTOLM_MASK` - missing global indices are masked by mapping them to a local index of -1
16116a05f60SBarry Smith -  `IS_GTOLM_DROP` - missing global indices are dropped
1625c20da3cSBarry Smith 
1635c20da3cSBarry Smith    Level: beginner
1645c20da3cSBarry Smith 
165db781477SPatrick Sanan .seealso: `ISGlobalToLocalMappingApplyBlock()`, `ISGlobalToLocalMappingApply()`
1665c20da3cSBarry Smith E*/
1679371c9d4SSatish Balay typedef enum {
1689371c9d4SSatish Balay   IS_GTOLM_MASK,
1699371c9d4SSatish Balay   IS_GTOLM_DROP
1709371c9d4SSatish Balay } ISGlobalToLocalMappingMode;
17190f02eecSBarry Smith 
172413f72f0SBarry Smith /*J
173413f72f0SBarry Smith    ISLocalToGlobalMappingType - String with the name of a mapping method
174413f72f0SBarry Smith 
17516a05f60SBarry Smith    Values:
17616a05f60SBarry Smith +  `ISLOCALTOGLOBALMAPPINGBASIC` - a non-memory scalable way of storing `ISLocalToGlobalMapping` that allows applying `ISGlobalToLocalMappingApply()` efficiently
17716a05f60SBarry Smith -  `ISLOCALTOGLOBALMAPPINGHASH`  - a memory scalable way of storing `ISLocalToGlobalMapping` that allows applying `ISGlobalToLocalMappingApply()` reasonably efficiently
17816a05f60SBarry Smith 
179413f72f0SBarry Smith    Level: beginner
180413f72f0SBarry Smith 
18116a05f60SBarry Smith .seealso: `ISLocalToGlobalMapping`, `ISLocalToGlobalMappingSetType()`, `ISLocalToGlobalSetFromOptions()`, `ISGlobalToLocalMappingMode`
182413f72f0SBarry Smith J*/
183413f72f0SBarry Smith typedef const char *ISLocalToGlobalMappingType;
184413f72f0SBarry Smith #define ISLOCALTOGLOBALMAPPINGBASIC "basic"
185413f72f0SBarry Smith #define ISLOCALTOGLOBALMAPPINGHASH  "hash"
186413f72f0SBarry Smith 
187413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetType(ISLocalToGlobalMapping, ISLocalToGlobalMappingType);
188a0d79125SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetType(ISLocalToGlobalMapping, ISLocalToGlobalMappingType *);
1891d36bdfdSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRegister(const char[], PetscErrorCode (*)(ISLocalToGlobalMapping));
190413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRegisterAll(void);
191f0413b6fSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm, PetscInt, PetscInt, const PetscInt[], PetscCopyMode, ISLocalToGlobalMapping *);
192014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS, ISLocalToGlobalMapping *);
193014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF, PetscInt, ISLocalToGlobalMapping *);
1947e99dc12SLawrence Mitchell PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetFromOptions(ISLocalToGlobalMapping);
195413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetUp(ISLocalToGlobalMapping);
196014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping, PetscViewer);
1977de13914SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingLoad(ISLocalToGlobalMapping, PetscViewer);
198fe2efc57SMark PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingViewFromOptions(ISLocalToGlobalMapping, PetscObject, const char[]);
199d4df40f3SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm, PetscInt, const ISLocalToGlobalMapping[], ISLocalToGlobalMapping *);
200d4df40f3SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDuplicate(ISLocalToGlobalMapping, ISLocalToGlobalMapping *);
201014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping *);
202d4df40f3SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping, PetscInt *);
203ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping, const PetscInt *[]);
204ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping, const PetscInt *[]);
205ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockIndices(ISLocalToGlobalMapping, const PetscInt *[]);
206ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockIndices(ISLocalToGlobalMapping, const PetscInt *[]);
207d4df40f3SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockSize(ISLocalToGlobalMapping, PetscInt *);
208d4df40f3SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetBlockSize(ISLocalToGlobalMapping, PetscInt);
209d4df40f3SStefano Zampini 
21004a59952SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping, PetscInt, const PetscInt[], PetscInt[]);
21145b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyBlock(ISLocalToGlobalMapping, PetscInt, const PetscInt[], PetscInt[]);
212014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping, IS, IS *);
213413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, PetscInt, const PetscInt[], PetscInt *, PetscInt[]);
214413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyBlock(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, PetscInt, const PetscInt[], PetscInt *, PetscInt[]);
215413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyIS(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, IS, IS *);
216d4df40f3SStefano Zampini 
2171bd0b88eSStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]);
2181bd0b88eSStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]);
219014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]);
220014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]);
221633354d9SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]);
222633354d9SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]);
2236a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]);
2246a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]);
225d4df40f3SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockMultiLeavesSF(ISLocalToGlobalMapping, PetscSF *);
22645b6f7e9SBarry Smith 
227b9617806SBarry Smith /*E
228b9617806SBarry Smith    ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
229b9617806SBarry Smith                     or for just the local ghosted portion
230b9617806SBarry Smith 
23116a05f60SBarry Smith    Values:
23216a05f60SBarry Smith +  `IS_COLORING_GLOBAL` - does not include the colors for ghost points, this is used when the function
23316a05f60SBarry Smith                           is called synchronously in parallel. This requires generating a "parallel coloring".
23416a05f60SBarry Smith -  `IS_COLORING_LOCAL`  - includes colors for ghost points, this is used when the function can be called
23516a05f60SBarry Smith                           separately on individual processes with the ghost points already filled in. Does not
23616a05f60SBarry Smith                           require a "parallel coloring", rather each process colors its local + ghost part.
23716a05f60SBarry Smith                           Using this can result in much less parallel communication. Currently only works
23816a05f60SBarry Smith                           with `DMDA` and if you call `MatFDColoringSetFunction()` with the local function.
23916a05f60SBarry Smith 
240b9617806SBarry Smith    Level: beginner
241b9617806SBarry Smith 
24216a05f60SBarry Smith .seealso: `ISColoring`, `ISColoringSetType()`, `ISColoringGetType()`, `DMCreateColoring()`
243b9617806SBarry Smith E*/
2449371c9d4SSatish Balay typedef enum {
2459371c9d4SSatish Balay   IS_COLORING_GLOBAL,
2469371c9d4SSatish Balay   IS_COLORING_LOCAL
2479371c9d4SSatish Balay } ISColoringType;
248af27ebaaSBarry Smith 
2496a6fc655SJed Brown PETSC_EXTERN const char *const                ISColoringTypes[];
250569ea7c4SPierre Jolivet typedef unsigned PETSC_IS_COLORING_VALUE_TYPE ISColoringValue;
251569ea7c4SPierre Jolivet #define IS_COLORING_MAX     PETSC_IS_COLORING_MAX
252569ea7c4SPierre Jolivet #define MPIU_COLORING_VALUE PETSC_MPIU_IS_COLORING_VALUE_TYPE
253014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm, PetscInt, ISColoringValue *, PetscInt *, ISColoringValue *[]);
254dde82324SBarry Smith 
2556497c311SBarry Smith /*@C
2566497c311SBarry Smith    ISColoringValueCast - casts an integer a `ISColoringValue` (which may be 1-bits in size), generates an
2576497c311SBarry Smith    error if the value is too large
2586497c311SBarry Smith 
2596497c311SBarry Smith    Not Collective; No Fortran Support
2606497c311SBarry Smith 
2616497c311SBarry Smith    Input Parameter:
2626497c311SBarry Smith .  a - the `PetscCount` value
2636497c311SBarry Smith 
2646497c311SBarry Smith    Output Parameter:
265ce78bad3SBarry Smith .  b - the resulting `ISColoringValue` value, optional, pass `NULL` if not needed
2666497c311SBarry Smith 
2676497c311SBarry Smith    Level: advanced
2686497c311SBarry Smith 
2696497c311SBarry Smith    Note:
2706497c311SBarry Smith    Errors if the integer is negative
2716497c311SBarry Smith 
2726497c311SBarry Smith .seealso: `ISColoringValue`, `ISColoringCreate()`, `PetscBLASInt`, `PetscMPIInt`, `PetscInt`, `PetscMPIIntCast()`, `PetscIntCast()`
2736497c311SBarry Smith @*/
ISColoringValueCast(PetscCount a,ISColoringValue * b)2746497c311SBarry Smith static inline PetscErrorCode ISColoringValueCast(PetscCount a, ISColoringValue *b)
2756497c311SBarry Smith {
2766497c311SBarry Smith   PetscFunctionBegin;
277ce78bad3SBarry Smith   if (b) *b = 0;
2786497c311SBarry Smith   PetscCheck(a >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Passing negative integer not supported");
2796497c311SBarry Smith   PetscCheck(a < PETSC_IS_COLORING_MAX, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Integer too large to convert");
280ce78bad3SBarry Smith   if (b) *b = (ISColoringValue)a;
2816497c311SBarry Smith   PetscFunctionReturn(PETSC_SUCCESS);
2826497c311SBarry Smith }
2836497c311SBarry Smith 
284aaf3ff59SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm, PetscInt, PetscInt, const ISColoringValue[], PetscCopyMode, ISColoring *);
285014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring *);
286014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring, PetscViewer);
2878aec7d55SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringViewFromOptions(ISColoring, PetscObject, const char[]);
288071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring, PetscCopyMode, PetscInt *, IS *[]);
289071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring, PetscCopyMode, IS *[]);
29049b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring);
29149b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring, ISColoringType);
292bdaf1daeSBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetType(ISColoring, ISColoringType *);
293ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetColors(ISColoring, PetscInt *, PetscInt *, const ISColoringValue *[]);
2943a7fca6bSBarry Smith 
29594f0491fSFande Kong PETSC_EXTERN PetscErrorCode ISBuildTwoSided(IS, IS, IS *);
296014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS, IS *);
297014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS, PetscInt, PetscInt[]);
298dbef8a1cSBarry Smith 
299014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt, PetscInt, PetscInt, PetscInt, const IS[], IS[]);
ISCompressIndicesSorted(PetscInt n,PetscInt bs,PetscInt imax,const IS is_in[],IS is_out[])300edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 19, 0, "ISCompressIndicesGeneral()", ) static inline PetscErrorCode ISCompressIndicesSorted(PetscInt n, PetscInt bs, PetscInt imax, const IS is_in[], IS is_out[])
301e37d522bSPierre Jolivet {
302e37d522bSPierre Jolivet   return ISCompressIndicesGeneral(n, bs, n, imax, is_in, is_out);
303e37d522bSPierre Jolivet }
304014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt, PetscInt, PetscInt, PetscInt, const IS[], IS[]);
305d9489beaSHong Zhang 
30669ce434fSBarry Smith struct _n_PetscLayout {
30769ce434fSBarry Smith   MPI_Comm               comm;
30838a25198SStefano Zampini   PetscMPIInt            size;
30969ce434fSBarry Smith   PetscInt               n, N;         /* local, global vector size */
31069ce434fSBarry Smith   PetscInt               rstart, rend; /* local start, local end + 1 */
31169ce434fSBarry Smith   PetscInt              *range;        /* the offset of each processor */
3129621ec18SVaclav Hapla   PetscBool              range_alloc;  /* should range be freed in Destroy? */
313*58b7e2c1SStefano Zampini   PetscInt               bs;           /* number of elements in each block (generally for multi-component problems) */
3142a7a6963SBarry Smith   PetscInt               refcnt;       /* MPI Vecs obtained with VecDuplicate() and from MatCreateVecs() reuse map of input object */
31569ce434fSBarry Smith   ISLocalToGlobalMapping mapping;      /* mapping used in Vec/MatSetValuesLocal() */
316ca5434daSLawrence Mitchell   PetscBool              setupcalled;  /* Forbid setup more than once */
317ca5434daSLawrence Mitchell   PetscInt               oldn, oldN;   /* Checking if setup is allowed */
318ca5434daSLawrence Mitchell   PetscInt               oldbs;        /* And again */
31969ce434fSBarry Smith };
32069ce434fSBarry Smith 
32101e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutCreate(MPI_Comm, PetscLayout *);
3225d83a8b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutFindOwner(PetscLayout, PetscInt, PetscMPIInt *);
3235d83a8b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutFindOwnerIndex(PetscLayout, PetscInt, PetscMPIInt *, PetscInt *);
3249621ec18SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscLayoutCreateFromSizes(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscLayout *);
3259621ec18SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscLayoutCreateFromRanges(MPI_Comm, const PetscInt[], PetscCopyMode, PetscInt, PetscLayout *);
32601e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetUp(PetscLayout);
32701e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDestroy(PetscLayout *);
32801e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDuplicate(PetscLayout, PetscLayout *);
32901e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutReference(PetscLayout, PetscLayout *);
33001e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetLocalSize(PetscLayout, PetscInt);
33101e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetLocalSize(PetscLayout, PetscInt *);
33201e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetSize(PetscLayout, PetscInt);
33301e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetSize(PetscLayout, PetscInt *);
33401e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetBlockSize(PetscLayout, PetscInt);
33501e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetBlockSize(PetscLayout, PetscInt *);
33601e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRange(PetscLayout, PetscInt *, PetscInt *);
33701e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRanges(PetscLayout, const PetscInt *[]);
338f92d6284SStefano Zampini PETSC_EXTERN PetscErrorCode PetscLayoutCompare(PetscLayout, PetscLayout, PetscBool *);
33901e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout, ISLocalToGlobalMapping);
340ce78bad3SBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutMapLocal(PetscLayout, PetscInt, const PetscInt[], PetscInt *, PetscInt *[], PetscInt *[]);
34101e13f73SMatthew G. Knepley 
342ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortInt(PetscLayout, PetscLayout, PetscInt *, PetscInt *);
343ce605777SToby Isaac 
34498480730SJames Wright /*S
34598480730SJames Wright   PetscKDTree - Implementation of KDTree for efficiently querying spatial points
34698480730SJames Wright 
34798480730SJames Wright   Level: advanced
34898480730SJames Wright 
34998480730SJames Wright   Note:
35098480730SJames Wright   See <https://en.wikipedia.org/wiki/K-d_tree> for a description of K-d trees
35198480730SJames Wright 
35298480730SJames Wright .seealso: `PetscKDTreeCreate()`, `PetscKDTreeDestroy()`, `PetscKDTreeView()`, `PetscKDTreeQueryPointsNearestNeighbor()`
35398480730SJames Wright S*/
35498480730SJames Wright typedef struct _n_PetscKDTree *PetscKDTree;
35598480730SJames Wright 
35698480730SJames Wright PETSC_EXTERN PetscErrorCode PetscKDTreeCreate(PetscCount, PetscInt, const PetscReal[], PetscCopyMode, PetscInt, PetscKDTree *);
35798480730SJames Wright PETSC_EXTERN PetscErrorCode PetscKDTreeDestroy(PetscKDTree *);
35898480730SJames Wright PETSC_EXTERN PetscErrorCode PetscKDTreeView(PetscKDTree, PetscViewer);
35998480730SJames Wright PETSC_EXTERN PetscErrorCode PetscKDTreeQueryPointsNearestNeighbor(PetscKDTree, PetscCount, const PetscReal[], PetscReal, PetscCount[], PetscReal[]);
36098480730SJames Wright 
361ce605777SToby Isaac PETSC_EXTERN PetscErrorCode ISGetLayout(IS, PetscLayout *);
3624e1d6e84SVaclav Hapla PETSC_EXTERN PetscErrorCode ISSetLayout(IS, PetscLayout);
363