xref: /petsc/include/petscis.h (revision 3a7fca6b988f1faea172e46abdf950477dbfaf76)
1*3a7fca6bSBarry Smith /* $Id: petscis.h,v 1.62 2001/04/19 18:08:04 bsmith Exp bsmith $ */
22eac72dbSBarry Smith 
32eac72dbSBarry Smith /*
4f8256253SLois Curfman McInnes    An index set is a generalization of a subset of integers.  Index sets
5f8256253SLois Curfman McInnes    are used for defining scatters and gathers.
62eac72dbSBarry Smith */
70a835dfdSSatish Balay #if !defined(__PETSCIS_H)
80a835dfdSSatish Balay #define __PETSCIS_H
92eac72dbSBarry Smith #include "petsc.h"
102eac72dbSBarry Smith 
119e25ed09SBarry Smith #define IS_COOKIE PETSC_COOKIE+2
12f0479e8cSBarry Smith 
135c20da3cSBarry Smith /*S
145c20da3cSBarry Smith      IS - Abstract PETSc object that indexing.
155c20da3cSBarry Smith 
165c20da3cSBarry Smith    Level: beginner
175c20da3cSBarry Smith 
185c20da3cSBarry Smith   Concepts: indexing, stride
195c20da3cSBarry Smith 
205c20da3cSBarry Smith .seealso:  ISCreateGeneral(), ISCreateBlock(), ISCreateStride(), ISGetIndices(), ISDestroy()
215c20da3cSBarry Smith S*/
22f09e8eb9SSatish Balay typedef struct _p_IS* IS;
232eac72dbSBarry Smith 
24639f9d9dSBarry Smith /*
25639f9d9dSBarry Smith     Default index set data structures that PETSc provides.
26639f9d9dSBarry Smith */
27639f9d9dSBarry Smith typedef enum {IS_GENERAL=0,IS_STRIDE=1,IS_BLOCK = 2} ISType;
28ca44d042SBarry Smith EXTERN int   ISCreateGeneral(MPI_Comm,int,const int[],IS *);
29ca44d042SBarry Smith EXTERN int   ISCreateBlock(MPI_Comm,int,int,const int[],IS *);
30ca44d042SBarry Smith EXTERN int   ISCreateStride(MPI_Comm,int,int,int,IS *);
314b0e389bSBarry Smith 
32ca44d042SBarry Smith EXTERN int   ISDestroy(IS);
334b0e389bSBarry Smith 
34ca44d042SBarry Smith EXTERN int   ISSetPermutation(IS);
35ca44d042SBarry Smith EXTERN int   ISPermutation(IS,PetscTruth*);
36ca44d042SBarry Smith EXTERN int   ISSetIdentity(IS);
37ca44d042SBarry Smith EXTERN int   ISIdentity(IS,PetscTruth*);
3808480c60SBarry Smith 
39ca44d042SBarry Smith EXTERN int   ISGetIndices(IS,int *[]);
40ca44d042SBarry Smith EXTERN int   ISRestoreIndices(IS,int *[]);
41ca44d042SBarry Smith EXTERN int   ISGetSize(IS,int *);
4205e11b22SBarry Smith EXTERN int   ISGetLocalSize(IS,int *);
43ca44d042SBarry Smith EXTERN int   ISInvertPermutation(IS,int,IS*);
44b0a32e0cSBarry Smith EXTERN int   ISView(IS,PetscViewer);
45ca44d042SBarry Smith EXTERN int   ISEqual(IS,IS,PetscTruth *);
46ca44d042SBarry Smith EXTERN int   ISSort(IS);
47ca44d042SBarry Smith EXTERN int   ISSorted(IS,PetscTruth *);
48ca44d042SBarry Smith EXTERN int   ISDifference(IS,IS,IS*);
49ca44d042SBarry Smith EXTERN int   ISSum(IS,IS,IS*);
50612dd529SBarry Smith 
51ca44d042SBarry Smith EXTERN int   ISBlock(IS,PetscTruth*);
52ca44d042SBarry Smith EXTERN int   ISBlockGetIndices(IS,int *[]);
53ca44d042SBarry Smith EXTERN int   ISBlockRestoreIndices(IS,int *[]);
54ca44d042SBarry Smith EXTERN int   ISBlockGetSize(IS,int *);
55ca44d042SBarry Smith EXTERN int   ISBlockGetBlockSize(IS,int *);
56c16cb8f2SBarry Smith 
57ca44d042SBarry Smith EXTERN int   ISStride(IS,PetscTruth*);
58ca44d042SBarry Smith EXTERN int   ISStrideGetInfo(IS,int *,int*);
59c16cb8f2SBarry Smith 
60ca44d042SBarry Smith EXTERN int   ISStrideToGeneral(IS);
6138f40f24SLois Curfman McInnes 
62ca44d042SBarry Smith EXTERN int   ISDuplicate(IS,IS*);
63ca44d042SBarry Smith EXTERN int   ISAllGather(IS,IS*);
6473d7d85fSBarry Smith EXTERN int   ISAllGatherIndices(MPI_Comm,int,int*,int*,int**);
65d64ed03dSBarry Smith 
6656cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
675c20da3cSBarry Smith #define IS_LTOGM_COOKIE PETSC_COOKIE+12
6856cd22aeSBarry Smith 
695c20da3cSBarry Smith /*S
705c20da3cSBarry Smith    ISLocalToGlobalMappings - mappings from an arbitrary
7190f02eecSBarry Smith       local ordering from 0 to n-1 to a global PETSc ordering
72d4bb536fSBarry Smith       used by a vector or matrix.
73d4bb536fSBarry Smith 
745c20da3cSBarry Smith    Level: intermediate
755c20da3cSBarry Smith 
76d4bb536fSBarry Smith    Note: mapping from Local to Global is scalable; but Global
77eec0b4cfSBarry Smith   to Local may not be if the range of global values represented locally
78d4bb536fSBarry Smith   is very large.
7974637425SBarry Smith 
8074637425SBarry Smith    Note: the ISLocalToGlobalMapping is actually a private object; it is included
8174637425SBarry Smith   here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since
8274637425SBarry Smith   it is used so often.
8374637425SBarry Smith 
845c20da3cSBarry Smith .seealso:  ISLocalToGlobalMappingCreate()
855c20da3cSBarry Smith S*/
8674637425SBarry Smith struct _p_ISLocalToGlobalMapping{
8774637425SBarry Smith   PETSCHEADER(int)
8874637425SBarry Smith   int n;                  /* number of local indices */
8974637425SBarry Smith   int *indices;           /* global index of each local index */
9074637425SBarry Smith   int globalstart;        /* first global referenced in indices */
9174637425SBarry Smith   int globalend;          /* last + 1 global referenced in indices */
9274637425SBarry Smith   int *globals;           /* local index for each global index between start and end */
9374637425SBarry Smith };
94f09e8eb9SSatish Balay typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
955c20da3cSBarry Smith 
965c20da3cSBarry Smith /*E
975c20da3cSBarry Smith     ISGlobalToLocalMappingType - Indicates if missing global indices are
985c20da3cSBarry Smith 
995c20da3cSBarry Smith    IS_GTOLM_MASK - missing global indices are replaced with -1
1005c20da3cSBarry Smith    IS_GTOLM_DROP - missing global indices are dropped
1015c20da3cSBarry Smith 
1025c20da3cSBarry Smith    Level: beginner
1035c20da3cSBarry Smith 
1045c20da3cSBarry Smith .seealso: ISGlobalToLocalMappingApply()
1055c20da3cSBarry Smith 
1065c20da3cSBarry Smith E*/
107987e4450SSatish Balay typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
10890f02eecSBarry Smith 
109ca44d042SBarry Smith EXTERN int ISLocalToGlobalMappingCreate(MPI_Comm,int,const int[],ISLocalToGlobalMapping*);
110ca44d042SBarry Smith EXTERN int ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
111b0a32e0cSBarry Smith EXTERN int ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
112ca44d042SBarry Smith EXTERN int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping);
113ca44d042SBarry Smith EXTERN int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
11474637425SBarry Smith EXTERN int ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,int,const int[],int*,int[]);
11574637425SBarry Smith EXTERN int ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,int*);
11674637425SBarry Smith EXTERN int ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,int*,int**,int**,int***);
11774637425SBarry Smith EXTERN int ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,int*,int**,int**,int***);
118323b833fSBarry Smith EXTERN int ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,int,ISLocalToGlobalMapping*);
11974637425SBarry Smith 
12074637425SBarry Smith #define ISLocalToGlobalMappingApply(mapping,N,in,out) 0;\
12174637425SBarry Smith {\
12274637425SBarry Smith   int _i,*_idx = (mapping)->indices,_Nmax = (mapping)->n;\
12374637425SBarry Smith   for (_i=0; _i<N; _i++) {\
12474637425SBarry Smith     if ((in)[_i] < 0) {(out)[_i] = (in)[_i]; continue;}\
12529bbc08cSBarry Smith     if ((in)[_i] >= _Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %d too large %d (max) at %d",(in)[_i],_Nmax,_i);\
12674637425SBarry Smith     (out)[_i] = _idx[(in)[_i]];\
12774637425SBarry Smith   }\
12874637425SBarry Smith }
12990f02eecSBarry Smith 
13056cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
131b9617806SBarry Smith /*E
132b9617806SBarry Smith     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
133b9617806SBarry Smith                      or for just the local ghosted portion
134b9617806SBarry Smith 
135b9617806SBarry Smith     Level: beginner
136b9617806SBarry Smith 
13773d7d85fSBarry Smith $   IS_COLORING_LOCAL - does not include the colors for ghost points
13873d7d85fSBarry Smith $   IS_COLORING_GHOSTED - includes colors for ghost points
13973d7d85fSBarry Smith 
140b9617806SBarry Smith .seealso: DAGetColoring()
141b9617806SBarry Smith E*/
14273d7d85fSBarry Smith typedef enum {IS_COLORING_LOCAL,IS_COLORING_GHOSTED} ISColoringType;
143b9617806SBarry Smith 
1445c20da3cSBarry Smith /*S
1455c20da3cSBarry Smith      ISColorings - sets of IS's that define a coloring
146639f9d9dSBarry Smith               of the underlying indices
1475c20da3cSBarry Smith 
1485c20da3cSBarry Smith    Level: intermediate
1495c20da3cSBarry Smith 
1505c20da3cSBarry Smith     Notes:
151b9617806SBarry Smith         One should not access the *is records below directly because they may not yet
1525c20da3cSBarry Smith     have been created. One should use ISColoringGetIS() to make sure they are
1535c20da3cSBarry Smith     created when needed.
1545c20da3cSBarry Smith 
1555c20da3cSBarry Smith .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
1565c20da3cSBarry Smith S*/
157f09e8eb9SSatish Balay struct _p_ISColoring {
15873d7d85fSBarry Smith   int            refct;
1595c20da3cSBarry Smith   int            n;                /* number of colors */
1605c20da3cSBarry Smith   IS             *is;              /* for each color indicates columns */
161639f9d9dSBarry Smith   MPI_Comm       comm;
1625c20da3cSBarry Smith   int            *colors;          /* for each column indicates color */
1635c20da3cSBarry Smith   int            N;                /* number of columns */
164b9617806SBarry Smith   ISColoringType ctype;
165639f9d9dSBarry Smith };
166f09e8eb9SSatish Balay typedef struct _p_ISColoring* ISColoring;
167639f9d9dSBarry Smith 
168ca44d042SBarry Smith EXTERN int ISColoringCreate(MPI_Comm,int,const int[],ISColoring*);
169ca44d042SBarry Smith EXTERN int ISColoringDestroy(ISColoring);
170b0a32e0cSBarry Smith EXTERN int ISColoringView(ISColoring,PetscViewer);
171ca44d042SBarry Smith EXTERN int ISColoringGetIS(ISColoring,int*,IS*[]);
17222327b12SSatish Balay EXTERN int ISColoringRestoreIS(ISColoring,IS*[]);
173*3a7fca6bSBarry Smith #define ISColoringReference(coloring) ((coloring)->refct++,0)
174*3a7fca6bSBarry Smith #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0)
175*3a7fca6bSBarry Smith 
176dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/
177dbef8a1cSBarry Smith 
178ca44d042SBarry Smith EXTERN int ISPartitioningToNumbering(IS,IS*);
179ca44d042SBarry Smith EXTERN int ISPartitioningCount(IS,int[]);
180dbef8a1cSBarry Smith 
181a2ce50c7SBarry Smith #endif
1827588ac45SBarry Smith 
1837588ac45SBarry Smith 
184639f9d9dSBarry Smith 
185639f9d9dSBarry Smith 
186