1 /* $Id: petscis.h,v 1.59 2001/01/17 19:43:59 bsmith Exp bsmith $ */ 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 #define IS_COOKIE PETSC_COOKIE+2 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 65 /* --------------------------------------------------------------------------*/ 66 #define IS_LTOGM_COOKIE PETSC_COOKIE+12 67 68 /*S 69 ISLocalToGlobalMappings - mappings from an arbitrary 70 local ordering from 0 to n-1 to a global PETSc ordering 71 used by a vector or matrix. 72 73 Level: intermediate 74 75 Note: mapping from Local to Global is scalable; but Global 76 to Local may not be if the range of global values represented locally 77 is very large. 78 79 Note: the ISLocalToGlobalMapping is actually a private object; it is included 80 here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since 81 it is used so often. 82 83 .seealso: ISLocalToGlobalMappingCreate() 84 S*/ 85 struct _p_ISLocalToGlobalMapping{ 86 PETSCHEADER(int) 87 int n; /* number of local indices */ 88 int *indices; /* global index of each local index */ 89 int globalstart; /* first global referenced in indices */ 90 int globalend; /* last + 1 global referenced in indices */ 91 int *globals; /* local index for each global index between start and end */ 92 }; 93 typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping; 94 95 /*E 96 ISGlobalToLocalMappingType - Indicates if missing global indices are 97 98 IS_GTOLM_MASK - missing global indices are replaced with -1 99 IS_GTOLM_DROP - missing global indices are dropped 100 101 Level: beginner 102 103 .seealso: ISGlobalToLocalMappingApply() 104 105 E*/ 106 typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType; 107 108 EXTERN int ISLocalToGlobalMappingCreate(MPI_Comm,int,const int[],ISLocalToGlobalMapping*); 109 EXTERN int ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *); 110 EXTERN int ISLocalToGlobalMappingView(ISLocalToGlobalMapping,PetscViewer); 111 EXTERN int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping); 112 EXTERN int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*); 113 EXTERN int ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,int,const int[],int*,int[]); 114 EXTERN int ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,int*); 115 EXTERN int ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,int*,int**,int**,int***); 116 EXTERN int ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,int*,int**,int**,int***); 117 EXTERN int ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping,int,ISLocalToGlobalMapping*); 118 119 #define ISLocalToGlobalMappingApply(mapping,N,in,out) 0;\ 120 {\ 121 int _i,*_idx = (mapping)->indices,_Nmax = (mapping)->n;\ 122 for (_i=0; _i<N; _i++) {\ 123 if ((in)[_i] < 0) {(out)[_i] = (in)[_i]; continue;}\ 124 if ((in)[_i] >= _Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %d too large %d (max) at %d",(in)[_i],_Nmax,_i);\ 125 (out)[_i] = _idx[(in)[_i]];\ 126 }\ 127 } 128 129 /* --------------------------------------------------------------------------*/ 130 /*S 131 ISColorings - sets of IS's that define a coloring 132 of the underlying indices 133 134 Level: intermediate 135 136 Notes: 137 One should not access the is records below because they may not yet 138 have been created. One should use ISColoringGetIS() to make sure they are 139 created when needed. 140 141 .seealso: ISColoringCreate(), ISColoringGetIS(), ISColoringView(), ISColoringGetIS() 142 S*/ 143 struct _p_ISColoring { 144 int n; /* number of colors */ 145 IS *is; /* for each color indicates columns */ 146 MPI_Comm comm; 147 int *colors; /* for each column indicates color */ 148 int N; /* number of columns */ 149 }; 150 typedef struct _p_ISColoring* ISColoring; 151 152 EXTERN int ISColoringCreate(MPI_Comm,int,const int[],ISColoring*); 153 EXTERN int ISColoringDestroy(ISColoring); 154 EXTERN int ISColoringView(ISColoring,PetscViewer); 155 EXTERN int ISColoringGetIS(ISColoring,int*,IS*[]); 156 EXTERN int ISColoringRestoreIS(ISColoring,IS*[]); 157 158 /* --------------------------------------------------------------------------*/ 159 160 EXTERN int ISPartitioningToNumbering(IS,IS*); 161 EXTERN int ISPartitioningCount(IS,int[]); 162 163 #endif 164 165 166 167 168