xref: /petsc/src/mat/impls/baij/seq/baijfact3.c (revision 359bf53fd806cdd853c362eb03caf614f9134eaa)
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->free_diag  = PETSC_TRUE;
239   b->ilen       = 0;
240   b->imax       = 0;
241   b->row        = isrow;
242   b->col        = iscol;
243   b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
244   ierr          = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
245   ierr          = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
246   b->icol       = isicol;
247   ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
248   ierr = PetscLogObjectMemory(B,(bi[2*n+1])*(sizeof(PetscInt)+sizeof(PetscScalar)*bs2));CHKERRQ(ierr);
249 
250   b->maxnz = b->nz = bi[2*n+1];
251   B->factor                =  MAT_FACTOR_LU;
252   B->info.factor_mallocs   = reallocs;
253   B->info.fill_ratio_given = f;
254 
255   if (ai[n] != 0) {
256     B->info.fill_ratio_needed = ((PetscReal)bi[2*n+1])/((PetscReal)ai[n]);
257   } else {
258     B->info.fill_ratio_needed = 0.0;
259   }
260 
261   B->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_N_newdatastruct;
262 
263   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
264   ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr);
265   both_identity = (PetscTruth) (row_identity && col_identity);
266   if(both_identity){
267      switch(bs){
268      case 2:
269         B->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_2_NaturalOrdering_newdatastruct;
270         B->ops->solve           = MatSolve_SeqBAIJ_2_NaturalOrdering_newdatastruct;
271         break;
272      case 3:
273 	B->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_3_NaturalOrdering_newdatastruct;
274         B->ops->solve = MatSolve_SeqBAIJ_3_NaturalOrdering_newdatastruct;
275         break;
276      case 4:
277         B->ops->solve = MatSolve_SeqBAIJ_4_NaturalOrdering_newdatastruct;
278         break;
279      case 5:
280         B->ops->solve = MatSolve_SeqBAIJ_5_NaturalOrdering_newdatastruct;
281         break;
282      case 6:
283         B->ops->solve = MatSolve_SeqBAIJ_6_NaturalOrdering_newdatastruct;
284         break;
285      case 7:
286         B->ops->solve = MatSolve_SeqBAIJ_7_NaturalOrdering_newdatastruct;
287         break;
288      default:
289         B->ops->solve = MatSolve_SeqBAIJ_N_NaturalOrdering_newdatastruct;
290       }
291    }
292    else {
293      switch(bs){
294      case 2:
295         B->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_2_newdatastruct;
296         B->ops->solve           = MatSolve_SeqBAIJ_2_newdatastruct;
297         break;
298      case 3:
299 	B->ops->lufactornumeric = MatLUFactorNumeric_SeqBAIJ_3_newdatastruct;
300         B->ops->solve = MatSolve_SeqBAIJ_3_newdatastruct;
301         break;
302      case 4:
303         B->ops->solve = MatSolve_SeqBAIJ_4_newdatastruct;
304         break;
305      case 5:
306         B->ops->solve = MatSolve_SeqBAIJ_5_newdatastruct;
307         break;
308      case 6:
309         B->ops->solve = MatSolve_SeqBAIJ_6_newdatastruct;
310         break;
311      case 7:
312         B->ops->solve = MatSolve_SeqBAIJ_7_newdatastruct;
313         break;
314      default:
315         B->ops->solve = MatSolve_SeqBAIJ_N_newdatastruct;
316       }
317    }
318   /*  ierr = MatSeqBAIJSetNumericFactorization(B,both_identity);CHKERRQ(ierr); */
319   PetscFunctionReturn(0);
320  }
321 
322 #undef __FUNCT__
323 #define __FUNCT__ "MatLUFactorSymbolic_SeqBAIJ"
324 PetscErrorCode MatLUFactorSymbolic_SeqBAIJ(Mat B,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
325 {
326   Mat_SeqBAIJ        *a = (Mat_SeqBAIJ*)A->data,*b;
327   PetscInt           n=a->mbs,bs = A->rmap->bs,bs2=a->bs2;
328   PetscTruth         row_identity,col_identity,both_identity;
329   IS                 isicol;
330   PetscErrorCode     ierr;
331   const PetscInt     *r,*ic;
332   PetscInt           i,*ai=a->i,*aj=a->j;
333   PetscInt           *bi,*bj,*ajtmp;
334   PetscInt           *bdiag,row,nnz,nzi,reallocs=0,nzbd,*im;
335   PetscReal          f;
336   PetscInt           nlnk,*lnk,k,**bi_ptr;
337   PetscFreeSpaceList free_space=PETSC_NULL,current_space=PETSC_NULL;
338   PetscBT            lnkbt;
339   PetscTruth         newdatastruct=PETSC_FALSE;
340 
341   PetscFunctionBegin;
342   ierr = PetscOptionsGetTruth(PETSC_NULL,"-lu_new",&newdatastruct,PETSC_NULL);CHKERRQ(ierr);
343   if(newdatastruct){
344     ierr = MatLUFactorSymbolic_SeqBAIJ_newdatastruct(B,A,isrow,iscol,info);CHKERRQ(ierr);
345     PetscFunctionReturn(0);
346   }
347 
348   if (A->rmap->N != A->cmap->N) SETERRQ(PETSC_ERR_ARG_WRONG,"matrix must be square");
349   ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr);
350   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
351   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
352 
353   /* get new row pointers */
354   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bi);CHKERRQ(ierr);
355   bi[0] = 0;
356 
357   /* bdiag is location of diagonal in factor */
358   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bdiag);CHKERRQ(ierr);
359   bdiag[0] = 0;
360 
361   /* linked list for storing column indices of the active row */
362   nlnk = n + 1;
363   ierr = PetscLLCreate(n,n,nlnk,lnk,lnkbt);CHKERRQ(ierr);
364 
365   ierr = PetscMalloc2(n+1,PetscInt**,&bi_ptr,n+1,PetscInt,&im);CHKERRQ(ierr);
366 
367   /* initial FreeSpace size is f*(ai[n]+1) */
368   f = info->fill;
369   ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space);CHKERRQ(ierr);
370   current_space = free_space;
371 
372   for (i=0; i<n; i++) {
373     /* copy previous fill into linked list */
374     nzi = 0;
375     nnz = ai[r[i]+1] - ai[r[i]];
376     if (!nnz) SETERRQ2(PETSC_ERR_MAT_LU_ZRPVT,"Empty row in matrix: row in original ordering %D in permuted ordering %D",r[i],i);
377     ajtmp = aj + ai[r[i]];
378     ierr = PetscLLAddPerm(nnz,ajtmp,ic,n,nlnk,lnk,lnkbt);CHKERRQ(ierr);
379     nzi += nlnk;
380 
381     /* add pivot rows into linked list */
382     row = lnk[n];
383     while (row < i) {
384       nzbd    = bdiag[row] - bi[row] + 1; /* num of entries in the row with column index <= row */
385       ajtmp   = bi_ptr[row] + nzbd; /* points to the entry next to the diagonal */
386       ierr = PetscLLAddSortedLU(ajtmp,row,nlnk,lnk,lnkbt,i,nzbd,im);CHKERRQ(ierr);
387       nzi += nlnk;
388       row  = lnk[row];
389     }
390     bi[i+1] = bi[i] + nzi;
391     im[i]   = nzi;
392 
393     /* mark bdiag */
394     nzbd = 0;
395     nnz  = nzi;
396     k    = lnk[n];
397     while (nnz-- && k < i){
398       nzbd++;
399       k = lnk[k];
400     }
401     bdiag[i] = bi[i] + nzbd;
402 
403     /* if free space is not available, make more free space */
404     if (current_space->local_remaining<nzi) {
405       nnz = (n - i)*nzi; /* estimated and max additional space needed */
406       ierr = PetscFreeSpaceGet(nnz,&current_space);CHKERRQ(ierr);
407       reallocs++;
408     }
409 
410     /* copy data into free space, then initialize lnk */
411     ierr = PetscLLClean(n,n,nzi,lnk,current_space->array,lnkbt);CHKERRQ(ierr);
412     bi_ptr[i] = current_space->array;
413     current_space->array           += nzi;
414     current_space->local_used      += nzi;
415     current_space->local_remaining -= nzi;
416   }
417 #if defined(PETSC_USE_INFO)
418   if (ai[n] != 0) {
419     PetscReal af = ((PetscReal)bi[n])/((PetscReal)ai[n]);
420     ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocs,f,af);CHKERRQ(ierr);
421     ierr = PetscInfo1(A,"Run with -pc_factor_fill %G or use \n",af);CHKERRQ(ierr);
422     ierr = PetscInfo1(A,"PCFactorSetFill(pc,%G);\n",af);CHKERRQ(ierr);
423     ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr);
424   } else {
425     ierr = PetscInfo(A,"Empty matrix\n");CHKERRQ(ierr);
426   }
427 #endif
428 
429   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
430   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
431 
432   /* destroy list of free space and other temporary array(s) */
433   ierr = PetscMalloc((bi[n]+1)*sizeof(PetscInt),&bj);CHKERRQ(ierr);
434   ierr = PetscFreeSpaceContiguous(&free_space,bj);CHKERRQ(ierr);
435   ierr = PetscLLDestroy(lnk,lnkbt);CHKERRQ(ierr);
436   ierr = PetscFree2(bi_ptr,im);CHKERRQ(ierr);
437 
438   /* put together the new matrix */
439   ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(B,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr);
440   ierr = PetscLogObjectParent(B,isicol);CHKERRQ(ierr);
441   b    = (Mat_SeqBAIJ*)(B)->data;
442   b->free_a       = PETSC_TRUE;
443   b->free_ij      = PETSC_TRUE;
444   b->singlemalloc = PETSC_FALSE;
445   ierr          = PetscMalloc((bi[n]+1)*sizeof(MatScalar)*bs2,&b->a);CHKERRQ(ierr);
446   b->j          = bj;
447   b->i          = bi;
448   b->diag       = bdiag;
449   b->free_diag  = PETSC_TRUE;
450   b->ilen       = 0;
451   b->imax       = 0;
452   b->row        = isrow;
453   b->col        = iscol;
454   b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
455   ierr          = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
456   ierr          = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
457   b->icol       = isicol;
458   ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
459   ierr = PetscLogObjectMemory(B,(bi[n]-n)*(sizeof(PetscInt)+sizeof(PetscScalar)*bs2));CHKERRQ(ierr);
460 
461   b->maxnz = b->nz = bi[n] ;
462   (B)->factor                =  MAT_FACTOR_LU;
463   (B)->info.factor_mallocs   = reallocs;
464   (B)->info.fill_ratio_given = f;
465 
466   if (ai[n] != 0) {
467     (B)->info.fill_ratio_needed = ((PetscReal)bi[n])/((PetscReal)ai[n]);
468   } else {
469     (B)->info.fill_ratio_needed = 0.0;
470   }
471 
472   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
473   ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr);
474   both_identity = (PetscTruth) (row_identity && col_identity);
475   ierr = MatSeqBAIJSetNumericFactorization(B,both_identity);CHKERRQ(ierr);
476   PetscFunctionReturn(0);
477  }
478 
479