1 #ifndef lint 2 static char vcid[] = "$Id: isltog.c,v 1.9 1997/04/25 21:56:05 curfman Exp balay $"; 3 #endif 4 5 #include "sys.h" /*I "sys.h" I*/ 6 #include "is.h" /*I "is.h" I*/ 7 8 #undef __FUNC__ 9 #define __FUNC__ "ISLocalToGlobalMappingCreate" /* ADIC Ignore */ 10 /*@ 11 ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n) 12 ordering and a global parallel ordering. 13 14 Input Parameters: 15 . n - the number of local elements 16 . indices - the global index for each local element 17 18 Output Parameters: 19 . mapping - new mapping data structure 20 21 .keywords: IS, local-to-global mapping, create 22 23 .seealso: ISLocalToGlobalMappingDestroy() 24 @*/ 25 int ISLocalToGlobalMappingCreate(int n, int *indices,ISLocalToGlobalMapping *mapping) 26 { 27 PetscValidIntPointer(indices); 28 PetscValidPointer(mapping); 29 30 *mapping = PetscNew(struct _p_ISLocalToGlobalMapping); CHKPTRQ(*mapping); 31 (*mapping)->refcnt = 1; 32 (*mapping)->indices = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ((*mapping)->indices); 33 PetscMemcpy((*mapping)->indices,indices,n*sizeof(int)); 34 return 0; 35 } 36 37 #undef __FUNC__ 38 #define __FUNC__ "ISLocalToGlobalMappingDestroy" /* ADIC Ignore */ 39 /*@ 40 ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n) 41 ordering and a global parallel ordering. 42 43 Input Parameters: 44 . mapping - mapping data structure 45 46 .keywords: IS, local-to-global mapping, destroy 47 48 .seealso: ISLocalToGlobalMappingCreate() 49 @*/ 50 int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping) 51 { 52 PetscValidPointer(mapping); 53 if (--mapping->refcnt) return 0; 54 55 PetscFree(mapping->indices); 56 PetscFree(mapping); 57 return 0; 58 } 59 60 #undef __FUNC__ 61 #define __FUNC__ "ISLocalToGlobalMappingApplyIS" /* ADIC Ignore */ 62 /*@ 63 ISLocalToGlobalMappingApplyIS - Creates from an IS in the local numbering 64 a new index set using the global numbering defined in an ISLocalToGlobalMapping 65 context. 66 67 Input Parameters: 68 . ISLocalToGlobalMapping - mapping between local and global numbering 69 . is - index set in local numbering 70 71 Output Parameters: 72 . newis - index set in global numbering 73 74 .keywords: IS, local-to-global mapping, apply 75 76 .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(), 77 ISLocalToGlobalMappingDestroy() 78 @*/ 79 int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping, IS is, IS *newis) 80 { 81 int ierr,n,i,*idxin,*idxmap,*idxout; 82 PetscValidPointer(mapping); 83 PetscValidHeaderSpecific(is,IS_COOKIE); 84 PetscValidPointer(newis); 85 86 ierr = ISGetSize(is,&n); CHKERRQ(ierr); 87 ierr = ISGetIndices(is,&idxin); CHKERRQ(ierr); 88 idxmap = mapping->indices; 89 90 idxout = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ(idxout); 91 for ( i=0; i<n; i++ ) { 92 idxout[i] = idxmap[idxin[i]]; 93 } 94 ierr = ISCreateGeneral(PETSC_COMM_SELF,n,idxout,newis); CHKERRQ(ierr); 95 PetscFree(idxout); 96 return 0; 97 } 98 99 #undef __FUNC__ 100 #define __FUNC__ "ISLocalToGlobalMappingApply" /* ADIC Ignore */ 101 /*MC 102 ISLocalToGlobalMappingApply - Takes a list of integers in a local numbering 103 and converts them to the global numbering. 104 105 Synopsis: 106 void ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,int N,int *in,int *out); 107 108 Input Parameters: 109 . mapping - the local to global mapping context 110 . N - number of integers 111 . in - input indices in local numbering 112 113 Output Parameter: 114 . out - indices in global numbering 115 116 .seealso: ISLocalToGlobalMappingCreate(),ISLocalToGlobalMappingDestroy(), 117 ISLocalToGlobalMappingApplyIS(),AOCreateDebug(),AOApplicationToPetsc(), 118 AOPetscToApplication() 119 120 .keywords: local-to-global, mapping, apply 121 M*/ 122 123