1 #ifndef lint 2 static char vcid[] = "$Id: isltog.c,v 1.1 1996/11/17 23:48:28 bsmith Exp bsmith $"; 3 #endif 4 5 #include "sys.h" /*I "sys.h" I*/ 6 #include "is.h" /*I "is.h" I*/ 7 8 /*@ 9 ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n) 10 ordering and a global parallel ordering. 11 12 Input Parameters: 13 . n - the number of local elements 14 . indices - the global index for each local element 15 16 Output Parameters: 17 . mapping - new mapping data structure 18 19 .keywords: IS, local to global mapping 20 21 .seealso: ISLocalToGlobalMappingDestroy(), 22 @*/ 23 int ISLocalToGlobalMappingCreate(int n, int *indices,ISLocalToGlobalMapping *mapping) 24 { 25 PetscValidIntPointer(indices); 26 PetscValidPointer(mapping); 27 28 *mapping = PetscNew(struct _ISLocalToGlobalMapping); CHKPTRQ(*mapping); 29 (*mapping)->refcnt = 1; 30 (*mapping)->indices = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ((*mapping)->indices); 31 PetscMemcpy((*mapping)->indices,indices,n*sizeof(int)); 32 return 0; 33 } 34 35 /*@ 36 ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n) 37 ordering and a global parallel ordering. 38 39 Input Parameters: 40 . mapping - mapping data structure 41 42 .keywords: IS, local to global mapping 43 44 .seealso: ISLocalToGlobalMappingCreate(), 45 @*/ 46 int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping) 47 { 48 PetscValidPointer(mapping); 49 if (--mapping->refcnt) return 0; 50 51 PetscFree(mapping->indices); 52 PetscFree(mapping); 53 return 0; 54 } 55 56 /*@ 57 ISLocalToGlobalMappingApplyIS - Creates a new IS using the global numbering 58 defined in an ISLocalToGlobalMapping from an IS in the local numbering. 59 60 Input Parameters: 61 . ISLocalToGlobalMapping - mapping between local and global numbering 62 . is - index set in local numbering 63 64 Output Parameters: 65 . newis - index set in global numbering 66 67 .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(), 68 ISLocalToGlobalMappingDestroy() 69 70 @*/ 71 int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping, IS is, IS *newis) 72 { 73 int ierr,n,i,*idxin,*idxmap,*idxout; 74 PetscValidPointer(mapping); 75 PetscValidHeaderSpecific(is,IS_COOKIE); 76 PetscValidPointer(newis); 77 78 ierr = ISGetSize(is,&n); CHKERRQ(ierr); 79 ierr = ISGetIndices(is,&idxin); CHKERRQ(ierr); 80 idxmap = mapping->indices; 81 82 idxout = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ(idxout); 83 for ( i=0; i<n; i++ ) { 84 idxout[i] = idxmap[idxin[i]]; 85 } 86 ierr = ISCreateGeneral(MPI_COMM_SELF,n,idxout,newis); CHKERRQ(ierr); 87 PetscFree(idxout); 88 return 0; 89 } 90 91 92 93