xref: /petsc/include/petscis.h (revision 77431f27ef6a796c710ee53da3b02f01a7247aeb)
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
72eac72dbSBarry Smith #include "petsc.h"
8e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
92eac72dbSBarry Smith 
106849ba73SBarry Smith extern PetscCookie IS_COOKIE;
11f0479e8cSBarry Smith 
125c20da3cSBarry Smith /*S
135c20da3cSBarry Smith      IS - Abstract PETSc object that indexing.
145c20da3cSBarry Smith 
155c20da3cSBarry Smith    Level: beginner
165c20da3cSBarry Smith 
175c20da3cSBarry Smith   Concepts: indexing, stride
185c20da3cSBarry Smith 
195c20da3cSBarry Smith .seealso:  ISCreateGeneral(), ISCreateBlock(), ISCreateStride(), ISGetIndices(), ISDestroy()
205c20da3cSBarry Smith S*/
21f09e8eb9SSatish Balay typedef struct _p_IS* IS;
222eac72dbSBarry Smith 
23639f9d9dSBarry Smith /*
24639f9d9dSBarry Smith     Default index set data structures that PETSc provides.
25639f9d9dSBarry Smith */
26639f9d9dSBarry Smith typedef enum {IS_GENERAL=0,IS_STRIDE=1,IS_BLOCK = 2} ISType;
2732dcc486SBarry Smith EXTERN PetscErrorCode   ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],IS *);
2832dcc486SBarry Smith EXTERN PetscErrorCode   ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],IS *);
2932dcc486SBarry Smith EXTERN PetscErrorCode   ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
304b0e389bSBarry Smith 
31dfbe8321SBarry Smith EXTERN PetscErrorCode   ISDestroy(IS);
324b0e389bSBarry Smith 
33dfbe8321SBarry Smith EXTERN PetscErrorCode   ISSetPermutation(IS);
34dfbe8321SBarry Smith EXTERN PetscErrorCode   ISPermutation(IS,PetscTruth*);
35dfbe8321SBarry Smith EXTERN PetscErrorCode   ISSetIdentity(IS);
36dfbe8321SBarry Smith EXTERN PetscErrorCode   ISIdentity(IS,PetscTruth*);
3708480c60SBarry Smith 
3832dcc486SBarry Smith EXTERN PetscErrorCode   ISGetIndices(IS,PetscInt *[]);
3932dcc486SBarry Smith EXTERN PetscErrorCode   ISRestoreIndices(IS,PetscInt *[]);
4032dcc486SBarry Smith EXTERN PetscErrorCode   ISGetSize(IS,PetscInt *);
4132dcc486SBarry Smith EXTERN PetscErrorCode   ISGetLocalSize(IS,PetscInt *);
4232dcc486SBarry Smith EXTERN PetscErrorCode   ISInvertPermutation(IS,PetscInt,IS*);
43dfbe8321SBarry Smith EXTERN PetscErrorCode   ISView(IS,PetscViewer);
44dfbe8321SBarry Smith EXTERN PetscErrorCode   ISEqual(IS,IS,PetscTruth *);
45dfbe8321SBarry Smith EXTERN PetscErrorCode   ISSort(IS);
46dfbe8321SBarry Smith EXTERN PetscErrorCode   ISSorted(IS,PetscTruth *);
47dfbe8321SBarry Smith EXTERN PetscErrorCode   ISDifference(IS,IS,IS*);
48dfbe8321SBarry Smith EXTERN PetscErrorCode   ISSum(IS,IS,IS*);
49612dd529SBarry Smith 
50dfbe8321SBarry Smith EXTERN PetscErrorCode   ISBlock(IS,PetscTruth*);
5132dcc486SBarry Smith EXTERN PetscErrorCode   ISBlockGetIndices(IS,PetscInt *[]);
5232dcc486SBarry Smith EXTERN PetscErrorCode   ISBlockRestoreIndices(IS,PetscInt *[]);
5332dcc486SBarry Smith EXTERN PetscErrorCode   ISBlockGetSize(IS,PetscInt *);
5432dcc486SBarry Smith EXTERN PetscErrorCode   ISBlockGetBlockSize(IS,PetscInt *);
55c16cb8f2SBarry Smith 
56dfbe8321SBarry Smith EXTERN PetscErrorCode   ISStride(IS,PetscTruth*);
5732dcc486SBarry Smith EXTERN PetscErrorCode   ISStrideGetInfo(IS,PetscInt *,PetscInt*);
58c16cb8f2SBarry Smith 
59dfbe8321SBarry Smith EXTERN PetscErrorCode   ISStrideToGeneral(IS);
6038f40f24SLois Curfman McInnes 
61dfbe8321SBarry Smith EXTERN PetscErrorCode   ISDuplicate(IS,IS*);
62dfbe8321SBarry Smith EXTERN PetscErrorCode   ISAllGather(IS,IS*);
6332dcc486SBarry Smith EXTERN PetscErrorCode   ISAllGatherIndices(MPI_Comm,PetscInt,const PetscInt[],PetscInt*,PetscInt*[]);
64d64ed03dSBarry Smith 
6556cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
666849ba73SBarry Smith extern PetscCookie IS_LTOGM_COOKIE;
6756cd22aeSBarry Smith 
685c20da3cSBarry Smith /*S
69d9ffb7b8SBarry Smith    ISLocalToGlobalMapping - mappings from an arbitrary
7090f02eecSBarry Smith       local ordering from 0 to n-1 to a global PETSc ordering
71d4bb536fSBarry Smith       used by a vector or matrix.
72d4bb536fSBarry Smith 
735c20da3cSBarry Smith    Level: intermediate
745c20da3cSBarry Smith 
75d4bb536fSBarry Smith    Note: mapping from Local to Global is scalable; but Global
76eec0b4cfSBarry Smith   to Local may not be if the range of global values represented locally
77d4bb536fSBarry Smith   is very large.
7874637425SBarry Smith 
7974637425SBarry Smith    Note: the ISLocalToGlobalMapping is actually a private object; it is included
8074637425SBarry Smith   here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since
8174637425SBarry Smith   it is used so often.
8274637425SBarry Smith 
835c20da3cSBarry Smith .seealso:  ISLocalToGlobalMappingCreate()
845c20da3cSBarry Smith S*/
8574637425SBarry Smith struct _p_ISLocalToGlobalMapping{
8674637425SBarry Smith   PETSCHEADER(int)
8732dcc486SBarry Smith   PetscInt n;                  /* number of local indices */
8832dcc486SBarry Smith   PetscInt *indices;           /* global index of each local index */
8932dcc486SBarry Smith   PetscInt globalstart;        /* first global referenced in indices */
9032dcc486SBarry Smith   PetscInt globalend;          /* last + 1 global referenced in indices */
9132dcc486SBarry Smith   PetscInt *globals;           /* local index for each global index between start and end */
9274637425SBarry Smith };
93f09e8eb9SSatish Balay typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
945c20da3cSBarry Smith 
955c20da3cSBarry Smith /*E
965c20da3cSBarry Smith     ISGlobalToLocalMappingType - Indicates if missing global indices are
975c20da3cSBarry Smith 
985c20da3cSBarry Smith    IS_GTOLM_MASK - missing global indices are replaced with -1
995c20da3cSBarry Smith    IS_GTOLM_DROP - missing global indices are dropped
1005c20da3cSBarry Smith 
1015c20da3cSBarry Smith    Level: beginner
1025c20da3cSBarry Smith 
1035c20da3cSBarry Smith .seealso: ISGlobalToLocalMappingApply()
1045c20da3cSBarry Smith 
1055c20da3cSBarry Smith E*/
106987e4450SSatish Balay typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
10790f02eecSBarry Smith 
10832dcc486SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
10932dcc486SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingCreateNC(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
110dfbe8321SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
111dfbe8321SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
112dfbe8321SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping);
113dfbe8321SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
11432dcc486SBarry Smith EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
11532dcc486SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
11632dcc486SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
11732dcc486SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
11832dcc486SBarry Smith EXTERN PetscErrorCode ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
11974637425SBarry Smith 
12074637425SBarry Smith #define ISLocalToGlobalMappingApply(mapping,N,in,out) 0;\
12174637425SBarry Smith {\
12232dcc486SBarry Smith   PetscInt _i,*_idx = (mapping)->indices,_Nmax = (mapping)->n;\
12374637425SBarry Smith   for (_i=0; _i<N; _i++) {\
12474637425SBarry Smith     if ((in)[_i] < 0) {(out)[_i] = (in)[_i]; continue;}\
125*77431f27SBarry Smith     if ((in)[_i] >= _Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %D too large %D (max) at %D",(in)[_i],_Nmax,_i);\
12674637425SBarry Smith     (out)[_i] = _idx[(in)[_i]];\
12774637425SBarry Smith   }\
12874637425SBarry Smith }
12990f02eecSBarry Smith 
13056cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
131b9617806SBarry Smith /*E
132b9617806SBarry Smith     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
133b9617806SBarry Smith                      or for just the local ghosted portion
134b9617806SBarry Smith 
135b9617806SBarry Smith     Level: beginner
136b9617806SBarry Smith 
13773d7d85fSBarry Smith $   IS_COLORING_LOCAL - does not include the colors for ghost points
13873d7d85fSBarry Smith $   IS_COLORING_GHOSTED - includes colors for ghost points
13973d7d85fSBarry Smith 
140b9617806SBarry Smith .seealso: DAGetColoring()
141b9617806SBarry Smith E*/
14273d7d85fSBarry Smith typedef enum {IS_COLORING_LOCAL,IS_COLORING_GHOSTED} ISColoringType;
143b9617806SBarry Smith 
14408b6dcc0SBarry Smith #define MPIU_COLORING_VALUE MPI_CHAR
14508b6dcc0SBarry Smith #define IS_COLORING_MAX     255
14608b6dcc0SBarry Smith typedef unsigned char ISColoringValue;
14732dcc486SBarry Smith EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
148dde82324SBarry Smith 
1495c20da3cSBarry Smith /*S
150dde82324SBarry Smith      ISColoring - sets of IS's that define a coloring
151639f9d9dSBarry Smith               of the underlying indices
1525c20da3cSBarry Smith 
1535c20da3cSBarry Smith    Level: intermediate
1545c20da3cSBarry Smith 
1555c20da3cSBarry Smith     Notes:
156b9617806SBarry Smith         One should not access the *is records below directly because they may not yet
1575c20da3cSBarry Smith     have been created. One should use ISColoringGetIS() to make sure they are
1585c20da3cSBarry Smith     created when needed.
1595c20da3cSBarry Smith 
1605c20da3cSBarry Smith .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
1615c20da3cSBarry Smith S*/
162f09e8eb9SSatish Balay struct _p_ISColoring {
16373d7d85fSBarry Smith   int             refct;
1645c20da3cSBarry Smith   int             n;                /* number of colors */
1655c20da3cSBarry Smith   IS              *is;              /* for each color indicates columns */
166639f9d9dSBarry Smith   MPI_Comm        comm;
16708b6dcc0SBarry Smith   ISColoringValue *colors;          /* for each column indicates color */
16832dcc486SBarry Smith   PetscInt        N;                /* number of columns */
169b9617806SBarry Smith   ISColoringType  ctype;
170639f9d9dSBarry Smith };
171f09e8eb9SSatish Balay typedef struct _p_ISColoring* ISColoring;
172639f9d9dSBarry Smith 
17332dcc486SBarry Smith EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,const ISColoringValue[],ISColoring*);
174dfbe8321SBarry Smith EXTERN PetscErrorCode ISColoringDestroy(ISColoring);
175dfbe8321SBarry Smith EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
17632dcc486SBarry Smith EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
177dfbe8321SBarry Smith EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]);
1783a7fca6bSBarry Smith #define ISColoringReference(coloring) ((coloring)->refct++,0)
1793a7fca6bSBarry Smith #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0)
1803a7fca6bSBarry Smith 
181dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/
182dbef8a1cSBarry Smith 
183dfbe8321SBarry Smith EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
18432dcc486SBarry Smith EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt[]);
185dbef8a1cSBarry Smith 
18632dcc486SBarry Smith EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
18732dcc486SBarry Smith EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
18832dcc486SBarry Smith EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
189d9489beaSHong Zhang 
190e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
191a2ce50c7SBarry Smith #endif
192