xref: /petsc/src/vec/is/utils/isltog.c (revision 2b6de112da0fc1f51a6da7a7bb5eef438765bf99)
10c735eedSKris Buschelman #define PETSCVEC_DLL
22362add9SBarry Smith 
3e1fa1e0fSSatish Balay #include "petscvec.h"   /*I "petscsys.h" I*/
412d94eddSLisandro Dalcin #include "include/private/isimpl.h"    /*I "petscis.h"  I*/
52362add9SBarry Smith 
6ad48de64SLisandro Dalcin PetscCookie PETSCVEC_DLLEXPORT IS_LTOGM_COOKIE = 0;
78e58c17dSMatthew Knepley 
84a2ae208SSatish Balay #undef __FUNCT__
94a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingGetSize"
103b9aefa3SBarry Smith /*@C
113b9aefa3SBarry Smith     ISLocalToGlobalMappingGetSize - Gets the local size of a local to global mapping.
123b9aefa3SBarry Smith 
133b9aefa3SBarry Smith     Not Collective
143b9aefa3SBarry Smith 
153b9aefa3SBarry Smith     Input Parameter:
163b9aefa3SBarry Smith .   ltog - local to global mapping
173b9aefa3SBarry Smith 
183b9aefa3SBarry Smith     Output Parameter:
193b9aefa3SBarry Smith .   n - the number of entries in the local mapping
203b9aefa3SBarry Smith 
213b9aefa3SBarry Smith     Level: advanced
223b9aefa3SBarry Smith 
23273d9f13SBarry Smith     Concepts: mapping^local to global
243b9aefa3SBarry Smith 
253b9aefa3SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate()
263b9aefa3SBarry Smith @*/
270c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingGetSize(ISLocalToGlobalMapping mapping,PetscInt *n)
283b9aefa3SBarry Smith {
293b9aefa3SBarry Smith   PetscFunctionBegin;
304482741eSBarry Smith   PetscValidHeaderSpecific(mapping,IS_LTOGM_COOKIE,1);
314482741eSBarry Smith   PetscValidIntPointer(n,2);
323b9aefa3SBarry Smith   *n = mapping->n;
333b9aefa3SBarry Smith   PetscFunctionReturn(0);
343b9aefa3SBarry Smith }
353b9aefa3SBarry Smith 
364a2ae208SSatish Balay #undef __FUNCT__
374a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingView"
385a5d4f66SBarry Smith /*@C
395a5d4f66SBarry Smith     ISLocalToGlobalMappingView - View a local to global mapping
405a5d4f66SBarry Smith 
41b9cd556bSLois Curfman McInnes     Not Collective
42b9cd556bSLois Curfman McInnes 
435a5d4f66SBarry Smith     Input Parameters:
443b9aefa3SBarry Smith +   ltog - local to global mapping
453b9aefa3SBarry Smith -   viewer - viewer
465a5d4f66SBarry Smith 
47a997ad1aSLois Curfman McInnes     Level: advanced
48a997ad1aSLois Curfman McInnes 
49273d9f13SBarry Smith     Concepts: mapping^local to global
505a5d4f66SBarry Smith 
515a5d4f66SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate()
525a5d4f66SBarry Smith @*/
530c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingView(ISLocalToGlobalMapping mapping,PetscViewer viewer)
545a5d4f66SBarry Smith {
5532dcc486SBarry Smith   PetscInt        i;
5632dcc486SBarry Smith   PetscMPIInt     rank;
5732077d6dSBarry Smith   PetscTruth      iascii;
586849ba73SBarry Smith   PetscErrorCode  ierr;
595a5d4f66SBarry Smith 
605a5d4f66SBarry Smith   PetscFunctionBegin;
614482741eSBarry Smith   PetscValidHeaderSpecific(mapping,IS_LTOGM_COOKIE,1);
623050cee2SBarry Smith   if (!viewer) {
637adad957SLisandro Dalcin     ierr = PetscViewerASCIIGetStdout(((PetscObject)mapping)->comm,&viewer);CHKERRQ(ierr);
643050cee2SBarry Smith   }
654482741eSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2);
665a5d4f66SBarry Smith 
677adad957SLisandro Dalcin   ierr = MPI_Comm_rank(((PetscObject)mapping)->comm,&rank);CHKERRQ(ierr);
6832077d6dSBarry Smith   ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr);
6932077d6dSBarry Smith   if (iascii) {
705a5d4f66SBarry Smith     for (i=0; i<mapping->n; i++) {
71b0a32e0cSBarry Smith       ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] %d %d\n",rank,i,mapping->indices[i]);CHKERRQ(ierr);
726831982aSBarry Smith     }
73b0a32e0cSBarry Smith     ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
746831982aSBarry Smith   } else {
75958c9bccSBarry Smith     SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported for ISLocalToGlobalMapping",((PetscObject)viewer)->type_name);
765a5d4f66SBarry Smith   }
775a5d4f66SBarry Smith 
785a5d4f66SBarry Smith   PetscFunctionReturn(0);
795a5d4f66SBarry Smith }
805a5d4f66SBarry Smith 
814a2ae208SSatish Balay #undef __FUNCT__
824a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingCreateIS"
831f428162SBarry Smith /*@
842bdab257SBarry Smith     ISLocalToGlobalMappingCreateIS - Creates a mapping between a local (0 to n)
852bdab257SBarry Smith     ordering and a global parallel ordering.
862bdab257SBarry Smith 
870f5bd95cSBarry Smith     Not collective
88b9cd556bSLois Curfman McInnes 
89a997ad1aSLois Curfman McInnes     Input Parameter:
902bdab257SBarry Smith .   is - index set containing the global numbers for each local
912bdab257SBarry Smith 
92a997ad1aSLois Curfman McInnes     Output Parameter:
932bdab257SBarry Smith .   mapping - new mapping data structure
942bdab257SBarry Smith 
95a997ad1aSLois Curfman McInnes     Level: advanced
96a997ad1aSLois Curfman McInnes 
97273d9f13SBarry Smith     Concepts: mapping^local to global
982bdab257SBarry Smith 
992bdab257SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate()
1002bdab257SBarry Smith @*/
1010c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreateIS(IS is,ISLocalToGlobalMapping *mapping)
1022bdab257SBarry Smith {
1036849ba73SBarry Smith   PetscErrorCode ierr;
10432dcc486SBarry Smith   PetscInt       n,*indices;
1052bdab257SBarry Smith   MPI_Comm       comm;
1063a40ed3dSBarry Smith 
1073a40ed3dSBarry Smith   PetscFunctionBegin;
1084482741eSBarry Smith   PetscValidHeaderSpecific(is,IS_COOKIE,1);
1094482741eSBarry Smith   PetscValidPointer(mapping,2);
1102bdab257SBarry Smith 
1112bdab257SBarry Smith   ierr = PetscObjectGetComm((PetscObject)is,&comm);CHKERRQ(ierr);
1123b9aefa3SBarry Smith   ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
1132bdab257SBarry Smith   ierr = ISGetIndices(is,&indices);CHKERRQ(ierr);
1142bdab257SBarry Smith   ierr = ISLocalToGlobalMappingCreate(comm,n,indices,mapping);CHKERRQ(ierr);
1152bdab257SBarry Smith   ierr = ISRestoreIndices(is,&indices);CHKERRQ(ierr);
1162bdab257SBarry Smith 
1173a40ed3dSBarry Smith   PetscFunctionReturn(0);
1182bdab257SBarry Smith }
1195a5d4f66SBarry Smith 
120b46b645bSBarry Smith 
1214a2ae208SSatish Balay #undef __FUNCT__
1224a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingCreate"
123ba5bb76aSSatish Balay /*@
12490f02eecSBarry Smith     ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n)
12590f02eecSBarry Smith     ordering and a global parallel ordering.
1262362add9SBarry Smith 
12789d82c54SBarry Smith     Not Collective, but communicator may have more than one process
128b9cd556bSLois Curfman McInnes 
1292362add9SBarry Smith     Input Parameters:
13089d82c54SBarry Smith +   comm - MPI communicator
13190f02eecSBarry Smith .   n - the number of local elements
132b9cd556bSLois Curfman McInnes -   indices - the global index for each local element
1332362add9SBarry Smith 
134a997ad1aSLois Curfman McInnes     Output Parameter:
13590f02eecSBarry Smith .   mapping - new mapping data structure
1362362add9SBarry Smith 
137a997ad1aSLois Curfman McInnes     Level: advanced
138a997ad1aSLois Curfman McInnes 
139273d9f13SBarry Smith     Concepts: mapping^local to global
1402362add9SBarry Smith 
141b46b645bSBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreateIS(), ISLocalToGlobalMappingCreateNC()
1422362add9SBarry Smith @*/
1430c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreate(MPI_Comm cm,PetscInt n,const PetscInt indices[],ISLocalToGlobalMapping *mapping)
1442362add9SBarry Smith {
1456849ba73SBarry Smith   PetscErrorCode ierr;
14632dcc486SBarry Smith   PetscInt       *in;
147b46b645bSBarry Smith 
148b46b645bSBarry Smith   PetscFunctionBegin;
14973911063SBarry Smith   if (n) PetscValidIntPointer(indices,3);
1504482741eSBarry Smith   PetscValidPointer(mapping,4);
1517c334f02SBarry Smith   ierr = PetscMalloc(n*sizeof(PetscInt),&in);CHKERRQ(ierr);
15232dcc486SBarry Smith   ierr = PetscMemcpy(in,indices,n*sizeof(PetscInt));CHKERRQ(ierr);
153b46b645bSBarry Smith   ierr = ISLocalToGlobalMappingCreateNC(cm,n,in,mapping);CHKERRQ(ierr);
154b46b645bSBarry Smith   PetscFunctionReturn(0);
155b46b645bSBarry Smith }
156b46b645bSBarry Smith 
157b46b645bSBarry Smith #undef __FUNCT__
158b46b645bSBarry Smith #define __FUNCT__ "ISLocalToGlobalMappingCreateNC"
159b46b645bSBarry Smith /*@C
160b46b645bSBarry Smith     ISLocalToGlobalMappingCreateNC - Creates a mapping between a local (0 to n)
161b46b645bSBarry Smith     ordering and a global parallel ordering.
162b46b645bSBarry Smith 
163b46b645bSBarry Smith     Not Collective, but communicator may have more than one process
164b46b645bSBarry Smith 
165b46b645bSBarry Smith     Input Parameters:
166b46b645bSBarry Smith +   comm - MPI communicator
167b46b645bSBarry Smith .   n - the number of local elements
168b46b645bSBarry Smith -   indices - the global index for each local element
169b46b645bSBarry Smith 
170b46b645bSBarry Smith     Output Parameter:
171b46b645bSBarry Smith .   mapping - new mapping data structure
172b46b645bSBarry Smith 
173b46b645bSBarry Smith     Level: developer
174b46b645bSBarry Smith 
175b46b645bSBarry Smith     Notes: Does not copy the indices, just keeps the pointer to the indices. The ISLocalToGlobalMappingDestroy()
176b46b645bSBarry Smith     will free the space so it must be obtained with PetscMalloc() and it must not be freed elsewhere.
177b46b645bSBarry Smith 
178b46b645bSBarry Smith     Concepts: mapping^local to global
179b46b645bSBarry Smith 
180b46b645bSBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreateIS(), ISLocalToGlobalMappingCreate()
181b46b645bSBarry Smith @*/
1820c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingCreateNC(MPI_Comm cm,PetscInt n,const PetscInt indices[],ISLocalToGlobalMapping *mapping)
183b46b645bSBarry Smith {
184dfbe8321SBarry Smith   PetscErrorCode ierr;
18523f7533aSBarry Smith 
1863a40ed3dSBarry Smith   PetscFunctionBegin;
187ad48de64SLisandro Dalcin   if (n) PetscValidIntPointer(indices,3);
1884482741eSBarry Smith   PetscValidPointer(mapping,4);
1898e58c17dSMatthew Knepley   *mapping = PETSC_NULL;
1908e58c17dSMatthew Knepley #ifndef PETSC_USE_DYNAMIC_LIBRARIES
191*2b6de112SBarry Smith   ierr = ISInitializePackage(PETSC_NULL);CHKERRQ(ierr);
1928e58c17dSMatthew Knepley #endif
1932362add9SBarry Smith 
19452e6d16bSBarry Smith   ierr = PetscHeaderCreate(*mapping,_p_ISLocalToGlobalMapping,int,IS_LTOGM_COOKIE,0,"ISLocalToGlobalMapping",
19552e6d16bSBarry Smith 			   cm,ISLocalToGlobalMappingDestroy,ISLocalToGlobalMappingView);CHKERRQ(ierr);
196d4bb536fSBarry Smith 
197d4bb536fSBarry Smith   (*mapping)->n       = n;
19832dcc486SBarry Smith   (*mapping)->indices = (PetscInt*)indices;
19938f2d2fdSLisandro Dalcin   ierr = PetscLogObjectMemory(*mapping,n*sizeof(PetscInt));CHKERRQ(ierr);
200d4bb536fSBarry Smith 
201d4bb536fSBarry Smith   /*
202d4bb536fSBarry Smith     Do not create the global to local mapping. This is only created if
203d4bb536fSBarry Smith     ISGlobalToLocalMapping() is called
204d4bb536fSBarry Smith   */
205d4bb536fSBarry Smith   (*mapping)->globals = 0;
2063a40ed3dSBarry Smith   PetscFunctionReturn(0);
2072362add9SBarry Smith }
2082362add9SBarry Smith 
2094a2ae208SSatish Balay #undef __FUNCT__
2104a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingBlock"
211bce096a4SSatish Balay /*@
212323b833fSBarry Smith     ISLocalToGlobalMappingBlock - Creates a blocked index version of an
213323b833fSBarry Smith        ISLocalToGlobalMapping that is appropriate for MatSetLocalToGlobalMappingBlock()
214323b833fSBarry Smith        and VecSetLocalToGlobalMappingBlock().
215323b833fSBarry Smith 
216323b833fSBarry Smith     Not Collective, but communicator may have more than one process
217323b833fSBarry Smith 
218323b833fSBarry Smith     Input Parameters:
219323b833fSBarry Smith +    inmap - original point-wise mapping
220323b833fSBarry Smith -    bs - block size
221323b833fSBarry Smith 
222323b833fSBarry Smith     Output Parameter:
22369eb54c3SBarry Smith .   outmap - block based mapping; the indices are relative to BLOCKS, not individual vector or matrix entries.
224323b833fSBarry Smith 
225323b833fSBarry Smith     Level: advanced
226323b833fSBarry Smith 
227323b833fSBarry Smith     Concepts: mapping^local to global
228323b833fSBarry Smith 
229323b833fSBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate(), ISLocalToGlobalMappingCreateIS()
230323b833fSBarry Smith @*/
2310c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingBlock(ISLocalToGlobalMapping inmap,PetscInt bs,ISLocalToGlobalMapping *outmap)
232323b833fSBarry Smith {
2336849ba73SBarry Smith   PetscErrorCode ierr;
23432dcc486SBarry Smith   PetscInt       *ii,i,n;
235323b833fSBarry Smith 
236323b833fSBarry Smith   PetscFunctionBegin;
237ad48de64SLisandro Dalcin   PetscValidHeaderSpecific(inmap,IS_LTOGM_COOKIE,1);
238ad48de64SLisandro Dalcin   PetscValidPointer(outmap,1);
239323b833fSBarry Smith   if (bs > 1) {
240323b833fSBarry Smith     n    = inmap->n/bs;
24112ce3465SBarry Smith     if (n*bs != inmap->n) SETERRQ(PETSC_ERR_ARG_INCOMP,"Pointwise mapping length is not divisible by block size");
24232dcc486SBarry Smith     ierr = PetscMalloc(n*sizeof(PetscInt),&ii);CHKERRQ(ierr);
243323b833fSBarry Smith     for (i=0; i<n; i++) {
244db032c9dSBarry Smith       ii[i] = inmap->indices[bs*i]/bs;
245323b833fSBarry Smith     }
2467adad957SLisandro Dalcin     ierr = ISLocalToGlobalMappingCreate(((PetscObject)inmap)->comm,n,ii,outmap);CHKERRQ(ierr);
247323b833fSBarry Smith     ierr = PetscFree(ii);CHKERRQ(ierr);
248323b833fSBarry Smith   } else {
249323b833fSBarry Smith     ierr    = PetscObjectReference((PetscObject)inmap);CHKERRQ(ierr);
250c3122656SLisandro Dalcin     *outmap = inmap;
251323b833fSBarry Smith   }
252323b833fSBarry Smith   PetscFunctionReturn(0);
253323b833fSBarry Smith }
254323b833fSBarry Smith 
2554a2ae208SSatish Balay #undef __FUNCT__
2564a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingDestroy"
25790f02eecSBarry Smith /*@
25890f02eecSBarry Smith    ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n)
25990f02eecSBarry Smith    ordering and a global parallel ordering.
26090f02eecSBarry Smith 
2610f5bd95cSBarry Smith    Note Collective
262b9cd556bSLois Curfman McInnes 
26390f02eecSBarry Smith    Input Parameters:
26490f02eecSBarry Smith .  mapping - mapping data structure
26590f02eecSBarry Smith 
266a997ad1aSLois Curfman McInnes    Level: advanced
267a997ad1aSLois Curfman McInnes 
2683acfe500SLois Curfman McInnes .seealso: ISLocalToGlobalMappingCreate()
26990f02eecSBarry Smith @*/
2700c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping)
27190f02eecSBarry Smith {
272dfbe8321SBarry Smith   PetscErrorCode ierr;
2733a40ed3dSBarry Smith   PetscFunctionBegin;
274ad48de64SLisandro Dalcin   PetscValidHeaderSpecific(mapping,IS_LTOGM_COOKIE,1);
2757adad957SLisandro Dalcin   if (--((PetscObject)mapping)->refct > 0) PetscFunctionReturn(0);
276606d414cSSatish Balay   ierr = PetscFree(mapping->indices);CHKERRQ(ierr);
27705b42c5fSBarry Smith   ierr = PetscFree(mapping->globals);CHKERRQ(ierr);
278d38fa0fbSBarry Smith   ierr = PetscHeaderDestroy(mapping);CHKERRQ(ierr);
2793a40ed3dSBarry Smith   PetscFunctionReturn(0);
28090f02eecSBarry Smith }
28190f02eecSBarry Smith 
2824a2ae208SSatish Balay #undef __FUNCT__
2834a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingApplyIS"
28490f02eecSBarry Smith /*@
2853acfe500SLois Curfman McInnes     ISLocalToGlobalMappingApplyIS - Creates from an IS in the local numbering
2863acfe500SLois Curfman McInnes     a new index set using the global numbering defined in an ISLocalToGlobalMapping
2873acfe500SLois Curfman McInnes     context.
28890f02eecSBarry Smith 
289b9cd556bSLois Curfman McInnes     Not collective
290b9cd556bSLois Curfman McInnes 
29190f02eecSBarry Smith     Input Parameters:
292b9cd556bSLois Curfman McInnes +   mapping - mapping between local and global numbering
293b9cd556bSLois Curfman McInnes -   is - index set in local numbering
29490f02eecSBarry Smith 
29590f02eecSBarry Smith     Output Parameters:
29690f02eecSBarry Smith .   newis - index set in global numbering
29790f02eecSBarry Smith 
298a997ad1aSLois Curfman McInnes     Level: advanced
299a997ad1aSLois Curfman McInnes 
300273d9f13SBarry Smith     Concepts: mapping^local to global
3013acfe500SLois Curfman McInnes 
30290f02eecSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(),
303d4bb536fSBarry Smith           ISLocalToGlobalMappingDestroy(), ISGlobalToLocalMappingApply()
30490f02eecSBarry Smith @*/
3050c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping,IS is,IS *newis)
30690f02eecSBarry Smith {
3076849ba73SBarry Smith   PetscErrorCode ierr;
30832dcc486SBarry Smith   PetscInt       n,i,*idxin,*idxmap,*idxout,Nmax = mapping->n;
3093a40ed3dSBarry Smith 
3103a40ed3dSBarry Smith   PetscFunctionBegin;
311ad48de64SLisandro Dalcin   PetscValidHeaderSpecific(mapping,IS_LTOGM_COOKIE,1);
3124482741eSBarry Smith   PetscValidHeaderSpecific(is,IS_COOKIE,2);
3134482741eSBarry Smith   PetscValidPointer(newis,3);
31490f02eecSBarry Smith 
3153b9aefa3SBarry Smith   ierr   = ISGetLocalSize(is,&n);CHKERRQ(ierr);
31690f02eecSBarry Smith   ierr   = ISGetIndices(is,&idxin);CHKERRQ(ierr);
31790f02eecSBarry Smith   idxmap = mapping->indices;
31890f02eecSBarry Smith 
3197c334f02SBarry Smith   ierr = PetscMalloc(n*sizeof(PetscInt),&idxout);CHKERRQ(ierr);
32090f02eecSBarry Smith   for (i=0; i<n; i++) {
321590ac198SBarry Smith     if (idxin[i] >= Nmax) SETERRQ3(PETSC_ERR_ARG_OUTOFRANGE,"Local index %d too large %d (max) at %d",idxin[i],Nmax-1,i);
32290f02eecSBarry Smith     idxout[i] = idxmap[idxin[i]];
32390f02eecSBarry Smith   }
3243b9aefa3SBarry Smith   ierr = ISRestoreIndices(is,&idxin);CHKERRQ(ierr);
325f7a1537bSLisandro Dalcin   ierr = ISCreateGeneralNC(PETSC_COMM_SELF,n,idxout,newis);CHKERRQ(ierr);
3263a40ed3dSBarry Smith   PetscFunctionReturn(0);
32790f02eecSBarry Smith }
32890f02eecSBarry Smith 
32989d82c54SBarry Smith /*MC
3303acfe500SLois Curfman McInnes    ISLocalToGlobalMappingApply - Takes a list of integers in a local numbering
3313acfe500SLois Curfman McInnes    and converts them to the global numbering.
33290f02eecSBarry Smith 
333b9cd556bSLois Curfman McInnes    Not collective
334b9cd556bSLois Curfman McInnes 
335bb25748dSBarry Smith    Input Parameters:
336b9cd556bSLois Curfman McInnes +  mapping - the local to global mapping context
337bb25748dSBarry Smith .  N - number of integers
338b9cd556bSLois Curfman McInnes -  in - input indices in local numbering
339bb25748dSBarry Smith 
340bb25748dSBarry Smith    Output Parameter:
341bb25748dSBarry Smith .  out - indices in global numbering
342bb25748dSBarry Smith 
3433b9aefa3SBarry Smith    Synopsis:
344d360dc6fSBarry Smith    PetscErrorCode ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,int N,int in[],int out[])
3453b9aefa3SBarry Smith 
346b9cd556bSLois Curfman McInnes    Notes:
347b9cd556bSLois Curfman McInnes    The in and out array parameters may be identical.
348d4bb536fSBarry Smith 
349a997ad1aSLois Curfman McInnes    Level: advanced
350a997ad1aSLois Curfman McInnes 
351bb25748dSBarry Smith .seealso: ISLocalToGlobalMappingCreate(),ISLocalToGlobalMappingDestroy(),
3520752156aSBarry Smith           ISLocalToGlobalMappingApplyIS(),AOCreateBasic(),AOApplicationToPetsc(),
353d4bb536fSBarry Smith           AOPetscToApplication(), ISGlobalToLocalMappingApply()
354bb25748dSBarry Smith 
355273d9f13SBarry Smith     Concepts: mapping^local to global
356d4bb536fSBarry Smith 
35789d82c54SBarry Smith M*/
358d4bb536fSBarry Smith 
359d4bb536fSBarry Smith /* -----------------------------------------------------------------------------------------*/
360d4bb536fSBarry Smith 
3614a2ae208SSatish Balay #undef __FUNCT__
3624a2ae208SSatish Balay #define __FUNCT__ "ISGlobalToLocalMappingSetUp_Private"
363d4bb536fSBarry Smith /*
364d4bb536fSBarry Smith     Creates the global fields in the ISLocalToGlobalMapping structure
365d4bb536fSBarry Smith */
3666849ba73SBarry Smith static PetscErrorCode ISGlobalToLocalMappingSetUp_Private(ISLocalToGlobalMapping mapping)
367d4bb536fSBarry Smith {
3686849ba73SBarry Smith   PetscErrorCode ierr;
36932dcc486SBarry Smith   PetscInt       i,*idx = mapping->indices,n = mapping->n,end,start,*globals;
370d4bb536fSBarry Smith 
3713a40ed3dSBarry Smith   PetscFunctionBegin;
372d4bb536fSBarry Smith   end   = 0;
373d4bb536fSBarry Smith   start = 100000000;
374d4bb536fSBarry Smith 
375d4bb536fSBarry Smith   for (i=0; i<n; i++) {
376d4bb536fSBarry Smith     if (idx[i] < 0) continue;
377d4bb536fSBarry Smith     if (idx[i] < start) start = idx[i];
378d4bb536fSBarry Smith     if (idx[i] > end)   end   = idx[i];
379d4bb536fSBarry Smith   }
380d4bb536fSBarry Smith   if (start > end) {start = 0; end = -1;}
381d4bb536fSBarry Smith   mapping->globalstart = start;
382d4bb536fSBarry Smith   mapping->globalend   = end;
383d4bb536fSBarry Smith 
38432dcc486SBarry Smith   ierr             = PetscMalloc((end-start+2)*sizeof(PetscInt),&globals);CHKERRQ(ierr);
385b0a32e0cSBarry Smith   mapping->globals = globals;
386d4bb536fSBarry Smith   for (i=0; i<end-start+1; i++) {
387d4bb536fSBarry Smith     globals[i] = -1;
388d4bb536fSBarry Smith   }
389d4bb536fSBarry Smith   for (i=0; i<n; i++) {
390d4bb536fSBarry Smith     if (idx[i] < 0) continue;
391d4bb536fSBarry Smith     globals[idx[i] - start] = i;
392d4bb536fSBarry Smith   }
393d4bb536fSBarry Smith 
39452e6d16bSBarry Smith   ierr = PetscLogObjectMemory(mapping,(end-start+1)*sizeof(PetscInt));CHKERRQ(ierr);
3953a40ed3dSBarry Smith   PetscFunctionReturn(0);
396d4bb536fSBarry Smith }
397d4bb536fSBarry Smith 
3984a2ae208SSatish Balay #undef __FUNCT__
3994a2ae208SSatish Balay #define __FUNCT__ "ISGlobalToLocalMappingApply"
400d4bb536fSBarry Smith /*@
401a997ad1aSLois Curfman McInnes     ISGlobalToLocalMappingApply - Provides the local numbering for a list of integers
402a997ad1aSLois Curfman McInnes     specified with a global numbering.
403d4bb536fSBarry Smith 
404b9cd556bSLois Curfman McInnes     Not collective
405b9cd556bSLois Curfman McInnes 
406d4bb536fSBarry Smith     Input Parameters:
407b9cd556bSLois Curfman McInnes +   mapping - mapping between local and global numbering
408d4bb536fSBarry Smith .   type - IS_GTOLM_MASK - replaces global indices with no local value with -1
409d4bb536fSBarry Smith            IS_GTOLM_DROP - drops the indices with no local value from the output list
410d4bb536fSBarry Smith .   n - number of global indices to map
411b9cd556bSLois Curfman McInnes -   idx - global indices to map
412d4bb536fSBarry Smith 
413d4bb536fSBarry Smith     Output Parameters:
414b9cd556bSLois Curfman McInnes +   nout - number of indices in output array (if type == IS_GTOLM_MASK then nout = n)
415b9cd556bSLois Curfman McInnes -   idxout - local index of each global index, one must pass in an array long enough
416e182c471SBarry Smith              to hold all the indices. You can call ISGlobalToLocalMappingApply() with
417e182c471SBarry Smith              idxout == PETSC_NULL to determine the required length (returned in nout)
418e182c471SBarry Smith              and then allocate the required space and call ISGlobalToLocalMappingApply()
419e182c471SBarry Smith              a second time to set the values.
420d4bb536fSBarry Smith 
421b9cd556bSLois Curfman McInnes     Notes:
422b9cd556bSLois Curfman McInnes     Either nout or idxout may be PETSC_NULL. idx and idxout may be identical.
423d4bb536fSBarry Smith 
4240f5bd95cSBarry Smith     This is not scalable in memory usage. Each processor requires O(Nglobal) size
4250f5bd95cSBarry Smith     array to compute these.
4260f5bd95cSBarry Smith 
427a997ad1aSLois Curfman McInnes     Level: advanced
428a997ad1aSLois Curfman McInnes 
429273d9f13SBarry Smith     Concepts: mapping^global to local
430d4bb536fSBarry Smith 
431d4bb536fSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(),
432d4bb536fSBarry Smith           ISLocalToGlobalMappingDestroy()
433d4bb536fSBarry Smith @*/
4340c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISGlobalToLocalMappingApply(ISLocalToGlobalMapping mapping,ISGlobalToLocalMappingType type,
43532dcc486SBarry Smith                                   PetscInt n,const PetscInt idx[],PetscInt *nout,PetscInt idxout[])
436d4bb536fSBarry Smith {
43732dcc486SBarry Smith   PetscInt       i,*globals,nf = 0,tmp,start,end;
4386849ba73SBarry Smith   PetscErrorCode ierr;
439d4bb536fSBarry Smith 
4403a40ed3dSBarry Smith   PetscFunctionBegin;
441ad48de64SLisandro Dalcin   PetscValidHeaderSpecific(mapping,IS_LTOGM_COOKIE,1);
442d4bb536fSBarry Smith   if (!mapping->globals) {
443d4bb536fSBarry Smith     ierr = ISGlobalToLocalMappingSetUp_Private(mapping);CHKERRQ(ierr);
444d4bb536fSBarry Smith   }
445d4bb536fSBarry Smith   globals = mapping->globals;
446d4bb536fSBarry Smith   start   = mapping->globalstart;
447d4bb536fSBarry Smith   end     = mapping->globalend;
448d4bb536fSBarry Smith 
449d4bb536fSBarry Smith   if (type == IS_GTOLM_MASK) {
450d4bb536fSBarry Smith     if (idxout) {
451d4bb536fSBarry Smith       for (i=0; i<n; i++) {
452d4bb536fSBarry Smith         if (idx[i] < 0) idxout[i] = idx[i];
453d4bb536fSBarry Smith         else if (idx[i] < start) idxout[i] = -1;
454d4bb536fSBarry Smith         else if (idx[i] > end)   idxout[i] = -1;
455d4bb536fSBarry Smith         else                     idxout[i] = globals[idx[i] - start];
456d4bb536fSBarry Smith       }
457d4bb536fSBarry Smith     }
458d4bb536fSBarry Smith     if (nout) *nout = n;
459d4bb536fSBarry Smith   } else {
460d4bb536fSBarry Smith     if (idxout) {
461d4bb536fSBarry Smith       for (i=0; i<n; i++) {
462d4bb536fSBarry Smith         if (idx[i] < 0) continue;
463d4bb536fSBarry Smith         if (idx[i] < start) continue;
464d4bb536fSBarry Smith         if (idx[i] > end) continue;
465d4bb536fSBarry Smith         tmp = globals[idx[i] - start];
466d4bb536fSBarry Smith         if (tmp < 0) continue;
467d4bb536fSBarry Smith         idxout[nf++] = tmp;
468d4bb536fSBarry Smith       }
469d4bb536fSBarry Smith     } else {
470d4bb536fSBarry Smith       for (i=0; i<n; i++) {
471d4bb536fSBarry Smith         if (idx[i] < 0) continue;
472d4bb536fSBarry Smith         if (idx[i] < start) continue;
473d4bb536fSBarry Smith         if (idx[i] > end) continue;
474d4bb536fSBarry Smith         tmp = globals[idx[i] - start];
475d4bb536fSBarry Smith         if (tmp < 0) continue;
476d4bb536fSBarry Smith         nf++;
477d4bb536fSBarry Smith       }
478d4bb536fSBarry Smith     }
479d4bb536fSBarry Smith     if (nout) *nout = nf;
480d4bb536fSBarry Smith   }
481d4bb536fSBarry Smith 
4823a40ed3dSBarry Smith   PetscFunctionReturn(0);
483d4bb536fSBarry Smith }
48490f02eecSBarry Smith 
4854a2ae208SSatish Balay #undef __FUNCT__
4864a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingGetInfo"
48789d82c54SBarry Smith /*@C
48889d82c54SBarry Smith     ISLocalToGlobalMappingGetInfo - Gets the neighbor information for each processor and
48989d82c54SBarry Smith      each index shared by more than one processor
49089d82c54SBarry Smith 
49189d82c54SBarry Smith     Collective on ISLocalToGlobalMapping
49289d82c54SBarry Smith 
49389d82c54SBarry Smith     Input Parameters:
49489d82c54SBarry Smith .   mapping - the mapping from local to global indexing
49589d82c54SBarry Smith 
49689d82c54SBarry Smith     Output Parameter:
49789d82c54SBarry Smith +   nproc - number of processors that are connected to this one
49889d82c54SBarry Smith .   proc - neighboring processors
49907b52d57SBarry Smith .   numproc - number of indices for each subdomain (processor)
50007b52d57SBarry Smith -   indices - indices of local nodes shared with neighbor (sorted by global numbering)
50189d82c54SBarry Smith 
50289d82c54SBarry Smith     Level: advanced
50389d82c54SBarry Smith 
504273d9f13SBarry Smith     Concepts: mapping^local to global
50589d82c54SBarry Smith 
5062cfcea29SBarry Smith     Fortran Usage:
5072cfcea29SBarry Smith $        ISLocalToGlobalMpngGetInfoSize(ISLocalToGlobalMapping,PetscInt nproc,PetscInt numprocmax,ierr) followed by
5082cfcea29SBarry Smith $        ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping,PetscInt nproc, PetscInt procs[nproc],PetscInt numprocs[nproc],
5092cfcea29SBarry Smith           PetscInt indices[nproc][numprocmax],ierr)
5102cfcea29SBarry Smith         There is no ISLocalToGlobalMappingRestoreInfo() in Fortran. You must make sure that procs[], numprocs[] and
5112cfcea29SBarry Smith         indices[][] are large enough arrays, either by allocating them dynamically or defining static ones large enough.
5122cfcea29SBarry Smith 
5132cfcea29SBarry Smith 
51407b52d57SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreateIS(), ISLocalToGlobalMappingCreate(),
51507b52d57SBarry Smith           ISLocalToGlobalMappingRestoreInfo()
51689d82c54SBarry Smith @*/
5170c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingGetInfo(ISLocalToGlobalMapping mapping,PetscInt *nproc,PetscInt *procs[],PetscInt *numprocs[],PetscInt **indices[])
51889d82c54SBarry Smith {
5196849ba73SBarry Smith   PetscErrorCode ierr;
52097f1f81fSBarry Smith   PetscMPIInt    size,rank,tag1,tag2,tag3,*len,*source,imdex;
52132dcc486SBarry Smith   PetscInt       i,n = mapping->n,Ng,ng,max = 0,*lindices = mapping->indices;
52232dcc486SBarry Smith   PetscInt       *nprocs,*owner,nsends,*sends,j,*starts,nmax,nrecvs,*recvs,proc;
52397f1f81fSBarry Smith   PetscInt       cnt,scale,*ownedsenders,*nownedsenders,rstart,nowned;
52432dcc486SBarry Smith   PetscInt       node,nownedm,nt,*sends2,nsends2,*starts2,*lens2,*dest,nrecvs2,*starts3,*recvs2,k,*bprocs,*tmp;
52532dcc486SBarry Smith   PetscInt       first_procs,first_numprocs,*first_indices;
52689d82c54SBarry Smith   MPI_Request    *recv_waits,*send_waits;
52730dcb7c9SBarry Smith   MPI_Status     recv_status,*send_status,*recv_statuses;
5287adad957SLisandro Dalcin   MPI_Comm       comm = ((PetscObject)mapping)->comm;
52907b52d57SBarry Smith   PetscTruth     debug = PETSC_FALSE;
53089d82c54SBarry Smith 
53189d82c54SBarry Smith   PetscFunctionBegin;
532ad48de64SLisandro Dalcin   PetscValidHeaderSpecific(mapping,IS_LTOGM_COOKIE,1);
53324cf384cSBarry Smith   ierr   = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
53424cf384cSBarry Smith   ierr   = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
53524cf384cSBarry Smith   if (size == 1) {
53624cf384cSBarry Smith     *nproc         = 0;
53724cf384cSBarry Smith     *procs         = PETSC_NULL;
53832dcc486SBarry Smith     ierr           = PetscMalloc(sizeof(PetscInt),numprocs);CHKERRQ(ierr);
5391e2105dcSBarry Smith     (*numprocs)[0] = 0;
54032dcc486SBarry Smith     ierr           = PetscMalloc(sizeof(PetscInt*),indices);CHKERRQ(ierr);
5411e2105dcSBarry Smith     (*indices)[0]  = PETSC_NULL;
54224cf384cSBarry Smith     PetscFunctionReturn(0);
54324cf384cSBarry Smith   }
54424cf384cSBarry Smith 
545b0a32e0cSBarry Smith   ierr = PetscOptionsHasName(PETSC_NULL,"-islocaltoglobalmappinggetinfo_debug",&debug);CHKERRQ(ierr);
54607b52d57SBarry Smith 
5473677ff5aSBarry Smith   /*
5483677ff5aSBarry Smith     Notes on ISLocalToGlobalMappingGetInfo
5493677ff5aSBarry Smith 
5503677ff5aSBarry Smith     globally owned node - the nodes that have been assigned to this processor in global
5513677ff5aSBarry Smith            numbering, just for this routine.
5523677ff5aSBarry Smith 
5533677ff5aSBarry Smith     nontrivial globally owned node - node assigned to this processor that is on a subdomain
5543677ff5aSBarry Smith            boundary (i.e. is has more than one local owner)
5553677ff5aSBarry Smith 
5563677ff5aSBarry Smith     locally owned node - node that exists on this processors subdomain
5573677ff5aSBarry Smith 
5583677ff5aSBarry Smith     nontrivial locally owned node - node that is not in the interior (i.e. has more than one
5593677ff5aSBarry Smith            local subdomain
5603677ff5aSBarry Smith   */
56124cf384cSBarry Smith   ierr = PetscObjectGetNewTag((PetscObject)mapping,&tag1);CHKERRQ(ierr);
56224cf384cSBarry Smith   ierr = PetscObjectGetNewTag((PetscObject)mapping,&tag2);CHKERRQ(ierr);
56324cf384cSBarry Smith   ierr = PetscObjectGetNewTag((PetscObject)mapping,&tag3);CHKERRQ(ierr);
56489d82c54SBarry Smith 
56589d82c54SBarry Smith   for (i=0; i<n; i++) {
56689d82c54SBarry Smith     if (lindices[i] > max) max = lindices[i];
56789d82c54SBarry Smith   }
56832dcc486SBarry Smith   ierr   = MPI_Allreduce(&max,&Ng,1,MPIU_INT,MPI_MAX,comm);CHKERRQ(ierr);
56978058e43SBarry Smith   Ng++;
57089d82c54SBarry Smith   ierr   = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
57189d82c54SBarry Smith   ierr   = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
572bc8ff85bSBarry Smith   scale  = Ng/size + 1;
573a2e34c3dSBarry Smith   ng     = scale; if (rank == size-1) ng = Ng - scale*(size-1); ng = PetscMax(1,ng);
574caba0dd0SBarry Smith   rstart = scale*rank;
57589d82c54SBarry Smith 
57689d82c54SBarry Smith   /* determine ownership ranges of global indices */
5777c334f02SBarry Smith   ierr = PetscMalloc(2*size*sizeof(PetscInt),&nprocs);CHKERRQ(ierr);
57832dcc486SBarry Smith   ierr = PetscMemzero(nprocs,2*size*sizeof(PetscInt));CHKERRQ(ierr);
57989d82c54SBarry Smith 
58089d82c54SBarry Smith   /* determine owners of each local node  */
5817c334f02SBarry Smith   ierr = PetscMalloc(n*sizeof(PetscInt),&owner);CHKERRQ(ierr);
58289d82c54SBarry Smith   for (i=0; i<n; i++) {
5833677ff5aSBarry Smith     proc             = lindices[i]/scale; /* processor that globally owns this index */
58427c402fcSBarry Smith     nprocs[2*proc+1] = 1;                 /* processor globally owns at least one of ours */
5853677ff5aSBarry Smith     owner[i]         = proc;
58627c402fcSBarry Smith     nprocs[2*proc]++;                     /* count of how many that processor globally owns of ours */
58789d82c54SBarry Smith   }
58827c402fcSBarry Smith   nsends = 0; for (i=0; i<size; i++) nsends += nprocs[2*i+1];
5891e2582c4SBarry Smith   ierr = PetscInfo1(mapping,"Number of global owners for my local data %d\n",nsends);CHKERRQ(ierr);
59089d82c54SBarry Smith 
59189d82c54SBarry Smith   /* inform other processors of number of messages and max length*/
59227c402fcSBarry Smith   ierr = PetscMaxSum(comm,nprocs,&nmax,&nrecvs);CHKERRQ(ierr);
5931e2582c4SBarry Smith   ierr = PetscInfo1(mapping,"Number of local owners for my global data %d\n",nrecvs);CHKERRQ(ierr);
59489d82c54SBarry Smith 
59589d82c54SBarry Smith   /* post receives for owned rows */
59632dcc486SBarry Smith   ierr = PetscMalloc((2*nrecvs+1)*(nmax+1)*sizeof(PetscInt),&recvs);CHKERRQ(ierr);
597b0a32e0cSBarry Smith   ierr = PetscMalloc((nrecvs+1)*sizeof(MPI_Request),&recv_waits);CHKERRQ(ierr);
59889d82c54SBarry Smith   for (i=0; i<nrecvs; i++) {
59932dcc486SBarry Smith     ierr = MPI_Irecv(recvs+2*nmax*i,2*nmax,MPIU_INT,MPI_ANY_SOURCE,tag1,comm,recv_waits+i);CHKERRQ(ierr);
60089d82c54SBarry Smith   }
60189d82c54SBarry Smith 
60289d82c54SBarry Smith   /* pack messages containing lists of local nodes to owners */
60332dcc486SBarry Smith   ierr       = PetscMalloc((2*n+1)*sizeof(PetscInt),&sends);CHKERRQ(ierr);
60432dcc486SBarry Smith   ierr       = PetscMalloc((size+1)*sizeof(PetscInt),&starts);CHKERRQ(ierr);
60589d82c54SBarry Smith   starts[0]  = 0;
60627c402fcSBarry Smith   for (i=1; i<size; i++) { starts[i] = starts[i-1] + 2*nprocs[2*i-2];}
60789d82c54SBarry Smith   for (i=0; i<n; i++) {
60889d82c54SBarry Smith     sends[starts[owner[i]]++] = lindices[i];
60930dcb7c9SBarry Smith     sends[starts[owner[i]]++] = i;
61089d82c54SBarry Smith   }
61189d82c54SBarry Smith   ierr = PetscFree(owner);CHKERRQ(ierr);
61289d82c54SBarry Smith   starts[0]  = 0;
61327c402fcSBarry Smith   for (i=1; i<size; i++) { starts[i] = starts[i-1] + 2*nprocs[2*i-2];}
61489d82c54SBarry Smith 
61589d82c54SBarry Smith   /* send the messages */
616b0a32e0cSBarry Smith   ierr = PetscMalloc((nsends+1)*sizeof(MPI_Request),&send_waits);CHKERRQ(ierr);
61732dcc486SBarry Smith   ierr = PetscMalloc((nsends+1)*sizeof(PetscInt),&dest);CHKERRQ(ierr);
61889d82c54SBarry Smith   cnt = 0;
61989d82c54SBarry Smith   for (i=0; i<size; i++) {
62027c402fcSBarry Smith     if (nprocs[2*i]) {
62132dcc486SBarry Smith       ierr      = MPI_Isend(sends+starts[i],2*nprocs[2*i],MPIU_INT,i,tag1,comm,send_waits+cnt);CHKERRQ(ierr);
62230dcb7c9SBarry Smith       dest[cnt] = i;
62389d82c54SBarry Smith       cnt++;
62489d82c54SBarry Smith     }
62589d82c54SBarry Smith   }
62689d82c54SBarry Smith   ierr = PetscFree(starts);CHKERRQ(ierr);
62789d82c54SBarry Smith 
62889d82c54SBarry Smith   /* wait on receives */
62997f1f81fSBarry Smith   ierr = PetscMalloc((nrecvs+1)*sizeof(PetscMPIInt),&source);CHKERRQ(ierr);
63097f1f81fSBarry Smith   ierr = PetscMalloc((nrecvs+1)*sizeof(PetscMPIInt),&len);CHKERRQ(ierr);
63189d82c54SBarry Smith   cnt  = nrecvs;
63232dcc486SBarry Smith   ierr = PetscMalloc((ng+1)*sizeof(PetscInt),&nownedsenders);CHKERRQ(ierr);
63332dcc486SBarry Smith   ierr = PetscMemzero(nownedsenders,ng*sizeof(PetscInt));CHKERRQ(ierr);
63489d82c54SBarry Smith   while (cnt) {
63589d82c54SBarry Smith     ierr = MPI_Waitany(nrecvs,recv_waits,&imdex,&recv_status);CHKERRQ(ierr);
63689d82c54SBarry Smith     /* unpack receives into our local space */
63732dcc486SBarry Smith     ierr           = MPI_Get_count(&recv_status,MPIU_INT,&len[imdex]);CHKERRQ(ierr);
63889d82c54SBarry Smith     source[imdex]  = recv_status.MPI_SOURCE;
63930dcb7c9SBarry Smith     len[imdex]     = len[imdex]/2;
640caba0dd0SBarry Smith     /* count how many local owners for each of my global owned indices */
64130dcb7c9SBarry Smith     for (i=0; i<len[imdex]; i++) nownedsenders[recvs[2*imdex*nmax+2*i]-rstart]++;
64289d82c54SBarry Smith     cnt--;
64389d82c54SBarry Smith   }
64489d82c54SBarry Smith   ierr = PetscFree(recv_waits);CHKERRQ(ierr);
64589d82c54SBarry Smith 
64630dcb7c9SBarry Smith   /* count how many globally owned indices are on an edge multiplied by how many processors own them. */
647bc8ff85bSBarry Smith   nowned  = 0;
648bc8ff85bSBarry Smith   nownedm = 0;
649bc8ff85bSBarry Smith   for (i=0; i<ng; i++) {
650bc8ff85bSBarry Smith     if (nownedsenders[i] > 1) {nownedm += nownedsenders[i]; nowned++;}
651bc8ff85bSBarry Smith   }
652bc8ff85bSBarry Smith 
653bc8ff85bSBarry Smith   /* create single array to contain rank of all local owners of each globally owned index */
65432dcc486SBarry Smith   ierr      = PetscMalloc((nownedm+1)*sizeof(PetscInt),&ownedsenders);CHKERRQ(ierr);
65532dcc486SBarry Smith   ierr      = PetscMalloc((ng+1)*sizeof(PetscInt),&starts);CHKERRQ(ierr);
656bc8ff85bSBarry Smith   starts[0] = 0;
657bc8ff85bSBarry Smith   for (i=1; i<ng; i++) {
658bc8ff85bSBarry Smith     if (nownedsenders[i-1] > 1) starts[i] = starts[i-1] + nownedsenders[i-1];
659bc8ff85bSBarry Smith     else starts[i] = starts[i-1];
660bc8ff85bSBarry Smith   }
661bc8ff85bSBarry Smith 
66230dcb7c9SBarry Smith   /* for each nontrival globally owned node list all arriving processors */
663bc8ff85bSBarry Smith   for (i=0; i<nrecvs; i++) {
664bc8ff85bSBarry Smith     for (j=0; j<len[i]; j++) {
66530dcb7c9SBarry Smith       node = recvs[2*i*nmax+2*j]-rstart;
666bc8ff85bSBarry Smith       if (nownedsenders[node] > 1) {
667bc8ff85bSBarry Smith         ownedsenders[starts[node]++] = source[i];
668bc8ff85bSBarry Smith       }
669bc8ff85bSBarry Smith     }
670bc8ff85bSBarry Smith   }
671bc8ff85bSBarry Smith 
67207b52d57SBarry Smith   if (debug) { /* -----------------------------------  */
67330dcb7c9SBarry Smith     starts[0]    = 0;
67430dcb7c9SBarry Smith     for (i=1; i<ng; i++) {
67530dcb7c9SBarry Smith       if (nownedsenders[i-1] > 1) starts[i] = starts[i-1] + nownedsenders[i-1];
67630dcb7c9SBarry Smith       else starts[i] = starts[i-1];
67730dcb7c9SBarry Smith     }
67830dcb7c9SBarry Smith     for (i=0; i<ng; i++) {
67930dcb7c9SBarry Smith       if (nownedsenders[i] > 1) {
68030dcb7c9SBarry Smith         ierr = PetscSynchronizedPrintf(comm,"[%d] global node %d local owner processors: ",rank,i+rstart);CHKERRQ(ierr);
68130dcb7c9SBarry Smith         for (j=0; j<nownedsenders[i]; j++) {
68230dcb7c9SBarry Smith           ierr = PetscSynchronizedPrintf(comm,"%d ",ownedsenders[starts[i]+j]);CHKERRQ(ierr);
68330dcb7c9SBarry Smith         }
68430dcb7c9SBarry Smith         ierr = PetscSynchronizedPrintf(comm,"\n");CHKERRQ(ierr);
68530dcb7c9SBarry Smith       }
68630dcb7c9SBarry Smith     }
68730dcb7c9SBarry Smith     ierr = PetscSynchronizedFlush(comm);CHKERRQ(ierr);
68807b52d57SBarry Smith   }/* -----------------------------------  */
68930dcb7c9SBarry Smith 
6903677ff5aSBarry Smith   /* wait on original sends */
6913a96401aSBarry Smith   if (nsends) {
692b0a32e0cSBarry Smith     ierr = PetscMalloc(nsends*sizeof(MPI_Status),&send_status);CHKERRQ(ierr);
6933a96401aSBarry Smith     ierr = MPI_Waitall(nsends,send_waits,send_status);CHKERRQ(ierr);
6943a96401aSBarry Smith     ierr = PetscFree(send_status);CHKERRQ(ierr);
6953a96401aSBarry Smith   }
69689d82c54SBarry Smith   ierr = PetscFree(send_waits);CHKERRQ(ierr);
6973a96401aSBarry Smith   ierr = PetscFree(sends);CHKERRQ(ierr);
6983677ff5aSBarry Smith   ierr = PetscFree(nprocs);CHKERRQ(ierr);
6993677ff5aSBarry Smith 
7003677ff5aSBarry Smith   /* pack messages to send back to local owners */
70130dcb7c9SBarry Smith   starts[0]    = 0;
70230dcb7c9SBarry Smith   for (i=1; i<ng; i++) {
70330dcb7c9SBarry Smith     if (nownedsenders[i-1] > 1) starts[i] = starts[i-1] + nownedsenders[i-1];
70430dcb7c9SBarry Smith     else starts[i] = starts[i-1];
70530dcb7c9SBarry Smith   }
70630dcb7c9SBarry Smith   nsends2 = nrecvs;
70732dcc486SBarry Smith   ierr    = PetscMalloc((nsends2+1)*sizeof(PetscInt),&nprocs);CHKERRQ(ierr); /* length of each message */
70830dcb7c9SBarry Smith   for (i=0; i<nrecvs; i++) {
70930dcb7c9SBarry Smith     nprocs[i] = 1;
71030dcb7c9SBarry Smith     for (j=0; j<len[i]; j++) {
71130dcb7c9SBarry Smith       node = recvs[2*i*nmax+2*j]-rstart;
71230dcb7c9SBarry Smith       if (nownedsenders[node] > 1) {
71330dcb7c9SBarry Smith         nprocs[i] += 2 + nownedsenders[node];
71430dcb7c9SBarry Smith       }
71530dcb7c9SBarry Smith     }
71630dcb7c9SBarry Smith   }
71730dcb7c9SBarry Smith   nt = 0; for (i=0; i<nsends2; i++) nt += nprocs[i];
71832dcc486SBarry Smith   ierr = PetscMalloc((nt+1)*sizeof(PetscInt),&sends2);CHKERRQ(ierr);
71932dcc486SBarry Smith   ierr = PetscMalloc((nsends2+1)*sizeof(PetscInt),&starts2);CHKERRQ(ierr);
72030dcb7c9SBarry Smith   starts2[0] = 0; for (i=1; i<nsends2; i++) starts2[i] = starts2[i-1] + nprocs[i-1];
72130dcb7c9SBarry Smith   /*
72230dcb7c9SBarry Smith      Each message is 1 + nprocs[i] long, and consists of
72330dcb7c9SBarry Smith        (0) the number of nodes being sent back
72430dcb7c9SBarry Smith        (1) the local node number,
72530dcb7c9SBarry Smith        (2) the number of processors sharing it,
72630dcb7c9SBarry Smith        (3) the processors sharing it
72730dcb7c9SBarry Smith   */
72830dcb7c9SBarry Smith   for (i=0; i<nsends2; i++) {
72930dcb7c9SBarry Smith     cnt = 1;
73030dcb7c9SBarry Smith     sends2[starts2[i]] = 0;
73130dcb7c9SBarry Smith     for (j=0; j<len[i]; j++) {
73230dcb7c9SBarry Smith       node = recvs[2*i*nmax+2*j]-rstart;
73330dcb7c9SBarry Smith       if (nownedsenders[node] > 1) {
73430dcb7c9SBarry Smith         sends2[starts2[i]]++;
73530dcb7c9SBarry Smith         sends2[starts2[i]+cnt++] = recvs[2*i*nmax+2*j+1];
73630dcb7c9SBarry Smith         sends2[starts2[i]+cnt++] = nownedsenders[node];
73732dcc486SBarry Smith         ierr = PetscMemcpy(&sends2[starts2[i]+cnt],&ownedsenders[starts[node]],nownedsenders[node]*sizeof(PetscInt));CHKERRQ(ierr);
73830dcb7c9SBarry Smith         cnt += nownedsenders[node];
73930dcb7c9SBarry Smith       }
74030dcb7c9SBarry Smith     }
74130dcb7c9SBarry Smith   }
74230dcb7c9SBarry Smith 
74330dcb7c9SBarry Smith   /* receive the message lengths */
74430dcb7c9SBarry Smith   nrecvs2 = nsends;
74532dcc486SBarry Smith   ierr = PetscMalloc((nrecvs2+1)*sizeof(PetscInt),&lens2);CHKERRQ(ierr);
74632dcc486SBarry Smith   ierr = PetscMalloc((nrecvs2+1)*sizeof(PetscInt),&starts3);CHKERRQ(ierr);
747d44834fbSBarry Smith   ierr = PetscMalloc((nrecvs2+1)*sizeof(MPI_Request),&recv_waits);CHKERRQ(ierr);
74830dcb7c9SBarry Smith   for (i=0; i<nrecvs2; i++) {
749d44834fbSBarry Smith     ierr = MPI_Irecv(&lens2[i],1,MPIU_INT,dest[i],tag2,comm,recv_waits+i);CHKERRQ(ierr);
75030dcb7c9SBarry Smith   }
751d44834fbSBarry Smith 
7528a8e0b3aSBarry Smith   /* send the message lengths */
7538a8e0b3aSBarry Smith   for (i=0; i<nsends2; i++) {
7548a8e0b3aSBarry Smith     ierr = MPI_Send(&nprocs[i],1,MPIU_INT,source[i],tag2,comm);CHKERRQ(ierr);
7558a8e0b3aSBarry Smith   }
7568a8e0b3aSBarry Smith 
757d44834fbSBarry Smith   /* wait on receives of lens */
7580c468ba9SBarry Smith   if (nrecvs2) {
7590c468ba9SBarry Smith     ierr = PetscMalloc(nrecvs2*sizeof(MPI_Status),&recv_statuses);CHKERRQ(ierr);
760d44834fbSBarry Smith     ierr = MPI_Waitall(nrecvs2,recv_waits,recv_statuses);CHKERRQ(ierr);
761d44834fbSBarry Smith     ierr = PetscFree(recv_statuses);CHKERRQ(ierr);
7620c468ba9SBarry Smith   }
763d44834fbSBarry Smith   ierr = PetscFree(recv_waits);
764d44834fbSBarry Smith 
76530dcb7c9SBarry Smith   starts3[0] = 0;
766d44834fbSBarry Smith   nt         = 0;
76730dcb7c9SBarry Smith   for (i=0; i<nrecvs2-1; i++) {
76830dcb7c9SBarry Smith     starts3[i+1] = starts3[i] + lens2[i];
769d44834fbSBarry Smith     nt          += lens2[i];
77030dcb7c9SBarry Smith   }
771d44834fbSBarry Smith   nt += lens2[nrecvs2-1];
772d44834fbSBarry Smith 
77332dcc486SBarry Smith   ierr = PetscMalloc((nt+1)*sizeof(PetscInt),&recvs2);CHKERRQ(ierr);
774b0a32e0cSBarry Smith   ierr = PetscMalloc((nrecvs2+1)*sizeof(MPI_Request),&recv_waits);CHKERRQ(ierr);
77552b72c4aSBarry Smith   for (i=0; i<nrecvs2; i++) {
77632dcc486SBarry Smith     ierr = MPI_Irecv(recvs2+starts3[i],lens2[i],MPIU_INT,dest[i],tag3,comm,recv_waits+i);CHKERRQ(ierr);
77730dcb7c9SBarry Smith   }
77830dcb7c9SBarry Smith 
77930dcb7c9SBarry Smith   /* send the messages */
780b0a32e0cSBarry Smith   ierr = PetscMalloc((nsends2+1)*sizeof(MPI_Request),&send_waits);CHKERRQ(ierr);
78130dcb7c9SBarry Smith   for (i=0; i<nsends2; i++) {
78232dcc486SBarry Smith     ierr = MPI_Isend(sends2+starts2[i],nprocs[i],MPIU_INT,source[i],tag3,comm,send_waits+i);CHKERRQ(ierr);
78330dcb7c9SBarry Smith   }
78430dcb7c9SBarry Smith 
78530dcb7c9SBarry Smith   /* wait on receives */
7860c468ba9SBarry Smith   if (nrecvs2) {
7870c468ba9SBarry Smith     ierr = PetscMalloc(nrecvs2*sizeof(MPI_Status),&recv_statuses);CHKERRQ(ierr);
78830dcb7c9SBarry Smith     ierr = MPI_Waitall(nrecvs2,recv_waits,recv_statuses);CHKERRQ(ierr);
78930dcb7c9SBarry Smith     ierr = PetscFree(recv_statuses);CHKERRQ(ierr);
7900c468ba9SBarry Smith   }
79130dcb7c9SBarry Smith   ierr = PetscFree(recv_waits);CHKERRQ(ierr);
79230dcb7c9SBarry Smith   ierr = PetscFree(nprocs);CHKERRQ(ierr);
79330dcb7c9SBarry Smith 
79407b52d57SBarry Smith   if (debug) { /* -----------------------------------  */
79530dcb7c9SBarry Smith     cnt = 0;
79630dcb7c9SBarry Smith     for (i=0; i<nrecvs2; i++) {
79730dcb7c9SBarry Smith       nt = recvs2[cnt++];
79830dcb7c9SBarry Smith       for (j=0; j<nt; j++) {
79930dcb7c9SBarry Smith         ierr = PetscSynchronizedPrintf(comm,"[%d] local node %d number of subdomains %d: ",rank,recvs2[cnt],recvs2[cnt+1]);CHKERRQ(ierr);
80030dcb7c9SBarry Smith         for (k=0; k<recvs2[cnt+1]; k++) {
80130dcb7c9SBarry Smith           ierr = PetscSynchronizedPrintf(comm,"%d ",recvs2[cnt+2+k]);CHKERRQ(ierr);
80230dcb7c9SBarry Smith         }
80330dcb7c9SBarry Smith         cnt += 2 + recvs2[cnt+1];
80430dcb7c9SBarry Smith         ierr = PetscSynchronizedPrintf(comm,"\n");CHKERRQ(ierr);
80530dcb7c9SBarry Smith       }
80630dcb7c9SBarry Smith     }
80730dcb7c9SBarry Smith     ierr = PetscSynchronizedFlush(comm);CHKERRQ(ierr);
80807b52d57SBarry Smith   } /* -----------------------------------  */
80930dcb7c9SBarry Smith 
81030dcb7c9SBarry Smith   /* count number subdomains for each local node */
81132dcc486SBarry Smith   ierr = PetscMalloc(size*sizeof(PetscInt),&nprocs);CHKERRQ(ierr);
81232dcc486SBarry Smith   ierr = PetscMemzero(nprocs,size*sizeof(PetscInt));CHKERRQ(ierr);
81330dcb7c9SBarry Smith   cnt  = 0;
81430dcb7c9SBarry Smith   for (i=0; i<nrecvs2; i++) {
81530dcb7c9SBarry Smith     nt = recvs2[cnt++];
81630dcb7c9SBarry Smith     for (j=0; j<nt; j++) {
81730dcb7c9SBarry Smith       for (k=0; k<recvs2[cnt+1]; k++) {
81830dcb7c9SBarry Smith         nprocs[recvs2[cnt+2+k]]++;
81930dcb7c9SBarry Smith       }
82030dcb7c9SBarry Smith       cnt += 2 + recvs2[cnt+1];
82130dcb7c9SBarry Smith     }
82230dcb7c9SBarry Smith   }
82330dcb7c9SBarry Smith   nt = 0; for (i=0; i<size; i++) nt += (nprocs[i] > 0);
82430dcb7c9SBarry Smith   *nproc    = nt;
82532dcc486SBarry Smith   ierr = PetscMalloc((nt+1)*sizeof(PetscInt),procs);CHKERRQ(ierr);
82632dcc486SBarry Smith   ierr = PetscMalloc((nt+1)*sizeof(PetscInt),numprocs);CHKERRQ(ierr);
82732dcc486SBarry Smith   ierr = PetscMalloc((nt+1)*sizeof(PetscInt*),indices);CHKERRQ(ierr);
82832dcc486SBarry Smith   ierr = PetscMalloc(size*sizeof(PetscInt),&bprocs);CHKERRQ(ierr);
82930dcb7c9SBarry Smith   cnt       = 0;
83030dcb7c9SBarry Smith   for (i=0; i<size; i++) {
83130dcb7c9SBarry Smith     if (nprocs[i] > 0) {
83230dcb7c9SBarry Smith       bprocs[i]        = cnt;
83330dcb7c9SBarry Smith       (*procs)[cnt]    = i;
83430dcb7c9SBarry Smith       (*numprocs)[cnt] = nprocs[i];
83532dcc486SBarry Smith       ierr             = PetscMalloc(nprocs[i]*sizeof(PetscInt),&(*indices)[cnt]);CHKERRQ(ierr);
83630dcb7c9SBarry Smith       cnt++;
83730dcb7c9SBarry Smith     }
83830dcb7c9SBarry Smith   }
83930dcb7c9SBarry Smith 
84030dcb7c9SBarry Smith   /* make the list of subdomains for each nontrivial local node */
84132dcc486SBarry Smith   ierr = PetscMemzero(*numprocs,nt*sizeof(PetscInt));CHKERRQ(ierr);
84230dcb7c9SBarry Smith   cnt  = 0;
84330dcb7c9SBarry Smith   for (i=0; i<nrecvs2; i++) {
84430dcb7c9SBarry Smith     nt = recvs2[cnt++];
84530dcb7c9SBarry Smith     for (j=0; j<nt; j++) {
84630dcb7c9SBarry Smith       for (k=0; k<recvs2[cnt+1]; k++) {
84730dcb7c9SBarry Smith         (*indices)[bprocs[recvs2[cnt+2+k]]][(*numprocs)[bprocs[recvs2[cnt+2+k]]]++] = recvs2[cnt];
84830dcb7c9SBarry Smith       }
84930dcb7c9SBarry Smith       cnt += 2 + recvs2[cnt+1];
85030dcb7c9SBarry Smith     }
85130dcb7c9SBarry Smith   }
85230dcb7c9SBarry Smith   ierr = PetscFree(bprocs);CHKERRQ(ierr);
85307b52d57SBarry Smith   ierr = PetscFree(recvs2);CHKERRQ(ierr);
85430dcb7c9SBarry Smith 
85507b52d57SBarry Smith   /* sort the node indexing by their global numbers */
85607b52d57SBarry Smith   nt = *nproc;
85707b52d57SBarry Smith   for (i=0; i<nt; i++) {
85832dcc486SBarry Smith     ierr = PetscMalloc(((*numprocs)[i])*sizeof(PetscInt),&tmp);CHKERRQ(ierr);
85907b52d57SBarry Smith     for (j=0; j<(*numprocs)[i]; j++) {
86007b52d57SBarry Smith       tmp[j] = lindices[(*indices)[i][j]];
86107b52d57SBarry Smith     }
86207b52d57SBarry Smith     ierr = PetscSortIntWithArray((*numprocs)[i],tmp,(*indices)[i]);CHKERRQ(ierr);
86307b52d57SBarry Smith     ierr = PetscFree(tmp);CHKERRQ(ierr);
86407b52d57SBarry Smith   }
86507b52d57SBarry Smith 
86607b52d57SBarry Smith   if (debug) { /* -----------------------------------  */
86730dcb7c9SBarry Smith     nt = *nproc;
86830dcb7c9SBarry Smith     for (i=0; i<nt; i++) {
86930dcb7c9SBarry Smith       ierr = PetscSynchronizedPrintf(comm,"[%d] subdomain %d number of indices %d: ",rank,(*procs)[i],(*numprocs)[i]);CHKERRQ(ierr);
87030dcb7c9SBarry Smith       for (j=0; j<(*numprocs)[i]; j++) {
87130dcb7c9SBarry Smith         ierr = PetscSynchronizedPrintf(comm,"%d ",(*indices)[i][j]);CHKERRQ(ierr);
87230dcb7c9SBarry Smith       }
87330dcb7c9SBarry Smith       ierr = PetscSynchronizedPrintf(comm,"\n");CHKERRQ(ierr);
87430dcb7c9SBarry Smith     }
87530dcb7c9SBarry Smith     ierr = PetscSynchronizedFlush(comm);CHKERRQ(ierr);
87607b52d57SBarry Smith   } /* -----------------------------------  */
87730dcb7c9SBarry Smith 
87830dcb7c9SBarry Smith   /* wait on sends */
87930dcb7c9SBarry Smith   if (nsends2) {
880b0a32e0cSBarry Smith     ierr = PetscMalloc(nsends2*sizeof(MPI_Status),&send_status);CHKERRQ(ierr);
88130dcb7c9SBarry Smith     ierr = MPI_Waitall(nsends2,send_waits,send_status);CHKERRQ(ierr);
88230dcb7c9SBarry Smith     ierr = PetscFree(send_status);CHKERRQ(ierr);
88330dcb7c9SBarry Smith   }
88430dcb7c9SBarry Smith 
88530dcb7c9SBarry Smith   ierr = PetscFree(starts3);CHKERRQ(ierr);
88630dcb7c9SBarry Smith   ierr = PetscFree(dest);CHKERRQ(ierr);
88730dcb7c9SBarry Smith   ierr = PetscFree(send_waits);CHKERRQ(ierr);
8883677ff5aSBarry Smith 
889bc8ff85bSBarry Smith   ierr = PetscFree(nownedsenders);CHKERRQ(ierr);
890bc8ff85bSBarry Smith   ierr = PetscFree(ownedsenders);CHKERRQ(ierr);
891bc8ff85bSBarry Smith   ierr = PetscFree(starts);CHKERRQ(ierr);
89230dcb7c9SBarry Smith   ierr = PetscFree(starts2);CHKERRQ(ierr);
89330dcb7c9SBarry Smith   ierr = PetscFree(lens2);CHKERRQ(ierr);
89489d82c54SBarry Smith 
89589d82c54SBarry Smith   ierr = PetscFree(source);CHKERRQ(ierr);
89697f1f81fSBarry Smith   ierr = PetscFree(len);CHKERRQ(ierr);
89789d82c54SBarry Smith   ierr = PetscFree(recvs);CHKERRQ(ierr);
8983a96401aSBarry Smith   ierr = PetscFree(nprocs);CHKERRQ(ierr);
89930dcb7c9SBarry Smith   ierr = PetscFree(sends2);CHKERRQ(ierr);
90024cf384cSBarry Smith 
90124cf384cSBarry Smith   /* put the information about myself as the first entry in the list */
90224cf384cSBarry Smith   first_procs    = (*procs)[0];
90324cf384cSBarry Smith   first_numprocs = (*numprocs)[0];
90424cf384cSBarry Smith   first_indices  = (*indices)[0];
90524cf384cSBarry Smith   for (i=0; i<*nproc; i++) {
90624cf384cSBarry Smith     if ((*procs)[i] == rank) {
90724cf384cSBarry Smith       (*procs)[0]    = (*procs)[i];
90824cf384cSBarry Smith       (*numprocs)[0] = (*numprocs)[i];
90924cf384cSBarry Smith       (*indices)[0]  = (*indices)[i];
91024cf384cSBarry Smith       (*procs)[i]    = first_procs;
91124cf384cSBarry Smith       (*numprocs)[i] = first_numprocs;
91224cf384cSBarry Smith       (*indices)[i]  = first_indices;
91324cf384cSBarry Smith       break;
91424cf384cSBarry Smith     }
91524cf384cSBarry Smith   }
91689d82c54SBarry Smith   PetscFunctionReturn(0);
91789d82c54SBarry Smith }
91889d82c54SBarry Smith 
9194a2ae208SSatish Balay #undef __FUNCT__
9204a2ae208SSatish Balay #define __FUNCT__ "ISLocalToGlobalMappingRestoreInfo"
92107b52d57SBarry Smith /*@C
92207b52d57SBarry Smith     ISLocalToGlobalMappingRestoreInfo - Frees the memory allocated by ISLocalToGlobalMappingGetInfo()
92389d82c54SBarry Smith 
92407b52d57SBarry Smith     Collective on ISLocalToGlobalMapping
92507b52d57SBarry Smith 
92607b52d57SBarry Smith     Input Parameters:
92707b52d57SBarry Smith .   mapping - the mapping from local to global indexing
92807b52d57SBarry Smith 
92907b52d57SBarry Smith     Output Parameter:
93007b52d57SBarry Smith +   nproc - number of processors that are connected to this one
93107b52d57SBarry Smith .   proc - neighboring processors
93207b52d57SBarry Smith .   numproc - number of indices for each processor
93307b52d57SBarry Smith -   indices - indices of local nodes shared with neighbor (sorted by global numbering)
93407b52d57SBarry Smith 
93507b52d57SBarry Smith     Level: advanced
93607b52d57SBarry Smith 
93707b52d57SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreateIS(), ISLocalToGlobalMappingCreate(),
93807b52d57SBarry Smith           ISLocalToGlobalMappingGetInfo()
93907b52d57SBarry Smith @*/
9400c735eedSKris Buschelman PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingRestoreInfo(ISLocalToGlobalMapping mapping,PetscInt *nproc,PetscInt *procs[],PetscInt *numprocs[],PetscInt **indices[])
94107b52d57SBarry Smith {
9426849ba73SBarry Smith   PetscErrorCode ierr;
94332dcc486SBarry Smith   PetscInt       i;
94407b52d57SBarry Smith 
94507b52d57SBarry Smith   PetscFunctionBegin;
94605b42c5fSBarry Smith   ierr = PetscFree(*procs);CHKERRQ(ierr);
94705b42c5fSBarry Smith   ierr = PetscFree(*numprocs);CHKERRQ(ierr);
94800ff320aSBarry Smith   if (*indices) {
94905b42c5fSBarry Smith     ierr = PetscFree((*indices)[0]);CHKERRQ(ierr);
95000ff320aSBarry Smith     for (i=1; i<*nproc; i++) {
95105b42c5fSBarry Smith       ierr = PetscFree((*indices)[i]);CHKERRQ(ierr);
95207b52d57SBarry Smith     }
95307b52d57SBarry Smith     ierr = PetscFree(*indices);CHKERRQ(ierr);
95424cf384cSBarry Smith   }
95507b52d57SBarry Smith   PetscFunctionReturn(0);
95607b52d57SBarry Smith }
957