1 /* $Id: petscis.h,v 1.56 2000/08/01 20:58:40 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 typedef struct _p_IS* IS; 14 15 /* 16 Default index set data structures that PETSc provides. 17 */ 18 typedef enum {IS_GENERAL=0,IS_STRIDE=1,IS_BLOCK = 2} ISType; 19 EXTERN int ISCreateGeneral(MPI_Comm,int,const int[],IS *); 20 EXTERN int ISCreateBlock(MPI_Comm,int,int,const int[],IS *); 21 EXTERN int ISCreateStride(MPI_Comm,int,int,int,IS *); 22 23 EXTERN int ISDestroy(IS); 24 25 EXTERN int ISSetPermutation(IS); 26 EXTERN int ISPermutation(IS,PetscTruth*); 27 EXTERN int ISSetIdentity(IS); 28 EXTERN int ISIdentity(IS,PetscTruth*); 29 30 EXTERN int ISGetIndices(IS,int *[]); 31 EXTERN int ISRestoreIndices(IS,int *[]); 32 EXTERN int ISGetSize(IS,int *); 33 EXTERN int ISGetLocalSize(IS,int *); 34 EXTERN int ISInvertPermutation(IS,int,IS*); 35 EXTERN int ISView(IS,Viewer); 36 EXTERN int ISEqual(IS,IS,PetscTruth *); 37 EXTERN int ISSort(IS); 38 EXTERN int ISSorted(IS,PetscTruth *); 39 EXTERN int ISDifference(IS,IS,IS*); 40 EXTERN int ISSum(IS,IS,IS*); 41 42 EXTERN int ISBlock(IS,PetscTruth*); 43 EXTERN int ISBlockGetIndices(IS,int *[]); 44 EXTERN int ISBlockRestoreIndices(IS,int *[]); 45 EXTERN int ISBlockGetSize(IS,int *); 46 EXTERN int ISBlockGetBlockSize(IS,int *); 47 48 EXTERN int ISStride(IS,PetscTruth*); 49 EXTERN int ISStrideGetInfo(IS,int *,int*); 50 51 EXTERN int ISStrideToGeneral(IS); 52 53 EXTERN int ISDuplicate(IS,IS*); 54 EXTERN int ISAllGather(IS,IS*); 55 56 /* --------------------------------------------------------------------------*/ 57 58 /* 59 ISLocalToGlobalMappings are mappings from an arbitrary 60 local ordering from 0 to n-1 to a global PETSc ordering 61 used by a vector or matrix. 62 63 Note: mapping from Local to Global is scalable; but Global 64 to Local may not be if the range of global values represented locally 65 is very large. 66 67 Note: the ISLocalToGlobalMapping is actually a private object; it is included 68 here for the MACRO ISLocalToGlobalMappingApply() to allow it to be inlined since 69 it is used so often. 70 */ 71 #define IS_LTOGM_COOKIE PETSC_COOKIE+12 72 73 struct _p_ISLocalToGlobalMapping{ 74 PETSCHEADER(int) 75 int n; /* number of local indices */ 76 int *indices; /* global index of each local index */ 77 int globalstart; /* first global referenced in indices */ 78 int globalend; /* last + 1 global referenced in indices */ 79 int *globals; /* local index for each global index between start and end */ 80 }; 81 typedef struct _p_ISLocalToGlobalMapping* ISLocalToGlobalMapping; 82 typedef enum {IS_GTOLM_MASK,IS_GTOLM_DROP} ISGlobalToLocalMappingType; 83 84 EXTERN int ISLocalToGlobalMappingCreate(MPI_Comm,int,const int[],ISLocalToGlobalMapping*); 85 EXTERN int ISLocalToGlobalMappingCreateIS(IS,ISLocalToGlobalMapping *); 86 EXTERN int ISLocalToGlobalMappingView(ISLocalToGlobalMapping,Viewer); 87 EXTERN int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping); 88 EXTERN int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping,IS,IS*); 89 EXTERN int ISGlobalToLocalMappingApply(ISLocalToGlobalMapping,ISGlobalToLocalMappingType,int,const int[],int*,int[]); 90 EXTERN int ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping,int*); 91 EXTERN int ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,int*,int**,int**,int***); 92 EXTERN int ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping,int*,int**,int**,int***); 93 94 #define ISLocalToGlobalMappingApply(mapping,N,in,out) 0;\ 95 {\ 96 int _i,*_idx = (mapping)->indices,_Nmax = (mapping)->n;\ 97 for (_i=0; _i<N; _i++) {\ 98 if ((in)[_i] < 0) {(out)[_i] = (in)[_i]; continue;}\ 99 if ((in)[_i] >= _Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %d too large %d (max) at %d",(in)[_i],_Nmax,_i);\ 100 (out)[_i] = _idx[(in)[_i]];\ 101 }\ 102 } 103 104 /* --------------------------------------------------------------------------*/ 105 106 /* 107 ISColorings are sets of IS's that define a coloring 108 of the underlying indices 109 */ 110 struct _p_ISColoring { 111 int n; 112 IS *is; 113 MPI_Comm comm; 114 }; 115 typedef struct _p_ISColoring* ISColoring; 116 117 EXTERN int ISColoringCreate(MPI_Comm,int,const int[],ISColoring*); 118 EXTERN int ISColoringDestroy(ISColoring); 119 EXTERN int ISColoringView(ISColoring,Viewer); 120 EXTERN int ISColoringGetIS(ISColoring,int*,IS*[]); 121 EXTERN int ISColoringRestoreIS(ISColoring,IS*[]); 122 123 /* --------------------------------------------------------------------------*/ 124 125 EXTERN int ISPartitioningToNumbering(IS,IS*); 126 EXTERN int ISPartitioningCount(IS,int[]); 127 128 #endif 129 130 131 132 133