xref: /petsc/include/petscis.h (revision 0040bde18f069f966ff342adc5a53be3404b34fd)
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 */
526bd1501SBarry Smith #if !defined(PETSCIS_H)
626bd1501SBarry Smith #define PETSCIS_H
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 
1297b48c8fSBarry Smith #define IS_FILE_CLASSID 1211218
13014dd563SJed Brown PETSC_EXTERN PetscClassId IS_CLASSID;
14f0479e8cSBarry Smith 
15607a6623SBarry Smith PETSC_EXTERN PetscErrorCode ISInitializePackage(void);
162b6de112SBarry Smith 
1776bdecfbSBarry Smith /*J
188f6c3df8SBarry Smith     ISType - String with the name of a PETSc index set type
1927bdab1eSBarry Smith 
2027bdab1eSBarry Smith    Level: beginner
2127bdab1eSBarry Smith 
228f6c3df8SBarry Smith .seealso: ISSetType(), IS, ISCreate(), ISRegister()
2376bdecfbSBarry Smith J*/
2419fd82e9SBarry Smith typedef const char* ISType;
2527bdab1eSBarry Smith #define ISGENERAL      "general"
2627bdab1eSBarry Smith #define ISSTRIDE       "stride"
2727bdab1eSBarry Smith #define ISBLOCK        "block"
2827bdab1eSBarry Smith 
2927bdab1eSBarry Smith /* Dynamic creation and loading functions */
30140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList ISList;
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));
34014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreate(MPI_Comm,IS*);
3527bdab1eSBarry Smith 
36639f9d9dSBarry Smith /*
37639f9d9dSBarry Smith     Default index set data structures that PETSc provides.
38639f9d9dSBarry Smith */
39014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,IS *);
40014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGeneralSetIndices(IS,PetscInt,const PetscInt[],PetscCopyMode);
41014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,IS *);
42014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockSetIndices(IS,PetscInt,PetscInt,const PetscInt[],PetscCopyMode);
43014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
44014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISStrideSetStride(IS,PetscInt,PetscInt,PetscInt);
454b0e389bSBarry 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 
53014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetIndices(IS,const PetscInt *[]);
54014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreIndices(IS,const PetscInt *[]);
55014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetTotalIndices(IS,const PetscInt *[]);
56014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreTotalIndices(IS,const PetscInt *[]);
57014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIndices(IS,const PetscInt *[]);
58014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIndices(IS,const PetscInt *[]);
59014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIS(IS, IS *is);
60014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIS(IS, IS *is);
61014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetSize(IS,PetscInt *);
62014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetLocalSize(IS,PetscInt *);
63014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISInvertPermutation(IS,PetscInt,IS*);
64014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISView(IS,PetscViewer);
65685405a1SBarry Smith PETSC_STATIC_INLINE PetscErrorCode ISViewFromOptions(IS A,PetscObject obj,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,obj,name);}
66235f7792SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISLoad(IS,PetscViewer);
67014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISEqual(IS,IS,PetscBool  *);
68e8386968SVaclav Hapla PETSC_EXTERN PetscErrorCode ISEqualUnsorted(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*);
753daafeecSToby Isaac PETSC_EXTERN PetscErrorCode ISIntersect(IS,IS,IS*);
76132da990SBarry Smith PETSC_EXTERN PetscErrorCode ISGetMinMax(IS,PetscInt*,PetscInt*);
77612dd529SBarry Smith 
78c3c3c9f4SToby Isaac PETSC_EXTERN PetscErrorCode ISLocate(IS,PetscInt,PetscInt*);
799305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISGetPointRange(IS,PetscInt*,PetscInt*,const PetscInt**);
809305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISRestorePointRange(IS,PetscInt*,PetscInt*,const PetscInt**);
819305a4c7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISGetPointSubrange(IS,PetscInt,PetscInt,const PetscInt*);
82c3c3c9f4SToby Isaac 
83014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS,const PetscInt *[]);
84014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS,const PetscInt *[]);
85014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS,PetscInt *);
86014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS,PetscInt *);
87014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS,PetscInt*);
88014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS,PetscInt);
89c16cb8f2SBarry Smith 
90014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*);
91c16cb8f2SBarry Smith 
92014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISToGeneral(IS);
9338f40f24SLois Curfman McInnes 
94014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDuplicate(IS,IS*);
95014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCopy(IS,IS);
96014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGather(IS,IS*);
97014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISComplement(IS,PetscInt,PetscInt,IS*);
98014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm,PetscInt,const IS[],IS*);
99bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm,PetscInt, IS[],IS*,IS*);
100bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISPairToList(IS,IS,PetscInt*, IS *[]);
101bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISEmbed(IS,IS,PetscBool,IS*);
1025ea6c424SDmitry Karpeev PETSC_EXTERN PetscErrorCode ISSortPermutation(IS,PetscBool,IS*);
103014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISOnComm(IS,MPI_Comm,PetscCopyMode,IS*);
1046583bcc1SStefano Zampini PETSC_EXTERN PetscErrorCode ISRenumber(IS,IS,PetscInt*,IS*);
1056c04a3c5SFande Kong PETSC_EXTERN PetscErrorCode ISCreateSubIS(IS,IS,IS*);
106d64ed03dSBarry Smith 
10753bb9c4cSVaclav Hapla PETSC_EXTERN PetscErrorCode ISGeneralFilter(IS,PetscInt,PetscInt);
10853bb9c4cSVaclav Hapla 
10956cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
110014dd563SJed Brown PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID;
11156cd22aeSBarry Smith 
1125c20da3cSBarry Smith /*E
113*0040bde1SJunchao Zhang     ISGlobalToLocalMappingMode - Indicates mapping behavior if global indices are missing
1145c20da3cSBarry Smith 
115*0040bde1SJunchao Zhang    IS_GTOLM_MASK - missing global indices are masked by mapping them to a local index of -1
1165c20da3cSBarry Smith    IS_GTOLM_DROP - missing global indices are dropped
1175c20da3cSBarry Smith 
1185c20da3cSBarry Smith    Level: beginner
1195c20da3cSBarry Smith 
120413f72f0SBarry Smith .seealso: ISGlobalToLocalMappingApplyBlock(), ISGlobalToLocalMappingApply()
1215c20da3cSBarry Smith 
1225c20da3cSBarry Smith E*/
123413f72f0SBarry Smith typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingMode;
12490f02eecSBarry Smith 
125413f72f0SBarry Smith /*J
126413f72f0SBarry Smith     ISLocalToGlobalMappingType - String with the name of a mapping method
127413f72f0SBarry Smith 
128413f72f0SBarry Smith    Level: beginner
129413f72f0SBarry Smith 
130413f72f0SBarry Smith .seealso: ISLocalToGlobalMappingSetType(), ISLocalToGlobalSetFromOptions()
131413f72f0SBarry Smith J*/
132413f72f0SBarry Smith typedef const char* ISLocalToGlobalMappingType;
133413f72f0SBarry Smith #define ISLOCALTOGLOBALMAPPINGBASIC "basic"
134413f72f0SBarry Smith #define ISLOCALTOGLOBALMAPPINGHASH  "hash"
135413f72f0SBarry Smith 
136413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetType(ISLocalToGlobalMapping,ISLocalToGlobalMappingType);
1371d36bdfdSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRegister(const char[],PetscErrorCode (*)(ISLocalToGlobalMapping));
138413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRegisterAll(void);
139f0413b6fSBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,ISLocalToGlobalMapping*);
140014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
141014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF,PetscInt,ISLocalToGlobalMapping*);
1427e99dc12SLawrence Mitchell PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetFromOptions(ISLocalToGlobalMapping);
143413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetUp(ISLocalToGlobalMapping);
144014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
145662df134SStefano Zampini PETSC_STATIC_INLINE PetscErrorCode ISLocalToGlobalMappingViewFromOptions(ISLocalToGlobalMapping A,PetscObject B,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,B,name);}
146662df134SStefano Zampini 
147014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping*);
14804a59952SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
14945b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyBlock(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
150014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
151413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingMode,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
152413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyBlock(ISLocalToGlobalMapping,ISGlobalToLocalMappingMode,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
153413f72f0SBarry Smith PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApplyIS(ISLocalToGlobalMapping,ISGlobalToLocalMappingMode,IS,IS*);
154014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
1551bd0b88eSStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetNodeInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt**[]);
1561bd0b88eSStefano Zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreNodeInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt**[]);
157014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
158014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
1596a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
1606a818285SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
161014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping,const PetscInt**);
162014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping,const PetscInt**);
16345b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockIndices(ISLocalToGlobalMapping,const PetscInt**);
16445b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreBlockIndices(ISLocalToGlobalMapping,const PetscInt**);
165014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm,PetscInt,const ISLocalToGlobalMapping[],ISLocalToGlobalMapping*);
16645b6f7e9SBarry Smith PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetBlockSize(ISLocalToGlobalMapping,PetscInt*);
16763fa5c83Sstefano_zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingSetBlockSize(ISLocalToGlobalMapping,PetscInt);
1686658fb44Sstefano_zampini PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDuplicate(ISLocalToGlobalMapping,ISLocalToGlobalMapping*);
16945b6f7e9SBarry Smith 
17074637425SBarry Smith 
17156cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
172b9617806SBarry Smith /*E
173b9617806SBarry Smith     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
174b9617806SBarry Smith                      or for just the local ghosted portion
175b9617806SBarry Smith 
176b9617806SBarry Smith     Level: beginner
177b9617806SBarry Smith 
1788ee2e534SBarry Smith $   IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function
1798ee2e534SBarry Smith $                        is called synchronously in parallel. This requires generating a "parallel coloring".
1805bdb020cSBarry Smith $   IS_COLORING_LOCAL - includes colors for ghost points, this is used when the function can be called
181bebe2cf6SSatish Balay $                         separately on individual processes with the ghost points already filled in. Does not
1828ee2e534SBarry Smith $                         require a "parallel coloring", rather each process colors its local + ghost part.
1835bdb020cSBarry Smith $                         Using this can result in much less parallel communication. Currently only works
1845bdb020cSBarry Smith $                         with DMDA and if you call MatFDColoringSetFunction() with the local function.
18573d7d85fSBarry Smith 
186e727c939SJed Brown .seealso: DMCreateColoring()
187b9617806SBarry Smith E*/
1885bdb020cSBarry Smith typedef enum {IS_COLORING_GLOBAL,IS_COLORING_LOCAL} ISColoringType;
1896a6fc655SJed Brown PETSC_EXTERN const char *const ISColoringTypes[];
1906c09f170SSatish Balay typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue;
191014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
192dde82324SBarry Smith 
193aaf3ff59SMatthew G. Knepley PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],PetscCopyMode,ISColoring*);
194014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring*);
195014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
1968aec7d55SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringViewFromOptions(ISColoring,PetscObject,const char[]);
197071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscCopyMode,PetscInt*,IS*[]);
198071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,PetscCopyMode,IS*[]);
19949b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring);
20049b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring,ISColoringType);
201bdaf1daeSBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetType(ISColoring,ISColoringType*);
202bdaf1daeSBarry Smith PETSC_EXTERN PetscErrorCode ISColoringGetColors(ISColoring,PetscInt*,PetscInt*,const ISColoringValue**);
2033a7fca6bSBarry Smith 
204dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/
20594f0491fSFande Kong PETSC_EXTERN PetscErrorCode ISBuildTwoSided(IS,IS,IS*);
206014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
207014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt,PetscInt[]);
208dbef8a1cSBarry Smith 
209014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
210014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
211014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
212d9489beaSHong Zhang 
21369ce434fSBarry Smith 
21469ce434fSBarry Smith struct _n_PetscLayout{
21569ce434fSBarry Smith   MPI_Comm               comm;
21669ce434fSBarry Smith   PetscInt               n,N;         /* local, global vector size */
21769ce434fSBarry Smith   PetscInt               rstart,rend; /* local start, local end + 1 */
21869ce434fSBarry Smith   PetscInt               *range;      /* the offset of each processor */
2199621ec18SVaclav Hapla   PetscBool              range_alloc; /* should range be freed in Destroy? */
22033d57670SJed Brown   PetscInt               bs;          /* number of elements in each block (generally for multi-component
22133d57670SJed Brown                                        * problems). Defaults to -1 and can be arbitrarily lazy so always use
22233d57670SJed Brown                                        * PetscAbs(map->bs) when accessing directly and expecting result to be
22333d57670SJed Brown                                        * positive. Do NOT multiply above numbers by bs */
2242a7a6963SBarry Smith   PetscInt               refcnt;      /* MPI Vecs obtained with VecDuplicate() and from MatCreateVecs() reuse map of input object */
22569ce434fSBarry Smith   ISLocalToGlobalMapping mapping;     /* mapping used in Vec/MatSetValuesLocal() */
226ca5434daSLawrence Mitchell   PetscBool              setupcalled; /* Forbid setup more than once */
227ca5434daSLawrence Mitchell   PetscInt               oldn,oldN;   /* Checking if setup is allowed */
228ca5434daSLawrence Mitchell   PetscInt               oldbs;       /* And again */
22969ce434fSBarry Smith };
23069ce434fSBarry Smith 
2317e3c27c9SBarry Smith /*@C
23269ce434fSBarry Smith      PetscLayoutFindOwner - Find the owning rank for a global index
23369ce434fSBarry Smith 
23469ce434fSBarry Smith     Not Collective
23569ce434fSBarry Smith 
23669ce434fSBarry Smith    Input Parameters:
23769ce434fSBarry Smith +    map - the layout
23869ce434fSBarry Smith -    idx - global index to find the owner of
23969ce434fSBarry Smith 
24069ce434fSBarry Smith    Output Parameter:
24169ce434fSBarry Smith .    owner - the owning rank
24269ce434fSBarry Smith 
24369ce434fSBarry Smith    Level: developer
24469ce434fSBarry Smith 
24569ce434fSBarry Smith     Fortran Notes:
24669ce434fSBarry Smith       Not available from Fortran
24769ce434fSBarry Smith 
24869ce434fSBarry Smith @*/
24969ce434fSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwner(PetscLayout map,PetscInt idx,PetscInt *owner)
25069ce434fSBarry Smith {
25169ce434fSBarry Smith   PetscErrorCode ierr;
25269ce434fSBarry Smith   PetscMPIInt    lo = 0,hi,t;
25369ce434fSBarry Smith 
25469ce434fSBarry Smith   PetscFunctionBegin;
25569ce434fSBarry Smith   *owner = -1;                  /* GCC erroneously issues warning about possibly uninitialized use when error condition */
25669ce434fSBarry Smith   if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first");
25769ce434fSBarry Smith   if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx);
25869ce434fSBarry Smith   ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr);
25969ce434fSBarry Smith   while (hi - lo > 1) {
26069ce434fSBarry Smith     t = lo + (hi - lo) / 2;
26169ce434fSBarry Smith     if (idx < map->range[t]) hi = t;
26269ce434fSBarry Smith     else                     lo = t;
26369ce434fSBarry Smith   }
26469ce434fSBarry Smith   *owner = lo;
26569ce434fSBarry Smith   PetscFunctionReturn(0);
26669ce434fSBarry Smith }
26769ce434fSBarry Smith 
26869ce434fSBarry Smith /*@C
26969ce434fSBarry Smith      PetscLayoutFindOwnerIndex - Find the owning rank and the local index for a global index
27069ce434fSBarry Smith 
27169ce434fSBarry Smith     Not Collective
27269ce434fSBarry Smith 
27369ce434fSBarry Smith    Input Parameters:
27469ce434fSBarry Smith +    map   - the layout
27569ce434fSBarry Smith -    idx   - global index to find the owner of
27669ce434fSBarry Smith 
27769ce434fSBarry Smith    Output Parameter:
27869ce434fSBarry Smith +    owner - the owning rank
27969ce434fSBarry Smith -    lidx  - local index used by the owner for idx
28069ce434fSBarry Smith 
28169ce434fSBarry Smith    Level: developer
28269ce434fSBarry Smith 
28369ce434fSBarry Smith     Fortran Notes:
28469ce434fSBarry Smith       Not available from Fortran
28569ce434fSBarry Smith 
28669ce434fSBarry Smith @*/
28769ce434fSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwnerIndex(PetscLayout map,PetscInt idx,PetscInt *owner, PetscInt *lidx)
28869ce434fSBarry Smith {
28969ce434fSBarry Smith   PetscErrorCode ierr;
29069ce434fSBarry Smith   PetscMPIInt    lo = 0,hi,t;
29169ce434fSBarry Smith 
29269ce434fSBarry Smith   PetscFunctionBegin;
29369ce434fSBarry Smith   if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first");
29469ce434fSBarry Smith   if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx);
29569ce434fSBarry Smith   ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr);
29669ce434fSBarry Smith   while (hi - lo > 1) {
29769ce434fSBarry Smith     t = lo + (hi - lo) / 2;
29869ce434fSBarry Smith     if (idx < map->range[t]) hi = t;
29969ce434fSBarry Smith     else                     lo = t;
30069ce434fSBarry Smith   }
30104799504SMark Adams   if (owner) *owner = lo;
30204799504SMark Adams   if (lidx) *lidx  = idx-map->range[lo];
30369ce434fSBarry Smith   PetscFunctionReturn(0);
30469ce434fSBarry Smith }
3059e03d832SJed Brown 
30601e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutCreate(MPI_Comm,PetscLayout*);
3079621ec18SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscLayoutCreateFromSizes(MPI_Comm,PetscInt,PetscInt,PetscInt,PetscLayout*);
3089621ec18SVaclav Hapla PETSC_EXTERN PetscErrorCode PetscLayoutCreateFromRanges(MPI_Comm,const PetscInt[],PetscCopyMode,PetscInt,PetscLayout*);
30901e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetUp(PetscLayout);
31001e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDestroy(PetscLayout*);
31101e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutDuplicate(PetscLayout,PetscLayout*);
31201e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutReference(PetscLayout,PetscLayout*);
31301e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetLocalSize(PetscLayout,PetscInt);
31401e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetLocalSize(PetscLayout,PetscInt *);
31501e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetSize(PetscLayout,PetscInt);
31601e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetSize(PetscLayout,PetscInt *);
31701e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetBlockSize(PetscLayout,PetscInt);
31801e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetBlockSize(PetscLayout,PetscInt*);
31901e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRange(PetscLayout,PetscInt *,PetscInt *);
32001e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutGetRanges(PetscLayout,const PetscInt *[]);
321f92d6284SStefano Zampini PETSC_EXTERN PetscErrorCode PetscLayoutCompare(PetscLayout,PetscLayout,PetscBool*);
32201e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout,ISLocalToGlobalMapping);
32307acc2aeSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutMapLocal(PetscLayout,PetscInt,const PetscInt[],PetscInt*,PetscInt**,PetscInt**);
32401e13f73SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSFSetGraphLayout(PetscSF,PetscLayout,PetscInt,const PetscInt*,PetscCopyMode,const PetscInt*);
32501e13f73SMatthew G. Knepley 
326d53a3d6fSBarry Smith /* PetscSF support */
327d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFConvertPartition(PetscSF, PetscSection, IS, ISLocalToGlobalMapping *, PetscSF *);
328d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFCreateRemoteOffsets(PetscSF, PetscSection, PetscSection, PetscInt **);
329d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFDistributeSection(PetscSF, PetscSection, PetscInt **, PetscSection);
330d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFCreateSectionSF(PetscSF, PetscSection, PetscInt [], PetscSection, PetscSF *);
331d53a3d6fSBarry Smith 
332a2ce50c7SBarry Smith #endif
333