xref: /petsc/include/petscis.h (revision 08b6dcc09476afde1cce98cc04f33d98301cef47)
173f4d377SMatthew Knepley /* $Id: petscis.h,v 1.63 2001/06/21 21:15:49 bsmith Exp $ */
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 
118ba1e511SMatthew Knepley extern int IS_COOKIE;
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
70d9ffb7b8SBarry Smith    ISLocalToGlobalMapping - 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*);
110b46b645bSBarry Smith EXTERN int ISLocalToGlobalMappingCreateNC(MPI_Comm,int,const int[],ISLocalToGlobalMapping*);
111ca44d042SBarry Smith EXTERN int ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
112b0a32e0cSBarry Smith EXTERN int ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
113ca44d042SBarry Smith EXTERN int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping);
114ca44d042SBarry Smith EXTERN int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
11574637425SBarry Smith EXTERN int ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,int,const int[],int*,int[]);
11674637425SBarry Smith EXTERN int ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,int*);
11774637425SBarry Smith EXTERN int ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,int*,int**,int**,int***);
11874637425SBarry Smith EXTERN int ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,int*,int**,int**,int***);
119323b833fSBarry Smith EXTERN int ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,int,ISLocalToGlobalMapping*);
12074637425SBarry Smith 
12174637425SBarry Smith #define ISLocalToGlobalMappingApply(mapping,N,in,out) 0;\
12274637425SBarry Smith {\
12374637425SBarry Smith   int _i,*_idx = (mapping)->indices,_Nmax = (mapping)->n;\
12474637425SBarry Smith   for (_i=0; _i<N; _i++) {\
12574637425SBarry Smith     if ((in)[_i] < 0) {(out)[_i] = (in)[_i]; continue;}\
12629bbc08cSBarry Smith     if ((in)[_i] >= _Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %d too large %d (max) at %d",(in)[_i],_Nmax,_i);\
12774637425SBarry Smith     (out)[_i] = _idx[(in)[_i]];\
12874637425SBarry Smith   }\
12974637425SBarry Smith }
13090f02eecSBarry Smith 
13156cd22aeSBarry Smith /* --------------------------------------------------------------------------*/
132b9617806SBarry Smith /*E
133b9617806SBarry Smith     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
134b9617806SBarry Smith                      or for just the local ghosted portion
135b9617806SBarry Smith 
136b9617806SBarry Smith     Level: beginner
137b9617806SBarry Smith 
13873d7d85fSBarry Smith $   IS_COLORING_LOCAL - does not include the colors for ghost points
13973d7d85fSBarry Smith $   IS_COLORING_GHOSTED - includes colors for ghost points
14073d7d85fSBarry Smith 
141b9617806SBarry Smith .seealso: DAGetColoring()
142b9617806SBarry Smith E*/
14373d7d85fSBarry Smith typedef enum {IS_COLORING_LOCAL,IS_COLORING_GHOSTED} ISColoringType;
144b9617806SBarry Smith 
145*08b6dcc0SBarry Smith #define MPIU_COLORING_VALUE MPI_CHAR
146*08b6dcc0SBarry Smith #define IS_COLORING_MAX     255
147*08b6dcc0SBarry Smith typedef unsigned char ISColoringValue;
148*08b6dcc0SBarry Smith EXTERN int ISAllGatherColors(MPI_Comm,int,ISColoringValue*,int*,ISColoringValue**);
1495c20da3cSBarry Smith /*S
1505c20da3cSBarry Smith      ISColorings - sets of IS's that define a coloring
151639f9d9dSBarry Smith               of the underlying indices
1525c20da3cSBarry Smith 
1535c20da3cSBarry Smith    Level: intermediate
1545c20da3cSBarry Smith 
1555c20da3cSBarry Smith     Notes:
156b9617806SBarry Smith         One should not access the *is records below directly because they may not yet
1575c20da3cSBarry Smith     have been created. One should use ISColoringGetIS() to make sure they are
1585c20da3cSBarry Smith     created when needed.
1595c20da3cSBarry Smith 
1605c20da3cSBarry Smith .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
1615c20da3cSBarry Smith S*/
162f09e8eb9SSatish Balay struct _p_ISColoring {
16373d7d85fSBarry Smith   int             refct;
1645c20da3cSBarry Smith   int             n;                /* number of colors */
1655c20da3cSBarry Smith   IS              *is;              /* for each color indicates columns */
166639f9d9dSBarry Smith   MPI_Comm        comm;
167*08b6dcc0SBarry Smith   ISColoringValue *colors;          /* for each column indicates color */
1685c20da3cSBarry Smith   int             N;                /* number of columns */
169b9617806SBarry Smith   ISColoringType  ctype;
170639f9d9dSBarry Smith };
171f09e8eb9SSatish Balay typedef struct _p_ISColoring* ISColoring;
172639f9d9dSBarry Smith 
173*08b6dcc0SBarry Smith EXTERN int ISColoringCreate(MPI_Comm,int,const ISColoringValue[],ISColoring*);
174ca44d042SBarry Smith EXTERN int ISColoringDestroy(ISColoring);
175b0a32e0cSBarry Smith EXTERN int ISColoringView(ISColoring,PetscViewer);
176ca44d042SBarry Smith EXTERN int ISColoringGetIS(ISColoring,int*,IS*[]);
17722327b12SSatish Balay EXTERN int ISColoringRestoreIS(ISColoring,IS*[]);
1783a7fca6bSBarry Smith #define ISColoringReference(coloring) ((coloring)->refct++,0)
1793a7fca6bSBarry Smith #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0)
1803a7fca6bSBarry Smith 
181dbef8a1cSBarry Smith /* --------------------------------------------------------------------------*/
182dbef8a1cSBarry Smith 
183ca44d042SBarry Smith EXTERN int ISPartitioningToNumbering(IS,IS*);
184ca44d042SBarry Smith EXTERN int ISPartitioningCount(IS,int[]);
185dbef8a1cSBarry Smith 
186a2ce50c7SBarry Smith #endif
1877588ac45SBarry Smith 
1887588ac45SBarry Smith 
189639f9d9dSBarry Smith 
190639f9d9dSBarry Smith 
191