xref: /petsc/include/petscis.h (revision ce94432eddcd14845bc7e8083b7f8ea723b9bf7d)
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 
138 PETSC_EXTERN PetscErrorCode ISBlockGetIndices(IS,const PetscInt *[]);
139 PETSC_EXTERN PetscErrorCode ISBlockRestoreIndices(IS,const PetscInt *[]);
140 PETSC_EXTERN PetscErrorCode ISBlockGetLocalSize(IS,PetscInt *);
141 PETSC_EXTERN PetscErrorCode ISBlockGetSize(IS,PetscInt *);
142 PETSC_EXTERN PetscErrorCode ISGetBlockSize(IS,PetscInt*);
143 PETSC_EXTERN PetscErrorCode ISSetBlockSize(IS,PetscInt);
144 
145 PETSC_EXTERN PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*);
146 
147 PETSC_EXTERN PetscErrorCode ISToGeneral(IS);
148 
149 PETSC_EXTERN PetscErrorCode ISDuplicate(IS,IS*);
150 PETSC_EXTERN PetscErrorCode ISCopy(IS,IS);
151 PETSC_EXTERN PetscErrorCode ISAllGather(IS,IS*);
152 PETSC_EXTERN PetscErrorCode ISComplement(IS,PetscInt,PetscInt,IS*);
153 PETSC_EXTERN PetscErrorCode ISConcatenate(MPI_Comm,PetscInt,const IS[],IS*);
154 PETSC_EXTERN PetscErrorCode ISListToPair(MPI_Comm,PetscInt, IS[],IS*,IS*);
155 PETSC_EXTERN PetscErrorCode ISPairToList(IS,IS,PetscInt*, IS *[]);
156 PETSC_EXTERN PetscErrorCode ISEmbed(IS,IS,PetscBool,IS*);
157 PETSC_EXTERN PetscErrorCode ISOnComm(IS,MPI_Comm,PetscCopyMode,IS*);
158 
159 /* --------------------------------------------------------------------------*/
160 PETSC_EXTERN PetscClassId IS_LTOGM_CLASSID;
161 
162 /*S
163    ISLocalToGlobalMapping - mappings from an arbitrary
164       local ordering from 0 to n-1 to a global PETSc ordering
165       used by a vector or matrix.
166 
167    Level: intermediate
168 
169    Note: mapping from Local to Global is scalable; but Global
170   to Local may not be if the range of global values represented locally
171   is very large.
172 
173    Note: the ISLocalToGlobalMapping is actually a private object; it is included
174   here for the inline function ISLocalToGlobalMappingApply() to allow it to be inlined since
175   it is used so often.
176 
177 .seealso:  ISLocalToGlobalMappingCreate()
178 S*/
179 typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
180 
181 /*E
182     ISGlobalToLocalMappingType - Indicates if missing global indices are
183 
184    IS_GTOLM_MASK - missing global indices are replaced with -1
185    IS_GTOLM_DROP - missing global indices are dropped
186 
187    Level: beginner
188 
189 .seealso: ISGlobalToLocalMappingApply()
190 
191 E*/
192 typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
193 
194 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,ISLocalToGlobalMapping*);
195 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
196 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingCreateSF(PetscSF,PetscInt,ISLocalToGlobalMapping*);
197 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
198 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping*);
199 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
200 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping,PetscInt,const PetscInt[],PetscInt[]);
201 PETSC_EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
202 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
203 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
204 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
205 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping,const PetscInt**);
206 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping,const PetscInt**);
207 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
208 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingUnBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
209 PETSC_EXTERN PetscErrorCode ISLocalToGlobalMappingConcatenate(MPI_Comm,PetscInt,const ISLocalToGlobalMapping[],ISLocalToGlobalMapping*);
210 
211 /* --------------------------------------------------------------------------*/
212 /*E
213     ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
214                      or for just the local ghosted portion
215 
216     Level: beginner
217 
218 $   IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function
219 $                        is called synchronously in parallel. This requires generating a "parallel coloring".
220 $   IS_COLORING_GHOSTED - includes colors for ghost points, this is used when the function can be called
221 $                         seperately on individual processes with the ghost points already filled in. Does not
222 $                         require a "parallel coloring", rather each process colors its local + ghost part.
223 $                         Using this can result in much less parallel communication. In the paradigm of
224 $                         DMGetLocalVector() and DMGetGlobalVector() this could be called IS_COLORING_LOCAL
225 
226 .seealso: DMCreateColoring()
227 E*/
228 typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType;
229 PETSC_EXTERN const char *const ISColoringTypes[];
230 typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue;
231 PETSC_EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
232 
233 /*S
234      ISColoring - sets of IS's that define a coloring
235               of the underlying indices
236 
237    Level: intermediate
238 
239     Notes:
240         One should not access the *is records below directly because they may not yet
241     have been created. One should use ISColoringGetIS() to make sure they are
242     created when needed.
243 
244     Developer Note: this is not a PetscObject
245 
246 .seealso:  ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
247 S*/
248 struct _n_ISColoring {
249   PetscInt        refct;
250   PetscInt        n;                /* number of colors */
251   IS              *is;              /* for each color indicates columns */
252   MPI_Comm        comm;
253   ISColoringValue *colors;          /* for each column indicates color */
254   PetscInt        N;                /* number of columns */
255   ISColoringType  ctype;
256 };
257 typedef struct _n_ISColoring* ISColoring;
258 
259 PETSC_EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*);
260 PETSC_EXTERN PetscErrorCode ISColoringDestroy(ISColoring*);
261 PETSC_EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
262 PETSC_EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
263 PETSC_EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]);
264 PETSC_EXTERN PetscErrorCode ISColoringReference(ISColoring);
265 PETSC_EXTERN PetscErrorCode ISColoringSetType(ISColoring,ISColoringType);
266 
267 
268 /* --------------------------------------------------------------------------*/
269 
270 PETSC_EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
271 PETSC_EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt,PetscInt[]);
272 
273 PETSC_EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
274 PETSC_EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
275 PETSC_EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,PetscInt,const IS[],IS[]);
276 
277 
278 /* Reset __FUNCT__ in case the user does not define it themselves */
279 #undef __FUNCT__
280 #define __FUNCT__ "User provided function"
281 
282 #endif
283