xref: /petsc/src/vec/is/utils/isltog.c (revision e090d5668ba2b2ea997ebb925e3a05be0dc5d9ab)
1*e090d566SSatish Balay /*$Id: isltog.c,v 1.39 2000/04/12 04:22:08 bsmith Exp balay $*/
22362add9SBarry Smith 
3*e090d566SSatish Balay #include "petscsys.h"   /*I "petscsys.h" I*/
4*e090d566SSatish Balay #include "src/vec/is/isimpl.h"    /*I "petscis.h"  I*/
52362add9SBarry Smith 
65615d1e5SSatish Balay #undef __FUNC__
7b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"ISLocalToGlobalMappingView"
85a5d4f66SBarry Smith /*@C
95a5d4f66SBarry Smith     ISLocalToGlobalMappingView - View a local to global mapping
105a5d4f66SBarry Smith 
11b9cd556bSLois Curfman McInnes     Not Collective
12b9cd556bSLois Curfman McInnes 
135a5d4f66SBarry Smith     Input Parameters:
145a5d4f66SBarry Smith .   ltog - local to global mapping
15b9cd556bSLois Curfman McInnes .   viewer - viewer
165a5d4f66SBarry Smith 
17a997ad1aSLois Curfman McInnes     Level: advanced
18a997ad1aSLois Curfman McInnes 
195a5d4f66SBarry Smith .keywords: IS, local-to-global mapping, create
205a5d4f66SBarry Smith 
215a5d4f66SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate()
225a5d4f66SBarry Smith @*/
235a5d4f66SBarry Smith int ISLocalToGlobalMappingView(ISLocalToGlobalMapping mapping,Viewer viewer)
245a5d4f66SBarry Smith {
25f1af5d2fSBarry Smith   int        i,ierr,rank;
266831982aSBarry Smith   PetscTruth isascii;
275a5d4f66SBarry Smith 
285a5d4f66SBarry Smith   PetscFunctionBegin;
296831982aSBarry Smith   PetscValidHeaderSpecific(mapping,IS_LTOGM_COOKIE);
303eda8832SBarry Smith   if (!viewer) viewer = VIEWER_STDOUT_(mapping->comm);
316831982aSBarry Smith   PetscValidHeaderSpecific(viewer,VIEWER_COOKIE);
326831982aSBarry Smith   PetscCheckSameComm(mapping,viewer);
335a5d4f66SBarry Smith 
34f1af5d2fSBarry Smith   ierr = MPI_Comm_rank(mapping->comm,&rank);CHKERRQ(ierr);
356831982aSBarry Smith   ierr = PetscTypeCompare((PetscObject)viewer,ASCII_VIEWER,&isascii);CHKERRQ(ierr);
366831982aSBarry Smith   if (isascii) {
375a5d4f66SBarry Smith     for (i=0; i<mapping->n; i++) {
38f1af5d2fSBarry Smith       ierr = ViewerASCIISynchronizedPrintf(viewer,"[%d] %d %d\n",rank,i,mapping->indices[i]);CHKERRQ(ierr);
396831982aSBarry Smith     }
406831982aSBarry Smith     ierr = ViewerFlush(viewer);CHKERRQ(ierr);
416831982aSBarry Smith   } else {
426831982aSBarry Smith     SETERRQ1(1,1,"Viewer type %s not supported for ISLocalToGlobalMapping",((PetscObject)viewer)->type_name);
435a5d4f66SBarry Smith   }
445a5d4f66SBarry Smith 
455a5d4f66SBarry Smith   PetscFunctionReturn(0);
465a5d4f66SBarry Smith }
475a5d4f66SBarry Smith 
485a5d4f66SBarry Smith #undef __FUNC__
49b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"ISLocalToGlobalMappingCreateIS"
502bdab257SBarry Smith /*@C
512bdab257SBarry Smith     ISLocalToGlobalMappingCreateIS - Creates a mapping between a local (0 to n)
522bdab257SBarry Smith     ordering and a global parallel ordering.
532bdab257SBarry Smith 
540f5bd95cSBarry Smith     Not collective
55b9cd556bSLois Curfman McInnes 
56a997ad1aSLois Curfman McInnes     Input Parameter:
572bdab257SBarry Smith .   is - index set containing the global numbers for each local
582bdab257SBarry Smith 
59a997ad1aSLois Curfman McInnes     Output Parameter:
602bdab257SBarry Smith .   mapping - new mapping data structure
612bdab257SBarry Smith 
62a997ad1aSLois Curfman McInnes     Level: advanced
63a997ad1aSLois Curfman McInnes 
642bdab257SBarry Smith .keywords: IS, local-to-global mapping, create
652bdab257SBarry Smith 
662bdab257SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate()
672bdab257SBarry Smith @*/
682bdab257SBarry Smith int ISLocalToGlobalMappingCreateIS(IS is,ISLocalToGlobalMapping *mapping)
692bdab257SBarry Smith {
702bdab257SBarry Smith   int      n,*indices,ierr;
712bdab257SBarry Smith   MPI_Comm comm;
723a40ed3dSBarry Smith 
733a40ed3dSBarry Smith   PetscFunctionBegin;
742bdab257SBarry Smith   PetscValidHeaderSpecific(is,IS_COOKIE);
752bdab257SBarry Smith 
762bdab257SBarry Smith   ierr = PetscObjectGetComm((PetscObject)is,&comm);CHKERRQ(ierr);
772bdab257SBarry Smith   ierr = ISGetSize(is,&n);CHKERRQ(ierr);
782bdab257SBarry Smith   ierr = ISGetIndices(is,&indices);CHKERRQ(ierr);
792bdab257SBarry Smith   ierr = ISLocalToGlobalMappingCreate(comm,n,indices,mapping);CHKERRQ(ierr);
802bdab257SBarry Smith   ierr = ISRestoreIndices(is,&indices);CHKERRQ(ierr);
812bdab257SBarry Smith 
823a40ed3dSBarry Smith   PetscFunctionReturn(0);
832bdab257SBarry Smith }
845a5d4f66SBarry Smith 
852bdab257SBarry Smith #undef __FUNC__
86b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"ISLocalToGlobalMappingCreate"
87dd7157adSSatish Balay /*@C
8890f02eecSBarry Smith     ISLocalToGlobalMappingCreate - Creates a mapping between a local (0 to n)
8990f02eecSBarry Smith     ordering and a global parallel ordering.
902362add9SBarry Smith 
910f5bd95cSBarry Smith     Not Collective
92b9cd556bSLois Curfman McInnes 
932362add9SBarry Smith     Input Parameters:
94b9cd556bSLois Curfman McInnes +   comm - MPI communicator of size 1.
9590f02eecSBarry Smith .   n - the number of local elements
96b9cd556bSLois Curfman McInnes -   indices - the global index for each local element
972362add9SBarry Smith 
98a997ad1aSLois Curfman McInnes     Output Parameter:
9990f02eecSBarry Smith .   mapping - new mapping data structure
1002362add9SBarry Smith 
101a997ad1aSLois Curfman McInnes     Level: advanced
102a997ad1aSLois Curfman McInnes 
1033acfe500SLois Curfman McInnes .keywords: IS, local-to-global mapping, create
1042362add9SBarry Smith 
1052bdab257SBarry Smith .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreateIS()
1062362add9SBarry Smith @*/
107987e4450SSatish Balay int ISLocalToGlobalMappingCreate(MPI_Comm cm,int n,const int indices[],ISLocalToGlobalMapping *mapping)
1082362add9SBarry Smith {
109549d3d68SSatish Balay   int ierr;
110549d3d68SSatish Balay 
1113a40ed3dSBarry Smith   PetscFunctionBegin;
11290f02eecSBarry Smith   PetscValidIntPointer(indices);
11390f02eecSBarry Smith   PetscValidPointer(mapping);
1142362add9SBarry Smith 
1153f1db9ecSBarry Smith   PetscHeaderCreate(*mapping,_p_ISLocalToGlobalMapping,int,IS_LTOGM_COOKIE,0,"ISLocalToGlobalMapping",
1163f1db9ecSBarry Smith                     cm,ISLocalToGlobalMappingDestroy,ISLocalToGlobalMappingView);
117d4bb536fSBarry Smith   PLogObjectCreate(*mapping);
118d4bb536fSBarry Smith   PLogObjectMemory(*mapping,sizeof(struct _p_ISLocalToGlobalMapping)+n*sizeof(int));
119d4bb536fSBarry Smith 
120d4bb536fSBarry Smith   (*mapping)->n       = n;
12190f02eecSBarry Smith   (*mapping)->indices = (int*)PetscMalloc((n+1)*sizeof(int));CHKPTRQ((*mapping)->indices);
122549d3d68SSatish Balay   ierr = PetscMemcpy((*mapping)->indices,indices,n*sizeof(int));CHKERRQ(ierr);
123d4bb536fSBarry Smith 
124d4bb536fSBarry Smith   /*
125d4bb536fSBarry Smith       Do not create the global to local mapping. This is only created if
126d4bb536fSBarry Smith      ISGlobalToLocalMapping() is called
127d4bb536fSBarry Smith   */
128d4bb536fSBarry Smith   (*mapping)->globals = 0;
1293a40ed3dSBarry Smith   PetscFunctionReturn(0);
1302362add9SBarry Smith }
1312362add9SBarry Smith 
1325615d1e5SSatish Balay #undef __FUNC__
133b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"ISLocalToGlobalMappingDestroy"
13490f02eecSBarry Smith /*@
13590f02eecSBarry Smith    ISLocalToGlobalMappingDestroy - Destroys a mapping between a local (0 to n)
13690f02eecSBarry Smith    ordering and a global parallel ordering.
13790f02eecSBarry Smith 
1380f5bd95cSBarry Smith    Note Collective
139b9cd556bSLois Curfman McInnes 
14090f02eecSBarry Smith    Input Parameters:
14190f02eecSBarry Smith .  mapping - mapping data structure
14290f02eecSBarry Smith 
143a997ad1aSLois Curfman McInnes    Level: advanced
144a997ad1aSLois Curfman McInnes 
1453acfe500SLois Curfman McInnes .keywords: IS, local-to-global mapping, destroy
14690f02eecSBarry Smith 
1473acfe500SLois Curfman McInnes .seealso: ISLocalToGlobalMappingCreate()
14890f02eecSBarry Smith @*/
14990f02eecSBarry Smith int ISLocalToGlobalMappingDestroy(ISLocalToGlobalMapping mapping)
15090f02eecSBarry Smith {
151606d414cSSatish Balay   int ierr;
1523a40ed3dSBarry Smith   PetscFunctionBegin;
15390f02eecSBarry Smith   PetscValidPointer(mapping);
1543a40ed3dSBarry Smith   if (--mapping->refct > 0) PetscFunctionReturn(0);
15585614651SBarry Smith   if (mapping->refct < 0) {
15685614651SBarry Smith     SETERRQ(1,1,"Mapping already destroyed");
15785614651SBarry Smith   }
15890f02eecSBarry Smith 
159606d414cSSatish Balay   ierr = PetscFree(mapping->indices);CHKERRQ(ierr);
160606d414cSSatish Balay   if (mapping->globals) {ierr = PetscFree(mapping->globals);CHKERRQ(ierr);}
161d4bb536fSBarry Smith   PLogObjectDestroy(mapping);
162d4bb536fSBarry Smith   PetscHeaderDestroy(mapping);
1633a40ed3dSBarry Smith   PetscFunctionReturn(0);
16490f02eecSBarry Smith }
16590f02eecSBarry Smith 
1665615d1e5SSatish Balay #undef __FUNC__
167b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"ISLocalToGlobalMappingApplyIS"
16890f02eecSBarry Smith /*@
1693acfe500SLois Curfman McInnes     ISLocalToGlobalMappingApplyIS - Creates from an IS in the local numbering
1703acfe500SLois Curfman McInnes     a new index set using the global numbering defined in an ISLocalToGlobalMapping
1713acfe500SLois Curfman McInnes     context.
17290f02eecSBarry Smith 
173b9cd556bSLois Curfman McInnes     Not collective
174b9cd556bSLois Curfman McInnes 
17590f02eecSBarry Smith     Input Parameters:
176b9cd556bSLois Curfman McInnes +   mapping - mapping between local and global numbering
177b9cd556bSLois Curfman McInnes -   is - index set in local numbering
17890f02eecSBarry Smith 
17990f02eecSBarry Smith     Output Parameters:
18090f02eecSBarry Smith .   newis - index set in global numbering
18190f02eecSBarry Smith 
182a997ad1aSLois Curfman McInnes     Level: advanced
183a997ad1aSLois Curfman McInnes 
1843acfe500SLois Curfman McInnes .keywords: IS, local-to-global mapping, apply
1853acfe500SLois Curfman McInnes 
18690f02eecSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(),
187d4bb536fSBarry Smith           ISLocalToGlobalMappingDestroy(), ISGlobalToLocalMappingApply()
18890f02eecSBarry Smith @*/
18990f02eecSBarry Smith int ISLocalToGlobalMappingApplyIS(ISLocalToGlobalMapping mapping,IS is,IS *newis)
19090f02eecSBarry Smith {
19190f02eecSBarry Smith   int ierr,n,i,*idxin,*idxmap,*idxout;
1923a40ed3dSBarry Smith 
1933a40ed3dSBarry Smith   PetscFunctionBegin;
19490f02eecSBarry Smith   PetscValidPointer(mapping);
19590f02eecSBarry Smith   PetscValidHeaderSpecific(is,IS_COOKIE);
19690f02eecSBarry Smith   PetscValidPointer(newis);
19790f02eecSBarry Smith 
19890f02eecSBarry Smith   ierr   = ISGetSize(is,&n);CHKERRQ(ierr);
19990f02eecSBarry Smith   ierr   = ISGetIndices(is,&idxin);CHKERRQ(ierr);
20090f02eecSBarry Smith   idxmap = mapping->indices;
20190f02eecSBarry Smith 
20290f02eecSBarry Smith   idxout = (int*)PetscMalloc((n+1)*sizeof(int));CHKPTRQ(idxout);
20390f02eecSBarry Smith   for (i=0; i<n; i++) {
20490f02eecSBarry Smith     idxout[i] = idxmap[idxin[i]];
20590f02eecSBarry Smith   }
206029af93fSBarry Smith   ierr = ISCreateGeneral(PETSC_COMM_SELF,n,idxout,newis);CHKERRQ(ierr);
207606d414cSSatish Balay   ierr = PetscFree(idxout);CHKERRQ(ierr);
2083a40ed3dSBarry Smith   PetscFunctionReturn(0);
20990f02eecSBarry Smith }
21090f02eecSBarry Smith 
2115615d1e5SSatish Balay #undef __FUNC__
212b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"ISLocalToGlobalMappingApply"
213a64dd6b6SSatish Balay /*@
2143acfe500SLois Curfman McInnes    ISLocalToGlobalMappingApply - Takes a list of integers in a local numbering
2153acfe500SLois Curfman McInnes    and converts them to the global numbering.
21690f02eecSBarry Smith 
217b9cd556bSLois Curfman McInnes    Not collective
218b9cd556bSLois Curfman McInnes 
219bb25748dSBarry Smith    Input Parameters:
220b9cd556bSLois Curfman McInnes +  mapping - the local to global mapping context
221bb25748dSBarry Smith .  N - number of integers
222b9cd556bSLois Curfman McInnes -  in - input indices in local numbering
223bb25748dSBarry Smith 
224bb25748dSBarry Smith    Output Parameter:
225bb25748dSBarry Smith .  out - indices in global numbering
226bb25748dSBarry Smith 
227b9cd556bSLois Curfman McInnes    Notes:
228b9cd556bSLois Curfman McInnes    The in and out array parameters may be identical.
229d4bb536fSBarry Smith 
230a997ad1aSLois Curfman McInnes    Level: advanced
231a997ad1aSLois Curfman McInnes 
232bb25748dSBarry Smith .seealso: ISLocalToGlobalMappingCreate(),ISLocalToGlobalMappingDestroy(),
2330752156aSBarry Smith           ISLocalToGlobalMappingApplyIS(),AOCreateBasic(),AOApplicationToPetsc(),
234d4bb536fSBarry Smith           AOPetscToApplication(), ISGlobalToLocalMappingApply()
235bb25748dSBarry Smith 
2363acfe500SLois Curfman McInnes .keywords: local-to-global, mapping, apply
237d4bb536fSBarry Smith 
238d4bb536fSBarry Smith @*/
239987e4450SSatish Balay int ISLocalToGlobalMappingApply(ISLocalToGlobalMapping mapping,int N,const int in[],int out[])
240d4bb536fSBarry Smith {
241d4bb536fSBarry Smith   int i,*idx = mapping->indices,Nmax = mapping->n;
2423a40ed3dSBarry Smith 
2433a40ed3dSBarry Smith   PetscFunctionBegin;
244d4bb536fSBarry Smith   for (i=0; i<N; i++) {
245d4bb536fSBarry Smith     if (in[i] < 0) {out[i] = in[i]; continue;}
246596552b5SBarry Smith     if (in[i] >= Nmax) SETERRQ2(PETSC_ERR_ARG_OUTOFRANGE,1,"Local index %d too large %d (max)",in[i],Nmax);
247d4bb536fSBarry Smith     out[i] = idx[in[i]];
248d4bb536fSBarry Smith   }
2493a40ed3dSBarry Smith   PetscFunctionReturn(0);
250d4bb536fSBarry Smith }
251d4bb536fSBarry Smith 
252d4bb536fSBarry Smith /* -----------------------------------------------------------------------------------------*/
253d4bb536fSBarry Smith 
254d4bb536fSBarry Smith #undef __FUNC__
255b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"ISGlobalToLocalMappingSetUp_Private"
256d4bb536fSBarry Smith /*
257d4bb536fSBarry Smith     Creates the global fields in the ISLocalToGlobalMapping structure
258d4bb536fSBarry Smith */
259d4bb536fSBarry Smith static int ISGlobalToLocalMappingSetUp_Private(ISLocalToGlobalMapping mapping)
260d4bb536fSBarry Smith {
261d4bb536fSBarry Smith   int i,*idx = mapping->indices,n = mapping->n,end,start,*globals;
262d4bb536fSBarry Smith 
2633a40ed3dSBarry Smith   PetscFunctionBegin;
264d4bb536fSBarry Smith   end   = 0;
265d4bb536fSBarry Smith   start = 100000000;
266d4bb536fSBarry Smith 
267d4bb536fSBarry Smith   for (i=0; i<n; i++) {
268d4bb536fSBarry Smith     if (idx[i] < 0) continue;
269d4bb536fSBarry Smith     if (idx[i] < start) start = idx[i];
270d4bb536fSBarry Smith     if (idx[i] > end)   end   = idx[i];
271d4bb536fSBarry Smith   }
272d4bb536fSBarry Smith   if (start > end) {start = 0; end = -1;}
273d4bb536fSBarry Smith   mapping->globalstart = start;
274d4bb536fSBarry Smith   mapping->globalend   = end;
275d4bb536fSBarry Smith 
276d4bb536fSBarry Smith   globals = mapping->globals = (int*)PetscMalloc((end-start+2)*sizeof(int));CHKPTRQ(mapping->globals);
277d4bb536fSBarry Smith   for (i=0; i<end-start+1; i++) {
278d4bb536fSBarry Smith     globals[i] = -1;
279d4bb536fSBarry Smith   }
280d4bb536fSBarry Smith   for (i=0; i<n; i++) {
281d4bb536fSBarry Smith     if (idx[i] < 0) continue;
282d4bb536fSBarry Smith     globals[idx[i] - start] = i;
283d4bb536fSBarry Smith   }
284d4bb536fSBarry Smith 
285d4bb536fSBarry Smith   PLogObjectMemory(mapping,(end-start+1)*sizeof(int));
2863a40ed3dSBarry Smith   PetscFunctionReturn(0);
287d4bb536fSBarry Smith }
288d4bb536fSBarry Smith 
289d4bb536fSBarry Smith #undef __FUNC__
290b2863d3aSBarry Smith #define __FUNC__ /*<a name=""></a>*/"ISGlobalToLocalMappingApply"
291d4bb536fSBarry Smith /*@
292a997ad1aSLois Curfman McInnes     ISGlobalToLocalMappingApply - Provides the local numbering for a list of integers
293a997ad1aSLois Curfman McInnes     specified with a global numbering.
294d4bb536fSBarry Smith 
295b9cd556bSLois Curfman McInnes     Not collective
296b9cd556bSLois Curfman McInnes 
297d4bb536fSBarry Smith     Input Parameters:
298b9cd556bSLois Curfman McInnes +   mapping - mapping between local and global numbering
299d4bb536fSBarry Smith .   type - IS_GTOLM_MASK - replaces global indices with no local value with -1
300d4bb536fSBarry Smith            IS_GTOLM_DROP - drops the indices with no local value from the output list
301d4bb536fSBarry Smith .   n - number of global indices to map
302b9cd556bSLois Curfman McInnes -   idx - global indices to map
303d4bb536fSBarry Smith 
304d4bb536fSBarry Smith     Output Parameters:
305b9cd556bSLois Curfman McInnes +   nout - number of indices in output array (if type == IS_GTOLM_MASK then nout = n)
306b9cd556bSLois Curfman McInnes -   idxout - local index of each global index, one must pass in an array long enough
307e182c471SBarry Smith              to hold all the indices. You can call ISGlobalToLocalMappingApply() with
308e182c471SBarry Smith              idxout == PETSC_NULL to determine the required length (returned in nout)
309e182c471SBarry Smith              and then allocate the required space and call ISGlobalToLocalMappingApply()
310e182c471SBarry Smith              a second time to set the values.
311d4bb536fSBarry Smith 
312b9cd556bSLois Curfman McInnes     Notes:
313b9cd556bSLois Curfman McInnes     Either nout or idxout may be PETSC_NULL. idx and idxout may be identical.
314d4bb536fSBarry Smith 
3150f5bd95cSBarry Smith     This is not scalable in memory usage. Each processor requires O(Nglobal) size
3160f5bd95cSBarry Smith     array to compute these.
3170f5bd95cSBarry Smith 
318a997ad1aSLois Curfman McInnes     Level: advanced
319a997ad1aSLois Curfman McInnes 
320d4bb536fSBarry Smith .keywords: IS, global-to-local mapping, apply
321d4bb536fSBarry Smith 
322d4bb536fSBarry Smith .seealso: ISLocalToGlobalMappingApply(), ISLocalToGlobalMappingCreate(),
323d4bb536fSBarry Smith           ISLocalToGlobalMappingDestroy()
324d4bb536fSBarry Smith @*/
325d4bb536fSBarry Smith int ISGlobalToLocalMappingApply(ISLocalToGlobalMapping mapping,ISGlobalToLocalMappingType type,
326987e4450SSatish Balay                                   int n,const int idx[],int *nout,int idxout[])
327d4bb536fSBarry Smith {
328d4bb536fSBarry Smith   int i,ierr,*globals,nf = 0,tmp,start,end;
329d4bb536fSBarry Smith 
3303a40ed3dSBarry Smith   PetscFunctionBegin;
331d4bb536fSBarry Smith   if (!mapping->globals) {
332d4bb536fSBarry Smith     ierr = ISGlobalToLocalMappingSetUp_Private(mapping);CHKERRQ(ierr);
333d4bb536fSBarry Smith   }
334d4bb536fSBarry Smith   globals = mapping->globals;
335d4bb536fSBarry Smith   start   = mapping->globalstart;
336d4bb536fSBarry Smith   end     = mapping->globalend;
337d4bb536fSBarry Smith 
338d4bb536fSBarry Smith   if (type == IS_GTOLM_MASK) {
339d4bb536fSBarry Smith     if (idxout) {
340d4bb536fSBarry Smith       for (i=0; i<n; i++) {
341d4bb536fSBarry Smith         if (idx[i] < 0) idxout[i] = idx[i];
342d4bb536fSBarry Smith         else if (idx[i] < start) idxout[i] = -1;
343d4bb536fSBarry Smith         else if (idx[i] > end)   idxout[i] = -1;
344d4bb536fSBarry Smith         else                     idxout[i] = globals[idx[i] - start];
345d4bb536fSBarry Smith       }
346d4bb536fSBarry Smith     }
347d4bb536fSBarry Smith     if (nout) *nout = n;
348d4bb536fSBarry Smith   } else {
349d4bb536fSBarry Smith     if (idxout) {
350d4bb536fSBarry Smith       for (i=0; i<n; i++) {
351d4bb536fSBarry Smith         if (idx[i] < 0) continue;
352d4bb536fSBarry Smith         if (idx[i] < start) continue;
353d4bb536fSBarry Smith         if (idx[i] > end) continue;
354d4bb536fSBarry Smith         tmp = globals[idx[i] - start];
355d4bb536fSBarry Smith         if (tmp < 0) continue;
356d4bb536fSBarry Smith         idxout[nf++] = tmp;
357d4bb536fSBarry Smith       }
358d4bb536fSBarry Smith     } else {
359d4bb536fSBarry Smith       for (i=0; i<n; i++) {
360d4bb536fSBarry Smith         if (idx[i] < 0) continue;
361d4bb536fSBarry Smith         if (idx[i] < start) continue;
362d4bb536fSBarry Smith         if (idx[i] > end) continue;
363d4bb536fSBarry Smith         tmp = globals[idx[i] - start];
364d4bb536fSBarry Smith         if (tmp < 0) continue;
365d4bb536fSBarry Smith         nf++;
366d4bb536fSBarry Smith       }
367d4bb536fSBarry Smith     }
368d4bb536fSBarry Smith     if (nout) *nout = nf;
369d4bb536fSBarry Smith   }
370d4bb536fSBarry Smith 
3713a40ed3dSBarry Smith   PetscFunctionReturn(0);
372d4bb536fSBarry Smith }
37390f02eecSBarry Smith 
374