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 72c8e378dSBarry Smith #include <petscsys.h> 80c312b8eSJed Brown #include <petscsftypes.h> 9ea844a1aSMatthew Knepley #include <petscsectiontypes.h> 104914ba2bSBarry Smith #include <petscistypes.h> /*I "petscis.h" I*/ 112eac72dbSBarry Smith 12ac09b921SBarry Smith /* SUBMANSEC = IS */ 13ac09b921SBarry Smith 1497b48c8fSBarry Smith #define IS_FILE_CLASSID 1211218 15014dd563SJed Brown PETSC_EXTERN PetscClassId IS_CLASSID; 16f0479e8cSBarry Smith 17607a6623SBarry Smith PETSC_EXTERN PetscErrorCode ISInitializePackage(void); 184bf303faSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode ISFinalizePackage(void); 192b6de112SBarry Smith 2076bdecfbSBarry Smith /*J 218f6c3df8SBarry Smith ISType - String with the name of a PETSc index set type 2227bdab1eSBarry Smith 2316a05f60SBarry Smith Values: 249c89aa79SPierre Jolivet + `ISGENERAL` - the values are stored with an array of indices and generally have no structure 2516a05f60SBarry Smith . `ISSTRIDE` - the values have a simple structure of an initial offset and then a step size between values 26af27ebaaSBarry Smith - `ISBLOCK` - values are an array of indices, each representing a block (of the same common length) of values 2716a05f60SBarry Smith 2827bdab1eSBarry Smith Level: beginner 2927bdab1eSBarry Smith 3016a05f60SBarry Smith .seealso: `ISSetType()`, `IS`, `ISCreateGeneral()`, `ISCreateStride()`, `ISCreateBlock()`, `ISCreate()`, `ISRegister()`, 3116a05f60SBarry Smith `VecScatterCreate()`, `MatGetSubMatrices()` 3276bdecfbSBarry Smith J*/ 3319fd82e9SBarry Smith typedef const char *ISType; 3427bdab1eSBarry Smith #define ISGENERAL "general" 3527bdab1eSBarry Smith #define ISSTRIDE "stride" 3627bdab1eSBarry Smith #define ISBLOCK "block" 3727bdab1eSBarry Smith 3827bdab1eSBarry Smith /* Dynamic creation and loading functions */ 39140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList ISList; 4019fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode ISSetType(IS, ISType); 4119fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode ISGetType(IS, ISType *); 42bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode ISRegister(const char[], PetscErrorCode (*)(IS)); 43da8c939bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode ISRegisterAll(void); 44014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreate(MPI_Comm, IS *); 4527bdab1eSBarry Smith 46014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDestroy(IS *); 47014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetPermutation(IS); 48014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPermutation(IS, PetscBool *); 49014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetIdentity(IS); 50014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISIdentity(IS, PetscBool *); 51014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISContiguousLocal(IS, PetscInt, PetscInt, PetscInt *, PetscBool *); 5208480c60SBarry Smith 532a1da528SToby Isaac /*E 542a1da528SToby Isaac ISInfo - Info that may either be computed or set as known for an index set 552a1da528SToby Isaac 5616a05f60SBarry Smith Level: intermediate 572a1da528SToby Isaac 5895bd0b28SBarry Smith Developer Note: 592a1da528SToby Isaac Entries that are negative need not be called collectively by all processes. 602a1da528SToby Isaac 6116a05f60SBarry Smith .seealso: `IS`, `ISType`, `ISSetInfo()` 622a1da528SToby Isaac E*/ 639371c9d4SSatish Balay typedef enum { 649371c9d4SSatish Balay IS_INFO_MIN = -1, 652a1da528SToby Isaac IS_SORTED = 0, 662a1da528SToby Isaac IS_UNIQUE = 1, 672a1da528SToby Isaac IS_PERMUTATION = 2, 682a1da528SToby Isaac IS_INTERVAL = 3, 692a1da528SToby Isaac IS_IDENTITY = 4, 709371c9d4SSatish Balay IS_INFO_MAX = 5 719371c9d4SSatish Balay } ISInfo; 722a1da528SToby Isaac 739371c9d4SSatish Balay typedef enum { 749371c9d4SSatish Balay IS_LOCAL, 759371c9d4SSatish Balay IS_GLOBAL 769371c9d4SSatish Balay } ISInfoType; 772a1da528SToby Isaac 782a1da528SToby Isaac PETSC_EXTERN PetscErrorCode ISSetInfo(IS, ISInfo, ISInfoType, PetscBool, PetscBool); 79657dc977SToby Isaac PETSC_EXTERN PetscErrorCode ISGetInfo(IS, ISInfo, ISInfoType, PetscBool, PetscBool *); 802a1da528SToby Isaac PETSC_EXTERN PetscErrorCode ISClearInfoCache(IS, PetscBool); 81014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetIndices(IS, const PetscInt *[]); 82014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreIndices(IS, const PetscInt *[]); 83014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetTotalIndices(IS, const PetscInt *[]); 84014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreTotalIndices(IS, const PetscInt *[]); 85014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIndices(IS, const PetscInt *[]); 86014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIndices(IS, const PetscInt *[]); 87d60670a5SStefano Zampini PETSC_EXTERN PetscErrorCode ISGetNonlocalIS(IS, IS *); 88d60670a5SStefano Zampini PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIS(IS, IS *); 89014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetSize(IS, PetscInt *); 90014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetLocalSize(IS, PetscInt *); 91014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISInvertPermutation(IS, PetscInt, IS *); 92014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISView(IS, PetscViewer); 93fe2efc57SMark PETSC_EXTERN PetscErrorCode ISViewFromOptions(IS, PetscObject, const char[]); 94235f7792SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISLoad(IS, PetscViewer); 95014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISEqual(IS, IS, PetscBool *); 96e8386968SVaclav Hapla PETSC_EXTERN PetscErrorCode ISEqualUnsorted(IS, IS, PetscBool *); 97014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSort(IS); 98b080c0f9SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISSortRemoveDups(IS); 99014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSorted(IS, PetscBool *); 100014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDifference(IS, IS, IS *); 101014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSum(IS, IS, IS *); 102014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpand(IS, IS, IS *); 1033daafeecSToby Isaac PETSC_EXTERN PetscErrorCode ISIntersect(IS, IS, IS *); 104132da990SBarry Smith PETSC_EXTERN PetscErrorCode ISGetMinMax(IS, PetscInt *, PetscInt *); 105612dd529SBarry Smith 106c3c3c9f4SToby Isaac PETSC_EXTERN PetscErrorCode ISLocate(IS, PetscInt, PetscInt *); 1079305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISGetPointRange(IS, PetscInt *, PetscInt *, const PetscInt **); 1089305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISRestorePointRange(IS, PetscInt *, PetscInt *, const PetscInt **); 1099305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISGetPointSubrange(IS, PetscInt, PetscInt, const PetscInt *); 110c3c3c9f4SToby Isaac 111014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS, PetscInt *); 112014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS, PetscInt); 113c16cb8f2SBarry Smith 114014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISToGeneral(IS); 11538f40f24SLois Curfman McInnes 116014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDuplicate(IS, IS *); 117014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCopy(IS, IS); 1189fdaf958SVaclav Hapla PETSC_EXTERN PetscErrorCode ISShift(IS, PetscInt, IS); 119014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGather(IS, IS *); 120014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISComplement(IS, PetscInt, PetscInt, IS *); 121014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm, PetscInt, const IS[], IS *); 122bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm, PetscInt, IS[], IS *, IS *); 123bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISPairToList(IS, IS, PetscInt *, IS *[]); 124bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISEmbed(IS, IS, PetscBool, IS *); 1255ea6c424SDmitry Karpeev PETSC_EXTERN PetscErrorCode ISSortPermutation(IS, PetscBool, IS *); 126014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISOnComm(IS, MPI_Comm, PetscCopyMode, IS *); 1276583bcc1SStefano Zampini PETSC_EXTERN PetscErrorCode ISRenumber(IS, IS, PetscInt *, IS *); 1286c04a3c5SFande Kong PETSC_EXTERN PetscErrorCode ISCreateSubIS(IS, IS, IS *); 129d64ed03dSBarry Smith 13084933e40SVaclav Hapla /* ISGENERAL specific */ 13184933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateGeneral(MPI_Comm, PetscInt, const PetscInt[], PetscCopyMode, IS *); 13284933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralSetIndices(IS, PetscInt, const PetscInt[], PetscCopyMode); 1339bc6f2f1SVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralSetIndicesFromMask(IS, PetscInt, PetscInt, const PetscBool[]); 13453bb9c4cSVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralFilter(IS, PetscInt, PetscInt); 13553bb9c4cSVaclav Hapla 13684933e40SVaclav Hapla /* ISBLOCK specific */ 13784933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateBlock(MPI_Comm, PetscInt, PetscInt, const PetscInt[], PetscCopyMode, IS *); 13884933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockSetIndices(IS, PetscInt, PetscInt, const PetscInt[], PetscCopyMode); 13984933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS, const PetscInt *[]); 14084933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS, const PetscInt *[]); 14184933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS, PetscInt *); 14284933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS, PetscInt *); 14384933e40SVaclav Hapla 14484933e40SVaclav Hapla /* ISSTRIDE specific */ 14584933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISCreateStride(MPI_Comm, PetscInt, PetscInt, PetscInt, IS *); 14684933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISStrideSetStride(IS, PetscInt, PetscInt, PetscInt); 14784933e40SVaclav Hapla PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS, PetscInt *, PetscInt *); 14884933e40SVaclav Hapla 149*7de13914SStefano Zampini #define IS_LTOGM_FILE_CLASSID 1211217 150014dd563SJed Brown PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID; 15156cd22aeSBarry Smith 1525c20da3cSBarry Smith /*E 1530040bde1SJunchao Zhang ISGlobalToLocalMappingMode - Indicates mapping behavior if global indices are missing 1545c20da3cSBarry Smith 15516a05f60SBarry Smith Values: 15616a05f60SBarry Smith + `IS_GTOLM_MASK` - missing global indices are masked by mapping them to a local index of -1 15716a05f60SBarry Smith - `IS_GTOLM_DROP` - missing global indices are dropped 1585c20da3cSBarry Smith 1595c20da3cSBarry Smith Level: beginner 1605c20da3cSBarry Smith 161db781477SPatrick Sanan .seealso: `ISGlobalToLocalMappingApplyBlock()`, `ISGlobalToLocalMappingApply()` 1625c20da3cSBarry Smith E*/ 1639371c9d4SSatish Balay typedef enum { 1649371c9d4SSatish Balay IS_GTOLM_MASK, 1659371c9d4SSatish Balay IS_GTOLM_DROP 1669371c9d4SSatish Balay } ISGlobalToLocalMappingMode; 16790f02eecSBarry Smith 168413f72f0SBarry Smith /*J 169413f72f0SBarry Smith ISLocalToGlobalMappingType - String with the name of a mapping method 170413f72f0SBarry Smith 17116a05f60SBarry Smith Values: 17216a05f60SBarry Smith + `ISLOCALTOGLOBALMAPPINGBASIC` - a non-memory scalable way of storing `ISLocalToGlobalMapping` that allows applying `ISGlobalToLocalMappingApply()` efficiently 17316a05f60SBarry Smith - `ISLOCALTOGLOBALMAPPINGHASH` - a memory scalable way of storing `ISLocalToGlobalMapping` that allows applying `ISGlobalToLocalMappingApply()` reasonably efficiently 17416a05f60SBarry Smith 175413f72f0SBarry Smith Level: beginner 176413f72f0SBarry Smith 17716a05f60SBarry Smith .seealso: `ISLocalToGlobalMapping`, `ISLocalToGlobalMappingSetType()`, `ISLocalToGlobalSetFromOptions()`, `ISGlobalToLocalMappingMode` 178413f72f0SBarry Smith J*/ 179413f72f0SBarry Smith typedef const char *ISLocalToGlobalMappingType; 180413f72f0SBarry Smith #define ISLOCALTOGLOBALMAPPINGBASIC "basic" 181413f72f0SBarry Smith #define ISLOCALTOGLOBALMAPPINGHASH "hash" 182413f72f0SBarry Smith 183413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetType(ISLocalToGlobalMapping, ISLocalToGlobalMappingType); 184a0d79125SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetType(ISLocalToGlobalMapping, ISLocalToGlobalMappingType *); 1851d36bdfdSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRegister(const char[], PetscErrorCode (*)(ISLocalToGlobalMapping)); 186413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRegisterAll(void); 187f0413b6fSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm, PetscInt, PetscInt, const PetscInt[], PetscCopyMode, ISLocalToGlobalMapping *); 188014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS, ISLocalToGlobalMapping *); 189014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF, PetscInt, ISLocalToGlobalMapping *); 1907e99dc12SLawrence Mitchell PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetFromOptions(ISLocalToGlobalMapping); 191413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetUp(ISLocalToGlobalMapping); 192014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping, PetscViewer); 193*7de13914SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingLoad(ISLocalToGlobalMapping, PetscViewer); 194fe2efc57SMark PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingViewFromOptions(ISLocalToGlobalMapping, PetscObject, const char[]); 195662df134SStefano Zampini 196014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping *); 19704a59952SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping, PetscInt, const PetscInt[], PetscInt[]); 19845b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyBlock(ISLocalToGlobalMapping, PetscInt, const PetscInt[], PetscInt[]); 199014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping, IS, IS *); 200413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, PetscInt, const PetscInt[], PetscInt *, PetscInt[]); 201413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyBlock(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, PetscInt, const PetscInt[], PetscInt *, PetscInt[]); 202413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyIS(ISLocalToGlobalMapping, ISGlobalToLocalMappingMode, IS, IS *); 203014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping, PetscInt *); 2041bd0b88eSStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]); 2051bd0b88eSStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]); 206014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]); 207014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]); 208633354d9SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]); 209633354d9SStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockNodeInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt **[]); 2106a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]); 2116a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockInfo(ISLocalToGlobalMapping, PetscInt *, PetscInt *[], PetscInt *[], PetscInt **[]); 212014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping, const PetscInt **); 213014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping, const PetscInt **); 21445b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockIndices(ISLocalToGlobalMapping, const PetscInt **); 21545b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockIndices(ISLocalToGlobalMapping, const PetscInt **); 216014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm, PetscInt, const ISLocalToGlobalMapping[], ISLocalToGlobalMapping *); 21745b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockSize(ISLocalToGlobalMapping, PetscInt *); 21863fa5c83Sstefano_zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetBlockSize(ISLocalToGlobalMapping, PetscInt); 2196658fb44Sstefano_zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDuplicate(ISLocalToGlobalMapping, ISLocalToGlobalMapping *); 22045b6f7e9SBarry Smith 221b9617806SBarry Smith /*E 222b9617806SBarry Smith ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix 223b9617806SBarry Smith or for just the local ghosted portion 224b9617806SBarry Smith 22516a05f60SBarry Smith Values: 22616a05f60SBarry Smith + `IS_COLORING_GLOBAL` - does not include the colors for ghost points, this is used when the function 22716a05f60SBarry Smith is called synchronously in parallel. This requires generating a "parallel coloring". 22816a05f60SBarry Smith - `IS_COLORING_LOCAL` - includes colors for ghost points, this is used when the function can be called 22916a05f60SBarry Smith separately on individual processes with the ghost points already filled in. Does not 23016a05f60SBarry Smith require a "parallel coloring", rather each process colors its local + ghost part. 23116a05f60SBarry Smith Using this can result in much less parallel communication. Currently only works 23216a05f60SBarry Smith with `DMDA` and if you call `MatFDColoringSetFunction()` with the local function. 23316a05f60SBarry Smith 234b9617806SBarry Smith Level: beginner 235b9617806SBarry Smith 23616a05f60SBarry Smith .seealso: `ISColoring`, `ISColoringSetType()`, `ISColoringGetType()`, `DMCreateColoring()` 237b9617806SBarry Smith E*/ 2389371c9d4SSatish Balay typedef enum { 2399371c9d4SSatish Balay IS_COLORING_GLOBAL, 2409371c9d4SSatish Balay IS_COLORING_LOCAL 2419371c9d4SSatish Balay } ISColoringType; 242af27ebaaSBarry Smith 2436a6fc655SJed Brown PETSC_EXTERN const char *const ISColoringTypes[]; 244569ea7c4SPierre Jolivet typedef unsigned PETSC_IS_COLORING_VALUE_TYPE ISColoringValue; 245569ea7c4SPierre Jolivet #define IS_COLORING_MAX PETSC_IS_COLORING_MAX 246569ea7c4SPierre Jolivet #define MPIU_COLORING_VALUE PETSC_MPIU_IS_COLORING_VALUE_TYPE 247014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm, PetscInt, ISColoringValue *, PetscInt *, ISColoringValue *[]); 248dde82324SBarry Smith 249aaf3ff59SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm, PetscInt, PetscInt, const ISColoringValue[], PetscCopyMode, ISColoring *); 250014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring *); 251014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring, PetscViewer); 2528aec7d55SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringViewFromOptions(ISColoring, PetscObject, const char[]); 253071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring, PetscCopyMode, PetscInt *, IS *[]); 254071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring, PetscCopyMode, IS *[]); 25549b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring); 25649b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring, ISColoringType); 257bdaf1daeSBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetType(ISColoring, ISColoringType *); 258bdaf1daeSBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetColors(ISColoring, PetscInt *, PetscInt *, const ISColoringValue **); 2593a7fca6bSBarry Smith 26094f0491fSFande Kong PETSC_EXTERN PetscErrorCode ISBuildTwoSided(IS, IS, IS *); 261014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS, IS *); 262014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS, PetscInt, PetscInt[]); 263dbef8a1cSBarry Smith 264014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt, PetscInt, PetscInt, PetscInt, const IS[], IS[]); 265edd03b47SJacob 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[]) 266e37d522bSPierre Jolivet { 267e37d522bSPierre Jolivet return ISCompressIndicesGeneral(n, bs, n, imax, is_in, is_out); 268e37d522bSPierre Jolivet } 269014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt, PetscInt, PetscInt, PetscInt, const IS[], IS[]); 270d9489beaSHong Zhang 27169ce434fSBarry Smith struct _n_PetscLayout { 27269ce434fSBarry Smith MPI_Comm comm; 27338a25198SStefano Zampini PetscMPIInt size; 27469ce434fSBarry Smith PetscInt n, N; /* local, global vector size */ 27569ce434fSBarry Smith PetscInt rstart, rend; /* local start, local end + 1 */ 27669ce434fSBarry Smith PetscInt *range; /* the offset of each processor */ 2779621ec18SVaclav Hapla PetscBool range_alloc; /* should range be freed in Destroy? */ 27833d57670SJed Brown PetscInt bs; /* number of elements in each block (generally for multi-component 27933d57670SJed Brown * problems). Defaults to -1 and can be arbitrarily lazy so always use 28033d57670SJed Brown * PetscAbs(map->bs) when accessing directly and expecting result to be 28133d57670SJed Brown * positive. Do NOT multiply above numbers by bs */ 2822a7a6963SBarry Smith PetscInt refcnt; /* MPI Vecs obtained with VecDuplicate() and from MatCreateVecs() reuse map of input object */ 28369ce434fSBarry Smith ISLocalToGlobalMapping mapping; /* mapping used in Vec/MatSetValuesLocal() */ 284ca5434daSLawrence Mitchell PetscBool setupcalled; /* Forbid setup more than once */ 285ca5434daSLawrence Mitchell PetscInt oldn, oldN; /* Checking if setup is allowed */ 286ca5434daSLawrence Mitchell PetscInt oldbs; /* And again */ 28769ce434fSBarry Smith }; 28869ce434fSBarry Smith 2897e3c27c9SBarry Smith /*@C 29095bd0b28SBarry Smith PetscLayoutFindOwner - Find the owning MPI process for a global index 29169ce434fSBarry Smith 29220f4b53cSBarry Smith Not Collective; No Fortran Support 29369ce434fSBarry Smith 29469ce434fSBarry Smith Input Parameters: 29569ce434fSBarry Smith + map - the layout 29669ce434fSBarry Smith - idx - global index to find the owner of 29769ce434fSBarry Smith 29869ce434fSBarry Smith Output Parameter: 29969ce434fSBarry Smith . owner - the owning rank 30069ce434fSBarry Smith 30169ce434fSBarry Smith Level: developer 30269ce434fSBarry Smith 30316a05f60SBarry Smith .seealso: `PetscLayout`, `PetscLayoutFindOwnerIndex()` 30469ce434fSBarry Smith @*/ 305d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscLayoutFindOwner(PetscLayout map, PetscInt idx, PetscMPIInt *owner) 306d71ae5a4SJacob Faibussowitsch { 30769ce434fSBarry Smith PetscMPIInt lo = 0, hi, t; 30869ce434fSBarry Smith 30969ce434fSBarry Smith PetscFunctionBegin; 31069ce434fSBarry Smith *owner = -1; /* GCC erroneously issues warning about possibly uninitialized use when error condition */ 311b498ca8aSPierre Jolivet PetscAssert((map->n >= 0) && (map->N >= 0) && (map->range), PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "PetscLayoutSetUp() must be called first"); 312b498ca8aSPierre Jolivet PetscAssert(idx >= 0 && idx <= map->N, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Index %" PetscInt_FMT " is out of range", idx); 31338a25198SStefano Zampini hi = map->size; 31469ce434fSBarry Smith while (hi - lo > 1) { 31569ce434fSBarry Smith t = lo + (hi - lo) / 2; 31669ce434fSBarry Smith if (idx < map->range[t]) hi = t; 31769ce434fSBarry Smith else lo = t; 31869ce434fSBarry Smith } 31969ce434fSBarry Smith *owner = lo; 3203ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 32169ce434fSBarry Smith } 32269ce434fSBarry Smith 32369ce434fSBarry Smith /*@C 32495bd0b28SBarry Smith PetscLayoutFindOwnerIndex - Find the owning MPI process and the local index on that process for a global index 32569ce434fSBarry Smith 32620f4b53cSBarry Smith Not Collective; No Fortran Support 32769ce434fSBarry Smith 32869ce434fSBarry Smith Input Parameters: 32969ce434fSBarry Smith + map - the layout 33069ce434fSBarry Smith - idx - global index to find the owner of 33169ce434fSBarry Smith 332d8d19677SJose E. Roman Output Parameters: 33369ce434fSBarry Smith + owner - the owning rank 33416a05f60SBarry Smith - lidx - local index used by the owner for `idx` 33569ce434fSBarry Smith 33669ce434fSBarry Smith Level: developer 33769ce434fSBarry Smith 33816a05f60SBarry Smith .seealso: `PetscLayout`, `PetscLayoutFindOwner()` 33969ce434fSBarry Smith @*/ 340d71ae5a4SJacob Faibussowitsch static inline PetscErrorCode PetscLayoutFindOwnerIndex(PetscLayout map, PetscInt idx, PetscMPIInt *owner, PetscInt *lidx) 341d71ae5a4SJacob Faibussowitsch { 34269ce434fSBarry Smith PetscMPIInt lo = 0, hi, t; 34369ce434fSBarry Smith 34469ce434fSBarry Smith PetscFunctionBegin; 345b498ca8aSPierre Jolivet PetscAssert((map->n >= 0) && (map->N >= 0) && (map->range), PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "PetscLayoutSetUp() must be called first"); 346b498ca8aSPierre Jolivet PetscAssert(idx >= 0 && idx <= map->N, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Index %" PetscInt_FMT " is out of range", idx); 34738a25198SStefano Zampini hi = map->size; 34869ce434fSBarry Smith while (hi - lo > 1) { 34969ce434fSBarry Smith t = lo + (hi - lo) / 2; 35069ce434fSBarry Smith if (idx < map->range[t]) hi = t; 35169ce434fSBarry Smith else lo = t; 35269ce434fSBarry Smith } 35304799504SMark Adams if (owner) *owner = lo; 35404799504SMark Adams if (lidx) *lidx = idx - map->range[lo]; 3553ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 35669ce434fSBarry Smith } 3579e03d832SJed Brown 35801e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutCreate(MPI_Comm, PetscLayout *); 3599621ec18SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscLayoutCreateFromSizes(MPI_Comm, PetscInt, PetscInt, PetscInt, PetscLayout *); 3609621ec18SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscLayoutCreateFromRanges(MPI_Comm, const PetscInt[], PetscCopyMode, PetscInt, PetscLayout *); 36101e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetUp(PetscLayout); 36201e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDestroy(PetscLayout *); 36301e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDuplicate(PetscLayout, PetscLayout *); 36401e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutReference(PetscLayout, PetscLayout *); 36501e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetLocalSize(PetscLayout, PetscInt); 36601e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetLocalSize(PetscLayout, PetscInt *); 36701e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetSize(PetscLayout, PetscInt); 36801e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetSize(PetscLayout, PetscInt *); 36901e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetBlockSize(PetscLayout, PetscInt); 37001e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetBlockSize(PetscLayout, PetscInt *); 37101e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRange(PetscLayout, PetscInt *, PetscInt *); 37201e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRanges(PetscLayout, const PetscInt *[]); 373f92d6284SStefano Zampini PETSC_EXTERN PetscErrorCode PetscLayoutCompare(PetscLayout, PetscLayout, PetscBool *); 37401e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout, ISLocalToGlobalMapping); 37507acc2aeSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutMapLocal(PetscLayout, PetscInt, const PetscInt[], PetscInt *, PetscInt **, PetscInt **); 37601e13f73SMatthew G. Knepley 377ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortInt(PetscLayout, PetscLayout, PetscInt *, PetscInt *); 378ce605777SToby Isaac 379ce605777SToby Isaac PETSC_EXTERN PetscErrorCode ISGetLayout(IS, PetscLayout *); 3804e1d6e84SVaclav Hapla PETSC_EXTERN PetscErrorCode ISSetLayout(IS, PetscLayout); 381