xref: /petsc/include/petscis.h (revision 8bc8193efbc389280f83b3d41dffa9e2d23e2ace)
1 /*
2    An index set is a generalization of a subset of integers.  Index sets
3    are used for defining scatters and gathers.
4 */
5 #if !defined(__PETSCIS_H)
6 #define __PETSCIS_H
7 #include "petsc.h"
8 PETSC_EXTERN_CXX_BEGIN
9 
10 extern PetscCookie IS_COOKIE;
11 
12 /*S
13      IS - Abstract PETSc object that indexing.
14 
15    Level: beginner
16 
17   Concepts: indexing, stride
18 
19 .seealso:  ISCreateGeneral(), ISCreateBlock(), ISCreateStride(), ISGetIndices(), ISDestroy()
20 S*/
21 typedef struct _p_IS* IS;
22 
23 /*
24     Default index set data structures that PETSc provides.
25 */
26 typedef enum {IS_GENERAL=0,IS_STRIDE=1,IS_BLOCK = 2} ISType;
27 EXTERN PetscErrorCode   ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],IS *);
28 EXTERN PetscErrorCode   ISCreateGeneralWithArray(MPI_Comm,PetscInt,PetscInt[],IS *);
29 EXTERN PetscErrorCode   ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],IS *);
30 EXTERN PetscErrorCode   ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
31 
32 EXTERN PetscErrorCode   ISDestroy(IS);
33 
34 EXTERN PetscErrorCode   ISSetPermutation(IS);
35 EXTERN PetscErrorCode   ISPermutation(IS,PetscTruth*);
36 EXTERN PetscErrorCode   ISSetIdentity(IS);
37 EXTERN PetscErrorCode   ISIdentity(IS,PetscTruth*);
38 
39 EXTERN PetscErrorCode   ISGetIndices(IS,PetscInt *[]);
40 EXTERN PetscErrorCode   ISRestoreIndices(IS,PetscInt *[]);
41 EXTERN PetscErrorCode   ISGetSize(IS,PetscInt *);
42 EXTERN PetscErrorCode   ISGetLocalSize(IS,PetscInt *);
43 EXTERN PetscErrorCode   ISInvertPermutation(IS,PetscInt,IS*);
44 EXTERN PetscErrorCode   ISView(IS,PetscViewer);
45 EXTERN PetscErrorCode   ISEqual(IS,IS,PetscTruth *);
46 EXTERN PetscErrorCode   ISSort(IS);
47 EXTERN PetscErrorCode   ISSorted(IS,PetscTruth *);
48 EXTERN PetscErrorCode   ISDifference(IS,IS,IS*);
49 EXTERN PetscErrorCode   ISSum(IS*,IS);
50 
51 EXTERN PetscErrorCode   ISBlock(IS,PetscTruth*);
52 EXTERN PetscErrorCode   ISBlockGetIndices(IS,PetscInt *[]);
53 EXTERN PetscErrorCode   ISBlockRestoreIndices(IS,PetscInt *[]);
54 EXTERN PetscErrorCode   ISBlockGetSize(IS,PetscInt *);
55 EXTERN PetscErrorCode   ISBlockGetBlockSize(IS,PetscInt *);
56 
57 EXTERN PetscErrorCode   ISStride(IS,PetscTruth*);
58 EXTERN PetscErrorCode   ISStrideGetInfo(IS,PetscInt *,PetscInt*);
59 
60 EXTERN PetscErrorCode   ISStrideToGeneral(IS);
61 
62 EXTERN PetscErrorCode   ISDuplicate(IS,IS*);
63 EXTERN PetscErrorCode   ISAllGather(IS,IS*);
64 EXTERN PetscErrorCode   ISAllGatherIndices(MPI_Comm,PetscInt,const PetscInt[],PetscInt*,PetscInt*[]);
65 
66 /* --------------------------------------------------------------------------*/
67 extern PetscCookie IS_LTOGM_COOKIE;
68 
69 /*S
70    ISLocalToGlobalMapping - mappings from an arbitrary
71       local ordering from 0 to n-1 to a global PETSc ordering
72       used by a vector or matrix.
73 
74    Level: intermediate
75 
76    Note: mapping from Local to Global is scalable; but Global
77   to Local may not be if the range of global values represented locally
78   is very large.
79 
80    Note: the ISLocalToGlobalMapping is actually a private object; it is included
81   here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since
82   it is used so often.
83 
84 .seealso:  ISLocalToGlobalMappingCreate()
85 S*/
86 struct _p_ISLocalToGlobalMapping{
87   PETSCHEADER(int)
88   PetscInt n;                  /* number of local indices */
89   PetscInt *indices;           /* global index of each local index */
90   PetscInt globalstart;        /* first global referenced in indices */
91   PetscInt globalend;          /* last + 1 global referenced in indices */
92   PetscInt *globals;           /* local index for each global index between start and end */
93 };
94 typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
95 
96 /*E
97     ISGlobalToLocalMappingType - Indicates if missing global indices are
98 
99    IS_GTOLM_MASK - missing global indices are replaced with -1
100    IS_GTOLM_DROP - missing global indices are dropped
101 
102    Level: beginner
103 
104 .seealso: ISGlobalToLocalMappingApply()
105 
106 E*/
107 typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
108 
109 EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
110 EXTERN PetscErrorCode ISLocalToGlobalMappingCreateNC(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
111 EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
112 EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
113 EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping);
114 EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
115 EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
116 EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
117 EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
118 EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
119 EXTERN PetscErrorCode ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
120 
121 #define ISLocalToGlobalMappingApply(mapping,N,in,out) 0;\
122 {\
123   PetscInt _i,*_idx = (mapping)->indices,_Nmax = (mapping)->n;\
124   for (_i=0; _i<N; _i++) {\
125     if ((in)[_i] < 0) {(out)[_i] = (in)[_i]; continue;}\
126     if ((in)[_i] >= _Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %D too large %D (max) at %D",(in)[_i],_Nmax,_i);\
127     (out)[_i] = _idx[(in)[_i]];\
128   }\
129 }
130 
131 /* --------------------------------------------------------------------------*/
132 /*E
133     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
134                      or for just the local ghosted portion
135 
136     Level: beginner
137 
138 $   IS_COLORING_LOCAL - does not include the colors for ghost points
139 $   IS_COLORING_GHOSTED - includes colors for ghost points
140 
141 .seealso: DAGetColoring()
142 E*/
143 typedef enum {IS_COLORING_LOCAL,IS_COLORING_GHOSTED} ISColoringType;
144 
145 #define MPIU_COLORING_VALUE MPI_CHAR
146 #define IS_COLORING_MAX     255
147 typedef unsigned char ISColoringValue;
148 EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
149 
150 /*S
151      ISColoring - sets of IS's that define a coloring
152               of the underlying indices
153 
154    Level: intermediate
155 
156     Notes:
157         One should not access the *is records below directly because they may not yet
158     have been created. One should use ISColoringGetIS() to make sure they are
159     created when needed.
160 
161 .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
162 S*/
163 struct _p_ISColoring {
164   PetscInt        refct;
165   PetscInt        n;                /* number of colors */
166   IS              *is;              /* for each color indicates columns */
167   MPI_Comm        comm;
168   ISColoringValue *colors;          /* for each column indicates color */
169   PetscInt        N;                /* number of columns */
170   ISColoringType  ctype;
171 };
172 typedef struct _p_ISColoring* ISColoring;
173 
174 EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,const ISColoringValue[],ISColoring*);
175 EXTERN PetscErrorCode ISColoringDestroy(ISColoring);
176 EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
177 EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
178 EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]);
179 #define ISColoringReference(coloring) ((coloring)->refct++,0)
180 #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0)
181 
182 /* --------------------------------------------------------------------------*/
183 
184 EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
185 EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt[]);
186 
187 EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
188 EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
189 EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
190 
191 PETSC_EXTERN_CXX_END
192 #endif
193