xref: /petsc/src/vec/is/utils/isltog.c (revision 029af93f72d387caa45cf6909ac9aed2d04296ca)
1 #ifndef lint
2 static char vcid[] = "$Id: isltog.c,v 1.7 1997/02/22 02:22:18 bsmith Exp bsmith $";
3 #endif
4 
5 #include "sys.h"   /*I "sys.h" I*/
6 #include "is.h"    /*I "is.h"  I*/
7 
8 #undef __FUNC__
9 #define __FUNC__ "ISLocalToGlobalMappingCreate" /* ADIC Ignore */
10 /*@
11     ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n)
12       ordering and a global parallel ordering.
13 
14    Input Parameters:
15 .    n - the number of local elements
16 .    indices - the global index for each local element
17 
18    Output Parameters:
19 .    mapping - new mapping data structure
20 
21 .keywords: IS, local-to-global mapping
22 
23 .seealso: ISLocalToGlobalMappingDestroy(),
24 @*/
25 int ISLocalToGlobalMappingCreate(int n, int *indices,ISLocalToGlobalMapping *mapping)
26 {
27   PetscValidIntPointer(indices);
28   PetscValidPointer(mapping);
29 
30   *mapping = PetscNew(struct _ISLocalToGlobalMapping); CHKPTRQ(*mapping);
31   (*mapping)->refcnt  = 1;
32   (*mapping)->indices = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ((*mapping)->indices);
33   PetscMemcpy((*mapping)->indices,indices,n*sizeof(int));
34   return 0;
35 }
36 
37 #undef __FUNC__
38 #define __FUNC__ "ISLocalToGlobalMappingDestroy" /* ADIC Ignore */
39 /*@
40     ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n)
41       ordering and a global parallel ordering.
42 
43    Input Parameters:
44 .    mapping - mapping data structure
45 
46 .keywords: IS, local-to-global mapping
47 
48 .seealso: ISLocalToGlobalMappingCreate(),
49 @*/
50 int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping)
51 {
52   PetscValidPointer(mapping);
53   if (--mapping->refcnt) return 0;
54 
55   PetscFree(mapping->indices);
56   PetscFree(mapping);
57   return 0;
58 }
59 
60 #undef __FUNC__
61 #define __FUNC__ "ISLocalToGlobalMappingApplyIS" /* ADIC Ignore */
62 /*@
63     ISLocalToGlobalMappingApplyIS - Creates a new IS using the global numbering
64       defined in an ISLocalToGlobalMapping from an IS in the local numbering.
65 
66    Input Parameters:
67 .   ISLocalToGlobalMapping - mapping between local and global numbering
68 .   is - index set in local numbering
69 
70    Output Parameters:
71 .   newis - index set in global numbering
72 
73 .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(),
74           ISLocalToGlobalMappingDestroy()
75 
76 @*/
77 int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping, IS is, IS *newis)
78 {
79   int ierr,n,i,*idxin,*idxmap,*idxout;
80   PetscValidPointer(mapping);
81   PetscValidHeaderSpecific(is,IS_COOKIE);
82   PetscValidPointer(newis);
83 
84   ierr   = ISGetSize(is,&n); CHKERRQ(ierr);
85   ierr   = ISGetIndices(is,&idxin); CHKERRQ(ierr);
86   idxmap = mapping->indices;
87 
88   idxout = (int *) PetscMalloc((n+1)*sizeof(int));CHKPTRQ(idxout);
89   for ( i=0; i<n; i++ ) {
90     idxout[i] = idxmap[idxin[i]];
91   }
92   ierr = ISCreateGeneral(PETSC_COMM_SELF,n,idxout,newis); CHKERRQ(ierr);
93   PetscFree(idxout);
94   return 0;
95 }
96 
97 #undef __FUNC__
98 #define __FUNC__ "ISLocalToGlobalMappingApply" /* ADIC Ignore */
99 /*MC
100        ISLocalToGlobalMappingApply - Takes a list of integers in local numbering
101               and converts them to global numbering.
102 
103    Synopsis:
104    void ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,int N,int *in,int *out);
105 
106    Input Parameters:
107 .  mapping - the local to global mapping context
108 .  N - number of integers
109 .  in - input indices in local numbering
110 
111    Output Parameter:
112 .  out - indices in global numbering
113 
114 
115 
116 .seealso: ISLocalToGlobalMappingCreate(),ISLocalToGlobalMappingDestroy(),
117           ISLocalToGlobalMappingApplyIS(),AOCreateDebug(),AOApplicationToPetsc(),
118           AOPetscToApplication()
119 
120 .keywords: local-to-global, mapping
121 M*/
122 
123