xref: /petsc/src/mat/impls/sbaij/mpi/sbaijov.c (revision 7d0a6c19129e7069c8a40e210b34ed62989173db)
1 
2 /*
3    Routines to compute overlapping regions of a parallel MPI matrix.
4    Used for finding submatrices that were shared across processors.
5 */
6 #include "../src/mat/impls/sbaij/mpi/mpisbaij.h"
7 #include "petscbt.h"
8 
9 static PetscErrorCode MatIncreaseOverlap_MPISBAIJ_Once(Mat,PetscInt,IS*);
10 static PetscErrorCode MatIncreaseOverlap_MPISBAIJ_Local(Mat,PetscInt*,PetscInt,PetscInt*,PetscBT*);
11 
12 #undef __FUNCT__
13 #define __FUNCT__ "MatIncreaseOverlap_MPISBAIJ"
14 PetscErrorCode MatIncreaseOverlap_MPISBAIJ(Mat C,PetscInt is_max,IS is[],PetscInt ov)
15 {
16   PetscErrorCode ierr;
17   PetscInt       i,N=C->cmap->N, bs=C->rmap->bs;
18   IS             *is_new;
19 
20   PetscFunctionBegin;
21   ierr = PetscMalloc(is_max*sizeof(IS),&is_new);CHKERRQ(ierr);
22   /* Convert the indices into block format */
23   ierr = ISCompressIndicesGeneral(N,bs,is_max,is,is_new);CHKERRQ(ierr);
24   if (ov < 0){ SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Negative overlap specified\n");}
25   for (i=0; i<ov; ++i) {
26     ierr = MatIncreaseOverlap_MPISBAIJ_Once(C,is_max,is_new);CHKERRQ(ierr);
27   }
28   for (i=0; i<is_max; i++) {ierr = ISDestroy(is[i]);CHKERRQ(ierr);}
29   ierr = ISExpandIndicesGeneral(N,bs,is_max,is_new,is);CHKERRQ(ierr);
30   for (i=0; i<is_max; i++) {ierr = ISDestroy(is_new[i]);CHKERRQ(ierr);}
31   ierr = PetscFree(is_new);CHKERRQ(ierr);
32   PetscFunctionReturn(0);
33 }
34 
35 typedef enum {MINE,OTHER} WhoseOwner;
36 /*  data1, odata1 and odata2 are packed in the format (for communication):
37        data[0]          = is_max, no of is
38        data[1]          = size of is[0]
39         ...
40        data[is_max]     = size of is[is_max-1]
41        data[is_max + 1] = data(is[0])
42         ...
43        data[is_max+1+sum(size of is[k]), k=0,...,i-1] = data(is[i])
44         ...
45    data2 is packed in the format (for creating output is[]):
46        data[0]          = is_max, no of is
47        data[1]          = size of is[0]
48         ...
49        data[is_max]     = size of is[is_max-1]
50        data[is_max + 1] = data(is[0])
51         ...
52        data[is_max + 1 + Mbs*i) = data(is[i])
53         ...
54 */
55 #undef __FUNCT__
56 #define __FUNCT__ "MatIncreaseOverlap_MPISBAIJ_Once"
57 static PetscErrorCode MatIncreaseOverlap_MPISBAIJ_Once(Mat C,PetscInt is_max,IS is[])
58 {
59   Mat_MPISBAIJ  *c = (Mat_MPISBAIJ*)C->data;
60   PetscErrorCode ierr;
61   PetscMPIInt    size,rank,tag1,tag2,*len_s,nrqr,nrqs,*id_r1,*len_r1,flag,len;
62   const PetscInt *idx_i;
63   PetscInt       idx,isz,col,*n,*data1,**data1_start,*data2,*data2_i,*data,*data_i,
64                  Mbs,i,j,k,*odata1,*odata2,
65                  proc_id,**odata2_ptr,*ctable=0,*btable,len_max,len_est;
66   PetscInt       proc_end=0,*iwork,len_unused,nodata2;
67   PetscInt       ois_max; /* max no of is[] in each of processor */
68   char           *t_p;
69   MPI_Comm       comm;
70   MPI_Request    *s_waits1,*s_waits2,r_req;
71   MPI_Status     *s_status,r_status;
72   PetscBT        *table;  /* mark indices of this processor's is[] */
73   PetscBT        table_i;
74   PetscBT        otable; /* mark indices of other processors' is[] */
75   PetscInt       bs=C->rmap->bs,Bn = c->B->cmap->n,Bnbs = Bn/bs,*Bowners;
76   IS             garray_local,garray_gl;
77 
78   PetscFunctionBegin;
79   comm = ((PetscObject)C)->comm;
80   size = c->size;
81   rank = c->rank;
82   Mbs  = c->Mbs;
83 
84   ierr = PetscObjectGetNewTag((PetscObject)C,&tag1);CHKERRQ(ierr);
85   ierr = PetscObjectGetNewTag((PetscObject)C,&tag2);CHKERRQ(ierr);
86 
87   /* create tables used in
88      step 1: table[i] - mark c->garray of proc [i]
89      step 3: table[i] - mark indices of is[i] when whose=MINE
90              table[0] - mark incideces of is[] when whose=OTHER */
91   len = PetscMax(is_max, size);CHKERRQ(ierr);
92   ierr = PetscMalloc2(len,PetscBT,&table,(Mbs/PETSC_BITS_PER_BYTE+1)*len,char,&t_p);CHKERRQ(ierr);
93   for (i=0; i<len; i++) {
94     table[i]  = t_p  + (Mbs/PETSC_BITS_PER_BYTE+1)*i;
95   }
96 
97   ierr = MPI_Allreduce(&is_max,&ois_max,1,MPIU_INT,MPI_MAX,comm);CHKERRQ(ierr);
98 
99   /* 1. Send this processor's is[] to other processors */
100   /*---------------------------------------------------*/
101   /* allocate spaces */
102   ierr = PetscMalloc(is_max*sizeof(PetscInt),&n);CHKERRQ(ierr);
103   len = 0;
104   for (i=0; i<is_max; i++) {
105     ierr = ISGetLocalSize(is[i],&n[i]);CHKERRQ(ierr);
106     len += n[i];
107   }
108   if (!len) {
109     is_max = 0;
110   } else {
111     len += 1 + is_max; /* max length of data1 for one processor */
112   }
113 
114 
115   ierr = PetscMalloc((size*len+1)*sizeof(PetscInt),&data1);CHKERRQ(ierr);
116   ierr = PetscMalloc(size*sizeof(PetscInt*),&data1_start);CHKERRQ(ierr);
117   for (i=0; i<size; i++) data1_start[i] = data1 + i*len;
118 
119   ierr = PetscMalloc4(size,PetscInt,&len_s,size,PetscInt,&btable,size,PetscInt,&iwork,size+1,PetscInt,&Bowners);CHKERRQ(ierr);
120 
121   /* gather c->garray from all processors */
122   ierr = ISCreateGeneral(comm,Bnbs,c->garray,PETSC_COPY_VALUES,&garray_local);CHKERRQ(ierr);
123   ierr = ISAllGather(garray_local, &garray_gl);CHKERRQ(ierr);
124   ierr = ISDestroy(garray_local);CHKERRQ(ierr);
125   ierr = MPI_Allgather(&Bnbs,1,MPIU_INT,Bowners+1,1,MPIU_INT,comm);CHKERRQ(ierr);
126   Bowners[0] = 0;
127   for (i=0; i<size; i++) Bowners[i+1] += Bowners[i];
128 
129   if (is_max){
130     /* hash table ctable which maps c->row to proc_id) */
131     ierr = PetscMalloc(Mbs*sizeof(PetscInt),&ctable);CHKERRQ(ierr);
132     for (proc_id=0,j=0; proc_id<size; proc_id++) {
133       for (; j<C->rmap->range[proc_id+1]/bs; j++) {
134         ctable[j] = proc_id;
135       }
136     }
137 
138     /* hash tables marking c->garray */
139     ierr = ISGetIndices(garray_gl,&idx_i);
140     for (i=0; i<size; i++){
141       table_i = table[i];
142       ierr    = PetscBTMemzero(Mbs,table_i);CHKERRQ(ierr);
143       for (j = Bowners[i]; j<Bowners[i+1]; j++){ /* go through B cols of proc[i]*/
144         ierr = PetscBTSet(table_i,idx_i[j]);CHKERRQ(ierr);
145       }
146     }
147     ierr = ISRestoreIndices(garray_gl,&idx_i);CHKERRQ(ierr);
148   }  /* if (is_max) */
149   ierr = ISDestroy(garray_gl);CHKERRQ(ierr);
150 
151   /* evaluate communication - mesg to who, length, and buffer space */
152   for (i=0; i<size; i++) len_s[i] = 0;
153 
154   /* header of data1 */
155   for (proc_id=0; proc_id<size; proc_id++){
156     iwork[proc_id] = 0;
157     *data1_start[proc_id] = is_max;
158     data1_start[proc_id]++;
159     for (j=0; j<is_max; j++) {
160       if (proc_id == rank){
161         *data1_start[proc_id] = n[j];
162       } else {
163         *data1_start[proc_id] = 0;
164       }
165       data1_start[proc_id]++;
166     }
167   }
168 
169   for (i=0; i<is_max; i++) {
170     ierr = ISGetIndices(is[i],&idx_i);CHKERRQ(ierr);
171     for (j=0; j<n[i]; j++){
172       idx = idx_i[j];
173       *data1_start[rank] = idx; data1_start[rank]++; /* for local proccessing */
174       proc_end = ctable[idx];
175       for (proc_id=0;  proc_id<=proc_end; proc_id++){ /* for others to process */
176         if (proc_id == rank ) continue; /* done before this loop */
177         if (proc_id < proc_end && !PetscBTLookup(table[proc_id],idx))
178           continue;   /* no need for sending idx to [proc_id] */
179         *data1_start[proc_id] = idx; data1_start[proc_id]++;
180         len_s[proc_id]++;
181       }
182     }
183     /* update header data */
184     for (proc_id=0; proc_id<size; proc_id++){
185       if (proc_id== rank) continue;
186       *(data1 + proc_id*len + 1 + i) = len_s[proc_id] - iwork[proc_id];
187       iwork[proc_id] = len_s[proc_id] ;
188     }
189     ierr = ISRestoreIndices(is[i],&idx_i);CHKERRQ(ierr);
190   }
191 
192   nrqs = 0; nrqr = 0;
193   for (i=0; i<size; i++){
194     data1_start[i] = data1 + i*len;
195     if (len_s[i]){
196       nrqs++;
197       len_s[i] += 1 + is_max; /* add no. of header msg */
198     }
199   }
200 
201   for (i=0; i<is_max; i++) {
202     ierr = ISDestroy(is[i]);CHKERRQ(ierr);
203   }
204   ierr = PetscFree(n);CHKERRQ(ierr);
205   ierr = PetscFree(ctable);CHKERRQ(ierr);
206 
207   /* Determine the number of messages to expect, their lengths, from from-ids */
208   ierr = PetscGatherNumberOfMessages(comm,PETSC_NULL,len_s,&nrqr);CHKERRQ(ierr);
209   ierr = PetscGatherMessageLengths(comm,nrqs,nrqr,len_s,&id_r1,&len_r1);CHKERRQ(ierr);
210 
211   /*  Now  post the sends */
212   ierr = PetscMalloc2(size,MPI_Request,&s_waits1,size,MPI_Request,&s_waits2);CHKERRQ(ierr);
213   k = 0;
214   for (proc_id=0; proc_id<size; proc_id++){  /* send data1 to processor [proc_id] */
215     if (len_s[proc_id]){
216       ierr = MPI_Isend(data1_start[proc_id],len_s[proc_id],MPIU_INT,proc_id,tag1,comm,s_waits1+k);CHKERRQ(ierr);
217       k++;
218     }
219   }
220 
221   /* 2. Receive other's is[] and process. Then send back */
222   /*-----------------------------------------------------*/
223   len = 0;
224   for (i=0; i<nrqr; i++){
225     if (len_r1[i] > len)len = len_r1[i];
226   }
227   ierr = PetscFree(len_r1);CHKERRQ(ierr);
228   ierr = PetscFree(id_r1);CHKERRQ(ierr);
229 
230   for (proc_id=0; proc_id<size; proc_id++)
231     len_s[proc_id] = iwork[proc_id] = 0;
232 
233   ierr = PetscMalloc((len+1)*sizeof(PetscInt),&odata1);CHKERRQ(ierr);
234   ierr = PetscMalloc(size*sizeof(PetscInt**),&odata2_ptr);CHKERRQ(ierr);
235   ierr = PetscBTCreate(Mbs,otable);CHKERRQ(ierr);
236 
237   len_max = ois_max*(Mbs+1);  /* max space storing all is[] for each receive */
238   len_est = 2*len_max; /* estimated space of storing is[] for all receiving messages */
239   ierr = PetscMalloc((len_est+1)*sizeof(PetscInt),&odata2);CHKERRQ(ierr);
240   nodata2 = 0;       /* nodata2+1: num of PetscMalloc(,&odata2_ptr[]) called */
241   odata2_ptr[nodata2] = odata2;
242   len_unused = len_est; /* unused space in the array odata2_ptr[nodata2]-- needs to be >= len_max  */
243 
244   k = 0;
245   while (k < nrqr){
246     /* Receive messages */
247     ierr = MPI_Iprobe(MPI_ANY_SOURCE,tag1,comm,&flag,&r_status);CHKERRQ(ierr);
248     if (flag){
249       ierr = MPI_Get_count(&r_status,MPIU_INT,&len);CHKERRQ(ierr);
250       proc_id = r_status.MPI_SOURCE;
251       ierr = MPI_Irecv(odata1,len,MPIU_INT,proc_id,r_status.MPI_TAG,comm,&r_req);CHKERRQ(ierr);
252       ierr = MPI_Wait(&r_req,&r_status);CHKERRQ(ierr);
253 
254       /*  Process messages */
255       /*  make sure there is enough unused space in odata2 array */
256       if (len_unused < len_max){ /* allocate more space for odata2 */
257         ierr = PetscMalloc((len_est+1)*sizeof(PetscInt),&odata2);CHKERRQ(ierr);
258         odata2_ptr[++nodata2] = odata2;
259         len_unused = len_est;
260       }
261 
262       ierr = MatIncreaseOverlap_MPISBAIJ_Local(C,odata1,OTHER,odata2,&otable);CHKERRQ(ierr);
263       len = 1 + odata2[0];
264       for (i=0; i<odata2[0]; i++){
265         len += odata2[1 + i];
266       }
267 
268       /* Send messages back */
269       ierr = MPI_Isend(odata2,len,MPIU_INT,proc_id,tag2,comm,s_waits2+k);CHKERRQ(ierr);
270       k++;
271       odata2     += len;
272       len_unused -= len;
273       len_s[proc_id] = len; /* num of messages sending back to [proc_id] by this proc */
274     }
275   }
276   ierr = PetscFree(odata1);CHKERRQ(ierr);
277   ierr = PetscBTDestroy(otable);CHKERRQ(ierr);
278 
279   /* 3. Do local work on this processor's is[] */
280   /*-------------------------------------------*/
281   /* make sure there is enough unused space in odata2(=data) array */
282   len_max = is_max*(Mbs+1); /* max space storing all is[] for this processor */
283   if (len_unused < len_max){ /* allocate more space for odata2 */
284     ierr = PetscMalloc((len_est+1)*sizeof(PetscInt),&odata2);CHKERRQ(ierr);
285     odata2_ptr[++nodata2] = odata2;
286     len_unused = len_est;
287   }
288 
289   data = odata2;
290   ierr = MatIncreaseOverlap_MPISBAIJ_Local(C,data1_start[rank],MINE,data,table);CHKERRQ(ierr);
291   ierr = PetscFree(data1_start);CHKERRQ(ierr);
292 
293   /* 4. Receive work done on other processors, then merge */
294   /*------------------------------------------------------*/
295   /* get max number of messages that this processor expects to recv */
296   ierr = MPI_Allreduce(len_s,iwork,size,MPIU_INT,MPI_MAX,comm);CHKERRQ(ierr);
297   ierr = PetscMalloc((iwork[rank]+1)*sizeof(PetscInt),&data2);CHKERRQ(ierr);
298   ierr = PetscFree4(len_s,btable,iwork,Bowners);CHKERRQ(ierr);
299 
300   k = 0;
301   while (k < nrqs){
302     /* Receive messages */
303     ierr = MPI_Iprobe(MPI_ANY_SOURCE,tag2,comm,&flag,&r_status);
304     if (flag){
305       ierr = MPI_Get_count(&r_status,MPIU_INT,&len);CHKERRQ(ierr);
306       proc_id = r_status.MPI_SOURCE;
307       ierr = MPI_Irecv(data2,len,MPIU_INT,proc_id,r_status.MPI_TAG,comm,&r_req);CHKERRQ(ierr);
308       ierr = MPI_Wait(&r_req,&r_status);CHKERRQ(ierr);
309       if (len > 1+is_max){ /* Add data2 into data */
310         data2_i = data2 + 1 + is_max;
311         for (i=0; i<is_max; i++){
312           table_i = table[i];
313           data_i  = data + 1 + is_max + Mbs*i;
314           isz     = data[1+i];
315           for (j=0; j<data2[1+i]; j++){
316             col = data2_i[j];
317             if (!PetscBTLookupSet(table_i,col)) {data_i[isz++] = col;}
318           }
319           data[1+i] = isz;
320           if (i < is_max - 1) data2_i += data2[1+i];
321         }
322       }
323       k++;
324     }
325   }
326   ierr = PetscFree(data2);CHKERRQ(ierr);
327   ierr = PetscFree2(table,t_p);CHKERRQ(ierr);
328 
329   /* phase 1 sends are complete */
330   ierr = PetscMalloc(size*sizeof(MPI_Status),&s_status);CHKERRQ(ierr);
331   if (nrqs) {ierr = MPI_Waitall(nrqs,s_waits1,s_status);CHKERRQ(ierr);}
332   ierr = PetscFree(data1);CHKERRQ(ierr);
333 
334   /* phase 2 sends are complete */
335   if (nrqr){ierr = MPI_Waitall(nrqr,s_waits2,s_status);CHKERRQ(ierr);}
336   ierr = PetscFree2(s_waits1,s_waits2);CHKERRQ(ierr);
337   ierr = PetscFree(s_status);CHKERRQ(ierr);
338 
339   /* 5. Create new is[] */
340   /*--------------------*/
341   for (i=0; i<is_max; i++) {
342     data_i = data + 1 + is_max + Mbs*i;
343     ierr = ISCreateGeneral(PETSC_COMM_SELF,data[1+i],data_i,PETSC_COPY_VALUES,is+i);CHKERRQ(ierr);
344   }
345   for (k=0; k<=nodata2; k++){
346     ierr = PetscFree(odata2_ptr[k]);CHKERRQ(ierr);
347   }
348   ierr = PetscFree(odata2_ptr);CHKERRQ(ierr);
349 
350   PetscFunctionReturn(0);
351 }
352 
353 #undef __FUNCT__
354 #define __FUNCT__ "MatIncreaseOverlap_MPISBAIJ_Local"
355 /*
356    MatIncreaseOverlap_MPISBAIJ_Local - Called by MatIncreaseOverlap, to do
357        the work on the local processor.
358 
359      Inputs:
360       C      - MAT_MPISBAIJ;
361       data   - holds is[]. See MatIncreaseOverlap_MPISBAIJ_Once() for the format.
362       whose  - whose is[] to be processed,
363                MINE:  this processor's is[]
364                OTHER: other processor's is[]
365      Output:
366        nidx  - whose = MINE:
367                      holds input and newly found indices in the same format as data
368                whose = OTHER:
369                      only holds the newly found indices
370        table - table[i]: mark the indices of is[i], i=0,...,is_max. Used only in the case 'whose=MINE'.
371 */
372 /* Would computation be reduced by swapping the loop 'for each is' and 'for each row'? */
373 static PetscErrorCode MatIncreaseOverlap_MPISBAIJ_Local(Mat C,PetscInt *data,PetscInt whose,PetscInt *nidx,PetscBT *table)
374 {
375   Mat_MPISBAIJ   *c = (Mat_MPISBAIJ*)C->data;
376   Mat_SeqSBAIJ   *a = (Mat_SeqSBAIJ*)(c->A)->data;
377   Mat_SeqBAIJ    *b = (Mat_SeqBAIJ*)(c->B)->data;
378   PetscErrorCode ierr;
379   PetscInt       row,mbs,Mbs,*nidx_i,col,col_max,isz,isz0,*ai,*aj,*bi,*bj,*garray,rstart,l;
380   PetscInt       a_start,a_end,b_start,b_end,i,j,k,is_max,*idx_i,n;
381   PetscBT        table0;  /* mark the indices of input is[] for look up */
382   PetscBT        table_i; /* poits to i-th table. When whose=OTHER, a single table is used for all is[] */
383 
384   PetscFunctionBegin;
385   Mbs = c->Mbs; mbs = a->mbs;
386   ai = a->i; aj = a->j;
387   bi = b->i; bj = b->j;
388   garray = c->garray;
389   rstart = c->rstartbs;
390   is_max = data[0];
391 
392   ierr = PetscBTCreate(Mbs,table0);CHKERRQ(ierr);
393 
394   nidx[0] = is_max;
395   idx_i   = data + is_max + 1; /* ptr to input is[0] array */
396   nidx_i  = nidx + is_max + 1; /* ptr to output is[0] array */
397   for (i=0; i<is_max; i++) { /* for each is */
398     isz  = 0;
399     n = data[1+i]; /* size of input is[i] */
400 
401     /* initialize and set table_i(mark idx and nidx) and table0(only mark idx) */
402     if (whose == MINE){ /* process this processor's is[] */
403       table_i = table[i];
404       nidx_i  = nidx + 1+ is_max + Mbs*i;
405     } else {            /* process other processor's is[] - only use one temp table */
406       table_i = table[0];
407     }
408     ierr = PetscBTMemzero(Mbs,table_i);CHKERRQ(ierr);
409     ierr = PetscBTMemzero(Mbs,table0);CHKERRQ(ierr);
410     if (n==0) {
411        nidx[1+i] = 0; /* size of new is[i] */
412        continue;
413     }
414 
415     isz0 = 0; col_max = 0;
416     for (j=0; j<n; j++){
417       col = idx_i[j];
418       if (col >= Mbs) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"index col %D >= Mbs %D",col,Mbs);
419       if(!PetscBTLookupSet(table_i,col)) {
420         ierr = PetscBTSet(table0,col);CHKERRQ(ierr);
421         if (whose == MINE) {nidx_i[isz0] = col;}
422         if (col_max < col) col_max = col;
423         isz0++;
424       }
425     }
426 
427     if (whose == MINE) {isz = isz0;}
428     k = 0;  /* no. of indices from input is[i] that have been examined */
429     for (row=0; row<mbs; row++){
430       a_start = ai[row]; a_end = ai[row+1];
431       b_start = bi[row]; b_end = bi[row+1];
432       if (PetscBTLookup(table0,row+rstart)){ /* row is on input is[i]:
433                                                 do row search: collect all col in this row */
434         for (l = a_start; l<a_end ; l++){ /* Amat */
435           col = aj[l] + rstart;
436           if (!PetscBTLookupSet(table_i,col)) {nidx_i[isz++] = col;}
437         }
438         for (l = b_start; l<b_end ; l++){ /* Bmat */
439           col = garray[bj[l]];
440           if (!PetscBTLookupSet(table_i,col)) {nidx_i[isz++] = col;}
441         }
442         k++;
443         if (k >= isz0) break; /* for (row=0; row<mbs; row++) */
444       } else { /* row is not on input is[i]:
445                   do col serach: add row onto nidx_i if there is a col in nidx_i */
446         for (l = a_start; l<a_end ; l++){ /* Amat */
447           col = aj[l] + rstart;
448           if (col > col_max) break;
449           if (PetscBTLookup(table0,col)){
450             if (!PetscBTLookupSet(table_i,row+rstart)) {nidx_i[isz++] = row+rstart;}
451             break; /* for l = start; l<end ; l++) */
452           }
453         }
454         for (l = b_start; l<b_end ; l++){ /* Bmat */
455           col = garray[bj[l]];
456           if (col > col_max) break;
457           if (PetscBTLookup(table0,col)){
458             if (!PetscBTLookupSet(table_i,row+rstart)) {nidx_i[isz++] = row+rstart;}
459             break; /* for l = start; l<end ; l++) */
460           }
461         }
462       }
463     }
464 
465     if (i < is_max - 1){
466       idx_i  += n;   /* ptr to input is[i+1] array */
467       nidx_i += isz; /* ptr to output is[i+1] array */
468     }
469     nidx[1+i] = isz; /* size of new is[i] */
470   } /* for each is */
471   ierr = PetscBTDestroy(table0);CHKERRQ(ierr);
472 
473   PetscFunctionReturn(0);
474 }
475 
476 
477