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