1*a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*a5eb4965SSatish Balay static char vcid[] = "$Id: isltog.c,v 1.10 1997/05/23 18:39:55 balay Exp balay $"; 32362add9SBarry Smith #endif 42362add9SBarry Smith 52362add9SBarry Smith #include "sys.h" /*I "sys.h" I*/ 62362add9SBarry Smith #include "is.h" /*I "is.h" I*/ 72362add9SBarry Smith 85615d1e5SSatish Balay #undef __FUNC__ 95eea60f9SBarry Smith #define __FUNC__ "ISLocalToGlobalMappingCreate" /* ADIC Ignore */ 1090f02eecSBarry Smith /*@ 1190f02eecSBarry Smith ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n) 1290f02eecSBarry Smith ordering and a global parallel ordering. 132362add9SBarry Smith 142362add9SBarry Smith Input Parameters: 1590f02eecSBarry Smith . n - the number of local elements 1690f02eecSBarry Smith . indices - the global index for each local element 172362add9SBarry Smith 182362add9SBarry Smith Output Parameters: 1990f02eecSBarry Smith . mapping - new mapping data structure 202362add9SBarry Smith 213acfe500SLois Curfman McInnes .keywords: IS, local-to-global mapping, create 222362add9SBarry Smith 233acfe500SLois Curfman McInnes .seealso: ISLocalToGlobalMappingDestroy() 242362add9SBarry Smith @*/ 2590f02eecSBarry Smith int ISLocalToGlobalMappingCreate(int n, int *indices,ISLocalToGlobalMapping *mapping) 262362add9SBarry Smith { 2790f02eecSBarry Smith PetscValidIntPointer(indices); 2890f02eecSBarry Smith PetscValidPointer(mapping); 292362add9SBarry Smith 30f09e8eb9SSatish Balay *mapping = PetscNew(struct _p_ISLocalToGlobalMapping); CHKPTRQ(*mapping); 3190f02eecSBarry Smith (*mapping)->refcnt = 1; 3290f02eecSBarry Smith (*mapping)->indices = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ((*mapping)->indices); 3390f02eecSBarry Smith PetscMemcpy((*mapping)->indices,indices,n*sizeof(int)); 342362add9SBarry Smith return 0; 352362add9SBarry Smith } 362362add9SBarry Smith 375615d1e5SSatish Balay #undef __FUNC__ 385eea60f9SBarry Smith #define __FUNC__ "ISLocalToGlobalMappingDestroy" /* ADIC Ignore */ 3990f02eecSBarry Smith /*@ 4090f02eecSBarry Smith ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n) 4190f02eecSBarry Smith ordering and a global parallel ordering. 4290f02eecSBarry Smith 4390f02eecSBarry Smith Input Parameters: 4490f02eecSBarry Smith . mapping - mapping data structure 4590f02eecSBarry Smith 463acfe500SLois Curfman McInnes .keywords: IS, local-to-global mapping, destroy 4790f02eecSBarry Smith 483acfe500SLois Curfman McInnes .seealso: ISLocalToGlobalMappingCreate() 4990f02eecSBarry Smith @*/ 5090f02eecSBarry Smith int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping) 5190f02eecSBarry Smith { 5290f02eecSBarry Smith PetscValidPointer(mapping); 5390f02eecSBarry Smith if (--mapping->refcnt) return 0; 5490f02eecSBarry Smith 5590f02eecSBarry Smith PetscFree(mapping->indices); 5690f02eecSBarry Smith PetscFree(mapping); 5790f02eecSBarry Smith return 0; 5890f02eecSBarry Smith } 5990f02eecSBarry Smith 605615d1e5SSatish Balay #undef __FUNC__ 615eea60f9SBarry Smith #define __FUNC__ "ISLocalToGlobalMappingApplyIS" /* ADIC Ignore */ 6290f02eecSBarry Smith /*@ 633acfe500SLois Curfman McInnes ISLocalToGlobalMappingApplyIS - Creates from an IS in the local numbering 643acfe500SLois Curfman McInnes a new index set using the global numbering defined in an ISLocalToGlobalMapping 653acfe500SLois Curfman McInnes context. 6690f02eecSBarry Smith 6790f02eecSBarry Smith Input Parameters: 6890f02eecSBarry Smith . ISLocalToGlobalMapping - mapping between local and global numbering 6990f02eecSBarry Smith . is - index set in local numbering 7090f02eecSBarry Smith 7190f02eecSBarry Smith Output Parameters: 7290f02eecSBarry Smith . newis - index set in global numbering 7390f02eecSBarry Smith 743acfe500SLois Curfman McInnes .keywords: IS, local-to-global mapping, apply 753acfe500SLois Curfman McInnes 7690f02eecSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(), 7790f02eecSBarry Smith ISLocalToGlobalMappingDestroy() 7890f02eecSBarry Smith @*/ 7990f02eecSBarry Smith int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping, IS is, IS *newis) 8090f02eecSBarry Smith { 8190f02eecSBarry Smith int ierr,n,i,*idxin,*idxmap,*idxout; 8290f02eecSBarry Smith PetscValidPointer(mapping); 8390f02eecSBarry Smith PetscValidHeaderSpecific(is,IS_COOKIE); 8490f02eecSBarry Smith PetscValidPointer(newis); 8590f02eecSBarry Smith 8690f02eecSBarry Smith ierr = ISGetSize(is,&n); CHKERRQ(ierr); 8790f02eecSBarry Smith ierr = ISGetIndices(is,&idxin); CHKERRQ(ierr); 8890f02eecSBarry Smith idxmap = mapping->indices; 8990f02eecSBarry Smith 9090f02eecSBarry Smith idxout = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ(idxout); 9190f02eecSBarry Smith for ( i=0; i<n; i++ ) { 9290f02eecSBarry Smith idxout[i] = idxmap[idxin[i]]; 9390f02eecSBarry Smith } 94029af93fSBarry Smith ierr = ISCreateGeneral(PETSC_COMM_SELF,n,idxout,newis); CHKERRQ(ierr); 9590f02eecSBarry Smith PetscFree(idxout); 9690f02eecSBarry Smith return 0; 9790f02eecSBarry Smith } 9890f02eecSBarry Smith 995615d1e5SSatish Balay #undef __FUNC__ 1005eea60f9SBarry Smith #define __FUNC__ "ISLocalToGlobalMappingApply" /* ADIC Ignore */ 101bb25748dSBarry Smith /*MC 1023acfe500SLois Curfman McInnes ISLocalToGlobalMappingApply - Takes a list of integers in a local numbering 1033acfe500SLois Curfman McInnes and converts them to the global numbering. 10490f02eecSBarry Smith 105bb25748dSBarry Smith Synopsis: 106bb25748dSBarry Smith void ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,int N,int *in,int *out); 107bb25748dSBarry Smith 108bb25748dSBarry Smith Input Parameters: 109bb25748dSBarry Smith . mapping - the local to global mapping context 110bb25748dSBarry Smith . N - number of integers 111bb25748dSBarry Smith . in - input indices in local numbering 112bb25748dSBarry Smith 113bb25748dSBarry Smith Output Parameter: 114bb25748dSBarry Smith . out - indices in global numbering 115bb25748dSBarry Smith 116bb25748dSBarry Smith .seealso: ISLocalToGlobalMappingCreate(),ISLocalToGlobalMappingDestroy(), 117bb25748dSBarry Smith ISLocalToGlobalMappingApplyIS(),AOCreateDebug(),AOApplicationToPetsc(), 118bb25748dSBarry Smith AOPetscToApplication() 119bb25748dSBarry Smith 1203acfe500SLois Curfman McInnes .keywords: local-to-global, mapping, apply 121bb25748dSBarry Smith M*/ 12290f02eecSBarry Smith 123