xref: /petsc/src/mat/impls/baij/seq/baijfact3.c (revision 911f9fe8bd6cba67889e436249bb2d60a401f759)
1 #define PETSCMAT_DLL
2 
3 /*
4     Factorization code for BAIJ format.
5 */
6 #include "../src/mat/impls/baij/seq/baij.h"
7 #include "../src/mat/blockinvert.h"
8 
9 #undef __FUNCT__
10 #define __FUNCT__ "MatSeqBAIJSetNumericFactorization"
11 /*
12    This is used to set the numeric factorization for both LU and ILU symbolic factorization
13 */
14 PetscErrorCode MatSeqBAIJSetNumericFactorization(Mat inA,PetscTruth natural)
15 {
16   PetscFunctionBegin;
17   if (natural) {
18     switch (inA->rmap->bs) {
19     case 1:
20       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_1;
21       break;
22     case 2:
23       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_2_NaturalOrdering;
24       break;
25     case 3:
26       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_3_NaturalOrdering;
27       break;
28     case 4:
29 #if defined(PETSC_USE_MAT_SINGLE)
30       {
31         PetscTruth  sse_enabled_local;
32         PetscErrorCode ierr;
33         ierr = PetscSSEIsEnabled(inA->comm,&sse_enabled_local,PETSC_NULL);CHKERRQ(ierr);
34         if (sse_enabled_local) {
35 #  if defined(PETSC_HAVE_SSE)
36           int i,*AJ=a->j,nz=a->nz,n=a->mbs;
37           if (n==(unsigned short)n) {
38             unsigned short *aj=(unsigned short *)AJ;
39             for (i=0;i<nz;i++) {
40               aj[i] = (unsigned short)AJ[i];
41             }
42             inA->ops->setunfactored   = MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE_usj;
43             inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_4_NaturalOrdering_SSE_usj;
44             ierr = PetscInfo(inA,"Using special SSE, in-place natural ordering, ushort j index factor BS=4\n");CHKERRQ(ierr);
45           } else {
46         /* Scale the column indices for easier indexing in MatSolve. */
47 /*            for (i=0;i<nz;i++) { */
48 /*              AJ[i] = AJ[i]*4; */
49 /*            } */
50             inA->ops->setunfactored   = MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE;
51             inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_4_NaturalOrdering_SSE;
52             ierr = PetscInfo(inA,"Using special SSE, in-place natural ordering, int j index factor BS=4\n");CHKERRQ(ierr);
53           }
54 #  else
55         /* This should never be reached.  If so, problem in PetscSSEIsEnabled. */
56           SETERRQ(PETSC_ERR_SUP,"SSE Hardware unavailable");
57 #  endif
58         } else {
59           inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_4_NaturalOrdering;
60         }
61       }
62 #else
63       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_4_NaturalOrdering;
64 #endif
65       break;
66     case 5:
67       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_5_NaturalOrdering;
68       break;
69     case 6:
70       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_6_NaturalOrdering;
71       break;
72     case 7:
73       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_7_NaturalOrdering;
74       break;
75     default:
76       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_N;
77       break;
78     }
79   } else {
80     switch (inA->rmap->bs) {
81     case 1:
82       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_1;
83       break;
84     case 2:
85       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_2;
86       break;
87     case 3:
88       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_3;
89       break;
90     case 4:
91       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_4;
92       break;
93     case 5:
94       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_5;
95       break;
96     case 6:
97       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_6;
98       break;
99     case 7:
100       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_7;
101       break;
102     default:
103       inA->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_N;
104       break;
105     }
106   }
107   PetscFunctionReturn(0);
108 }
109 
110 /*
111     The symbolic factorization code is identical to that for AIJ format,
112   except for very small changes since this is now a SeqBAIJ datastructure.
113   NOT good code reuse.
114 */
115 #include "petscbt.h"
116 #include "../src/mat/utils/freespace.h"
117 
118 #undef __FUNCT__
119 #define __FUNCT__ "MatLUFactorSymbolic_SeqBAIJ_newdatastruct"
120 PetscErrorCode MatLUFactorSymbolic_SeqBAIJ_newdatastruct(Mat B,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
121 {
122   Mat_SeqBAIJ        *a = (Mat_SeqBAIJ*)A->data,*b;
123   PetscInt           n=a->mbs,bs = A->rmap->bs,bs2=a->bs2;
124   PetscTruth         row_identity,col_identity,both_identity;
125   IS                 isicol;
126   PetscErrorCode     ierr;
127   const PetscInt     *r,*ic;
128   PetscInt           i,*ai=a->i,*aj=a->j;
129   PetscInt           *bi,*bj,*ajtmp;
130   PetscInt           *bdiag,row,nnz,nzi,reallocs=0,nzbd,*im;
131   PetscReal          f;
132   PetscInt           nlnk,*lnk,k,**bi_ptr;
133   PetscFreeSpaceList free_space=PETSC_NULL,current_space=PETSC_NULL;
134   PetscBT            lnkbt;
135 
136   PetscFunctionBegin;
137   if (A->rmap->N != A->cmap->N) SETERRQ(PETSC_ERR_ARG_WRONG,"matrix must be square");
138   ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr);
139   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
140   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
141 
142   /* get new row pointers */
143   ierr = PetscMalloc((2*n+2)*sizeof(PetscInt),&bi);CHKERRQ(ierr);
144   bi[0] = 0;
145 
146   /* bdiag is location of diagonal in factor */
147   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bdiag);CHKERRQ(ierr);
148   bdiag[0] = 0;
149 
150   /* linked list for storing column indices of the active row */
151   nlnk = n + 1;
152   ierr = PetscLLCreate(n,n,nlnk,lnk,lnkbt);CHKERRQ(ierr);
153 
154   ierr = PetscMalloc2(n+1,PetscInt**,&bi_ptr,n+1,PetscInt,&im);CHKERRQ(ierr);
155 
156   /* initial FreeSpace size is f*(ai[n]+1) */
157   f = info->fill;
158   ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space);CHKERRQ(ierr);
159   current_space = free_space;
160 
161   for (i=0; i<n; i++) {
162     /* copy previous fill into linked list */
163     nzi = 0;
164     nnz = ai[r[i]+1] - ai[r[i]];
165     if (!nnz) SETERRQ2(PETSC_ERR_MAT_LU_ZRPVT,"Empty row in matrix: row in original ordering %D in permuted ordering %D",r[i],i);
166     ajtmp = aj + ai[r[i]];
167     ierr = PetscLLAddPerm(nnz,ajtmp,ic,n,nlnk,lnk,lnkbt);CHKERRQ(ierr);
168     nzi += nlnk;
169 
170     /* add pivot rows into linked list */
171     row = lnk[n];
172     while (row < i) {
173       nzbd    = bdiag[row] + 1; /* num of entries in the row with column index <= row */
174       ajtmp   = bi_ptr[row] + nzbd; /* points to the entry next to the diagonal */
175       ierr = PetscLLAddSortedLU(ajtmp,row,nlnk,lnk,lnkbt,i,nzbd,im);CHKERRQ(ierr);
176       nzi += nlnk;
177       row  = lnk[row];
178     }
179     bi[i+1] = bi[i] + nzi;
180     im[i]   = nzi;
181 
182     /* mark bdiag */
183     nzbd = 0;
184     nnz  = nzi;
185     k    = lnk[n];
186     while (nnz-- && k < i){
187       nzbd++;
188       k = lnk[k];
189     }
190     bdiag[i] = nzbd; /* note : bdaig[i] = nnzL as input for PetscFreeSpaceContiguous_LU() */
191 
192     /* if free space is not available, make more free space */
193     if (current_space->local_remaining<nzi) {
194       nnz = 2*(n - i)*nzi; /* estimated and max additional space needed */
195       ierr = PetscFreeSpaceGet(nnz,&current_space);CHKERRQ(ierr);
196       reallocs++;
197     }
198 
199     /* copy data into free space, then initialize lnk */
200     ierr = PetscLLClean(n,n,nzi,lnk,current_space->array,lnkbt);CHKERRQ(ierr);
201     bi_ptr[i] = current_space->array;
202     current_space->array           += nzi;
203     current_space->local_used      += nzi;
204     current_space->local_remaining -= nzi;
205   }
206 #if defined(PETSC_USE_INFO)
207   if (ai[n] != 0) {
208     PetscReal af = ((PetscReal)bi[n])/((PetscReal)ai[n]);
209     ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocs,f,af);CHKERRQ(ierr);
210     ierr = PetscInfo1(A,"Run with -pc_factor_fill %G or use \n",af);CHKERRQ(ierr);
211     ierr = PetscInfo1(A,"PCFactorSetFill(pc,%G);\n",af);CHKERRQ(ierr);
212     ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr);
213   } else {
214     ierr = PetscInfo(A,"Empty matrix\n");CHKERRQ(ierr);
215   }
216 #endif
217 
218   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
219   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
220 
221   /* destroy list of free space and other temporary array(s) */
222   ierr = PetscMalloc((bi[n]+1)*sizeof(PetscInt),&bj);CHKERRQ(ierr);
223   ierr = PetscFreeSpaceContiguous_LU(&free_space,bj,n,bi,bdiag);CHKERRQ(ierr);
224   ierr = PetscLLDestroy(lnk,lnkbt);CHKERRQ(ierr);
225   ierr = PetscFree2(bi_ptr,im);CHKERRQ(ierr);
226 
227   /* put together the new matrix */
228   ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(B,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr);
229   ierr = PetscLogObjectParent(B,isicol);CHKERRQ(ierr);
230   b    = (Mat_SeqBAIJ*)(B)->data;
231   b->free_a       = PETSC_TRUE;
232   b->free_ij      = PETSC_TRUE;
233   b->singlemalloc = PETSC_FALSE;
234   ierr          = PetscMalloc((bi[2*n+1])*sizeof(MatScalar)*bs2,&b->a);CHKERRQ(ierr);
235   b->j          = bj;
236   b->i          = bi;
237   b->diag       = bdiag;
238   b->ilen       = 0;
239   b->imax       = 0;
240   b->row        = isrow;
241   b->col        = iscol;
242   b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
243   ierr          = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
244   ierr          = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
245   b->icol       = isicol;
246   ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
247   ierr = PetscLogObjectMemory(B,(bi[2*n+1])*(sizeof(PetscInt)+sizeof(PetscScalar)*bs2));CHKERRQ(ierr);
248 
249   b->maxnz = b->nz = bi[2*n+1];
250   B->factor                =  MAT_FACTOR_LU;
251   B->info.factor_mallocs   = reallocs;
252   B->info.fill_ratio_given = f;
253 
254   if (ai[n] != 0) {
255     B->info.fill_ratio_needed = ((PetscReal)bi[2*n+1])/((PetscReal)ai[n]);
256   } else {
257     B->info.fill_ratio_needed = 0.0;
258   }
259 
260   B->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_N_newdatastruct;
261 
262   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
263   ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr);
264   both_identity = (PetscTruth) (row_identity && col_identity);
265   if(both_identity){
266      switch(bs){
267      case 2:
268         B->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_2_NaturalOrdering_newdatastruct;
269         B->ops->solve           = MatSolve_SeqBAIJ_2_NaturalOrdering_newdatastruct;
270         break;
271      case 3:
272         B->ops->solve = MatSolve_SeqBAIJ_3_NaturalOrdering_newdatastruct;
273         break;
274      case 4:
275         B->ops->solve = MatSolve_SeqBAIJ_4_NaturalOrdering_newdatastruct;
276         break;
277      case 5:
278         B->ops->solve = MatSolve_SeqBAIJ_5_NaturalOrdering_newdatastruct;
279         break;
280      case 6:
281         B->ops->solve = MatSolve_SeqBAIJ_6_NaturalOrdering_newdatastruct;
282         break;
283      case 7:
284         B->ops->solve = MatSolve_SeqBAIJ_7_NaturalOrdering_newdatastruct;
285         break;
286      default:
287         B->ops->solve = MatSolve_SeqBAIJ_N_NaturalOrdering_newdatastruct;
288       }
289    }
290    else {
291      switch(bs){
292      case 2:
293         B->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_2_newdatastruct;
294         B->ops->solve           = MatSolve_SeqBAIJ_2_newdatastruct;
295         break;
296      case 3:
297         B->ops->solve = MatSolve_SeqBAIJ_3_newdatastruct;
298         break;
299      case 4:
300         B->ops->solve = MatSolve_SeqBAIJ_4_newdatastruct;
301         break;
302      case 5:
303         B->ops->solve = MatSolve_SeqBAIJ_5_newdatastruct;
304         break;
305      case 6:
306         B->ops->solve = MatSolve_SeqBAIJ_6_newdatastruct;
307         break;
308      case 7:
309         B->ops->solve = MatSolve_SeqBAIJ_7_newdatastruct;
310         break;
311      default:
312         B->ops->solve = MatSolve_SeqBAIJ_N_newdatastruct;
313       }
314    }
315   /*  ierr = MatSeqBAIJSetNumericFactorization(B,both_identity);CHKERRQ(ierr); */
316   PetscFunctionReturn(0);
317  }
318 
319 #undef __FUNCT__
320 #define __FUNCT__ "MatLUFactorSymbolic_SeqBAIJ"
321 PetscErrorCode MatLUFactorSymbolic_SeqBAIJ(Mat B,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
322 {
323   Mat_SeqBAIJ        *a = (Mat_SeqBAIJ*)A->data,*b;
324   PetscInt           n=a->mbs,bs = A->rmap->bs,bs2=a->bs2;
325   PetscTruth         row_identity,col_identity,both_identity;
326   IS                 isicol;
327   PetscErrorCode     ierr;
328   const PetscInt     *r,*ic;
329   PetscInt           i,*ai=a->i,*aj=a->j;
330   PetscInt           *bi,*bj,*ajtmp;
331   PetscInt           *bdiag,row,nnz,nzi,reallocs=0,nzbd,*im;
332   PetscReal          f;
333   PetscInt           nlnk,*lnk,k,**bi_ptr;
334   PetscFreeSpaceList free_space=PETSC_NULL,current_space=PETSC_NULL;
335   PetscBT            lnkbt;
336   PetscTruth         newdatastruct=PETSC_FALSE;
337 
338   PetscFunctionBegin;
339   ierr = PetscOptionsGetTruth(PETSC_NULL,"-lu_new",&newdatastruct,PETSC_NULL);CHKERRQ(ierr);
340   if(newdatastruct){
341     ierr = MatLUFactorSymbolic_SeqBAIJ_newdatastruct(B,A,isrow,iscol,info);CHKERRQ(ierr);
342     PetscFunctionReturn(0);
343   }
344 
345   if (A->rmap->N != A->cmap->N) SETERRQ(PETSC_ERR_ARG_WRONG,"matrix must be square");
346   ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr);
347   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
348   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
349 
350   /* get new row pointers */
351   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bi);CHKERRQ(ierr);
352   bi[0] = 0;
353 
354   /* bdiag is location of diagonal in factor */
355   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bdiag);CHKERRQ(ierr);
356   bdiag[0] = 0;
357 
358   /* linked list for storing column indices of the active row */
359   nlnk = n + 1;
360   ierr = PetscLLCreate(n,n,nlnk,lnk,lnkbt);CHKERRQ(ierr);
361 
362   ierr = PetscMalloc2(n+1,PetscInt**,&bi_ptr,n+1,PetscInt,&im);CHKERRQ(ierr);
363 
364   /* initial FreeSpace size is f*(ai[n]+1) */
365   f = info->fill;
366   ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space);CHKERRQ(ierr);
367   current_space = free_space;
368 
369   for (i=0; i<n; i++) {
370     /* copy previous fill into linked list */
371     nzi = 0;
372     nnz = ai[r[i]+1] - ai[r[i]];
373     if (!nnz) SETERRQ2(PETSC_ERR_MAT_LU_ZRPVT,"Empty row in matrix: row in original ordering %D in permuted ordering %D",r[i],i);
374     ajtmp = aj + ai[r[i]];
375     ierr = PetscLLAddPerm(nnz,ajtmp,ic,n,nlnk,lnk,lnkbt);CHKERRQ(ierr);
376     nzi += nlnk;
377 
378     /* add pivot rows into linked list */
379     row = lnk[n];
380     while (row < i) {
381       nzbd    = bdiag[row] - bi[row] + 1; /* num of entries in the row with column index <= row */
382       ajtmp   = bi_ptr[row] + nzbd; /* points to the entry next to the diagonal */
383       ierr = PetscLLAddSortedLU(ajtmp,row,nlnk,lnk,lnkbt,i,nzbd,im);CHKERRQ(ierr);
384       nzi += nlnk;
385       row  = lnk[row];
386     }
387     bi[i+1] = bi[i] + nzi;
388     im[i]   = nzi;
389 
390     /* mark bdiag */
391     nzbd = 0;
392     nnz  = nzi;
393     k    = lnk[n];
394     while (nnz-- && k < i){
395       nzbd++;
396       k = lnk[k];
397     }
398     bdiag[i] = bi[i] + nzbd;
399 
400     /* if free space is not available, make more free space */
401     if (current_space->local_remaining<nzi) {
402       nnz = (n - i)*nzi; /* estimated and max additional space needed */
403       ierr = PetscFreeSpaceGet(nnz,&current_space);CHKERRQ(ierr);
404       reallocs++;
405     }
406 
407     /* copy data into free space, then initialize lnk */
408     ierr = PetscLLClean(n,n,nzi,lnk,current_space->array,lnkbt);CHKERRQ(ierr);
409     bi_ptr[i] = current_space->array;
410     current_space->array           += nzi;
411     current_space->local_used      += nzi;
412     current_space->local_remaining -= nzi;
413   }
414 #if defined(PETSC_USE_INFO)
415   if (ai[n] != 0) {
416     PetscReal af = ((PetscReal)bi[n])/((PetscReal)ai[n]);
417     ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocs,f,af);CHKERRQ(ierr);
418     ierr = PetscInfo1(A,"Run with -pc_factor_fill %G or use \n",af);CHKERRQ(ierr);
419     ierr = PetscInfo1(A,"PCFactorSetFill(pc,%G);\n",af);CHKERRQ(ierr);
420     ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr);
421   } else {
422     ierr = PetscInfo(A,"Empty matrix\n");CHKERRQ(ierr);
423   }
424 #endif
425 
426   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
427   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
428 
429   /* destroy list of free space and other temporary array(s) */
430   ierr = PetscMalloc((bi[n]+1)*sizeof(PetscInt),&bj);CHKERRQ(ierr);
431   ierr = PetscFreeSpaceContiguous(&free_space,bj);CHKERRQ(ierr);
432   ierr = PetscLLDestroy(lnk,lnkbt);CHKERRQ(ierr);
433   ierr = PetscFree2(bi_ptr,im);CHKERRQ(ierr);
434 
435   /* put together the new matrix */
436   ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(B,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr);
437   ierr = PetscLogObjectParent(B,isicol);CHKERRQ(ierr);
438   b    = (Mat_SeqBAIJ*)(B)->data;
439   b->free_a       = PETSC_TRUE;
440   b->free_ij      = PETSC_TRUE;
441   b->singlemalloc = PETSC_FALSE;
442   ierr          = PetscMalloc((bi[n]+1)*sizeof(MatScalar)*bs2,&b->a);CHKERRQ(ierr);
443   b->j          = bj;
444   b->i          = bi;
445   b->diag       = bdiag;
446   b->ilen       = 0;
447   b->imax       = 0;
448   b->row        = isrow;
449   b->col        = iscol;
450   b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
451   ierr          = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
452   ierr          = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
453   b->icol       = isicol;
454   ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
455   ierr = PetscLogObjectMemory(B,(bi[n]-n)*(sizeof(PetscInt)+sizeof(PetscScalar)*bs2));CHKERRQ(ierr);
456 
457   b->maxnz = b->nz = bi[n] ;
458   (B)->factor                =  MAT_FACTOR_LU;
459   (B)->info.factor_mallocs   = reallocs;
460   (B)->info.fill_ratio_given = f;
461 
462   if (ai[n] != 0) {
463     (B)->info.fill_ratio_needed = ((PetscReal)bi[n])/((PetscReal)ai[n]);
464   } else {
465     (B)->info.fill_ratio_needed = 0.0;
466   }
467 
468   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
469   ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr);
470   both_identity = (PetscTruth) (row_identity && col_identity);
471   ierr = MatSeqBAIJSetNumericFactorization(B,both_identity);CHKERRQ(ierr);
472   PetscFunctionReturn(0);
473  }
474 
475