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/inline/ilu.h" 8 9 /* ------------------------------------------------------------*/ 10 /* 11 Version for when blocks are 2 by 2 12 */ 13 #undef __FUNCT__ 14 #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_2" 15 PetscErrorCode MatLUFactorNumeric_SeqBAIJ_2(Mat B,Mat A,const MatFactorInfo *info) 16 { 17 Mat C = B; 18 Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 19 IS isrow = b->row,isicol = b->icol; 20 PetscErrorCode ierr; 21 const PetscInt *r,*ic; 22 PetscInt i,j,n = a->mbs,*bi = b->i,*bj = b->j; 23 PetscInt *ajtmpold,*ajtmp,nz,row; 24 PetscInt *diag_offset=b->diag,idx,*ai=a->i,*aj=a->j,*pj; 25 MatScalar *pv,*v,*rtmp,m1,m2,m3,m4,*pc,*w,*x,x1,x2,x3,x4; 26 MatScalar p1,p2,p3,p4; 27 MatScalar *ba = b->a,*aa = a->a; 28 PetscReal shift = info->shiftinblocks; 29 30 PetscFunctionBegin; 31 ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 32 ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 33 ierr = PetscMalloc(4*(n+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr); 34 35 for (i=0; i<n; i++) { 36 nz = bi[i+1] - bi[i]; 37 ajtmp = bj + bi[i]; 38 for (j=0; j<nz; j++) { 39 x = rtmp+4*ajtmp[j]; x[0] = x[1] = x[2] = x[3] = 0.0; 40 } 41 /* load in initial (unfactored row) */ 42 idx = r[i]; 43 nz = ai[idx+1] - ai[idx]; 44 ajtmpold = aj + ai[idx]; 45 v = aa + 4*ai[idx]; 46 for (j=0; j<nz; j++) { 47 x = rtmp+4*ic[ajtmpold[j]]; 48 x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 49 v += 4; 50 } 51 row = *ajtmp++; 52 while (row < i) { 53 pc = rtmp + 4*row; 54 p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 55 if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0) { 56 pv = ba + 4*diag_offset[row]; 57 pj = bj + diag_offset[row] + 1; 58 x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 59 pc[0] = m1 = p1*x1 + p3*x2; 60 pc[1] = m2 = p2*x1 + p4*x2; 61 pc[2] = m3 = p1*x3 + p3*x4; 62 pc[3] = m4 = p2*x3 + p4*x4; 63 nz = bi[row+1] - diag_offset[row] - 1; 64 pv += 4; 65 for (j=0; j<nz; j++) { 66 x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 67 x = rtmp + 4*pj[j]; 68 x[0] -= m1*x1 + m3*x2; 69 x[1] -= m2*x1 + m4*x2; 70 x[2] -= m1*x3 + m3*x4; 71 x[3] -= m2*x3 + m4*x4; 72 pv += 4; 73 } 74 ierr = PetscLogFlops(16*nz+12);CHKERRQ(ierr); 75 } 76 row = *ajtmp++; 77 } 78 /* finished row so stick it into b->a */ 79 pv = ba + 4*bi[i]; 80 pj = bj + bi[i]; 81 nz = bi[i+1] - bi[i]; 82 for (j=0; j<nz; j++) { 83 x = rtmp+4*pj[j]; 84 pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 85 pv += 4; 86 } 87 /* invert diagonal block */ 88 w = ba + 4*diag_offset[i]; 89 ierr = Kernel_A_gets_inverse_A_2(w,shift);CHKERRQ(ierr); 90 } 91 92 ierr = PetscFree(rtmp);CHKERRQ(ierr); 93 ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 94 ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 95 C->ops->solve = MatSolve_SeqBAIJ_2; 96 C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_2; 97 C->assembled = PETSC_TRUE; 98 ierr = PetscLogFlops(1.3333*8*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */ 99 PetscFunctionReturn(0); 100 } 101 /* 102 Version for when blocks are 2 by 2 Using natural ordering 103 */ 104 #undef __FUNCT__ 105 #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_2_NaturalOrdering" 106 PetscErrorCode MatLUFactorNumeric_SeqBAIJ_2_NaturalOrdering(Mat C,Mat A,const MatFactorInfo *info) 107 { 108 Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 109 PetscErrorCode ierr; 110 PetscInt i,j,n = a->mbs,*bi = b->i,*bj = b->j; 111 PetscInt *ajtmpold,*ajtmp,nz,row; 112 PetscInt *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj; 113 MatScalar *pv,*v,*rtmp,*pc,*w,*x; 114 MatScalar p1,p2,p3,p4,m1,m2,m3,m4,x1,x2,x3,x4; 115 MatScalar *ba = b->a,*aa = a->a; 116 PetscReal shift = info->shiftinblocks; 117 118 PetscFunctionBegin; 119 ierr = PetscMalloc(4*(n+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr); 120 121 for (i=0; i<n; i++) { 122 nz = bi[i+1] - bi[i]; 123 ajtmp = bj + bi[i]; 124 for (j=0; j<nz; j++) { 125 x = rtmp+4*ajtmp[j]; 126 x[0] = x[1] = x[2] = x[3] = 0.0; 127 } 128 /* load in initial (unfactored row) */ 129 nz = ai[i+1] - ai[i]; 130 ajtmpold = aj + ai[i]; 131 v = aa + 4*ai[i]; 132 for (j=0; j<nz; j++) { 133 x = rtmp+4*ajtmpold[j]; 134 x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3]; 135 v += 4; 136 } 137 row = *ajtmp++; 138 while (row < i) { 139 pc = rtmp + 4*row; 140 p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3]; 141 if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0) { 142 pv = ba + 4*diag_offset[row]; 143 pj = bj + diag_offset[row] + 1; 144 x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 145 pc[0] = m1 = p1*x1 + p3*x2; 146 pc[1] = m2 = p2*x1 + p4*x2; 147 pc[2] = m3 = p1*x3 + p3*x4; 148 pc[3] = m4 = p2*x3 + p4*x4; 149 nz = bi[row+1] - diag_offset[row] - 1; 150 pv += 4; 151 for (j=0; j<nz; j++) { 152 x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3]; 153 x = rtmp + 4*pj[j]; 154 x[0] -= m1*x1 + m3*x2; 155 x[1] -= m2*x1 + m4*x2; 156 x[2] -= m1*x3 + m3*x4; 157 x[3] -= m2*x3 + m4*x4; 158 pv += 4; 159 } 160 ierr = PetscLogFlops(16*nz+12);CHKERRQ(ierr); 161 } 162 row = *ajtmp++; 163 } 164 /* finished row so stick it into b->a */ 165 pv = ba + 4*bi[i]; 166 pj = bj + bi[i]; 167 nz = bi[i+1] - bi[i]; 168 for (j=0; j<nz; j++) { 169 x = rtmp+4*pj[j]; 170 pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3]; 171 pv += 4; 172 } 173 /* invert diagonal block */ 174 w = ba + 4*diag_offset[i]; 175 ierr = Kernel_A_gets_inverse_A_2(w,shift);CHKERRQ(ierr); 176 } 177 178 ierr = PetscFree(rtmp);CHKERRQ(ierr); 179 C->ops->solve = MatSolve_SeqBAIJ_2_NaturalOrdering; 180 C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_2_NaturalOrdering; 181 C->assembled = PETSC_TRUE; 182 ierr = PetscLogFlops(1.3333*8*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */ 183 PetscFunctionReturn(0); 184 } 185 186 /* ----------------------------------------------------------- */ 187 /* 188 Version for when blocks are 1 by 1. 189 */ 190 #undef __FUNCT__ 191 #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_1" 192 PetscErrorCode MatLUFactorNumeric_SeqBAIJ_1(Mat C,Mat A,const MatFactorInfo *info) 193 { 194 Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data; 195 IS isrow = b->row,isicol = b->icol; 196 PetscErrorCode ierr; 197 const PetscInt *r,*ic; 198 PetscInt i,j,n = a->mbs,*bi = b->i,*bj = b->j; 199 PetscInt *ajtmpold,*ajtmp,nz,row,*ai = a->i,*aj = a->j; 200 PetscInt *diag_offset = b->diag,diag,*pj; 201 MatScalar *pv,*v,*rtmp,multiplier,*pc; 202 MatScalar *ba = b->a,*aa = a->a; 203 204 PetscFunctionBegin; 205 ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 206 ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 207 ierr = PetscMalloc((n+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr); 208 209 for (i=0; i<n; i++) { 210 nz = bi[i+1] - bi[i]; 211 ajtmp = bj + bi[i]; 212 for (j=0; j<nz; j++) rtmp[ajtmp[j]] = 0.0; 213 214 /* load in initial (unfactored row) */ 215 nz = ai[r[i]+1] - ai[r[i]]; 216 ajtmpold = aj + ai[r[i]]; 217 v = aa + ai[r[i]]; 218 for (j=0; j<nz; j++) rtmp[ic[ajtmpold[j]]] = v[j]; 219 220 row = *ajtmp++; 221 while (row < i) { 222 pc = rtmp + row; 223 if (*pc != 0.0) { 224 pv = ba + diag_offset[row]; 225 pj = bj + diag_offset[row] + 1; 226 multiplier = *pc * *pv++; 227 *pc = multiplier; 228 nz = bi[row+1] - diag_offset[row] - 1; 229 for (j=0; j<nz; j++) rtmp[pj[j]] -= multiplier * pv[j]; 230 ierr = PetscLogFlops(1+2*nz);CHKERRQ(ierr); 231 } 232 row = *ajtmp++; 233 } 234 /* finished row so stick it into b->a */ 235 pv = ba + bi[i]; 236 pj = bj + bi[i]; 237 nz = bi[i+1] - bi[i]; 238 for (j=0; j<nz; j++) {pv[j] = rtmp[pj[j]];} 239 diag = diag_offset[i] - bi[i]; 240 /* check pivot entry for current row */ 241 if (pv[diag] == 0.0) { 242 SETERRQ(PETSC_ERR_MAT_LU_ZRPVT,"Zero pivot"); 243 } 244 pv[diag] = 1.0/pv[diag]; 245 } 246 247 ierr = PetscFree(rtmp);CHKERRQ(ierr); 248 ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 249 ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 250 C->ops->solve = MatSolve_SeqBAIJ_1; 251 C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_1; 252 C->assembled = PETSC_TRUE; 253 ierr = PetscLogFlops(C->cmap->n);CHKERRQ(ierr); 254 PetscFunctionReturn(0); 255 } 256 257 EXTERN_C_BEGIN 258 #undef __FUNCT__ 259 #define __FUNCT__ "MatGetFactor_seqbaij_petsc" 260 PetscErrorCode MatGetFactor_seqbaij_petsc(Mat A,MatFactorType ftype,Mat *B) 261 { 262 PetscInt n = A->rmap->n; 263 PetscErrorCode ierr; 264 265 PetscFunctionBegin; 266 ierr = MatCreate(((PetscObject)A)->comm,B);CHKERRQ(ierr); 267 ierr = MatSetSizes(*B,n,n,n,n);CHKERRQ(ierr); 268 if (ftype == MAT_FACTOR_LU || ftype == MAT_FACTOR_ILU) { 269 ierr = MatSetType(*B,MATSEQBAIJ);CHKERRQ(ierr); 270 (*B)->ops->lufactorsymbolic = MatLUFactorSymbolic_SeqBAIJ; 271 (*B)->ops->ilufactorsymbolic = MatILUFactorSymbolic_SeqBAIJ; 272 } else if (ftype == MAT_FACTOR_CHOLESKY || ftype == MAT_FACTOR_ICC) { 273 ierr = MatSetType(*B,MATSEQSBAIJ);CHKERRQ(ierr); 274 ierr = MatSeqSBAIJSetPreallocation(*B,1,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr); 275 (*B)->ops->iccfactorsymbolic = MatICCFactorSymbolic_SeqBAIJ; 276 (*B)->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SeqBAIJ; 277 } else SETERRQ(PETSC_ERR_SUP,"Factor type not supported"); 278 (*B)->factor = ftype; 279 PetscFunctionReturn(0); 280 } 281 EXTERN_C_END 282 283 EXTERN_C_BEGIN 284 #undef __FUNCT__ 285 #define __FUNCT__ "MatGetFactorAvailable_seqaij_petsc" 286 PetscErrorCode MatGetFactorAvailable_seqbaij_petsc(Mat A,MatFactorType ftype,PetscTruth *flg) 287 { 288 PetscFunctionBegin; 289 *flg = PETSC_TRUE; 290 PetscFunctionReturn(0); 291 } 292 EXTERN_C_END 293 294 /* ----------------------------------------------------------- */ 295 #undef __FUNCT__ 296 #define __FUNCT__ "MatLUFactor_SeqBAIJ" 297 PetscErrorCode MatLUFactor_SeqBAIJ(Mat A,IS row,IS col,const MatFactorInfo *info) 298 { 299 PetscErrorCode ierr; 300 Mat C; 301 302 PetscFunctionBegin; 303 ierr = MatGetFactor(A,MAT_SOLVER_PETSC,MAT_FACTOR_LU,&C);CHKERRQ(ierr); 304 ierr = MatLUFactorSymbolic(C,A,row,col,info);CHKERRQ(ierr); 305 ierr = MatLUFactorNumeric(C,A,info);CHKERRQ(ierr); 306 A->ops->solve = C->ops->solve; 307 A->ops->solvetranspose = C->ops->solvetranspose; 308 ierr = MatHeaderCopy(A,C);CHKERRQ(ierr); 309 ierr = PetscLogObjectParent(A,((Mat_SeqBAIJ*)(A->data))->icol);CHKERRQ(ierr); 310 PetscFunctionReturn(0); 311 } 312 313 #include "src/mat/impls/sbaij/seq/sbaij.h" 314 #undef __FUNCT__ 315 #define __FUNCT__ "MatCholeskyFactorNumeric_SeqBAIJ_N" 316 PetscErrorCode MatCholeskyFactorNumeric_SeqBAIJ_N(Mat C,Mat A,const MatFactorInfo *info) 317 { 318 PetscErrorCode ierr; 319 Mat_SeqBAIJ *a=(Mat_SeqBAIJ*)A->data; 320 Mat_SeqSBAIJ *b=(Mat_SeqSBAIJ*)C->data; 321 IS ip=b->row; 322 const PetscInt *rip; 323 PetscInt i,j,mbs=a->mbs,bs=A->rmap->bs,*bi=b->i,*bj=b->j,*bcol; 324 PetscInt *ai=a->i,*aj=a->j; 325 PetscInt k,jmin,jmax,*jl,*il,col,nexti,ili,nz; 326 MatScalar *rtmp,*ba=b->a,*bval,*aa=a->a,dk,uikdi; 327 PetscReal zeropivot,rs,shiftnz; 328 PetscReal shiftpd; 329 ChShift_Ctx sctx; 330 PetscInt newshift; 331 332 PetscFunctionBegin; 333 if (bs > 1) { 334 if (!a->sbaijMat){ 335 ierr = MatConvert(A,MATSEQSBAIJ,MAT_INITIAL_MATRIX,&a->sbaijMat);CHKERRQ(ierr); 336 } 337 ierr = (a->sbaijMat)->ops->choleskyfactornumeric(C,a->sbaijMat,info);CHKERRQ(ierr); 338 ierr = MatDestroy(a->sbaijMat);CHKERRQ(ierr); 339 a->sbaijMat = PETSC_NULL; 340 PetscFunctionReturn(0); 341 } 342 343 /* initialization */ 344 shiftnz = info->shiftnz; 345 shiftpd = info->shiftpd; 346 zeropivot = info->zeropivot; 347 348 ierr = ISGetIndices(ip,&rip);CHKERRQ(ierr); 349 nz = (2*mbs+1)*sizeof(PetscInt)+mbs*sizeof(MatScalar); 350 ierr = PetscMalloc(nz,&il);CHKERRQ(ierr); 351 jl = il + mbs; 352 rtmp = (MatScalar*)(jl + mbs); 353 354 sctx.shift_amount = 0; 355 sctx.nshift = 0; 356 do { 357 sctx.chshift = PETSC_FALSE; 358 for (i=0; i<mbs; i++) { 359 rtmp[i] = 0.0; jl[i] = mbs; il[0] = 0; 360 } 361 362 for (k = 0; k<mbs; k++){ 363 bval = ba + bi[k]; 364 /* initialize k-th row by the perm[k]-th row of A */ 365 jmin = ai[rip[k]]; jmax = ai[rip[k]+1]; 366 for (j = jmin; j < jmax; j++){ 367 col = rip[aj[j]]; 368 if (col >= k){ /* only take upper triangular entry */ 369 rtmp[col] = aa[j]; 370 *bval++ = 0.0; /* for in-place factorization */ 371 } 372 } 373 374 /* shift the diagonal of the matrix */ 375 if (sctx.nshift) rtmp[k] += sctx.shift_amount; 376 377 /* modify k-th row by adding in those rows i with U(i,k)!=0 */ 378 dk = rtmp[k]; 379 i = jl[k]; /* first row to be added to k_th row */ 380 381 while (i < k){ 382 nexti = jl[i]; /* next row to be added to k_th row */ 383 384 /* compute multiplier, update diag(k) and U(i,k) */ 385 ili = il[i]; /* index of first nonzero element in U(i,k:bms-1) */ 386 uikdi = - ba[ili]*ba[bi[i]]; /* diagonal(k) */ 387 dk += uikdi*ba[ili]; 388 ba[ili] = uikdi; /* -U(i,k) */ 389 390 /* add multiple of row i to k-th row */ 391 jmin = ili + 1; jmax = bi[i+1]; 392 if (jmin < jmax){ 393 for (j=jmin; j<jmax; j++) rtmp[bj[j]] += uikdi*ba[j]; 394 /* update il and jl for row i */ 395 il[i] = jmin; 396 j = bj[jmin]; jl[i] = jl[j]; jl[j] = i; 397 } 398 i = nexti; 399 } 400 401 /* shift the diagonals when zero pivot is detected */ 402 /* compute rs=sum of abs(off-diagonal) */ 403 rs = 0.0; 404 jmin = bi[k]+1; 405 nz = bi[k+1] - jmin; 406 if (nz){ 407 bcol = bj + jmin; 408 while (nz--){ 409 rs += PetscAbsScalar(rtmp[*bcol]); 410 bcol++; 411 } 412 } 413 414 sctx.rs = rs; 415 sctx.pv = dk; 416 ierr = MatCholeskyCheckShift_inline(info,sctx,k,newshift);CHKERRQ(ierr); 417 if (newshift == 1) break; 418 419 /* copy data into U(k,:) */ 420 ba[bi[k]] = 1.0/dk; /* U(k,k) */ 421 jmin = bi[k]+1; jmax = bi[k+1]; 422 if (jmin < jmax) { 423 for (j=jmin; j<jmax; j++){ 424 col = bj[j]; ba[j] = rtmp[col]; rtmp[col] = 0.0; 425 } 426 /* add the k-th row into il and jl */ 427 il[k] = jmin; 428 i = bj[jmin]; jl[k] = jl[i]; jl[i] = k; 429 } 430 } 431 } while (sctx.chshift); 432 ierr = PetscFree(il);CHKERRQ(ierr); 433 434 ierr = ISRestoreIndices(ip,&rip);CHKERRQ(ierr); 435 C->assembled = PETSC_TRUE; 436 C->preallocated = PETSC_TRUE; 437 ierr = PetscLogFlops(C->rmap->N);CHKERRQ(ierr); 438 if (sctx.nshift){ 439 if (shiftpd) { 440 ierr = PetscInfo2(A,"number of shiftpd tries %D, shift_amount %G\n",sctx.nshift,sctx.shift_amount);CHKERRQ(ierr); 441 } else if (shiftnz) { 442 ierr = PetscInfo2(A,"number of shiftnz tries %D, shift_amount %G\n",sctx.nshift,sctx.shift_amount);CHKERRQ(ierr); 443 } 444 } 445 PetscFunctionReturn(0); 446 } 447 448 #undef __FUNCT__ 449 #define __FUNCT__ "MatCholeskyFactorNumeric_SeqBAIJ_N_NaturalOrdering" 450 PetscErrorCode MatCholeskyFactorNumeric_SeqBAIJ_N_NaturalOrdering(Mat C,Mat A,const MatFactorInfo *info) 451 { 452 Mat_SeqBAIJ *a=(Mat_SeqBAIJ*)A->data; 453 Mat_SeqSBAIJ *b=(Mat_SeqSBAIJ*)C->data; 454 PetscErrorCode ierr; 455 PetscInt i,j,am=a->mbs; 456 PetscInt *ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j; 457 PetscInt k,jmin,*jl,*il,nexti,ili,*acol,*bcol,nz; 458 MatScalar *rtmp,*ba=b->a,*aa=a->a,dk,uikdi,*aval,*bval; 459 PetscReal zeropivot,rs,shiftnz; 460 PetscReal shiftpd; 461 ChShift_Ctx sctx; 462 PetscInt newshift; 463 464 PetscFunctionBegin; 465 /* initialization */ 466 shiftnz = info->shiftnz; 467 shiftpd = info->shiftpd; 468 zeropivot = info->zeropivot; 469 470 nz = (2*am+1)*sizeof(PetscInt)+am*sizeof(MatScalar); 471 ierr = PetscMalloc(nz,&il);CHKERRQ(ierr); 472 jl = il + am; 473 rtmp = (MatScalar*)(jl + am); 474 475 sctx.shift_amount = 0; 476 sctx.nshift = 0; 477 do { 478 sctx.chshift = PETSC_FALSE; 479 for (i=0; i<am; i++) { 480 rtmp[i] = 0.0; jl[i] = am; il[0] = 0; 481 } 482 483 for (k = 0; k<am; k++){ 484 /* initialize k-th row with elements nonzero in row perm(k) of A */ 485 nz = ai[k+1] - ai[k]; 486 acol = aj + ai[k]; 487 aval = aa + ai[k]; 488 bval = ba + bi[k]; 489 while (nz -- ){ 490 if (*acol < k) { /* skip lower triangular entries */ 491 acol++; aval++; 492 } else { 493 rtmp[*acol++] = *aval++; 494 *bval++ = 0.0; /* for in-place factorization */ 495 } 496 } 497 498 /* shift the diagonal of the matrix */ 499 if (sctx.nshift) rtmp[k] += sctx.shift_amount; 500 501 /* modify k-th row by adding in those rows i with U(i,k)!=0 */ 502 dk = rtmp[k]; 503 i = jl[k]; /* first row to be added to k_th row */ 504 505 while (i < k){ 506 nexti = jl[i]; /* next row to be added to k_th row */ 507 /* compute multiplier, update D(k) and U(i,k) */ 508 ili = il[i]; /* index of first nonzero element in U(i,k:bms-1) */ 509 uikdi = - ba[ili]*ba[bi[i]]; 510 dk += uikdi*ba[ili]; 511 ba[ili] = uikdi; /* -U(i,k) */ 512 513 /* add multiple of row i to k-th row ... */ 514 jmin = ili + 1; 515 nz = bi[i+1] - jmin; 516 if (nz > 0){ 517 bcol = bj + jmin; 518 bval = ba + jmin; 519 while (nz --) rtmp[*bcol++] += uikdi*(*bval++); 520 /* update il and jl for i-th row */ 521 il[i] = jmin; 522 j = bj[jmin]; jl[i] = jl[j]; jl[j] = i; 523 } 524 i = nexti; 525 } 526 527 /* shift the diagonals when zero pivot is detected */ 528 /* compute rs=sum of abs(off-diagonal) */ 529 rs = 0.0; 530 jmin = bi[k]+1; 531 nz = bi[k+1] - jmin; 532 if (nz){ 533 bcol = bj + jmin; 534 while (nz--){ 535 rs += PetscAbsScalar(rtmp[*bcol]); 536 bcol++; 537 } 538 } 539 540 sctx.rs = rs; 541 sctx.pv = dk; 542 ierr = MatCholeskyCheckShift_inline(info,sctx,k,newshift);CHKERRQ(ierr); 543 if (newshift == 1) break; /* sctx.shift_amount is updated */ 544 545 /* copy data into U(k,:) */ 546 ba[bi[k]] = 1.0/dk; 547 jmin = bi[k]+1; 548 nz = bi[k+1] - jmin; 549 if (nz){ 550 bcol = bj + jmin; 551 bval = ba + jmin; 552 while (nz--){ 553 *bval++ = rtmp[*bcol]; 554 rtmp[*bcol++] = 0.0; 555 } 556 /* add k-th row into il and jl */ 557 il[k] = jmin; 558 i = bj[jmin]; jl[k] = jl[i]; jl[i] = k; 559 } 560 } 561 } while (sctx.chshift); 562 ierr = PetscFree(il);CHKERRQ(ierr); 563 564 C->ops->solve = MatSolve_SeqSBAIJ_1_NaturalOrdering; 565 C->ops->solvetranspose = MatSolve_SeqSBAIJ_1_NaturalOrdering; 566 C->assembled = PETSC_TRUE; 567 C->preallocated = PETSC_TRUE; 568 ierr = PetscLogFlops(C->rmap->N);CHKERRQ(ierr); 569 if (sctx.nshift){ 570 if (shiftnz) { 571 ierr = PetscInfo2(A,"number of shiftnz tries %D, shift_amount %G\n",sctx.nshift,sctx.shift_amount);CHKERRQ(ierr); 572 } else if (shiftpd) { 573 ierr = PetscInfo2(A,"number of shiftpd tries %D, shift_amount %G\n",sctx.nshift,sctx.shift_amount);CHKERRQ(ierr); 574 } 575 } 576 PetscFunctionReturn(0); 577 } 578 579 #include "petscbt.h" 580 #include "src/mat/utils/freespace.h" 581 #undef __FUNCT__ 582 #define __FUNCT__ "MatICCFactorSymbolic_SeqBAIJ" 583 PetscErrorCode MatICCFactorSymbolic_SeqBAIJ(Mat fact,Mat A,IS perm,const MatFactorInfo *info) 584 { 585 Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data; 586 Mat_SeqSBAIJ *b; 587 Mat B; 588 PetscErrorCode ierr; 589 PetscTruth perm_identity; 590 PetscInt reallocs=0,i,*ai=a->i,*aj=a->j,am=a->mbs,bs=A->rmap->bs,*ui; 591 const PetscInt *rip; 592 PetscInt jmin,jmax,nzk,k,j,*jl,prow,*il,nextprow; 593 PetscInt nlnk,*lnk,*lnk_lvl=PETSC_NULL,ncols,ncols_upper,*cols,*cols_lvl,*uj,**uj_ptr,**uj_lvl_ptr; 594 PetscReal fill=info->fill,levels=info->levels; 595 PetscFreeSpaceList free_space=PETSC_NULL,current_space=PETSC_NULL; 596 PetscFreeSpaceList free_space_lvl=PETSC_NULL,current_space_lvl=PETSC_NULL; 597 PetscBT lnkbt; 598 599 PetscFunctionBegin; 600 if (bs > 1){ 601 if (!a->sbaijMat){ 602 ierr = MatConvert(A,MATSEQSBAIJ,MAT_INITIAL_MATRIX,&a->sbaijMat);CHKERRQ(ierr); 603 } 604 (fact)->ops->iccfactorsymbolic = MatICCFactorSymbolic_SeqSBAIJ; /* undue the change made in MatGetFactor_seqbaij_petsc */ 605 ierr = MatICCFactorSymbolic(fact,a->sbaijMat,perm,info);CHKERRQ(ierr); 606 PetscFunctionReturn(0); 607 } 608 609 ierr = ISIdentity(perm,&perm_identity);CHKERRQ(ierr); 610 ierr = ISGetIndices(perm,&rip);CHKERRQ(ierr); 611 612 /* special case that simply copies fill pattern */ 613 if (!levels && perm_identity) { 614 ierr = MatMarkDiagonal_SeqBAIJ(A);CHKERRQ(ierr); 615 ierr = PetscMalloc((am+1)*sizeof(PetscInt),&ui);CHKERRQ(ierr); 616 for (i=0; i<am; i++) { 617 ui[i] = ai[i+1] - a->diag[i]; /* ui: rowlengths - changes when !perm_identity */ 618 } 619 B = fact; 620 ierr = MatSeqSBAIJSetPreallocation(B,1,0,ui);CHKERRQ(ierr); 621 622 623 b = (Mat_SeqSBAIJ*)B->data; 624 uj = b->j; 625 for (i=0; i<am; i++) { 626 aj = a->j + a->diag[i]; 627 for (j=0; j<ui[i]; j++){ 628 *uj++ = *aj++; 629 } 630 b->ilen[i] = ui[i]; 631 } 632 ierr = PetscFree(ui);CHKERRQ(ierr); 633 B->factor = MAT_FACTOR_NONE; 634 ierr = MatAssemblyBegin(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 635 ierr = MatAssemblyEnd(B,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 636 B->factor = MAT_FACTOR_ICC; 637 638 B->ops->choleskyfactornumeric = MatCholeskyFactorNumeric_SeqBAIJ_N_NaturalOrdering; 639 PetscFunctionReturn(0); 640 } 641 642 /* initialization */ 643 ierr = PetscMalloc((am+1)*sizeof(PetscInt),&ui);CHKERRQ(ierr); 644 ui[0] = 0; 645 ierr = PetscMalloc((2*am+1)*sizeof(PetscInt),&cols_lvl);CHKERRQ(ierr); 646 647 /* jl: linked list for storing indices of the pivot rows 648 il: il[i] points to the 1st nonzero entry of U(i,k:am-1) */ 649 ierr = PetscMalloc((2*am+1)*sizeof(PetscInt)+2*am*sizeof(PetscInt*),&jl);CHKERRQ(ierr); 650 il = jl + am; 651 uj_ptr = (PetscInt**)(il + am); 652 uj_lvl_ptr = (PetscInt**)(uj_ptr + am); 653 for (i=0; i<am; i++){ 654 jl[i] = am; il[i] = 0; 655 } 656 657 /* create and initialize a linked list for storing column indices of the active row k */ 658 nlnk = am + 1; 659 ierr = PetscIncompleteLLCreate(am,am,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr); 660 661 /* initial FreeSpace size is fill*(ai[am]+1) */ 662 ierr = PetscFreeSpaceGet((PetscInt)(fill*(ai[am]+1)),&free_space);CHKERRQ(ierr); 663 current_space = free_space; 664 ierr = PetscFreeSpaceGet((PetscInt)(fill*(ai[am]+1)),&free_space_lvl);CHKERRQ(ierr); 665 current_space_lvl = free_space_lvl; 666 667 for (k=0; k<am; k++){ /* for each active row k */ 668 /* initialize lnk by the column indices of row rip[k] of A */ 669 nzk = 0; 670 ncols = ai[rip[k]+1] - ai[rip[k]]; 671 ncols_upper = 0; 672 cols = cols_lvl + am; 673 for (j=0; j<ncols; j++){ 674 i = rip[*(aj + ai[rip[k]] + j)]; 675 if (i >= k){ /* only take upper triangular entry */ 676 cols[ncols_upper] = i; 677 cols_lvl[ncols_upper] = -1; /* initialize level for nonzero entries */ 678 ncols_upper++; 679 } 680 } 681 ierr = PetscIncompleteLLAdd(ncols_upper,cols,levels,cols_lvl,am,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr); 682 nzk += nlnk; 683 684 /* update lnk by computing fill-in for each pivot row to be merged in */ 685 prow = jl[k]; /* 1st pivot row */ 686 687 while (prow < k){ 688 nextprow = jl[prow]; 689 690 /* merge prow into k-th row */ 691 jmin = il[prow] + 1; /* index of the 2nd nzero entry in U(prow,k:am-1) */ 692 jmax = ui[prow+1]; 693 ncols = jmax-jmin; 694 i = jmin - ui[prow]; 695 cols = uj_ptr[prow] + i; /* points to the 2nd nzero entry in U(prow,k:am-1) */ 696 for (j=0; j<ncols; j++) cols_lvl[j] = *(uj_lvl_ptr[prow] + i + j); 697 ierr = PetscIncompleteLLAddSorted(ncols,cols,levels,cols_lvl,am,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr); 698 nzk += nlnk; 699 700 /* update il and jl for prow */ 701 if (jmin < jmax){ 702 il[prow] = jmin; 703 j = *cols; jl[prow] = jl[j]; jl[j] = prow; 704 } 705 prow = nextprow; 706 } 707 708 /* if free space is not available, make more free space */ 709 if (current_space->local_remaining<nzk) { 710 i = am - k + 1; /* num of unfactored rows */ 711 i = PetscMin(i*nzk, i*(i-1)); /* i*nzk, i*(i-1): estimated and max additional space needed */ 712 ierr = PetscFreeSpaceGet(i,¤t_space);CHKERRQ(ierr); 713 ierr = PetscFreeSpaceGet(i,¤t_space_lvl);CHKERRQ(ierr); 714 reallocs++; 715 } 716 717 /* copy data into free_space and free_space_lvl, then initialize lnk */ 718 ierr = PetscIncompleteLLClean(am,am,nzk,lnk,lnk_lvl,current_space->array,current_space_lvl->array,lnkbt);CHKERRQ(ierr); 719 720 /* add the k-th row into il and jl */ 721 if (nzk-1 > 0){ 722 i = current_space->array[1]; /* col value of the first nonzero element in U(k, k+1:am-1) */ 723 jl[k] = jl[i]; jl[i] = k; 724 il[k] = ui[k] + 1; 725 } 726 uj_ptr[k] = current_space->array; 727 uj_lvl_ptr[k] = current_space_lvl->array; 728 729 current_space->array += nzk; 730 current_space->local_used += nzk; 731 current_space->local_remaining -= nzk; 732 733 current_space_lvl->array += nzk; 734 current_space_lvl->local_used += nzk; 735 current_space_lvl->local_remaining -= nzk; 736 737 ui[k+1] = ui[k] + nzk; 738 } 739 740 #if defined(PETSC_USE_INFO) 741 if (ai[am] != 0) { 742 PetscReal af = ((PetscReal)(2*ui[am]-am))/((PetscReal)ai[am]); 743 ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocs,fill,af);CHKERRQ(ierr); 744 ierr = PetscInfo1(A,"Run with -pc_factor_fill %G or use \n",af);CHKERRQ(ierr); 745 ierr = PetscInfo1(A,"PCFactorSetFill(pc,%G) for best performance.\n",af);CHKERRQ(ierr); 746 } else { 747 ierr = PetscInfo(A,"Empty matrix.\n");CHKERRQ(ierr); 748 } 749 #endif 750 751 ierr = ISRestoreIndices(perm,&rip);CHKERRQ(ierr); 752 ierr = PetscFree(jl);CHKERRQ(ierr); 753 ierr = PetscFree(cols_lvl);CHKERRQ(ierr); 754 755 /* destroy list of free space and other temporary array(s) */ 756 ierr = PetscMalloc((ui[am]+1)*sizeof(PetscInt),&uj);CHKERRQ(ierr); 757 ierr = PetscFreeSpaceContiguous(&free_space,uj);CHKERRQ(ierr); 758 ierr = PetscIncompleteLLDestroy(lnk,lnkbt);CHKERRQ(ierr); 759 ierr = PetscFreeSpaceDestroy(free_space_lvl);CHKERRQ(ierr); 760 761 /* put together the new matrix in MATSEQSBAIJ format */ 762 B = fact; 763 ierr = MatSeqSBAIJSetPreallocation(B,1,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr); 764 765 b = (Mat_SeqSBAIJ*)B->data; 766 b->singlemalloc = PETSC_FALSE; 767 b->free_a = PETSC_TRUE; 768 b->free_ij = PETSC_TRUE; 769 ierr = PetscMalloc((ui[am]+1)*sizeof(MatScalar),&b->a);CHKERRQ(ierr); 770 b->j = uj; 771 b->i = ui; 772 b->diag = 0; 773 b->ilen = 0; 774 b->imax = 0; 775 b->row = perm; 776 b->pivotinblocks = PETSC_FALSE; /* need to get from MatFactorInfo */ 777 ierr = PetscObjectReference((PetscObject)perm);CHKERRQ(ierr); 778 b->icol = perm; 779 ierr = PetscObjectReference((PetscObject)perm);CHKERRQ(ierr); 780 ierr = PetscMalloc((am+1)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr); 781 ierr = PetscLogObjectMemory(B,(ui[am]-am)*(sizeof(PetscInt)+sizeof(MatScalar)));CHKERRQ(ierr); 782 b->maxnz = b->nz = ui[am]; 783 784 B->info.factor_mallocs = reallocs; 785 B->info.fill_ratio_given = fill; 786 if (ai[am] != 0) { 787 B->info.fill_ratio_needed = ((PetscReal)ui[am])/((PetscReal)ai[am]); 788 } else { 789 B->info.fill_ratio_needed = 0.0; 790 } 791 if (perm_identity){ 792 B->ops->solve = MatSolve_SeqSBAIJ_1_NaturalOrdering; 793 B->ops->solvetranspose = MatSolve_SeqSBAIJ_1_NaturalOrdering; 794 B->ops->choleskyfactornumeric = MatCholeskyFactorNumeric_SeqBAIJ_N_NaturalOrdering; 795 } else { 796 (fact)->ops->choleskyfactornumeric = MatCholeskyFactorNumeric_SeqBAIJ_N; 797 } 798 PetscFunctionReturn(0); 799 } 800 801 #undef __FUNCT__ 802 #define __FUNCT__ "MatCholeskyFactorSymbolic_SeqBAIJ" 803 PetscErrorCode MatCholeskyFactorSymbolic_SeqBAIJ(Mat fact,Mat A,IS perm,const MatFactorInfo *info) 804 { 805 Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data; 806 Mat_SeqSBAIJ *b; 807 Mat B; 808 PetscErrorCode ierr; 809 PetscTruth perm_identity; 810 PetscReal fill = info->fill; 811 const PetscInt *rip; 812 PetscInt i,mbs=a->mbs,bs=A->rmap->bs,*ai=a->i,*aj=a->j,reallocs=0,prow; 813 PetscInt *jl,jmin,jmax,nzk,*ui,k,j,*il,nextprow; 814 PetscInt nlnk,*lnk,ncols,ncols_upper,*cols,*uj,**ui_ptr,*uj_ptr; 815 PetscFreeSpaceList free_space=PETSC_NULL,current_space=PETSC_NULL; 816 PetscBT lnkbt; 817 818 PetscFunctionBegin; 819 if (bs > 1) { /* convert to seqsbaij */ 820 if (!a->sbaijMat){ 821 ierr = MatConvert(A,MATSEQSBAIJ,MAT_INITIAL_MATRIX,&a->sbaijMat);CHKERRQ(ierr); 822 } 823 (fact)->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SeqSBAIJ; /* undue the change made in MatGetFactor_seqbaij_petsc */ 824 ierr = MatCholeskyFactorSymbolic(fact,a->sbaijMat,perm,info);CHKERRQ(ierr); 825 PetscFunctionReturn(0); 826 } 827 828 /* check whether perm is the identity mapping */ 829 ierr = ISIdentity(perm,&perm_identity);CHKERRQ(ierr); 830 if (!perm_identity) SETERRQ(PETSC_ERR_SUP,"Matrix reordering is not supported"); 831 ierr = ISGetIndices(perm,&rip);CHKERRQ(ierr); 832 833 /* initialization */ 834 ierr = PetscMalloc((mbs+1)*sizeof(PetscInt),&ui);CHKERRQ(ierr); 835 ui[0] = 0; 836 837 /* jl: linked list for storing indices of the pivot rows 838 il: il[i] points to the 1st nonzero entry of U(i,k:mbs-1) */ 839 ierr = PetscMalloc((3*mbs+1)*sizeof(PetscInt)+mbs*sizeof(PetscInt*),&jl);CHKERRQ(ierr); 840 il = jl + mbs; 841 cols = il + mbs; 842 ui_ptr = (PetscInt**)(cols + mbs); 843 for (i=0; i<mbs; i++){ 844 jl[i] = mbs; il[i] = 0; 845 } 846 847 /* create and initialize a linked list for storing column indices of the active row k */ 848 nlnk = mbs + 1; 849 ierr = PetscLLCreate(mbs,mbs,nlnk,lnk,lnkbt);CHKERRQ(ierr); 850 851 /* initial FreeSpace size is fill*(ai[mbs]+1) */ 852 ierr = PetscFreeSpaceGet((PetscInt)(fill*(ai[mbs]+1)),&free_space);CHKERRQ(ierr); 853 current_space = free_space; 854 855 for (k=0; k<mbs; k++){ /* for each active row k */ 856 /* initialize lnk by the column indices of row rip[k] of A */ 857 nzk = 0; 858 ncols = ai[rip[k]+1] - ai[rip[k]]; 859 ncols_upper = 0; 860 for (j=0; j<ncols; j++){ 861 i = rip[*(aj + ai[rip[k]] + j)]; 862 if (i >= k){ /* only take upper triangular entry */ 863 cols[ncols_upper] = i; 864 ncols_upper++; 865 } 866 } 867 ierr = PetscLLAdd(ncols_upper,cols,mbs,nlnk,lnk,lnkbt);CHKERRQ(ierr); 868 nzk += nlnk; 869 870 /* update lnk by computing fill-in for each pivot row to be merged in */ 871 prow = jl[k]; /* 1st pivot row */ 872 873 while (prow < k){ 874 nextprow = jl[prow]; 875 /* merge prow into k-th row */ 876 jmin = il[prow] + 1; /* index of the 2nd nzero entry in U(prow,k:mbs-1) */ 877 jmax = ui[prow+1]; 878 ncols = jmax-jmin; 879 uj_ptr = ui_ptr[prow] + jmin - ui[prow]; /* points to the 2nd nzero entry in U(prow,k:mbs-1) */ 880 ierr = PetscLLAddSorted(ncols,uj_ptr,mbs,nlnk,lnk,lnkbt);CHKERRQ(ierr); 881 nzk += nlnk; 882 883 /* update il and jl for prow */ 884 if (jmin < jmax){ 885 il[prow] = jmin; 886 j = *uj_ptr; jl[prow] = jl[j]; jl[j] = prow; 887 } 888 prow = nextprow; 889 } 890 891 /* if free space is not available, make more free space */ 892 if (current_space->local_remaining<nzk) { 893 i = mbs - k + 1; /* num of unfactored rows */ 894 i = PetscMin(i*nzk, i*(i-1)); /* i*nzk, i*(i-1): estimated and max additional space needed */ 895 ierr = PetscFreeSpaceGet(i,¤t_space);CHKERRQ(ierr); 896 reallocs++; 897 } 898 899 /* copy data into free space, then initialize lnk */ 900 ierr = PetscLLClean(mbs,mbs,nzk,lnk,current_space->array,lnkbt);CHKERRQ(ierr); 901 902 /* add the k-th row into il and jl */ 903 if (nzk-1 > 0){ 904 i = current_space->array[1]; /* col value of the first nonzero element in U(k, k+1:mbs-1) */ 905 jl[k] = jl[i]; jl[i] = k; 906 il[k] = ui[k] + 1; 907 } 908 ui_ptr[k] = current_space->array; 909 current_space->array += nzk; 910 current_space->local_used += nzk; 911 current_space->local_remaining -= nzk; 912 913 ui[k+1] = ui[k] + nzk; 914 } 915 916 #if defined(PETSC_USE_INFO) 917 if (ai[mbs] != 0) { 918 PetscReal af = ((PetscReal)ui[mbs])/((PetscReal)ai[mbs]); 919 ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocs,fill,af);CHKERRQ(ierr); 920 ierr = PetscInfo1(A,"Run with -pc_factor_fill %G or use \n",af);CHKERRQ(ierr); 921 ierr = PetscInfo1(A,"PCFactorSetFill(pc,%G) for best performance.\n",af);CHKERRQ(ierr); 922 } else { 923 ierr = PetscInfo(A,"Empty matrix.\n");CHKERRQ(ierr); 924 } 925 #endif 926 927 ierr = ISRestoreIndices(perm,&rip);CHKERRQ(ierr); 928 ierr = PetscFree(jl);CHKERRQ(ierr); 929 930 /* destroy list of free space and other temporary array(s) */ 931 ierr = PetscMalloc((ui[mbs]+1)*sizeof(PetscInt),&uj);CHKERRQ(ierr); 932 ierr = PetscFreeSpaceContiguous(&free_space,uj);CHKERRQ(ierr); 933 ierr = PetscLLDestroy(lnk,lnkbt);CHKERRQ(ierr); 934 935 /* put together the new matrix in MATSEQSBAIJ format */ 936 B = fact; 937 ierr = MatSeqSBAIJSetPreallocation(B,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr); 938 939 b = (Mat_SeqSBAIJ*)B->data; 940 b->singlemalloc = PETSC_FALSE; 941 b->free_a = PETSC_TRUE; 942 b->free_ij = PETSC_TRUE; 943 ierr = PetscMalloc((ui[mbs]+1)*sizeof(MatScalar),&b->a);CHKERRQ(ierr); 944 b->j = uj; 945 b->i = ui; 946 b->diag = 0; 947 b->ilen = 0; 948 b->imax = 0; 949 b->row = perm; 950 b->pivotinblocks = PETSC_FALSE; /* need to get from MatFactorInfo */ 951 ierr = PetscObjectReference((PetscObject)perm);CHKERRQ(ierr); 952 b->icol = perm; 953 ierr = PetscObjectReference((PetscObject)perm);CHKERRQ(ierr); 954 ierr = PetscMalloc((mbs+1)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr); 955 ierr = PetscLogObjectMemory(B,(ui[mbs]-mbs)*(sizeof(PetscInt)+sizeof(MatScalar)));CHKERRQ(ierr); 956 b->maxnz = b->nz = ui[mbs]; 957 958 B->info.factor_mallocs = reallocs; 959 B->info.fill_ratio_given = fill; 960 if (ai[mbs] != 0) { 961 B->info.fill_ratio_needed = ((PetscReal)ui[mbs])/((PetscReal)ai[mbs]); 962 } else { 963 B->info.fill_ratio_needed = 0.0; 964 } 965 if (perm_identity){ 966 B->ops->choleskyfactornumeric = MatCholeskyFactorNumeric_SeqBAIJ_N_NaturalOrdering; 967 } else { 968 B->ops->choleskyfactornumeric = MatCholeskyFactorNumeric_SeqBAIJ_N; 969 } 970 PetscFunctionReturn(0); 971 } 972