xref: /petsc/src/vec/is/utils/isltog.c (revision bb25748d72370f0bce37b5d69203c6ad5a9041b2)
12362add9SBarry Smith #ifndef lint
2*bb25748dSBarry Smith static char vcid[] = "$Id: isltog.c,v 1.2 1996/11/19 16:29:21 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 
890f02eecSBarry Smith /*@
990f02eecSBarry Smith     ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n)
1090f02eecSBarry Smith       ordering and a global parallel ordering.
112362add9SBarry Smith 
122362add9SBarry Smith    Input Parameters:
1390f02eecSBarry Smith .    n - the number of local elements
1490f02eecSBarry Smith .    indices - the global index for each local element
152362add9SBarry Smith 
162362add9SBarry Smith    Output Parameters:
1790f02eecSBarry Smith .    mapping - new mapping data structure
182362add9SBarry Smith 
1990f02eecSBarry Smith .keywords: IS, local to global mapping
202362add9SBarry Smith 
2190f02eecSBarry Smith .seealso: ISLocalToGlobalMappingDestroy(),
222362add9SBarry Smith @*/
2390f02eecSBarry Smith int ISLocalToGlobalMappingCreate(int n, int *indices,ISLocalToGlobalMapping *mapping)
242362add9SBarry Smith {
2590f02eecSBarry Smith   PetscValidIntPointer(indices);
2690f02eecSBarry Smith   PetscValidPointer(mapping);
272362add9SBarry Smith 
2890f02eecSBarry Smith   *mapping = PetscNew(struct _ISLocalToGlobalMapping); CHKPTRQ(*mapping);
2990f02eecSBarry Smith   (*mapping)->refcnt  = 1;
3090f02eecSBarry Smith   (*mapping)->indices = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ((*mapping)->indices);
3190f02eecSBarry Smith   PetscMemcpy((*mapping)->indices,indices,n*sizeof(int));
322362add9SBarry Smith   return 0;
332362add9SBarry Smith }
342362add9SBarry Smith 
3590f02eecSBarry Smith /*@
3690f02eecSBarry Smith     ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n)
3790f02eecSBarry Smith       ordering and a global parallel ordering.
3890f02eecSBarry Smith 
3990f02eecSBarry Smith    Input Parameters:
4090f02eecSBarry Smith .    mapping - mapping data structure
4190f02eecSBarry Smith 
4290f02eecSBarry Smith .keywords: IS, local to global mapping
4390f02eecSBarry Smith 
4490f02eecSBarry Smith .seealso: ISLocalToGlobalMappingCreate(),
4590f02eecSBarry Smith @*/
4690f02eecSBarry Smith int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping)
4790f02eecSBarry Smith {
4890f02eecSBarry Smith   PetscValidPointer(mapping);
4990f02eecSBarry Smith   if (--mapping->refcnt) return 0;
5090f02eecSBarry Smith 
5190f02eecSBarry Smith   PetscFree(mapping->indices);
5290f02eecSBarry Smith   PetscFree(mapping);
5390f02eecSBarry Smith   return 0;
5490f02eecSBarry Smith }
5590f02eecSBarry Smith 
5690f02eecSBarry Smith /*@
5790f02eecSBarry Smith     ISLocalToGlobalMappingApplyIS - Creates a new IS using the global numbering
5890f02eecSBarry Smith       defined in an ISLocalToGlobalMapping from an IS in the local numbering.
5990f02eecSBarry Smith 
6090f02eecSBarry Smith    Input Parameters:
6190f02eecSBarry Smith .   ISLocalToGlobalMapping - mapping between local and global numbering
6290f02eecSBarry Smith .   is - index set in local numbering
6390f02eecSBarry Smith 
6490f02eecSBarry Smith    Output Parameters:
6590f02eecSBarry Smith .   newis - index set in global numbering
6690f02eecSBarry Smith 
6790f02eecSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(),
6890f02eecSBarry Smith           ISLocalToGlobalMappingDestroy()
6990f02eecSBarry Smith 
7090f02eecSBarry Smith @*/
7190f02eecSBarry Smith int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping, IS is, IS *newis)
7290f02eecSBarry Smith {
7390f02eecSBarry Smith   int ierr,n,i,*idxin,*idxmap,*idxout;
7490f02eecSBarry Smith   PetscValidPointer(mapping);
7590f02eecSBarry Smith   PetscValidHeaderSpecific(is,IS_COOKIE);
7690f02eecSBarry Smith   PetscValidPointer(newis);
7790f02eecSBarry Smith 
7890f02eecSBarry Smith   ierr   = ISGetSize(is,&n); CHKERRQ(ierr);
7990f02eecSBarry Smith   ierr   = ISGetIndices(is,&idxin); CHKERRQ(ierr);
8090f02eecSBarry Smith   idxmap = mapping->indices;
8190f02eecSBarry Smith 
8290f02eecSBarry Smith   idxout = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ(idxout);
8390f02eecSBarry Smith   for ( i=0; i<n; i++ ) {
8490f02eecSBarry Smith     idxout[i] = idxmap[idxin[i]];
8590f02eecSBarry Smith   }
8690f02eecSBarry Smith   ierr = ISCreateGeneral(MPI_COMM_SELF,n,idxout,newis); CHKERRQ(ierr);
8790f02eecSBarry Smith   PetscFree(idxout);
8890f02eecSBarry Smith   return 0;
8990f02eecSBarry Smith }
9090f02eecSBarry Smith 
91*bb25748dSBarry Smith /*MC
92*bb25748dSBarry Smith        ISLocalToGlobalMappingApply - Takes a list of integers in local numbering
93*bb25748dSBarry Smith               and converts them to global numbering.
9490f02eecSBarry Smith 
95*bb25748dSBarry Smith    Synopsis:
96*bb25748dSBarry Smith    void ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,int N,int *in,int *out);
97*bb25748dSBarry Smith 
98*bb25748dSBarry Smith    Input Parameters:
99*bb25748dSBarry Smith .  mapping - the local to global mapping context
100*bb25748dSBarry Smith .  N - number of integers
101*bb25748dSBarry Smith .  in - input indices in local numbering
102*bb25748dSBarry Smith 
103*bb25748dSBarry Smith    Output Parameter:
104*bb25748dSBarry Smith .  out - indices in global numbering
105*bb25748dSBarry Smith 
106*bb25748dSBarry Smith 
107*bb25748dSBarry Smith 
108*bb25748dSBarry Smith .seealso: ISLocalToGlobalMappingCreate(),ISLocalToGlobalMappingDestroy(),
109*bb25748dSBarry Smith           ISLocalToGlobalMappingApplyIS(),AOCreateDebug(),AOApplicationToPetsc(),
110*bb25748dSBarry Smith           AOPetscToApplication()
111*bb25748dSBarry Smith 
112*bb25748dSBarry Smith .keywords: local to global, mapping
113*bb25748dSBarry Smith M*/
11490f02eecSBarry Smith 
115