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 ISCreateGeneralWithArray(MPI_Comm,PetscInt,PetscInt[],IS *);
29: EXTERN PetscErrorCode ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],IS *);
30: EXTERN PetscErrorCode ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *);
32: EXTERN PetscErrorCode ISDestroy(IS);
34: EXTERN PetscErrorCode ISSetPermutation(IS);
35: EXTERN PetscErrorCode ISPermutation(IS,PetscTruth*);
36: EXTERN PetscErrorCode ISSetIdentity(IS);
37: EXTERN PetscErrorCode ISIdentity(IS,PetscTruth*);
39: EXTERN PetscErrorCode ISGetIndices(IS,PetscInt *[]);
40: EXTERN PetscErrorCode ISRestoreIndices(IS,PetscInt *[]);
41: EXTERN PetscErrorCode ISGetSize(IS,PetscInt *);
42: EXTERN PetscErrorCode ISGetLocalSize(IS,PetscInt *);
43: EXTERN PetscErrorCode ISInvertPermutation(IS,PetscInt,IS*);
44: EXTERN PetscErrorCode ISView(IS,PetscViewer);
45: EXTERN PetscErrorCode ISEqual(IS,IS,PetscTruth *);
46: EXTERN PetscErrorCode ISSort(IS);
47: EXTERN PetscErrorCode ISSorted(IS,PetscTruth *);
48: EXTERN PetscErrorCode ISDifference(IS,IS,IS*);
49: EXTERN PetscErrorCode ISSum(IS*,IS);
50: EXTERN PetscErrorCode ISExpand(IS,IS,IS*);
52: EXTERN PetscErrorCode ISBlock(IS,PetscTruth*);
53: EXTERN PetscErrorCode ISBlockGetIndices(IS,PetscInt *[]);
54: EXTERN PetscErrorCode ISBlockRestoreIndices(IS,PetscInt *[]);
55: EXTERN PetscErrorCode ISBlockGetSize(IS,PetscInt *);
56: EXTERN PetscErrorCode ISBlockGetBlockSize(IS,PetscInt *);
58: EXTERN PetscErrorCode ISStride(IS,PetscTruth*);
59: EXTERN PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*);
61: EXTERN PetscErrorCode ISStrideToGeneral(IS);
63: EXTERN PetscErrorCode ISDuplicate(IS,IS*);
64: EXTERN PetscErrorCode ISAllGather(IS,IS*);
65: EXTERN PetscErrorCode ISAllGatherIndices(MPI_Comm,PetscInt,const PetscInt[],PetscInt*,PetscInt*[]);
67: /* --------------------------------------------------------------------------*/
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.
75: Level: intermediate
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.
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.
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;
97: /*E
98: ISGlobalToLocalMappingType - Indicates if missing global indices are
100: IS_GTOLM_MASK - missing global indices are replaced with -1
101: IS_GTOLM_DROP - missing global indices are dropped
103: Level: beginner
105: .seealso: ISGlobalToLocalMappingApply()
107: E*/
108: typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType;
110: EXTERN PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
111: EXTERN PetscErrorCode ISLocalToGlobalMappingCreateNC(MPI_Comm,PetscInt,const PetscInt[],ISLocalToGlobalMapping*);
112: EXTERN PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *);
113: EXTERN PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer);
114: EXTERN PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping);
115: EXTERN PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*);
116: EXTERN PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]);
117: EXTERN PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*);
118: EXTERN PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
119: EXTERN PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]);
120: EXTERN PetscErrorCode ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*);
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: }
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
137: Level: beginner
139: $ IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function
140: $ is called synchronously in parallel. This requires generating a "parallel coloring".
141: $ IS_COLORING_GHOSTED - includes colors for ghost points, this is used when the function can be called
142: $ seperately on individual processes with the ghost points already filled in. Does not
143: $ require a "parallel coloring", rather each process colors its local + ghost part.
144: $ Using this can result in much less parallel communication. In the paradigm of
145: $ DAGetLocalVector() and DAGetGlobalVector() this could be called IS_COLORING_LOCAL
147: .seealso: DAGetColoring()
148: E*/
149: typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType;
151: typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue;
152: EXTERN PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]);
154: /*S
155: ISColoring - sets of IS's that define a coloring
156: of the underlying indices
158: Level: intermediate
160: Notes:
161: One should not access the *is records below directly because they may not yet
162: have been created. One should use ISColoringGetIS() to make sure they are
163: created when needed.
165: .seealso: ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS()
166: S*/
167: struct _n_ISColoring {
168: PetscInt refct;
169: PetscInt n; /* number of colors */
170: IS *is; /* for each color indicates columns */
171: MPI_Comm comm;
172: ISColoringValue *colors; /* for each column indicates color */
173: PetscInt N; /* number of columns */
174: ISColoringType ctype;
175: };
176: typedef struct _n_ISColoring* ISColoring;
178: EXTERN PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*);
179: EXTERN PetscErrorCode ISColoringDestroy(ISColoring);
180: EXTERN PetscErrorCode ISColoringView(ISColoring,PetscViewer);
181: EXTERN PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]);
182: EXTERN PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]);
183: #define ISColoringReference(coloring) ((coloring)->refct++,0)
184: #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0)
186: /* --------------------------------------------------------------------------*/
188: EXTERN PetscErrorCode ISPartitioningToNumbering(IS,IS*);
189: EXTERN PetscErrorCode ISPartitioningCount(IS,PetscInt[]);
191: EXTERN PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
192: EXTERN PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
193: EXTERN PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]);
196: #endif