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