xref: /petsc/include/petscis.h (revision e32f2f54e699d0aa6e733466c00da7e34666fe5e)
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
7d382aafbSBarry Smith #include "petscsys.h"
8e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
92eac72dbSBarry Smith 
100700a824SBarry Smith extern PETSCVEC_DLLEXPORT PetscClassId IS_CLASSID;
11f0479e8cSBarry Smith 
122b6de112SBarry Smith EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISInitializePackage(const char[]);
132b6de112SBarry Smith 
145c20da3cSBarry Smith /*S
15f22f69f0SBarry Smith      IS - Abstract PETSc object that allows indexing.
165c20da3cSBarry Smith 
175c20da3cSBarry Smith    Level: beginner
185c20da3cSBarry Smith 
195c20da3cSBarry Smith   Concepts: indexing, stride
205c20da3cSBarry Smith 
215c20da3cSBarry Smith .seealso:  ISCreateGeneral(), ISCreateBlock(), ISCreateStride(), ISGetIndices(), ISDestroy()
225c20da3cSBarry Smith S*/
23f09e8eb9SSatish Balay typedef struct _p_IS* IS;
242eac72dbSBarry Smith 
25639f9d9dSBarry Smith /*
26639f9d9dSBarry Smith     Default index set data structures that PETSc provides.
27639f9d9dSBarry Smith */
28639f9d9dSBarry Smith typedef enum {IS_GENERAL=0,IS_STRIDE=1,IS_BLOCK = 2} ISType;
290c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],IS *);
30edb16ee7SLisandro Dalcin EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISCreateGeneralNC(MPI_Comm,PetscInt,const PetscInt[],IS *);
310c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISCreateGeneralWithArray(MPI_Comm,PetscInt,PetscInt[],IS *);
320c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],IS *);
330c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
344b0e389bSBarry Smith 
350c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISDestroy(IS);
364b0e389bSBarry Smith 
370c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISSetPermutation(IS);
380c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISPermutation(IS,PetscTruth*);
390c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISSetIdentity(IS);
400c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISIdentity(IS,PetscTruth*);
4108480c60SBarry Smith 
425d0c19d7SBarry Smith EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISGetIndices(IS,const PetscInt *[]);
435d0c19d7SBarry Smith EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISRestoreIndices(IS,const PetscInt *[]);
440c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISGetSize(IS,PetscInt *);
450c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISGetLocalSize(IS,PetscInt *);
460c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISInvertPermutation(IS,PetscInt,IS*);
470c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISView(IS,PetscViewer);
480c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISEqual(IS,IS,PetscTruth *);
490c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISSort(IS);
500c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISSorted(IS,PetscTruth *);
510c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISDifference(IS,IS,IS*);
529a05e725SBarry Smith EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISSum(IS,IS,IS*);
536ab11f9bSSatish Balay EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISExpand(IS,IS,IS*);
54612dd529SBarry Smith 
550c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISBlock(IS,PetscTruth*);
565d0c19d7SBarry Smith EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISBlockGetIndices(IS,const PetscInt *[]);
575d0c19d7SBarry Smith EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISBlockRestoreIndices(IS,const PetscInt *[]);
584c31538fSLisandro Dalcin EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISBlockGetLocalSize(IS,PetscInt *);
590c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISBlockGetSize(IS,PetscInt *);
600c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISBlockGetBlockSize(IS,PetscInt *);
61c16cb8f2SBarry Smith 
620c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISStride(IS,PetscTruth*);
630c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISStrideGetInfo(IS,PetscInt *,PetscInt*);
64c16cb8f2SBarry Smith 
650c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISStrideToGeneral(IS);
6638f40f24SLois Curfman McInnes 
670c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISDuplicate(IS,IS*);
6839d8913bSJed Brown EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISCopy(IS,IS);
690c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISAllGather(IS,IS*);
70edf189efSBarry Smith EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISComplement(IS,PetscInt,PetscInt,IS*);
710c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT   ISAllGatherIndices(MPI_Comm,PetscInt,const PetscInt[],PetscInt*,PetscInt*[]);
72d64ed03dSBarry Smith 
7356cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
740700a824SBarry Smith extern PETSCVEC_DLLEXPORT PetscClassId IS_LTOGM_CLASSID;
7556cd22aeSBarry Smith 
765c20da3cSBarry Smith /*S
77d9ffb7b8SBarry Smith    ISLocalToGlobalMapping - mappings from an arbitrary
7890f02eecSBarry Smith       local ordering from 0 to n-1 to a global PETSc ordering
79d4bb536fSBarry Smith       used by a vector or matrix.
80d4bb536fSBarry Smith 
815c20da3cSBarry Smith    Level: intermediate
825c20da3cSBarry Smith 
83d4bb536fSBarry Smith    Note: mapping from Local to Global is scalable; but Global
84eec0b4cfSBarry Smith   to Local may not be if the range of global values represented locally
85d4bb536fSBarry Smith   is very large.
8674637425SBarry Smith 
8774637425SBarry Smith    Note: the ISLocalToGlobalMapping is actually a private object; it is included
8874637425SBarry Smith   here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since
8974637425SBarry Smith   it is used so often.
9074637425SBarry Smith 
915c20da3cSBarry Smith .seealso:  ISLocalToGlobalMappingCreate()
925c20da3cSBarry Smith S*/
9374637425SBarry Smith struct _p_ISLocalToGlobalMapping{
94011f5a45SSatish Balay   PETSCHEADER(int);
9532dcc486SBarry Smith   PetscInt n;                  /* number of local indices */
9632dcc486SBarry Smith   PetscInt *indices;           /* global index of each local index */
9732dcc486SBarry Smith   PetscInt globalstart;        /* first global referenced in indices */
9832dcc486SBarry Smith   PetscInt globalend;          /* last + 1 global referenced in indices */
9932dcc486SBarry Smith   PetscInt *globals;           /* local index for each global index between start and end */
10074637425SBarry Smith };
101f09e8eb9SSatish Balay typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
1025c20da3cSBarry Smith 
1035c20da3cSBarry Smith /*E
1045c20da3cSBarry Smith     ISGlobalToLocalMappingType - Indicates if missing global indices are
1055c20da3cSBarry Smith 
1065c20da3cSBarry Smith    IS_GTOLM_MASK - missing global indices are replaced with -1
1075c20da3cSBarry Smith    IS_GTOLM_DROP - missing global indices are dropped
1085c20da3cSBarry Smith 
1095c20da3cSBarry Smith    Level: beginner
1105c20da3cSBarry Smith 
1115c20da3cSBarry Smith .seealso: ISGlobalToLocalMappingApply()
1125c20da3cSBarry Smith 
1135c20da3cSBarry Smith E*/
114987e4450SSatish Balay typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
11590f02eecSBarry Smith 
1160c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
1170c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreateNC(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
1180c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
1190c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
1200c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping);
1210c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
1220c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
1230c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
1240c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
1250c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
1260c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
12774637425SBarry Smith 
128d0f46423SBarry Smith PETSC_STATIC_INLINE PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,PetscInt N,const PetscInt in[],PetscInt out[])
129d0f46423SBarry Smith {
1301620fd73SBarry Smith   PetscInt i,*idx = mapping->indices,Nmax = mapping->n;
1311620fd73SBarry Smith   for (i=0; i<N; i++) {
1321620fd73SBarry Smith     if (in[i] < 0) {out[i] = in[i]; continue;}
133*e32f2f54SBarry Smith     if (in[i] >= Nmax) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Local index %D too large %D (max) at %D",in[i],Nmax,i);
1341620fd73SBarry Smith     out[i] = idx[in[i]];
1351620fd73SBarry Smith   }
1361620fd73SBarry Smith   PetscFunctionReturn(0);
13774637425SBarry Smith }
13890f02eecSBarry Smith 
13956cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
140b9617806SBarry Smith /*E
141b9617806SBarry Smith     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
142b9617806SBarry Smith                      or for just the local ghosted portion
143b9617806SBarry Smith 
144b9617806SBarry Smith     Level: beginner
145b9617806SBarry Smith 
1468ee2e534SBarry Smith $   IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function
1478ee2e534SBarry Smith $                        is called synchronously in parallel. This requires generating a "parallel coloring".
1488ee2e534SBarry Smith $   IS_COLORING_GHOSTED - includes colors for ghost points, this is used when the function can be called
1498ee2e534SBarry Smith $                         seperately on individual processes with the ghost points already filled in. Does not
1508ee2e534SBarry Smith $                         require a "parallel coloring", rather each process colors its local + ghost part.
1518ee2e534SBarry Smith $                         Using this can result in much less parallel communication. In the paradigm of
1528ee2e534SBarry Smith $                         DAGetLocalVector() and DAGetGlobalVector() this could be called IS_COLORING_LOCAL
15373d7d85fSBarry Smith 
154b9617806SBarry Smith .seealso: DAGetColoring()
155b9617806SBarry Smith E*/
1568ee2e534SBarry Smith typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType;
157a34d58ebSBarry Smith extern const char *ISColoringTypes[];
1586c09f170SSatish Balay typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue;
1590c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
160dde82324SBarry Smith 
1615c20da3cSBarry Smith /*S
162dde82324SBarry Smith      ISColoring - sets of IS's that define a coloring
163639f9d9dSBarry Smith               of the underlying indices
1645c20da3cSBarry Smith 
1655c20da3cSBarry Smith    Level: intermediate
1665c20da3cSBarry Smith 
1675c20da3cSBarry Smith     Notes:
168b9617806SBarry Smith         One should not access the *is records below directly because they may not yet
1695c20da3cSBarry Smith     have been created. One should use ISColoringGetIS() to make sure they are
1705c20da3cSBarry Smith     created when needed.
1715c20da3cSBarry Smith 
1725c20da3cSBarry Smith .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
1735c20da3cSBarry Smith S*/
17495fbd943SSatish Balay struct _n_ISColoring {
175a7cc72afSBarry Smith   PetscInt        refct;
176a7cc72afSBarry Smith   PetscInt        n;                /* number of colors */
1775c20da3cSBarry Smith   IS              *is;              /* for each color indicates columns */
178639f9d9dSBarry Smith   MPI_Comm        comm;
17908b6dcc0SBarry Smith   ISColoringValue *colors;          /* for each column indicates color */
18032dcc486SBarry Smith   PetscInt        N;                /* number of columns */
181b9617806SBarry Smith   ISColoringType  ctype;
182639f9d9dSBarry Smith };
18395fbd943SSatish Balay typedef struct _n_ISColoring* ISColoring;
184639f9d9dSBarry Smith 
18506262987SSatish Balay EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*);
1860c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringDestroy(ISColoring);
1870c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringView(ISColoring,PetscViewer);
1880c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
1890c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringRestoreIS(ISColoring,IS*[]);
1903a7fca6bSBarry Smith #define ISColoringReference(coloring) ((coloring)->refct++,0)
1913a7fca6bSBarry Smith #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0)
1923a7fca6bSBarry Smith 
193dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/
194dbef8a1cSBarry Smith 
1950c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISPartitioningToNumbering(IS,IS*);
1966308e1d5SBarry Smith EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISPartitioningCount(IS,PetscInt,PetscInt[]);
197dbef8a1cSBarry Smith 
1980c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
1990c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
2000c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
201d9489beaSHong Zhang 
202e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
203a2ce50c7SBarry Smith #endif
204