xref: /petsc/include/petscis.h (revision 665c2ded495bb9782a7454dcfef3abf1536c3670)
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>
8*665c2dedSJed Brown #include <petscviewertypes.h>
92c8e378dSBarry Smith #include <petscsf.h>
102eac72dbSBarry Smith 
1197b48c8fSBarry Smith #define IS_FILE_CLASSID 1211218
12014dd563SJed Brown PETSC_EXTERN PetscClassId IS_CLASSID;
13f0479e8cSBarry Smith 
14014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISInitializePackage(const char[]);
152b6de112SBarry Smith 
165c20da3cSBarry Smith /*S
17f22f69f0SBarry Smith      IS - Abstract PETSc object that allows indexing.
185c20da3cSBarry Smith 
195c20da3cSBarry Smith    Level: beginner
205c20da3cSBarry Smith 
215c20da3cSBarry Smith   Concepts: indexing, stride
225c20da3cSBarry Smith 
235c20da3cSBarry Smith .seealso:  ISCreateGeneral(), ISCreateBlock(), ISCreateStride(), ISGetIndices(), ISDestroy()
245c20da3cSBarry Smith S*/
25f09e8eb9SSatish Balay typedef struct _p_IS* IS;
262eac72dbSBarry Smith 
2776bdecfbSBarry Smith /*J
2827bdab1eSBarry Smith     ISType - String with the name of a PETSc vector or the creation function
2927bdab1eSBarry Smith        with an optional dynamic library name, for example
3027bdab1eSBarry Smith        http://www.mcs.anl.gov/petsc/lib.a:myveccreate()
3127bdab1eSBarry Smith 
3227bdab1eSBarry Smith    Level: beginner
3327bdab1eSBarry Smith 
3427bdab1eSBarry Smith .seealso: ISSetType(), IS
3576bdecfbSBarry Smith J*/
3619fd82e9SBarry Smith typedef const char* ISType;
3727bdab1eSBarry Smith #define ISGENERAL      "general"
3827bdab1eSBarry Smith #define ISSTRIDE       "stride"
3927bdab1eSBarry Smith #define ISBLOCK        "block"
4027bdab1eSBarry Smith 
4127bdab1eSBarry Smith /* Dynamic creation and loading functions */
42140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList ISList;
43014dd563SJed Brown PETSC_EXTERN PetscBool         ISRegisterAllCalled;
4419fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode ISSetType(IS, ISType);
4519fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode ISGetType(IS, ISType *);
46014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRegister(const char[],const char[],const char[],PetscErrorCode (*)(IS));
47014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRegisterAll(const char []);
48014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRegisterDestroy(void);
49014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreate(MPI_Comm,IS*);
5027bdab1eSBarry Smith 
5127bdab1eSBarry Smith /*MC
52f2ba6396SBarry Smith   ISRegisterDynamic - Adds a new index set implementation
5327bdab1eSBarry Smith 
5427bdab1eSBarry Smith   Synopsis:
55f2ba6396SBarry Smith   #include "petscis.h"
5627bdab1eSBarry Smith   PetscErrorCode ISRegisterDynamic(const char *name, const char *path, const char *func_name, PetscErrorCode (*create_func)(IS))
5727bdab1eSBarry Smith 
5827bdab1eSBarry Smith   Not Collective
5927bdab1eSBarry Smith 
6027bdab1eSBarry Smith   Input Parameters:
6127bdab1eSBarry Smith + name        - The name of a new user-defined creation routine
6227bdab1eSBarry Smith . path        - The path (either absolute or relative) of the library containing this routine
6327bdab1eSBarry Smith . func_name   - The name of routine to create method context
6427bdab1eSBarry Smith - create_func - The creation routine itself
6527bdab1eSBarry Smith 
6627bdab1eSBarry Smith   Notes:
6727bdab1eSBarry Smith   ISRegisterDynamic() may be called multiple times to add several user-defined vectors
6827bdab1eSBarry Smith 
6927bdab1eSBarry Smith   If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.
7027bdab1eSBarry Smith 
7127bdab1eSBarry Smith   Sample usage:
7227bdab1eSBarry Smith .vb
73bb7a0047SJed Brown     ISRegisterDynamic("my_is_name","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyISCreate", MyISCreate);
7427bdab1eSBarry Smith .ve
7527bdab1eSBarry Smith 
7627bdab1eSBarry Smith   Then, your vector type can be chosen with the procedural interface via
7727bdab1eSBarry Smith .vb
7827bdab1eSBarry Smith     ISCreate(MPI_Comm, IS *);
79bb7a0047SJed Brown     ISSetType(IS,"my_is_name");
8027bdab1eSBarry Smith .ve
8127bdab1eSBarry Smith    or at runtime via the option
8227bdab1eSBarry Smith .vb
83bb7a0047SJed Brown     -is_type my_is_name
8427bdab1eSBarry Smith .ve
8527bdab1eSBarry Smith 
8627bdab1eSBarry Smith   Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
8727bdab1eSBarry Smith          If your function is not being put into a shared library then use ISRegister() instead
8827bdab1eSBarry Smith 
89bb7a0047SJed Brown   This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
90bb7a0047SJed Brown   dynamic registration of custom IS types will be of limited use to users.
91bb7a0047SJed Brown 
92bb7a0047SJed Brown   Level: developer
9327bdab1eSBarry Smith 
9427bdab1eSBarry Smith .keywords: IS, register
9527bdab1eSBarry Smith .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister()
9627bdab1eSBarry Smith M*/
9727bdab1eSBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
9827bdab1eSBarry Smith #define ISRegisterDynamic(a,b,c,d) ISRegister(a,b,c,0)
9927bdab1eSBarry Smith #else
10027bdab1eSBarry Smith #define ISRegisterDynamic(a,b,c,d) ISRegister(a,b,c,d)
10127bdab1eSBarry Smith #endif
10227bdab1eSBarry Smith 
103639f9d9dSBarry Smith /*
104639f9d9dSBarry Smith     Default index set data structures that PETSc provides.
105639f9d9dSBarry Smith */
106014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,IS *);
107014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGeneralSetIndices(IS,PetscInt,const PetscInt[],PetscCopyMode);
108014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,IS *);
109014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockSetIndices(IS,PetscInt,PetscInt,const PetscInt[],PetscCopyMode);
110014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
111014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISStrideSetStride(IS,PetscInt,PetscInt,PetscInt);
1124b0e389bSBarry Smith 
113014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDestroy(IS*);
114014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetPermutation(IS);
115014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPermutation(IS,PetscBool *);
116014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetIdentity(IS);
117014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISIdentity(IS,PetscBool *);
118014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISContiguousLocal(IS,PetscInt,PetscInt,PetscInt*,PetscBool*);
11908480c60SBarry Smith 
120014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetIndices(IS,const PetscInt *[]);
121014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreIndices(IS,const PetscInt *[]);
122014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetTotalIndices(IS,const PetscInt *[]);
123014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreTotalIndices(IS,const PetscInt *[]);
124014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIndices(IS,const PetscInt *[]);
125014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIndices(IS,const PetscInt *[]);
126014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetNonlocalIS(IS, IS *is);
127014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIS(IS, IS *is);
128014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetSize(IS,PetscInt *);
129014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetLocalSize(IS,PetscInt *);
130014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISInvertPermutation(IS,PetscInt,IS*);
131014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISView(IS,PetscViewer);
132014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISEqual(IS,IS,PetscBool  *);
133014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSort(IS);
134014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSorted(IS,PetscBool  *);
135014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDifference(IS,IS,IS*);
136014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSum(IS,IS,IS*);
137014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpand(IS,IS,IS*);
138132da990SBarry Smith PETSC_EXTERN PetscErrorCode ISGetMinMax(IS,PetscInt*,PetscInt*);
139612dd529SBarry Smith 
140014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS,const PetscInt *[]);
141014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS,const PetscInt *[]);
142014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS,PetscInt *);
143014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS,PetscInt *);
144014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS,PetscInt*);
145014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS,PetscInt);
146c16cb8f2SBarry Smith 
147014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*);
148c16cb8f2SBarry Smith 
149014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISToGeneral(IS);
15038f40f24SLois Curfman McInnes 
151014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISDuplicate(IS,IS*);
152014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCopy(IS,IS);
153014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGather(IS,IS*);
154014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISComplement(IS,PetscInt,PetscInt,IS*);
155014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm,PetscInt,const IS[],IS*);
156bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm,PetscInt, IS[],IS*,IS*);
157bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISPairToList(IS,IS,PetscInt*, IS *[]);
158bb74729cSDmitry Karpeev PETSC_EXTERN PetscErrorCode ISEmbed(IS,IS,PetscBool,IS*);
159014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISOnComm(IS,MPI_Comm,PetscCopyMode,IS*);
160d64ed03dSBarry Smith 
16156cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
162014dd563SJed Brown PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID;
16356cd22aeSBarry Smith 
1645c20da3cSBarry Smith /*S
165d9ffb7b8SBarry Smith    ISLocalToGlobalMapping - mappings from an arbitrary
16690f02eecSBarry Smith       local ordering from 0 to n-1 to a global PETSc ordering
167d4bb536fSBarry Smith       used by a vector or matrix.
168d4bb536fSBarry Smith 
1695c20da3cSBarry Smith    Level: intermediate
1705c20da3cSBarry Smith 
171d4bb536fSBarry Smith    Note: mapping from Local to Global is scalable; but Global
172eec0b4cfSBarry Smith   to Local may not be if the range of global values represented locally
173d4bb536fSBarry Smith   is very large.
17474637425SBarry Smith 
17574637425SBarry Smith    Note: the ISLocalToGlobalMapping is actually a private object; it is included
176992144d0SBarry Smith   here for the inline function ISLocalToGlobalMappingApply() to allow it to be inlined since
17774637425SBarry Smith   it is used so often.
17874637425SBarry Smith 
1795c20da3cSBarry Smith .seealso:  ISLocalToGlobalMappingCreate()
1805c20da3cSBarry Smith S*/
181f09e8eb9SSatish Balay typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
1825c20da3cSBarry Smith 
1835c20da3cSBarry Smith /*E
1845c20da3cSBarry Smith     ISGlobalToLocalMappingType - Indicates if missing global indices are
1855c20da3cSBarry Smith 
1865c20da3cSBarry Smith    IS_GTOLM_MASK - missing global indices are replaced with -1
1875c20da3cSBarry Smith    IS_GTOLM_DROP - missing global indices are dropped
1885c20da3cSBarry Smith 
1895c20da3cSBarry Smith    Level: beginner
1905c20da3cSBarry Smith 
1915c20da3cSBarry Smith .seealso: ISGlobalToLocalMappingApply()
1925c20da3cSBarry Smith 
1935c20da3cSBarry Smith E*/
194987e4450SSatish Balay typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
19590f02eecSBarry Smith 
196014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,ISLocalToGlobalMapping*);
197014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
198014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF,PetscInt,ISLocalToGlobalMapping*);
199014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
200014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping*);
201014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
202afcb2eb5SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
203014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
204014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
205014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
206014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
207014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping,const PetscInt**);
208014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping,const PetscInt**);
209014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
210014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingUnBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
211014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm,PetscInt,const ISLocalToGlobalMapping[],ISLocalToGlobalMapping*);
212186d4ecdSBarry Smith PETSC_EXTERN PetscErrorCode ISG2LMapApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
21374637425SBarry Smith 
21456cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
215b9617806SBarry Smith /*E
216b9617806SBarry Smith     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
217b9617806SBarry Smith                      or for just the local ghosted portion
218b9617806SBarry Smith 
219b9617806SBarry Smith     Level: beginner
220b9617806SBarry Smith 
2218ee2e534SBarry Smith $   IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function
2228ee2e534SBarry Smith $                        is called synchronously in parallel. This requires generating a "parallel coloring".
2238ee2e534SBarry Smith $   IS_COLORING_GHOSTED - includes colors for ghost points, this is used when the function can be called
2248ee2e534SBarry Smith $                         seperately on individual processes with the ghost points already filled in. Does not
2258ee2e534SBarry Smith $                         require a "parallel coloring", rather each process colors its local + ghost part.
2268ee2e534SBarry Smith $                         Using this can result in much less parallel communication. In the paradigm of
2279a42bb27SBarry Smith $                         DMGetLocalVector() and DMGetGlobalVector() this could be called IS_COLORING_LOCAL
22873d7d85fSBarry Smith 
229e727c939SJed Brown .seealso: DMCreateColoring()
230b9617806SBarry Smith E*/
2318ee2e534SBarry Smith typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType;
2326a6fc655SJed Brown PETSC_EXTERN const char *const ISColoringTypes[];
2336c09f170SSatish Balay typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue;
234014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
235dde82324SBarry Smith 
2365c20da3cSBarry Smith /*S
237dde82324SBarry Smith      ISColoring - sets of IS's that define a coloring
238639f9d9dSBarry Smith               of the underlying indices
2395c20da3cSBarry Smith 
2405c20da3cSBarry Smith    Level: intermediate
2415c20da3cSBarry Smith 
2425c20da3cSBarry Smith     Notes:
243b9617806SBarry Smith         One should not access the *is records below directly because they may not yet
2445c20da3cSBarry Smith     have been created. One should use ISColoringGetIS() to make sure they are
2455c20da3cSBarry Smith     created when needed.
2465c20da3cSBarry Smith 
247a5057860SBarry Smith     Developer Note: this is not a PetscObject
248a5057860SBarry Smith 
2495c20da3cSBarry Smith .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
2505c20da3cSBarry Smith S*/
25195fbd943SSatish Balay struct _n_ISColoring {
252a7cc72afSBarry Smith   PetscInt        refct;
253a7cc72afSBarry Smith   PetscInt        n;                /* number of colors */
2545c20da3cSBarry Smith   IS              *is;              /* for each color indicates columns */
255639f9d9dSBarry Smith   MPI_Comm        comm;
25608b6dcc0SBarry Smith   ISColoringValue *colors;          /* for each column indicates color */
25732dcc486SBarry Smith   PetscInt        N;                /* number of columns */
258b9617806SBarry Smith   ISColoringType  ctype;
259639f9d9dSBarry Smith };
26095fbd943SSatish Balay typedef struct _n_ISColoring* ISColoring;
261639f9d9dSBarry Smith 
262014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*);
263014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring*);
264014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
265014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
266014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]);
26749b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring);
26849b734d2SBarry Smith PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring,ISColoringType);
26949b734d2SBarry Smith 
2703a7fca6bSBarry Smith 
271dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/
272dbef8a1cSBarry Smith 
273014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
274014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt,PetscInt[]);
275dbef8a1cSBarry Smith 
276014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
277014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
278014dd563SJed Brown PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
279d9489beaSHong Zhang 
28069ce434fSBarry Smith /*S
28169ce434fSBarry Smith      PetscLayout - defines layout of vectors and matrices across processes (which rows are owned by which processes)
28269ce434fSBarry Smith 
28369ce434fSBarry Smith    Level: developer
28469ce434fSBarry Smith 
28569ce434fSBarry Smith 
28669ce434fSBarry Smith .seealso:  PetscLayoutCreate(), PetscLayoutDestroy()
28769ce434fSBarry Smith S*/
28869ce434fSBarry Smith typedef struct _n_PetscLayout* PetscLayout;
28969ce434fSBarry Smith struct _n_PetscLayout{
29069ce434fSBarry Smith   MPI_Comm               comm;
29169ce434fSBarry Smith   PetscInt               n,N;         /* local, global vector size */
29269ce434fSBarry Smith   PetscInt               rstart,rend; /* local start, local end + 1 */
29369ce434fSBarry Smith   PetscInt               *range;      /* the offset of each processor */
29469ce434fSBarry Smith   PetscInt               bs;          /* number of elements in each block (generally for multi-component problems) Do NOT multiply above numbers by bs */
29569ce434fSBarry Smith   PetscInt               refcnt;      /* MPI Vecs obtained with VecDuplicate() and from MatGetVecs() reuse map of input object */
29669ce434fSBarry Smith   ISLocalToGlobalMapping mapping;     /* mapping used in Vec/MatSetValuesLocal() */
29769ce434fSBarry Smith   ISLocalToGlobalMapping bmapping;    /* mapping used in Vec/MatSetValuesBlockedLocal() */
29869ce434fSBarry Smith   PetscInt               *trstarts;   /* local start for each thread */
29969ce434fSBarry Smith };
30069ce434fSBarry Smith 
30169ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutCreate(MPI_Comm,PetscLayout*);
30269ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetUp(PetscLayout);
30369ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutDestroy(PetscLayout*);
30469ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutDuplicate(PetscLayout,PetscLayout*);
30569ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutReference(PetscLayout,PetscLayout*);
30669ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetLocalSize(PetscLayout,PetscInt);
30769ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetLocalSize(PetscLayout,PetscInt *);
30869ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetSize(PetscLayout,PetscInt);
30969ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetSize(PetscLayout,PetscInt *);
31069ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetBlockSize(PetscLayout,PetscInt);
31169ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetBlockSize(PetscLayout,PetscInt*);
31269ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetRange(PetscLayout,PetscInt *,PetscInt *);
31369ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutGetRanges(PetscLayout,const PetscInt *[]);
31469ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMapping(PetscLayout,ISLocalToGlobalMapping);
31569ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLayoutSetISLocalToGlobalMappingBlock(PetscLayout,ISLocalToGlobalMapping);
31669ce434fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFSetGraphLayout(PetscSF,PetscLayout,PetscInt,const PetscInt*,PetscCopyMode,const PetscInt*);
31769ce434fSBarry Smith 
31869ce434fSBarry Smith #undef __FUNCT__
31969ce434fSBarry Smith #define __FUNCT__ "PetscLayoutFindOwner"
32069ce434fSBarry Smith /*@C
32169ce434fSBarry Smith      PetscLayoutFindOwner - Find the owning rank for a global index
32269ce434fSBarry Smith 
32369ce434fSBarry Smith     Not Collective
32469ce434fSBarry Smith 
32569ce434fSBarry Smith    Input Parameters:
32669ce434fSBarry Smith +    map - the layout
32769ce434fSBarry Smith -    idx - global index to find the owner of
32869ce434fSBarry Smith 
32969ce434fSBarry Smith    Output Parameter:
33069ce434fSBarry Smith .    owner - the owning rank
33169ce434fSBarry Smith 
33269ce434fSBarry Smith    Level: developer
33369ce434fSBarry Smith 
33469ce434fSBarry Smith     Fortran Notes:
33569ce434fSBarry Smith       Not available from Fortran
33669ce434fSBarry Smith 
33769ce434fSBarry Smith @*/
33869ce434fSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwner(PetscLayout map,PetscInt idx,PetscInt *owner)
33969ce434fSBarry Smith {
34069ce434fSBarry Smith   PetscErrorCode ierr;
34169ce434fSBarry Smith   PetscMPIInt    lo = 0,hi,t;
34269ce434fSBarry Smith 
34369ce434fSBarry Smith   PetscFunctionBegin;
34469ce434fSBarry Smith   *owner = -1;                  /* GCC erroneously issues warning about possibly uninitialized use when error condition */
34569ce434fSBarry Smith   if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first");
34669ce434fSBarry Smith   if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx);
34769ce434fSBarry Smith   ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr);
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   }
35369ce434fSBarry Smith   *owner = lo;
35469ce434fSBarry Smith   PetscFunctionReturn(0);
35569ce434fSBarry Smith }
35669ce434fSBarry Smith 
35769ce434fSBarry Smith #undef __FUNCT__
35869ce434fSBarry Smith #define __FUNCT__ "PetscLayoutFindOwnerIndex"
35969ce434fSBarry Smith /*@C
36069ce434fSBarry Smith      PetscLayoutFindOwnerIndex - Find the owning rank and the local index for a global index
36169ce434fSBarry Smith 
36269ce434fSBarry Smith     Not Collective
36369ce434fSBarry Smith 
36469ce434fSBarry Smith    Input Parameters:
36569ce434fSBarry Smith +    map   - the layout
36669ce434fSBarry Smith -    idx   - global index to find the owner of
36769ce434fSBarry Smith 
36869ce434fSBarry Smith    Output Parameter:
36969ce434fSBarry Smith +    owner - the owning rank
37069ce434fSBarry Smith -    lidx  - local index used by the owner for idx
37169ce434fSBarry Smith 
37269ce434fSBarry Smith    Level: developer
37369ce434fSBarry Smith 
37469ce434fSBarry Smith     Fortran Notes:
37569ce434fSBarry Smith       Not available from Fortran
37669ce434fSBarry Smith 
37769ce434fSBarry Smith @*/
37869ce434fSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLayoutFindOwnerIndex(PetscLayout map,PetscInt idx,PetscInt *owner, PetscInt *lidx)
37969ce434fSBarry Smith {
38069ce434fSBarry Smith   PetscErrorCode ierr;
38169ce434fSBarry Smith   PetscMPIInt    lo = 0,hi,t;
38269ce434fSBarry Smith 
38369ce434fSBarry Smith   PetscFunctionBegin;
38469ce434fSBarry Smith   if (!((map->n >= 0) && (map->N >= 0) && (map->range))) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"PetscLayoutSetUp() must be called first");
38569ce434fSBarry Smith   if (idx < 0 || idx > map->N) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Index %D is out of range",idx);
38669ce434fSBarry Smith   ierr = MPI_Comm_size(map->comm,&hi);CHKERRQ(ierr);
38769ce434fSBarry Smith   while (hi - lo > 1) {
38869ce434fSBarry Smith     t = lo + (hi - lo) / 2;
38969ce434fSBarry Smith     if (idx < map->range[t]) hi = t;
39069ce434fSBarry Smith     else                     lo = t;
39169ce434fSBarry Smith   }
39269ce434fSBarry Smith   *owner = lo;
39369ce434fSBarry Smith   *lidx  = idx-map->range[lo];
39469ce434fSBarry Smith   PetscFunctionReturn(0);
39569ce434fSBarry Smith }
3969e03d832SJed Brown 
397d53a3d6fSBarry Smith /*S
398d53a3d6fSBarry Smith   PetscSection - This is a mapping from DMMESH points to sets of values, which is
399d53a3d6fSBarry Smith   our presentation of a fibre bundle.
400d53a3d6fSBarry Smith 
401d53a3d6fSBarry Smith   Level: developer
402d53a3d6fSBarry Smith 
403d53a3d6fSBarry Smith .seealso:  PetscSectionCreate(), PetscSectionDestroy()
404d53a3d6fSBarry Smith S*/
405d53a3d6fSBarry Smith typedef struct _n_PetscSection *PetscSection;
406d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreate(MPI_Comm,PetscSection*);
407d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionClone(PetscSection, PetscSection*);
408d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetNumFields(PetscSection, PetscInt *);
409d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetNumFields(PetscSection, PetscInt);
410d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldName(PetscSection, PetscInt, const char *[]);
411d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldName(PetscSection, PetscInt, const char []);
412d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldComponents(PetscSection, PetscInt, PetscInt *);
413d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldComponents(PetscSection, PetscInt, PetscInt);
414d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetChart(PetscSection, PetscInt *, PetscInt *);
415d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetChart(PetscSection, PetscInt, PetscInt);
416d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetDof(PetscSection, PetscInt, PetscInt*);
417d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetDof(PetscSection, PetscInt, PetscInt);
418d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddDof(PetscSection, PetscInt, PetscInt);
419d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldDof(PetscSection, PetscInt, PetscInt, PetscInt*);
420d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldDof(PetscSection, PetscInt, PetscInt, PetscInt);
421d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddFieldDof(PetscSection, PetscInt, PetscInt, PetscInt);
422d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstraintDof(PetscSection, PetscInt, PetscInt*);
423d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetConstraintDof(PetscSection, PetscInt, PetscInt);
424d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddConstraintDof(PetscSection, PetscInt, PetscInt);
425d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt*);
426d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt);
427d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionAddFieldConstraintDof(PetscSection, PetscInt, PetscInt, PetscInt);
428d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstraintIndices(PetscSection, PetscInt, const PetscInt**);
429d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetConstraintIndices(PetscSection, PetscInt, const PetscInt*);
430d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldConstraintIndices(PetscSection, PetscInt, PetscInt, const PetscInt**);
431d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldConstraintIndices(PetscSection, PetscInt, PetscInt, const PetscInt*);
432d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetUpBC(PetscSection);
433d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetUp(PetscSection);
434d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetMaxDof(PetscSection, PetscInt*);
435d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetStorageSize(PetscSection, PetscInt*);
436d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetConstrainedStorageSize(PetscSection, PetscInt*);
437d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetOffset(PetscSection, PetscInt, PetscInt*);
438d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetOffset(PetscSection, PetscInt, PetscInt);
439d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetFieldOffset(PetscSection, PetscInt, PetscInt, PetscInt*);
440d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionSetFieldOffset(PetscSection, PetscInt, PetscInt, PetscInt);
441d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetOffsetRange(PetscSection, PetscInt *, PetscInt *);
442d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionView(PetscSection, PetscViewer);
443d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionReset(PetscSection);
444d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionDestroy(PetscSection*);
445d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateGlobalSection(PetscSection, PetscSF, PetscBool, PetscSection *);
446d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateGlobalSectionCensored(PetscSection, PetscSF, PetscBool, PetscInt, const PetscInt [], PetscSection *);
447d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateSubsection(PetscSection, PetscInt, PetscInt [], PetscSection *);
448d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionCreateSubmeshSection(PetscSection, IS, PetscSection *);
449d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetPointLayout(MPI_Comm, PetscSection, PetscLayout *);
450d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSectionGetValueLayout(MPI_Comm, PetscSection, PetscLayout *);
451d53a3d6fSBarry Smith 
452d53a3d6fSBarry Smith /* PetscSF support */
453d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFConvertPartition(PetscSF, PetscSection, IS, ISLocalToGlobalMapping *, PetscSF *);
454d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFCreateRemoteOffsets(PetscSF, PetscSection, PetscSection, PetscInt **);
455d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFDistributeSection(PetscSF, PetscSection, PetscInt **, PetscSection);
456d53a3d6fSBarry Smith PETSC_EXTERN PetscErrorCode PetscSFCreateSectionSF(PetscSF, PetscSection, PetscInt [], PetscSection, PetscSF *);
457d53a3d6fSBarry Smith 
4589e03d832SJed Brown /* Reset __FUNCT__ in case the user does not define it themselves */
4599e03d832SJed Brown #undef __FUNCT__
4609e03d832SJed Brown #define __FUNCT__ "User provided function"
4619e03d832SJed Brown 
462a2ce50c7SBarry Smith #endif
463