xref: /petsc/src/vec/is/utils/isltog.c (revision 029af93f72d387caa45cf6909ac9aed2d04296ca)
12362add9SBarry Smith #ifndef lint
2*029af93fSBarry Smith static char vcid[] = "$Id: isltog.c,v 1.7 1997/02/22 02:22:18 bsmith Exp bsmith $";
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 
215e8aa356SBarry Smith .keywords: IS, local-to-global mapping
222362add9SBarry Smith 
2390f02eecSBarry Smith .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 
3090f02eecSBarry Smith   *mapping = PetscNew(struct _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 
465e8aa356SBarry Smith .keywords: IS, local-to-global mapping
4790f02eecSBarry Smith 
4890f02eecSBarry Smith .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 /*@
6390f02eecSBarry Smith     ISLocalToGlobalMappingApplyIS - Creates a new IS using the global numbering
6490f02eecSBarry Smith       defined in an ISLocalToGlobalMapping from an IS in the local numbering.
6590f02eecSBarry Smith 
6690f02eecSBarry Smith    Input Parameters:
6790f02eecSBarry Smith .   ISLocalToGlobalMapping - mapping between local and global numbering
6890f02eecSBarry Smith .   is - index set in local numbering
6990f02eecSBarry Smith 
7090f02eecSBarry Smith    Output Parameters:
7190f02eecSBarry Smith .   newis - index set in global numbering
7290f02eecSBarry Smith 
7390f02eecSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(),
7490f02eecSBarry Smith           ISLocalToGlobalMappingDestroy()
7590f02eecSBarry Smith 
7690f02eecSBarry Smith @*/
7790f02eecSBarry Smith int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping, IS is, IS *newis)
7890f02eecSBarry Smith {
7990f02eecSBarry Smith   int ierr,n,i,*idxin,*idxmap,*idxout;
8090f02eecSBarry Smith   PetscValidPointer(mapping);
8190f02eecSBarry Smith   PetscValidHeaderSpecific(is,IS_COOKIE);
8290f02eecSBarry Smith   PetscValidPointer(newis);
8390f02eecSBarry Smith 
8490f02eecSBarry Smith   ierr   = ISGetSize(is,&n); CHKERRQ(ierr);
8590f02eecSBarry Smith   ierr   = ISGetIndices(is,&idxin); CHKERRQ(ierr);
8690f02eecSBarry Smith   idxmap = mapping->indices;
8790f02eecSBarry Smith 
8890f02eecSBarry Smith   idxout = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ(idxout);
8990f02eecSBarry Smith   for ( i=0; i<n; i++ ) {
9090f02eecSBarry Smith     idxout[i] = idxmap[idxin[i]];
9190f02eecSBarry Smith   }
92*029af93fSBarry Smith   ierr = ISCreateGeneral(PETSC_COMM_SELF,n,idxout,newis); CHKERRQ(ierr);
9390f02eecSBarry Smith   PetscFree(idxout);
9490f02eecSBarry Smith   return 0;
9590f02eecSBarry Smith }
9690f02eecSBarry Smith 
975615d1e5SSatish Balay #undef __FUNC__
985eea60f9SBarry Smith #define __FUNC__ "ISLocalToGlobalMappingApply" /* ADIC Ignore */
99bb25748dSBarry Smith /*MC
100bb25748dSBarry Smith        ISLocalToGlobalMappingApply - Takes a list of integers in local numbering
101bb25748dSBarry Smith               and converts them to global numbering.
10290f02eecSBarry Smith 
103bb25748dSBarry Smith    Synopsis:
104bb25748dSBarry Smith    void ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,int N,int *in,int *out);
105bb25748dSBarry Smith 
106bb25748dSBarry Smith    Input Parameters:
107bb25748dSBarry Smith .  mapping - the local to global mapping context
108bb25748dSBarry Smith .  N - number of integers
109bb25748dSBarry Smith .  in - input indices in local numbering
110bb25748dSBarry Smith 
111bb25748dSBarry Smith    Output Parameter:
112bb25748dSBarry Smith .  out - indices in global numbering
113bb25748dSBarry Smith 
114bb25748dSBarry Smith 
115bb25748dSBarry Smith 
116bb25748dSBarry Smith .seealso: ISLocalToGlobalMappingCreate(),ISLocalToGlobalMappingDestroy(),
117bb25748dSBarry Smith           ISLocalToGlobalMappingApplyIS(),AOCreateDebug(),AOApplicationToPetsc(),
118bb25748dSBarry Smith           AOPetscToApplication()
119bb25748dSBarry Smith 
1205e8aa356SBarry Smith .keywords: local-to-global, mapping
121bb25748dSBarry Smith M*/
12290f02eecSBarry Smith 
123