Actual source code: petscis.h
1: /*
2: An index set is a generalization of a subset of integers. Index sets
3: are used for defining scatters and gathers.
4: */
7: #include petsc.h
12: /*S
13: IS - Abstract PETSc object that indexing.
15: Level: beginner
17: Concepts: indexing, stride
19: .seealso: ISCreateGeneral(), ISCreateBlock(), ISCreateStride(), ISGetIndices(), ISDestroy()
20: S*/
21: typedef struct _p_IS* IS;
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 ISCreateGeneralNC(MPI_Comm,PetscInt,const PetscInt[],IS *);
29: EXTERN PetscErrorCode ISCreateGeneralWithArray(MPI_Comm,PetscInt,PetscInt[],IS *);
30: EXTERN PetscErrorCode ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],IS *);
31: EXTERN PetscErrorCode ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
33: EXTERN PetscErrorCode ISDestroy(IS);
35: EXTERN PetscErrorCode ISSetPermutation(IS);
36: EXTERN PetscErrorCode ISPermutation(IS,PetscTruth*);
37: EXTERN PetscErrorCode ISSetIdentity(IS);
38: EXTERN PetscErrorCode ISIdentity(IS,PetscTruth*);
40: EXTERN PetscErrorCode ISGetIndices(IS,PetscInt *[]);
41: EXTERN PetscErrorCode ISRestoreIndices(IS,PetscInt *[]);
42: EXTERN PetscErrorCode ISGetSize(IS,PetscInt *);
43: EXTERN PetscErrorCode ISGetLocalSize(IS,PetscInt *);
44: EXTERN PetscErrorCode ISInvertPermutation(IS,PetscInt,IS*);
45: EXTERN PetscErrorCode ISView(IS,PetscViewer);
46: EXTERN PetscErrorCode ISEqual(IS,IS,PetscTruth *);
47: EXTERN PetscErrorCode ISSort(IS);
48: EXTERN PetscErrorCode ISSorted(IS,PetscTruth *);
49: EXTERN PetscErrorCode ISDifference(IS,IS,IS*);
50: EXTERN PetscErrorCode ISSum(IS,IS,IS*);
51: EXTERN PetscErrorCode ISExpand(IS,IS,IS*);
53: EXTERN PetscErrorCode ISBlock(IS,PetscTruth*);
54: EXTERN PetscErrorCode ISBlockGetIndices(IS,PetscInt *[]);
55: EXTERN PetscErrorCode ISBlockRestoreIndices(IS,PetscInt *[]);
56: EXTERN PetscErrorCode ISBlockGetSize(IS,PetscInt *);
57: EXTERN PetscErrorCode ISBlockGetBlockSize(IS,PetscInt *);
59: EXTERN PetscErrorCode ISStride(IS,PetscTruth*);
60: EXTERN PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*);
62: EXTERN PetscErrorCode ISStrideToGeneral(IS);
64: EXTERN PetscErrorCode ISDuplicate(IS,IS*);
65: EXTERN PetscErrorCode ISAllGather(IS,IS*);
66: EXTERN PetscErrorCode ISAllGatherIndices(MPI_Comm,PetscInt,const PetscInt[],PetscInt*,PetscInt*[]);
68: /* --------------------------------------------------------------------------*/
71: /*S
72: ISLocalToGlobalMapping - mappings from an arbitrary
73: local ordering from 0 to n-1 to a global PETSc ordering
74: used by a vector or matrix.
76: Level: intermediate
78: Note: mapping from Local to Global is scalable; but Global
79: to Local may not be if the range of global values represented locally
80: is very large.
82: Note: the ISLocalToGlobalMapping is actually a private object; it is included
83: here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since
84: it is used so often.
86: .seealso: ISLocalToGlobalMappingCreate()
87: S*/
88: struct _p_ISLocalToGlobalMapping{
89: PETSCHEADER(int);
90: PetscInt n; /* number of local indices */
91: PetscInt *indices; /* global index of each local index */
92: PetscInt globalstart; /* first global referenced in indices */
93: PetscInt globalend; /* last + 1 global referenced in indices */
94: PetscInt *globals; /* local index for each global index between start and end */
95: };
96: typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping;
98: /*E
99: ISGlobalToLocalMappingType - Indicates if missing global indices are
101: IS_GTOLM_MASK - missing global indices are replaced with -1
102: IS_GTOLM_DROP - missing global indices are dropped
104: Level: beginner
106: .seealso: ISGlobalToLocalMappingApply()
108: E*/
109: typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
111: EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
112: EXTERN PetscErrorCode ISLocalToGlobalMappingCreateNC(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
113: EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
114: EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
115: EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping);
116: EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
117: EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
118: EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
119: EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
120: EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
121: EXTERN PetscErrorCode ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
123: #define ISLocalToGlobalMappingApply(mapping,N,in,out) 0;\
124: {\
125: PetscInt _i,*_idx = (mapping)->indices,_Nmax = (mapping)->n;\
126: for (_i=0; _i<N; _i++) {\
127: if ((in)[_i] < 0) {(out)[_i] = (in)[_i]; continue;}\
128: if ((in)[_i] >= _Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %D too large %D (max) at %D",(in)[_i],_Nmax,_i);\
129: (out)[_i] = _idx[(in)[_i]];\
130: }\
131: }
133: /* --------------------------------------------------------------------------*/
134: /*E
135: ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix
136: or for just the local ghosted portion
138: Level: beginner
140: $ IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function
141: $ is called synchronously in parallel. This requires generating a "parallel coloring".
142: $ IS_COLORING_GHOSTED - includes colors for ghost points, this is used when the function can be called
143: $ seperately on individual processes with the ghost points already filled in. Does not
144: $ require a "parallel coloring", rather each process colors its local + ghost part.
145: $ Using this can result in much less parallel communication. In the paradigm of
146: $ DAGetLocalVector() and DAGetGlobalVector() this could be called IS_COLORING_LOCAL
148: .seealso: DAGetColoring()
149: E*/
150: typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType;
152: typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue;
153: EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
155: /*S
156: ISColoring - sets of IS's that define a coloring
157: of the underlying indices
159: Level: intermediate
161: Notes:
162: One should not access the *is records below directly because they may not yet
163: have been created. One should use ISColoringGetIS() to make sure they are
164: created when needed.
166: .seealso: ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
167: S*/
168: struct _n_ISColoring {
169: PetscInt refct;
170: PetscInt n; /* number of colors */
171: IS *is; /* for each color indicates columns */
172: MPI_Comm comm;
173: ISColoringValue *colors; /* for each column indicates color */
174: PetscInt N; /* number of columns */
175: ISColoringType ctype;
176: };
177: typedef struct _n_ISColoring* ISColoring;
179: EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*);
180: EXTERN PetscErrorCode ISColoringDestroy(ISColoring);
181: EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
182: EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
183: EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]);
184: #define ISColoringReference(coloring) ((coloring)->refct++,0)
185: #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0)
187: /* --------------------------------------------------------------------------*/
189: EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
190: EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt[]);
192: EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
193: EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
194: EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
197: #endif