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 72c8e378dSBarry Smith #include <petscsys.h> 80c312b8eSJed Brown #include <petscsftypes.h> 9*01e13f73SMatthew G. Knepley #include <petscistypes.h> 102eac72dbSBarry Smith 1197b48c8fSBarry Smith #define IS_FILE_CLASSID 1211218 12014dd563SJed Brown PETSC_EXTERN PetscClassId IS_CLASSID; 13f0479e8cSBarry Smith 14607a6623SBarry Smith PETSC_EXTERN PetscErrorCode ISInitializePackage(void); 152b6de112SBarry Smith 1676bdecfbSBarry Smith /*J 178f6c3df8SBarry Smith ISType - String with the name of a PETSc index set type 1827bdab1eSBarry Smith 1927bdab1eSBarry Smith Level: beginner 2027bdab1eSBarry Smith 218f6c3df8SBarry Smith .seealso: ISSetType(), IS, ISCreate(), ISRegister() 2276bdecfbSBarry Smith J*/ 2319fd82e9SBarry Smith typedef const char* ISType; 2427bdab1eSBarry Smith #define ISGENERAL "general" 2527bdab1eSBarry Smith #define ISSTRIDE "stride" 2627bdab1eSBarry Smith #define ISBLOCK "block" 2727bdab1eSBarry Smith 2827bdab1eSBarry Smith /* Dynamic creation and loading functions */ 29140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList ISList; 30014dd563SJed Brown PETSC_EXTERN PetscBool ISRegisterAllCalled; 3119fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode ISSetType(IS, ISType); 3219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode ISGetType(IS, ISType *); 33bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode ISRegister(const char[],PetscErrorCode (*)(IS)); 34607a6623SBarry Smith PETSC_EXTERN PetscErrorCode ISRegisterAll(void); 35014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreate(MPI_Comm,IS*); 3627bdab1eSBarry Smith 37639f9d9dSBarry Smith /* 38639f9d9dSBarry Smith Default index set data structures that PETSc provides. 39639f9d9dSBarry Smith */ 40014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,IS *); 41014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGeneralSetIndices(IS,PetscInt,const PetscInt[],PetscCopyMode); 42014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,IS *); 43014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockSetIndices(IS,PetscInt,PetscInt,const PetscInt[],PetscCopyMode); 44014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *); 45014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISStrideSetStride(IS,PetscInt,PetscInt,PetscInt); 464b0e389bSBarry Smith 47014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDestroy(IS*); 48014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetPermutation(IS); 49014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPermutation(IS,PetscBool *); 50014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetIdentity(IS); 51014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISIdentity(IS,PetscBool *); 52014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISContiguousLocal(IS,PetscInt,PetscInt,PetscInt*,PetscBool*); 5308480c60SBarry Smith 54014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetIndices(IS,const PetscInt *[]); 55014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreIndices(IS,const PetscInt *[]); 56014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetTotalIndices(IS,const PetscInt *[]); 57014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreTotalIndices(IS,const PetscInt *[]); 58014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIndices(IS,const PetscInt *[]); 59014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIndices(IS,const PetscInt *[]); 60014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIS(IS, IS *is); 61014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIS(IS, IS *is); 62014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetSize(IS,PetscInt *); 63014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetLocalSize(IS,PetscInt *); 64014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISInvertPermutation(IS,PetscInt,IS*); 65014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISView(IS,PetscViewer); 66ce1779c8SBarry Smith PETSC_STATIC_INLINE PetscErrorCode ISViewFromOptions(IS A,const char prefix[],const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,prefix,name);} 67235f7792SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISLoad(IS,PetscViewer); 68014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISEqual(IS,IS,PetscBool *); 69014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSort(IS); 70b080c0f9SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISSortRemoveDups(IS); 71014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSorted(IS,PetscBool *); 72014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDifference(IS,IS,IS*); 73014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSum(IS,IS,IS*); 74014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpand(IS,IS,IS*); 75132da990SBarry Smith PETSC_EXTERN PetscErrorCode ISGetMinMax(IS,PetscInt*,PetscInt*); 76612dd529SBarry Smith 77014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS,const PetscInt *[]); 78014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS,const PetscInt *[]); 79014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS,PetscInt *); 80014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS,PetscInt *); 81014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS,PetscInt*); 82014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS,PetscInt); 83c16cb8f2SBarry Smith 84014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*); 85c16cb8f2SBarry Smith 86014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISToGeneral(IS); 8738f40f24SLois Curfman McInnes 88014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDuplicate(IS,IS*); 89014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCopy(IS,IS); 90014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGather(IS,IS*); 91014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISComplement(IS,PetscInt,PetscInt,IS*); 92014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm,PetscInt,const IS[],IS*); 93bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm,PetscInt, IS[],IS*,IS*); 94bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISPairToList(IS,IS,PetscInt*, IS *[]); 95bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISEmbed(IS,IS,PetscBool,IS*); 96014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISOnComm(IS,MPI_Comm,PetscCopyMode,IS*); 97d64ed03dSBarry Smith 9856cd22aeSBarry Smith /* --------------------------------------------------------------------------*/ 99014dd563SJed Brown PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID; 10056cd22aeSBarry Smith 1015c20da3cSBarry Smith /*E 1025c20da3cSBarry Smith ISGlobalToLocalMappingType - Indicates if missing global indices are 1035c20da3cSBarry Smith 1045c20da3cSBarry Smith IS_GTOLM_MASK - missing global indices are replaced with -1 1055c20da3cSBarry Smith IS_GTOLM_DROP - missing global indices are dropped 1065c20da3cSBarry Smith 1075c20da3cSBarry Smith Level: beginner 1085c20da3cSBarry Smith 1099d90f715SBarry Smith .seealso: ISGlobalToLocalMappingApplyBlock() 1105c20da3cSBarry Smith 1115c20da3cSBarry Smith E*/ 112987e4450SSatish Balay typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType; 11390f02eecSBarry Smith 114f0413b6fSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,ISLocalToGlobalMapping*); 115014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *); 116014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF,PetscInt,ISLocalToGlobalMapping*); 117014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer); 118014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping*); 11904a59952SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]); 12045b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyBlock(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]); 121014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*); 122014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]); 1239d90f715SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyBlock(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]); 124d4fe737eSStefano Zampini PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyIS(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,IS,IS*); 125014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*); 126014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]); 127014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]); 1286a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]); 1296a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]); 130014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping,const PetscInt**); 131014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping,const PetscInt**); 13245b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockIndices(ISLocalToGlobalMapping,const PetscInt**); 13345b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockIndices(ISLocalToGlobalMapping,const PetscInt**); 134014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm,PetscInt,const ISLocalToGlobalMapping[],ISLocalToGlobalMapping*); 135186d4ecdSBarry Smith PETSC_EXTERN PetscErrorCode ISG2LMapApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]); 13645b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockSize(ISLocalToGlobalMapping,PetscInt*); 13745b6f7e9SBarry Smith 13874637425SBarry 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 1529a42bb27SBarry Smith $ DMGetLocalVector() and DMGetGlobalVector() this could be called IS_COLORING_LOCAL 15373d7d85fSBarry Smith 154e727c939SJed Brown .seealso: DMCreateColoring() 155b9617806SBarry Smith E*/ 1568ee2e534SBarry Smith typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType; 1576a6fc655SJed Brown PETSC_EXTERN const char *const ISColoringTypes[]; 1586c09f170SSatish Balay typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue; 159014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]); 160dde82324SBarry Smith 161014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*); 162014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring*); 163014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer); 164ce1779c8SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringViewFromOptions(ISColoring,const char[],const char[]); 165014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]); 166014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]); 16749b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring); 16849b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring,ISColoringType); 16949b734d2SBarry Smith 1703a7fca6bSBarry Smith 171dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/ 172dbef8a1cSBarry Smith 173014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*); 174014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt,PetscInt[]); 175dbef8a1cSBarry Smith 176014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]); 177014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]); 178014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]); 179d9489beaSHong Zhang 18069ce434fSBarry Smith 18169ce434fSBarry Smith struct _n_PetscLayout{ 18269ce434fSBarry Smith MPI_Comm comm; 18369ce434fSBarry Smith PetscInt n,N; /* local, global vector size */ 18469ce434fSBarry Smith PetscInt rstart,rend; /* local start, local end + 1 */ 18569ce434fSBarry Smith PetscInt *range; /* the offset of each processor */ 18633d57670SJed Brown PetscInt bs; /* number of elements in each block (generally for multi-component 18733d57670SJed Brown * problems). Defaults to -1 and can be arbitrarily lazy so always use 18833d57670SJed Brown * PetscAbs(map->bs) when accessing directly and expecting result to be 18933d57670SJed Brown * positive. Do NOT multiply above numbers by bs */ 1902a7a6963SBarry Smith PetscInt refcnt; /* MPI Vecs obtained with VecDuplicate() and from MatCreateVecs() reuse map of input object */ 19169ce434fSBarry Smith ISLocalToGlobalMapping mapping; /* mapping used in Vec/MatSetValuesLocal() */ 19269ce434fSBarry Smith PetscInt *trstarts; /* local start for each thread */ 19369ce434fSBarry Smith }; 19469ce434fSBarry Smith 19569ce434fSBarry Smith #undef __FUNCT__ 19669ce434fSBarry Smith #define __FUNCT__ "PetscLayoutFindOwner" 19769ce434fSBarry Smith /*@C 19869ce434fSBarry Smith PetscLayoutFindOwner - Find the owning rank for a global index 19969ce434fSBarry Smith 20069ce434fSBarry Smith Not Collective 20169ce434fSBarry Smith 20269ce434fSBarry Smith Input Parameters: 20369ce434fSBarry Smith + map - the layout 20469ce434fSBarry Smith - idx - global index to find the owner of 20569ce434fSBarry Smith 20669ce434fSBarry Smith Output Parameter: 20769ce434fSBarry Smith . owner - the owning rank 20869ce434fSBarry Smith 20969ce434fSBarry Smith Level: developer 21069ce434fSBarry Smith 21169ce434fSBarry Smith Fortran Notes: 21269ce434fSBarry Smith Not available from Fortran 21369ce434fSBarry Smith 21469ce434fSBarry Smith @*/ 21569ce434fSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwner(PetscLayout map,PetscInt idx,PetscInt *owner) 21669ce434fSBarry Smith { 21769ce434fSBarry Smith PetscErrorCode ierr; 21869ce434fSBarry Smith PetscMPIInt lo = 0,hi,t; 21969ce434fSBarry Smith 22069ce434fSBarry Smith PetscFunctionBegin; 22169ce434fSBarry Smith *owner = -1; /* GCC erroneously issues warning about possibly uninitialized use when error condition */ 22269ce434fSBarry Smith if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first"); 22369ce434fSBarry Smith if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx); 22469ce434fSBarry Smith ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr); 22569ce434fSBarry Smith while (hi - lo > 1) { 22669ce434fSBarry Smith t = lo + (hi - lo) / 2; 22769ce434fSBarry Smith if (idx < map->range[t]) hi = t; 22869ce434fSBarry Smith else lo = t; 22969ce434fSBarry Smith } 23069ce434fSBarry Smith *owner = lo; 23169ce434fSBarry Smith PetscFunctionReturn(0); 23269ce434fSBarry Smith } 23369ce434fSBarry Smith 23469ce434fSBarry Smith #undef __FUNCT__ 23569ce434fSBarry Smith #define __FUNCT__ "PetscLayoutFindOwnerIndex" 23669ce434fSBarry Smith /*@C 23769ce434fSBarry Smith PetscLayoutFindOwnerIndex - Find the owning rank and the local index for a global index 23869ce434fSBarry Smith 23969ce434fSBarry Smith Not Collective 24069ce434fSBarry Smith 24169ce434fSBarry Smith Input Parameters: 24269ce434fSBarry Smith + map - the layout 24369ce434fSBarry Smith - idx - global index to find the owner of 24469ce434fSBarry Smith 24569ce434fSBarry Smith Output Parameter: 24669ce434fSBarry Smith + owner - the owning rank 24769ce434fSBarry Smith - lidx - local index used by the owner for idx 24869ce434fSBarry Smith 24969ce434fSBarry Smith Level: developer 25069ce434fSBarry Smith 25169ce434fSBarry Smith Fortran Notes: 25269ce434fSBarry Smith Not available from Fortran 25369ce434fSBarry Smith 25469ce434fSBarry Smith @*/ 25569ce434fSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwnerIndex(PetscLayout map,PetscInt idx,PetscInt *owner, PetscInt *lidx) 25669ce434fSBarry Smith { 25769ce434fSBarry Smith PetscErrorCode ierr; 25869ce434fSBarry Smith PetscMPIInt lo = 0,hi,t; 25969ce434fSBarry Smith 26069ce434fSBarry Smith PetscFunctionBegin; 26169ce434fSBarry Smith if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first"); 26269ce434fSBarry Smith if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx); 26369ce434fSBarry Smith ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr); 26469ce434fSBarry Smith while (hi - lo > 1) { 26569ce434fSBarry Smith t = lo + (hi - lo) / 2; 26669ce434fSBarry Smith if (idx < map->range[t]) hi = t; 26769ce434fSBarry Smith else lo = t; 26869ce434fSBarry Smith } 26969ce434fSBarry Smith *owner = lo; 27069ce434fSBarry Smith *lidx = idx-map->range[lo]; 27169ce434fSBarry Smith PetscFunctionReturn(0); 27269ce434fSBarry Smith } 2739e03d832SJed Brown 274*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutCreate(MPI_Comm,PetscLayout*); 275*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetUp(PetscLayout); 276*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDestroy(PetscLayout*); 277*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDuplicate(PetscLayout,PetscLayout*); 278*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutReference(PetscLayout,PetscLayout*); 279*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetLocalSize(PetscLayout,PetscInt); 280*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetLocalSize(PetscLayout,PetscInt *); 281*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetSize(PetscLayout,PetscInt); 282*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetSize(PetscLayout,PetscInt *); 283*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetBlockSize(PetscLayout,PetscInt); 284*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetBlockSize(PetscLayout,PetscInt*); 285*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRange(PetscLayout,PetscInt *,PetscInt *); 286*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRanges(PetscLayout,const PetscInt *[]); 287*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout,ISLocalToGlobalMapping); 288*01e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSFSetGraphLayout(PetscSF,PetscLayout,PetscInt,const PetscInt*,PetscCopyMode,const PetscInt*); 289*01e13f73SMatthew G. Knepley 2901d799100SJed Brown PETSC_EXTERN PetscClassId PETSC_SECTION_CLASSID; 2911d799100SJed Brown 292d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreate(MPI_Comm,PetscSection*); 293d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionClone(PetscSection, PetscSection*); 294d902297bSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionCopy(PetscSection, PetscSection); 295d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetNumFields(PetscSection, PetscInt *); 296d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetNumFields(PetscSection, PetscInt); 297d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldName(PetscSection, PetscInt, const char *[]); 298d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldName(PetscSection, PetscInt, const char []); 299d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldComponents(PetscSection, PetscInt, PetscInt *); 300d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldComponents(PetscSection, PetscInt, PetscInt); 301d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetChart(PetscSection, PetscInt *, PetscInt *); 302d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetChart(PetscSection, PetscInt, PetscInt); 3034c0d72c2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionGetPermutation(PetscSection, IS *); 3044c0d72c2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionSetPermutation(PetscSection, IS); 305d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetDof(PetscSection, PetscInt, PetscInt*); 306d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetDof(PetscSection, PetscInt, PetscInt); 307d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddDof(PetscSection, PetscInt, PetscInt); 308d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldDof(PetscSection, PetscInt, PetscInt, PetscInt*); 309d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldDof(PetscSection, PetscInt, PetscInt, PetscInt); 310d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddFieldDof(PetscSection, PetscInt, PetscInt, PetscInt); 3117ba4506dSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionHasConstraints(PetscSection, PetscBool *); 312d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstraintDof(PetscSection, PetscInt, PetscInt*); 313d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetConstraintDof(PetscSection, PetscInt, PetscInt); 314d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddConstraintDof(PetscSection, PetscInt, PetscInt); 315d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt*); 316d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt); 317d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt); 318d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstraintIndices(PetscSection, PetscInt, const PetscInt**); 319d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetConstraintIndices(PetscSection, PetscInt, const PetscInt*); 320d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection, PetscInt, PetscInt, const PetscInt**); 321d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection, PetscInt, PetscInt, const PetscInt*); 322d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetUpBC(PetscSection); 323d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetUp(PetscSection); 324d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetMaxDof(PetscSection, PetscInt*); 325d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetStorageSize(PetscSection, PetscInt*); 326d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection, PetscInt*); 327d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetOffset(PetscSection, PetscInt, PetscInt*); 328d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetOffset(PetscSection, PetscInt, PetscInt); 329d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldOffset(PetscSection, PetscInt, PetscInt, PetscInt*); 330d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldOffset(PetscSection, PetscInt, PetscInt, PetscInt); 331d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetOffsetRange(PetscSection, PetscInt *, PetscInt *); 332d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionView(PetscSection, PetscViewer); 333ce1779c8SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscSectionViewFromOptions(PetscSection A,const char prefix[],const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,prefix,name);} 334d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionReset(PetscSection); 335d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionDestroy(PetscSection*); 336d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateGlobalSection(PetscSection, PetscSF, PetscBool, PetscSection *); 337d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection, PetscSF, PetscBool, PetscInt, const PetscInt [], PetscSection *); 338d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateSubsection(PetscSection, PetscInt, PetscInt [], PetscSection *); 339d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection, IS, PetscSection *); 340d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetPointLayout(MPI_Comm, PetscSection, PetscLayout *); 341d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetValueLayout(MPI_Comm, PetscSection, PetscLayout *); 342b348688eSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionPermute(PetscSection, IS, PetscSection *); 343a7c23f90SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionGetField(PetscSection, PetscInt, PetscSection *); 344d53a3d6fSBarry Smith 34505eca2e3SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionSetClosureIndex(PetscSection, PetscObject, PetscSection, IS); 34605eca2e3SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSectionGetClosureIndex(PetscSection, PetscObject, PetscSection *, IS *); 347d53a3d6fSBarry Smith 348d53a3d6fSBarry Smith /* PetscSF support */ 349d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFConvertPartition(PetscSF, PetscSection, IS, ISLocalToGlobalMapping *, PetscSF *); 350d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFCreateRemoteOffsets(PetscSF, PetscSection, PetscSection, PetscInt **); 351d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFDistributeSection(PetscSF, PetscSection, PetscInt **, PetscSection); 352d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFCreateSectionSF(PetscSF, PetscSection, PetscInt [], PetscSection, PetscSF *); 353d53a3d6fSBarry Smith 3549e03d832SJed Brown /* Reset __FUNCT__ in case the user does not define it themselves */ 3559e03d832SJed Brown #undef __FUNCT__ 3569e03d832SJed Brown #define __FUNCT__ "User provided function" 3579e03d832SJed Brown 358a2ce50c7SBarry Smith #endif 359