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 10*0c735eedSKris Buschelman extern PETSCVEC_DLLEXPORT 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; 27*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],IS *); 28*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISCreateGeneralWithArray(MPI_Comm,PetscInt,PetscInt[],IS *); 29*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],IS *); 30*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *); 314b0e389bSBarry Smith 32*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISDestroy(IS); 334b0e389bSBarry Smith 34*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISSetPermutation(IS); 35*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISPermutation(IS,PetscTruth*); 36*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISSetIdentity(IS); 37*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISIdentity(IS,PetscTruth*); 3808480c60SBarry Smith 39*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISGetIndices(IS,PetscInt *[]); 40*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISRestoreIndices(IS,PetscInt *[]); 41*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISGetSize(IS,PetscInt *); 42*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISGetLocalSize(IS,PetscInt *); 43*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISInvertPermutation(IS,PetscInt,IS*); 44*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISView(IS,PetscViewer); 45*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISEqual(IS,IS,PetscTruth *); 46*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISSort(IS); 47*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISSorted(IS,PetscTruth *); 48*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISDifference(IS,IS,IS*); 49*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISSum(IS*,IS); 50612dd529SBarry Smith 51*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISBlock(IS,PetscTruth*); 52*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISBlockGetIndices(IS,PetscInt *[]); 53*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISBlockRestoreIndices(IS,PetscInt *[]); 54*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISBlockGetSize(IS,PetscInt *); 55*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISBlockGetBlockSize(IS,PetscInt *); 56c16cb8f2SBarry Smith 57*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISStride(IS,PetscTruth*); 58*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISStrideGetInfo(IS,PetscInt *,PetscInt*); 59c16cb8f2SBarry Smith 60*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISStrideToGeneral(IS); 6138f40f24SLois Curfman McInnes 62*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISDuplicate(IS,IS*); 63*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISAllGather(IS,IS*); 64*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISAllGatherIndices(MPI_Comm,PetscInt,const PetscInt[],PetscInt*,PetscInt*[]); 65d64ed03dSBarry Smith 6656cd22aeSBarry Smith /* --------------------------------------------------------------------------*/ 67*0c735eedSKris Buschelman extern PETSCVEC_DLLEXPORT PetscCookie IS_LTOGM_COOKIE; 6856cd22aeSBarry Smith 695c20da3cSBarry Smith /*S 70d9ffb7b8SBarry Smith ISLocalToGlobalMapping - mappings from an arbitrary 7190f02eecSBarry Smith local ordering from 0 to n-1 to a global PETSc ordering 72d4bb536fSBarry Smith used by a vector or matrix. 73d4bb536fSBarry Smith 745c20da3cSBarry Smith Level: intermediate 755c20da3cSBarry Smith 76d4bb536fSBarry Smith Note: mapping from Local to Global is scalable; but Global 77eec0b4cfSBarry Smith to Local may not be if the range of global values represented locally 78d4bb536fSBarry Smith is very large. 7974637425SBarry Smith 8074637425SBarry Smith Note: the ISLocalToGlobalMapping is actually a private object; it is included 8174637425SBarry Smith here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since 8274637425SBarry Smith it is used so often. 8374637425SBarry Smith 845c20da3cSBarry Smith .seealso: ISLocalToGlobalMappingCreate() 855c20da3cSBarry Smith S*/ 8674637425SBarry Smith struct _p_ISLocalToGlobalMapping{ 87011f5a45SSatish Balay PETSCHEADER(int); 8832dcc486SBarry Smith PetscInt n; /* number of local indices */ 8932dcc486SBarry Smith PetscInt *indices; /* global index of each local index */ 9032dcc486SBarry Smith PetscInt globalstart; /* first global referenced in indices */ 9132dcc486SBarry Smith PetscInt globalend; /* last + 1 global referenced in indices */ 9232dcc486SBarry Smith PetscInt *globals; /* local index for each global index between start and end */ 9374637425SBarry Smith }; 94f09e8eb9SSatish Balay typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping; 955c20da3cSBarry Smith 965c20da3cSBarry Smith /*E 975c20da3cSBarry Smith ISGlobalToLocalMappingType - Indicates if missing global indices are 985c20da3cSBarry Smith 995c20da3cSBarry Smith IS_GTOLM_MASK - missing global indices are replaced with -1 1005c20da3cSBarry Smith IS_GTOLM_DROP - missing global indices are dropped 1015c20da3cSBarry Smith 1025c20da3cSBarry Smith Level: beginner 1035c20da3cSBarry Smith 1045c20da3cSBarry Smith .seealso: ISGlobalToLocalMappingApply() 1055c20da3cSBarry Smith 1065c20da3cSBarry Smith E*/ 107987e4450SSatish Balay typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType; 10890f02eecSBarry Smith 109*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*); 110*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreateNC(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*); 111*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *); 112*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer); 113*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping); 114*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*); 115*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]); 116*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*); 117*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]); 118*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]); 119*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*); 12074637425SBarry Smith 12174637425SBarry Smith #define ISLocalToGlobalMappingApply(mapping,N,in,out) 0;\ 12274637425SBarry Smith {\ 12332dcc486SBarry Smith PetscInt _i,*_idx = (mapping)->indices,_Nmax = (mapping)->n;\ 12474637425SBarry Smith for (_i=0; _i<N; _i++) {\ 12574637425SBarry Smith if ((in)[_i] < 0) {(out)[_i] = (in)[_i]; continue;}\ 12677431f27SBarry Smith if ((in)[_i] >= _Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %D too large %D (max) at %D",(in)[_i],_Nmax,_i);\ 12774637425SBarry Smith (out)[_i] = _idx[(in)[_i]];\ 12874637425SBarry Smith }\ 12974637425SBarry Smith } 13090f02eecSBarry Smith 13156cd22aeSBarry Smith /* --------------------------------------------------------------------------*/ 132b9617806SBarry Smith /*E 133b9617806SBarry Smith ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix 134b9617806SBarry Smith or for just the local ghosted portion 135b9617806SBarry Smith 136b9617806SBarry Smith Level: beginner 137b9617806SBarry Smith 13873d7d85fSBarry Smith $ IS_COLORING_LOCAL - does not include the colors for ghost points 13973d7d85fSBarry Smith $ IS_COLORING_GHOSTED - includes colors for ghost points 14073d7d85fSBarry Smith 141b9617806SBarry Smith .seealso: DAGetColoring() 142b9617806SBarry Smith E*/ 14373d7d85fSBarry Smith typedef enum {IS_COLORING_LOCAL,IS_COLORING_GHOSTED} ISColoringType; 144b9617806SBarry Smith 14508b6dcc0SBarry Smith #define MPIU_COLORING_VALUE MPI_CHAR 14608b6dcc0SBarry Smith #define IS_COLORING_MAX 255 14708b6dcc0SBarry Smith typedef unsigned char ISColoringValue; 148*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]); 149dde82324SBarry Smith 1505c20da3cSBarry Smith /*S 151dde82324SBarry Smith ISColoring - sets of IS's that define a coloring 152639f9d9dSBarry Smith of the underlying indices 1535c20da3cSBarry Smith 1545c20da3cSBarry Smith Level: intermediate 1555c20da3cSBarry Smith 1565c20da3cSBarry Smith Notes: 157b9617806SBarry Smith One should not access the *is records below directly because they may not yet 1585c20da3cSBarry Smith have been created. One should use ISColoringGetIS() to make sure they are 1595c20da3cSBarry Smith created when needed. 1605c20da3cSBarry Smith 1615c20da3cSBarry Smith .seealso: ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS() 1625c20da3cSBarry Smith S*/ 163f09e8eb9SSatish Balay struct _p_ISColoring { 164a7cc72afSBarry Smith PetscInt refct; 165a7cc72afSBarry Smith PetscInt n; /* number of colors */ 1665c20da3cSBarry Smith IS *is; /* for each color indicates columns */ 167639f9d9dSBarry Smith MPI_Comm comm; 16808b6dcc0SBarry Smith ISColoringValue *colors; /* for each column indicates color */ 16932dcc486SBarry Smith PetscInt N; /* number of columns */ 170b9617806SBarry Smith ISColoringType ctype; 171639f9d9dSBarry Smith }; 172f09e8eb9SSatish Balay typedef struct _p_ISColoring* ISColoring; 173639f9d9dSBarry Smith 174*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringCreate(MPI_Comm,PetscInt,const ISColoringValue[],ISColoring*); 175*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringDestroy(ISColoring); 176*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringView(ISColoring,PetscViewer); 177*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringGetIS(ISColoring,PetscInt*,IS*[]); 178*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISColoringRestoreIS(ISColoring,IS*[]); 1793a7fca6bSBarry Smith #define ISColoringReference(coloring) ((coloring)->refct++,0) 1803a7fca6bSBarry Smith #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0) 1813a7fca6bSBarry Smith 182dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/ 183dbef8a1cSBarry Smith 184*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISPartitioningToNumbering(IS,IS*); 185*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISPartitioningCount(IS,PetscInt[]); 186dbef8a1cSBarry Smith 187*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]); 188*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]); 189*0c735eedSKris Buschelman EXTERN PetscErrorCode PETSCVEC_DLLEXPORT ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]); 190d9489beaSHong Zhang 191e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 192a2ce50c7SBarry Smith #endif 193