xref: /petsc/src/vec/is/utils/isltog.c (revision 90f02eec332fcca4c33b4e7b21cabed76bf0614e)
12362add9SBarry Smith #ifndef lint
2*90f02eecSBarry Smith static char vcid[] = "$Id: isltog.c,v 1.1 1996/11/17 23:48:28 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 
8*90f02eecSBarry Smith /*@
9*90f02eecSBarry Smith     ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n)
10*90f02eecSBarry Smith       ordering and a global parallel ordering.
112362add9SBarry Smith 
122362add9SBarry Smith    Input Parameters:
13*90f02eecSBarry Smith .    n - the number of local elements
14*90f02eecSBarry Smith .    indices - the global index for each local element
152362add9SBarry Smith 
162362add9SBarry Smith    Output Parameters:
17*90f02eecSBarry Smith .    mapping - new mapping data structure
182362add9SBarry Smith 
19*90f02eecSBarry Smith .keywords: IS, local to global mapping
202362add9SBarry Smith 
21*90f02eecSBarry Smith .seealso: ISLocalToGlobalMappingDestroy(),
222362add9SBarry Smith @*/
23*90f02eecSBarry Smith int ISLocalToGlobalMappingCreate(int n, int *indices,ISLocalToGlobalMapping *mapping)
242362add9SBarry Smith {
25*90f02eecSBarry Smith   PetscValidIntPointer(indices);
26*90f02eecSBarry Smith   PetscValidPointer(mapping);
272362add9SBarry Smith 
28*90f02eecSBarry Smith   *mapping = PetscNew(struct _ISLocalToGlobalMapping); CHKPTRQ(*mapping);
29*90f02eecSBarry Smith   (*mapping)->refcnt  = 1;
30*90f02eecSBarry Smith   (*mapping)->indices = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ((*mapping)->indices);
31*90f02eecSBarry Smith   PetscMemcpy((*mapping)->indices,indices,n*sizeof(int));
322362add9SBarry Smith   return 0;
332362add9SBarry Smith }
342362add9SBarry Smith 
35*90f02eecSBarry Smith /*@
36*90f02eecSBarry Smith     ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n)
37*90f02eecSBarry Smith       ordering and a global parallel ordering.
38*90f02eecSBarry Smith 
39*90f02eecSBarry Smith    Input Parameters:
40*90f02eecSBarry Smith .    mapping - mapping data structure
41*90f02eecSBarry Smith 
42*90f02eecSBarry Smith .keywords: IS, local to global mapping
43*90f02eecSBarry Smith 
44*90f02eecSBarry Smith .seealso: ISLocalToGlobalMappingCreate(),
45*90f02eecSBarry Smith @*/
46*90f02eecSBarry Smith int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping)
47*90f02eecSBarry Smith {
48*90f02eecSBarry Smith   PetscValidPointer(mapping);
49*90f02eecSBarry Smith   if (--mapping->refcnt) return 0;
50*90f02eecSBarry Smith 
51*90f02eecSBarry Smith   PetscFree(mapping->indices);
52*90f02eecSBarry Smith   PetscFree(mapping);
53*90f02eecSBarry Smith   return 0;
54*90f02eecSBarry Smith }
55*90f02eecSBarry Smith 
56*90f02eecSBarry Smith /*@
57*90f02eecSBarry Smith     ISLocalToGlobalMappingApplyIS - Creates a new IS using the global numbering
58*90f02eecSBarry Smith       defined in an ISLocalToGlobalMapping from an IS in the local numbering.
59*90f02eecSBarry Smith 
60*90f02eecSBarry Smith    Input Parameters:
61*90f02eecSBarry Smith .   ISLocalToGlobalMapping - mapping between local and global numbering
62*90f02eecSBarry Smith .   is - index set in local numbering
63*90f02eecSBarry Smith 
64*90f02eecSBarry Smith    Output Parameters:
65*90f02eecSBarry Smith .   newis - index set in global numbering
66*90f02eecSBarry Smith 
67*90f02eecSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(),
68*90f02eecSBarry Smith           ISLocalToGlobalMappingDestroy()
69*90f02eecSBarry Smith 
70*90f02eecSBarry Smith @*/
71*90f02eecSBarry Smith int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping, IS is, IS *newis)
72*90f02eecSBarry Smith {
73*90f02eecSBarry Smith   int ierr,n,i,*idxin,*idxmap,*idxout;
74*90f02eecSBarry Smith   PetscValidPointer(mapping);
75*90f02eecSBarry Smith   PetscValidHeaderSpecific(is,IS_COOKIE);
76*90f02eecSBarry Smith   PetscValidPointer(newis);
77*90f02eecSBarry Smith 
78*90f02eecSBarry Smith   ierr   = ISGetSize(is,&n); CHKERRQ(ierr);
79*90f02eecSBarry Smith   ierr   = ISGetIndices(is,&idxin); CHKERRQ(ierr);
80*90f02eecSBarry Smith   idxmap = mapping->indices;
81*90f02eecSBarry Smith 
82*90f02eecSBarry Smith   idxout = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ(idxout);
83*90f02eecSBarry Smith   for ( i=0; i<n; i++ ) {
84*90f02eecSBarry Smith     idxout[i] = idxmap[idxin[i]];
85*90f02eecSBarry Smith   }
86*90f02eecSBarry Smith   ierr = ISCreateGeneral(MPI_COMM_SELF,n,idxout,newis); CHKERRQ(ierr);
87*90f02eecSBarry Smith   PetscFree(idxout);
88*90f02eecSBarry Smith   return 0;
89*90f02eecSBarry Smith }
90*90f02eecSBarry Smith 
91*90f02eecSBarry Smith 
92*90f02eecSBarry Smith 
93