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 PETSC_EXTERN_CXX_BEGIN 9 10 #define IS_FILE_CLASSID 1211218 11 extern PetscClassId IS_CLASSID; 12 13 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 /*E 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 E*/ 35 #define ISType char* 36 #define ISGENERAL "general" 37 #define ISSTRIDE "stride" 38 #define ISBLOCK "block" 39 40 /* Dynamic creation and loading functions */ 41 extern PetscFList ISList; 42 extern PetscBool ISRegisterAllCalled; 43 extern PetscErrorCode ISSetType(IS, const ISType); 44 extern PetscErrorCode ISGetType(IS, const ISType *); 45 extern PetscErrorCode ISRegister(const char[],const char[],const char[],PetscErrorCode (*)(IS)); 46 extern PetscErrorCode ISRegisterAll(const char []); 47 extern PetscErrorCode ISRegisterDestroy(void); 48 extern PetscErrorCode ISCreate(MPI_Comm,IS*); 49 50 /*MC 51 ISRegisterDynamic - Adds a new vector component implementation 52 53 Synopsis: 54 PetscErrorCode ISRegisterDynamic(const char *name, const char *path, const char *func_name, PetscErrorCode (*create_func)(IS)) 55 56 Not Collective 57 58 Input Parameters: 59 + name - The name of a new user-defined creation routine 60 . path - The path (either absolute or relative) of the library containing this routine 61 . func_name - The name of routine to create method context 62 - create_func - The creation routine itself 63 64 Notes: 65 ISRegisterDynamic() may be called multiple times to add several user-defined vectors 66 67 If dynamic libraries are used, then the fourth input argument (routine_create) is ignored. 68 69 Sample usage: 70 .vb 71 ISRegisterDynamic("my_is","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyIStorCreate", MyIStorCreate); 72 .ve 73 74 Then, your vector type can be chosen with the procedural interface via 75 .vb 76 ISCreate(MPI_Comm, IS *); 77 ISSetType(IS,"my_vector_name"); 78 .ve 79 or at runtime via the option 80 .vb 81 -vec_type my_vector_name 82 .ve 83 84 Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 85 If your function is not being put into a shared library then use ISRegister() instead 86 87 Level: advanced 88 89 .keywords: IS, register 90 .seealso: ISRegisterAll(), ISRegisterDestroy(), ISRegister() 91 M*/ 92 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 93 #define ISRegisterDynamic(a,b,c,d) ISRegister(a,b,c,0) 94 #else 95 #define ISRegisterDynamic(a,b,c,d) ISRegister(a,b,c,d) 96 #endif 97 98 /* 99 Default index set data structures that PETSc provides. 100 */ 101 extern PetscErrorCode ISCreateGeneral(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,IS *); 102 extern PetscErrorCode ISGeneralSetIndices(IS,PetscInt,const PetscInt[],PetscCopyMode); 103 extern PetscErrorCode ISCreateBlock(MPI_Comm,PetscInt,PetscInt,const PetscInt[],PetscCopyMode,IS *); 104 extern PetscErrorCode ISBlockSetIndices(IS,PetscInt,PetscInt,const PetscInt[],PetscCopyMode); 105 extern PetscErrorCode ISCreateStride(MPI_Comm,PetscInt,PetscInt,PetscInt,IS *); 106 extern PetscErrorCode ISStrideSetStride(IS,PetscInt,PetscInt,PetscInt); 107 108 extern PetscErrorCode ISDestroy_(IS); 109 #define ISDestroy(a) (ISDestroy_(a) || (((a) = 0),0)) 110 111 extern PetscErrorCode ISSetPermutation(IS); 112 extern PetscErrorCode ISPermutation(IS,PetscBool *); 113 extern PetscErrorCode ISSetIdentity(IS); 114 extern PetscErrorCode ISIdentity(IS,PetscBool *); 115 extern PetscErrorCode ISContiguousLocal(IS,PetscInt,PetscInt,PetscInt*,PetscBool*); 116 117 extern PetscErrorCode ISGetIndices(IS,const PetscInt *[]); 118 extern PetscErrorCode ISRestoreIndices(IS,const PetscInt *[]); 119 extern PetscErrorCode ISGetTotalIndices(IS,const PetscInt *[]); 120 extern PetscErrorCode ISRestoreTotalIndices(IS,const PetscInt *[]); 121 extern PetscErrorCode ISGetNonlocalIndices(IS,const PetscInt *[]); 122 extern PetscErrorCode ISRestoreNonlocalIndices(IS,const PetscInt *[]); 123 extern PetscErrorCode ISGetNonlocalIS(IS, IS *is); 124 extern PetscErrorCode ISRestoreNonlocalIS(IS, IS *is); 125 extern PetscErrorCode ISGetSize(IS,PetscInt *); 126 extern PetscErrorCode ISGetLocalSize(IS,PetscInt *); 127 extern PetscErrorCode ISInvertPermutation(IS,PetscInt,IS*); 128 extern PetscErrorCode ISView(IS,PetscViewer); 129 extern PetscErrorCode ISEqual(IS,IS,PetscBool *); 130 extern PetscErrorCode ISSort(IS); 131 extern PetscErrorCode ISSorted(IS,PetscBool *); 132 extern PetscErrorCode ISDifference(IS,IS,IS*); 133 extern PetscErrorCode ISSum(IS,IS,IS*); 134 extern PetscErrorCode ISExpand(IS,IS,IS*); 135 136 extern PetscErrorCode ISBlockGetIndices(IS,const PetscInt *[]); 137 extern PetscErrorCode ISBlockRestoreIndices(IS,const PetscInt *[]); 138 extern PetscErrorCode ISBlockGetLocalSize(IS,PetscInt *); 139 extern PetscErrorCode ISBlockGetSize(IS,PetscInt *); 140 extern PetscErrorCode ISGetBlockSize(IS,PetscInt*); 141 extern PetscErrorCode ISSetBlockSize(IS,PetscInt); 142 143 extern PetscErrorCode ISStrideGetInfo(IS,PetscInt *,PetscInt*); 144 145 extern PetscErrorCode ISToGeneral(IS); 146 147 extern PetscErrorCode ISDuplicate(IS,IS*); 148 extern PetscErrorCode ISCopy(IS,IS); 149 extern PetscErrorCode ISAllGather(IS,IS*); 150 extern PetscErrorCode ISComplement(IS,PetscInt,PetscInt,IS*); 151 extern PetscErrorCode ISOnComm(IS,MPI_Comm,PetscCopyMode,IS*); 152 153 /* --------------------------------------------------------------------------*/ 154 extern PetscClassId IS_LTOGM_CLASSID; 155 156 /*S 157 ISLocalToGlobalMapping - mappings from an arbitrary 158 local ordering from 0 to n-1 to a global PETSc ordering 159 used by a vector or matrix. 160 161 Level: intermediate 162 163 Note: mapping from Local to Global is scalable; but Global 164 to Local may not be if the range of global values represented locally 165 is very large. 166 167 Note: the ISLocalToGlobalMapping is actually a private object; it is included 168 here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since 169 it is used so often. 170 171 .seealso: ISLocalToGlobalMappingCreate() 172 S*/ 173 struct _p_ISLocalToGlobalMapping{ 174 PETSCHEADER(int); 175 PetscInt n; /* number of local indices */ 176 PetscInt *indices; /* global index of each local index */ 177 PetscInt globalstart; /* first global referenced in indices */ 178 PetscInt globalend; /* last + 1 global referenced in indices */ 179 PetscInt *globals; /* local index for each global index between start and end */ 180 }; 181 typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping; 182 183 /*E 184 ISGlobalToLocalMappingType - Indicates if missing global indices are 185 186 IS_GTOLM_MASK - missing global indices are replaced with -1 187 IS_GTOLM_DROP - missing global indices are dropped 188 189 Level: beginner 190 191 .seealso: ISGlobalToLocalMappingApply() 192 193 E*/ 194 typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType; 195 196 extern PetscErrorCode ISLocalToGlobalMappingCreate(MPI_Comm,PetscInt,const PetscInt[],PetscCopyMode,ISLocalToGlobalMapping*); 197 extern PetscErrorCode ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *); 198 extern PetscErrorCode ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer); 199 extern PetscErrorCode ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping); 200 extern PetscErrorCode ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*); 201 extern PetscErrorCode ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,PetscInt,const PetscInt[],PetscInt*,PetscInt[]); 202 extern PetscErrorCode ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,PetscInt*); 203 extern PetscErrorCode ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]); 204 extern PetscErrorCode ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,PetscInt*,PetscInt*[],PetscInt*[],PetscInt**[]); 205 extern PetscErrorCode ISLocalToGlobalMappingGetIndices(ISLocalToGlobalMapping,const PetscInt**); 206 extern PetscErrorCode ISLocalToGlobalMappingRestoreIndices(ISLocalToGlobalMapping,const PetscInt**); 207 extern PetscErrorCode ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*); 208 extern PetscErrorCode ISLocalToGlobalMappingUnBlock(ISLocalToGlobalMapping,PetscInt,ISLocalToGlobalMapping*); 209 210 PETSC_STATIC_INLINE PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,PetscInt N,const PetscInt in[],PetscInt out[]) 211 { 212 PetscInt i,Nmax = mapping->n; 213 const PetscInt *idx = mapping->indices; 214 PetscFunctionBegin; 215 for (i=0; i<N; i++) { 216 if (in[i] < 0) {out[i] = in[i]; continue;} 217 if (in[i] >= Nmax) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Local index %D too large %D (max) at %D",in[i],Nmax,i); 218 out[i] = idx[in[i]]; 219 } 220 PetscFunctionReturn(0); 221 } 222 223 /* --------------------------------------------------------------------------*/ 224 /*E 225 ISColoringType - determines if the coloring is for the entire parallel grid/graph/matrix 226 or for just the local ghosted portion 227 228 Level: beginner 229 230 $ IS_COLORING_GLOBAL - does not include the colors for ghost points, this is used when the function 231 $ is called synchronously in parallel. This requires generating a "parallel coloring". 232 $ IS_COLORING_GHOSTED - includes colors for ghost points, this is used when the function can be called 233 $ seperately on individual processes with the ghost points already filled in. Does not 234 $ require a "parallel coloring", rather each process colors its local + ghost part. 235 $ Using this can result in much less parallel communication. In the paradigm of 236 $ DMGetLocalVector() and DMGetGlobalVector() this could be called IS_COLORING_LOCAL 237 238 .seealso: DMGetColoring() 239 E*/ 240 typedef enum {IS_COLORING_GLOBAL,IS_COLORING_GHOSTED} ISColoringType; 241 extern const char *ISColoringTypes[]; 242 typedef unsigned PETSC_IS_COLOR_VALUE_TYPE ISColoringValue; 243 extern PetscErrorCode ISAllGatherColors(MPI_Comm,PetscInt,ISColoringValue*,PetscInt*,ISColoringValue*[]); 244 245 /*S 246 ISColoring - sets of IS's that define a coloring 247 of the underlying indices 248 249 Level: intermediate 250 251 Notes: 252 One should not access the *is records below directly because they may not yet 253 have been created. One should use ISColoringGetIS() to make sure they are 254 created when needed. 255 256 .seealso: ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS() 257 S*/ 258 struct _n_ISColoring { 259 PetscInt refct; 260 PetscInt n; /* number of colors */ 261 IS *is; /* for each color indicates columns */ 262 MPI_Comm comm; 263 ISColoringValue *colors; /* for each column indicates color */ 264 PetscInt N; /* number of columns */ 265 ISColoringType ctype; 266 }; 267 typedef struct _n_ISColoring* ISColoring; 268 269 extern PetscErrorCode ISColoringCreate(MPI_Comm,PetscInt,PetscInt,const ISColoringValue[],ISColoring*); 270 extern PetscErrorCode ISColoringDestroy(ISColoring); 271 extern PetscErrorCode ISColoringView(ISColoring,PetscViewer); 272 extern PetscErrorCode ISColoringGetIS(ISColoring,PetscInt*,IS*[]); 273 extern PetscErrorCode ISColoringRestoreIS(ISColoring,IS*[]); 274 #define ISColoringReference(coloring) ((coloring)->refct++,0) 275 #define ISColoringSetType(coloring,type) ((coloring)->ctype = type,0) 276 277 /* --------------------------------------------------------------------------*/ 278 279 extern PetscErrorCode ISPartitioningToNumbering(IS,IS*); 280 extern PetscErrorCode ISPartitioningCount(IS,PetscInt,PetscInt[]); 281 282 extern PetscErrorCode ISCompressIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]); 283 extern PetscErrorCode ISCompressIndicesSorted(PetscInt,PetscInt,PetscInt,const IS[],IS[]); 284 extern PetscErrorCode ISExpandIndicesGeneral(PetscInt,PetscInt,PetscInt,const IS[],IS[]); 285 286 287 PETSC_EXTERN_CXX_END 288 #endif 289