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