xref: /petsc/include/petscis.h (revision 186d4ecdc2f8f3d4a2a0951ddba16cdc5cd22fa1)
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 <petscsys.h>
8 #include <petscsf.h>
9 
10 #define IS_FILE_CLASSID 1211218
11 PETSC_EXTERN PetscClassId IS_CLASSID;
12 
13 PETSC_EXTERN PetscErrorCode ISInitializePackage(const char[]);
14 
15 /*S
16      IS - Abstract PETSc object that allows indexing.
17 
18    Level: beginner
19 
20   Concepts: indexing, stride
21 
22 .seealso:  ISCreateGeneral(), ISCreateBlock(), ISCreateStride(), ISGetIndices(), ISDestroy()
23 S*/
24 typedef struct _p_IS* IS;
25 
26 /*J
27     ISType - String with the name of a PETSc vector or the creation function
28        with an optional dynamic library name, for example
29        http://www.mcs.anl.gov/petsc/lib.a:myveccreate()
30 
31    Level: beginner
32 
33 .seealso: ISSetType(), IS
34 J*/
35 typedef const char* ISType;
36 #define ISGENERAL      "general"
37 #define ISSTRIDE       "stride"
38 #define ISBLOCK        "block"
39 
40 /* Dynamic creation and loading functions */
41 PETSC_EXTERN PetscFunctionList ISList;
42 PETSC_EXTERN PetscBool         ISRegisterAllCalled;
43 PETSC_EXTERN PetscErrorCode ISSetType(IS, ISType);
44 PETSC_EXTERN PetscErrorCode ISGetType(IS, ISType *);
45 PETSC_EXTERN PetscErrorCode ISRegister(const char[],const char[],const char[],PetscErrorCode (*)(IS));
46 PETSC_EXTERN PetscErrorCode ISRegisterAll(const char []);
47 PETSC_EXTERN PetscErrorCode ISRegisterDestroy(void);
48 PETSC_EXTERN PetscErrorCode ISCreate(MPI_Comm,IS*);
49 
50 /*MC
51   ISRegisterDynamic - Adds a new index set implementation
52 
53   Synopsis:
54   #include "petscis.h"
55   PetscErrorCode ISRegisterDynamic(const char *name, const char *path, const char *func_name, PetscErrorCode (*create_func)(IS))
56 
57   Not Collective
58 
59   Input Parameters:
60 + name        - The name of a new user-defined creation routine
61 . path        - The path (either absolute or relative) of the library containing this routine
62 . func_name   - The name of routine to create method context
63 - create_func - The creation routine itself
64 
65   Notes:
66   ISRegisterDynamic() may be called multiple times to add several user-defined vectors
67 
68   If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.
69 
70   Sample usage:
71 .vb
72     ISRegisterDynamic("my_is_name","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyISCreate", MyISCreate);
73 .ve
74 
75   Then, your vector type can be chosen with the procedural interface via
76 .vb
77     ISCreate(MPI_Comm, IS *);
78     ISSetType(IS,"my_is_name");
79 .ve
80    or at runtime via the option
81 .vb
82     -is_type my_is_name
83 .ve
84 
85   Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
86          If your function is not being put into a shared library then use ISRegister() instead
87 
88   This is no ISSetFromOptions() and the current implementations do not have a way to dynamically determine type, so
89   dynamic registration of custom IS types will be of limited use to users.
90 
91   Level: developer
92 
93 .keywords: IS, register
94 .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister()
95 M*/
96 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
97 #define ISRegisterDynamic(a,b,c,d) ISRegister(a,b,c,0)
98 #else
99 #define ISRegisterDynamic(a,b,c,d) ISRegister(a,b,c,d)
100 #endif
101 
102 /*
103     Default index set data structures that PETSc provides.
104 */
105 PETSC_EXTERN PetscErrorCode ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,IS *);
106 PETSC_EXTERN PetscErrorCode ISGeneralSetIndices(IS,PetscInt,const PetscInt[],PetscCopyMode);
107 PETSC_EXTERN PetscErrorCode ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,IS *);
108 PETSC_EXTERN PetscErrorCode ISBlockSetIndices(IS,PetscInt,PetscInt,const PetscInt[],PetscCopyMode);
109 PETSC_EXTERN PetscErrorCode ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
110 PETSC_EXTERN PetscErrorCode ISStrideSetStride(IS,PetscInt,PetscInt,PetscInt);
111 
112 PETSC_EXTERN PetscErrorCode ISDestroy(IS*);
113 PETSC_EXTERN PetscErrorCode ISSetPermutation(IS);
114 PETSC_EXTERN PetscErrorCode ISPermutation(IS,PetscBool *);
115 PETSC_EXTERN PetscErrorCode ISSetIdentity(IS);
116 PETSC_EXTERN PetscErrorCode ISIdentity(IS,PetscBool *);
117 PETSC_EXTERN PetscErrorCode ISContiguousLocal(IS,PetscInt,PetscInt,PetscInt*,PetscBool*);
118 
119 PETSC_EXTERN PetscErrorCode ISGetIndices(IS,const PetscInt *[]);
120 PETSC_EXTERN PetscErrorCode ISRestoreIndices(IS,const PetscInt *[]);
121 PETSC_EXTERN PetscErrorCode ISGetTotalIndices(IS,const PetscInt *[]);
122 PETSC_EXTERN PetscErrorCode ISRestoreTotalIndices(IS,const PetscInt *[]);
123 PETSC_EXTERN PetscErrorCode ISGetNonlocalIndices(IS,const PetscInt *[]);
124 PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIndices(IS,const PetscInt *[]);
125 PETSC_EXTERN PetscErrorCode ISGetNonlocalIS(IS, IS *is);
126 PETSC_EXTERN PetscErrorCode ISRestoreNonlocalIS(IS, IS *is);
127 PETSC_EXTERN PetscErrorCode ISGetSize(IS,PetscInt *);
128 PETSC_EXTERN PetscErrorCode ISGetLocalSize(IS,PetscInt *);
129 PETSC_EXTERN PetscErrorCode ISInvertPermutation(IS,PetscInt,IS*);
130 PETSC_EXTERN PetscErrorCode ISView(IS,PetscViewer);
131 PETSC_EXTERN PetscErrorCode ISEqual(IS,IS,PetscBool  *);
132 PETSC_EXTERN PetscErrorCode ISSort(IS);
133 PETSC_EXTERN PetscErrorCode ISSorted(IS,PetscBool  *);
134 PETSC_EXTERN PetscErrorCode ISDifference(IS,IS,IS*);
135 PETSC_EXTERN PetscErrorCode ISSum(IS,IS,IS*);
136 PETSC_EXTERN PetscErrorCode ISExpand(IS,IS,IS*);
137 PETSC_EXTERN PetscErrorCode ISGetMinMax(IS,PetscInt*,PetscInt*);
138 
139 PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS,const PetscInt *[]);
140 PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS,const PetscInt *[]);
141 PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS,PetscInt *);
142 PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS,PetscInt *);
143 PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS,PetscInt*);
144 PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS,PetscInt);
145 
146 PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*);
147 
148 PETSC_EXTERN PetscErrorCode ISToGeneral(IS);
149 
150 PETSC_EXTERN PetscErrorCode ISDuplicate(IS,IS*);
151 PETSC_EXTERN PetscErrorCode ISCopy(IS,IS);
152 PETSC_EXTERN PetscErrorCode ISAllGather(IS,IS*);
153 PETSC_EXTERN PetscErrorCode ISComplement(IS,PetscInt,PetscInt,IS*);
154 PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm,PetscInt,const IS[],IS*);
155 PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm,PetscInt, IS[],IS*,IS*);
156 PETSC_EXTERN PetscErrorCode ISPairToList(IS,IS,PetscInt*, IS *[]);
157 PETSC_EXTERN PetscErrorCode ISEmbed(IS,IS,PetscBool,IS*);
158 PETSC_EXTERN PetscErrorCode ISOnComm(IS,MPI_Comm,PetscCopyMode,IS*);
159 
160 /* --------------------------------------------------------------------------*/
161 PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID;
162 
163 /*S
164    ISLocalToGlobalMapping - mappings from an arbitrary
165       local ordering from 0 to n-1 to a global PETSc ordering
166       used by a vector or matrix.
167 
168    Level: intermediate
169 
170    Note: mapping from Local to Global is scalable; but Global
171   to Local may not be if the range of global values represented locally
172   is very large.
173 
174    Note: the ISLocalToGlobalMapping is actually a private object; it is included
175   here for the inline function ISLocalToGlobalMappingApply() to allow it to be inlined since
176   it is used so often.
177 
178 .seealso:  ISLocalToGlobalMappingCreate()
179 S*/
180 typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
181 
182 /*E
183     ISGlobalToLocalMappingType - Indicates if missing global indices are
184 
185    IS_GTOLM_MASK - missing global indices are replaced with -1
186    IS_GTOLM_DROP - missing global indices are dropped
187 
188    Level: beginner
189 
190 .seealso: ISGlobalToLocalMappingApply()
191 
192 E*/
193 typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
194 
195 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,ISLocalToGlobalMapping*);
196 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
197 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF,PetscInt,ISLocalToGlobalMapping*);
198 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
199 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping*);
200 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
201 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
202 PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
203 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
204 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
205 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
206 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping,const PetscInt**);
207 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping,const PetscInt**);
208 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
209 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingUnBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
210 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm,PetscInt,const ISLocalToGlobalMapping[],ISLocalToGlobalMapping*);
211 PETSC_EXTERN PetscErrorCode ISG2LMapApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
212 
213 /* --------------------------------------------------------------------------*/
214 /*E
215     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
216                      or for just the local ghosted portion
217 
218     Level: beginner
219 
220 $   IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function
221 $                        is called synchronously in parallel. This requires generating a "parallel coloring".
222 $   IS_COLORING_GHOSTED - includes colors for ghost points, this is used when the function can be called
223 $                         seperately on individual processes with the ghost points already filled in. Does not
224 $                         require a "parallel coloring", rather each process colors its local + ghost part.
225 $                         Using this can result in much less parallel communication. In the paradigm of
226 $                         DMGetLocalVector() and DMGetGlobalVector() this could be called IS_COLORING_LOCAL
227 
228 .seealso: DMCreateColoring()
229 E*/
230 typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType;
231 PETSC_EXTERN const char *const ISColoringTypes[];
232 typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue;
233 PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
234 
235 /*S
236      ISColoring - sets of IS's that define a coloring
237               of the underlying indices
238 
239    Level: intermediate
240 
241     Notes:
242         One should not access the *is records below directly because they may not yet
243     have been created. One should use ISColoringGetIS() to make sure they are
244     created when needed.
245 
246     Developer Note: this is not a PetscObject
247 
248 .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
249 S*/
250 struct _n_ISColoring {
251   PetscInt        refct;
252   PetscInt        n;                /* number of colors */
253   IS              *is;              /* for each color indicates columns */
254   MPI_Comm        comm;
255   ISColoringValue *colors;          /* for each column indicates color */
256   PetscInt        N;                /* number of columns */
257   ISColoringType  ctype;
258 };
259 typedef struct _n_ISColoring* ISColoring;
260 
261 PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*);
262 PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring*);
263 PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
264 PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
265 PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]);
266 PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring);
267 PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring,ISColoringType);
268 
269 
270 /* --------------------------------------------------------------------------*/
271 
272 PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
273 PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt,PetscInt[]);
274 
275 PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
276 PETSC_EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
277 PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
278 
279 
280 /* Reset __FUNCT__ in case the user does not define it themselves */
281 #undef __FUNCT__
282 #define __FUNCT__ "User provided function"
283 
284 #endif
285