Actual source code: baijfact4.c
1: #define PETSCMAT_DLL
3: /*
4: Factorization code for BAIJ format.
5: */
6: #include ../src/mat/impls/baij/seq/baij.h
7: #include ../src/mat/blockinvert.h
9: /* ----------------------------------------------------------- */
12: PetscErrorCode MatLUFactorNumeric_SeqBAIJ_N_inplace(Mat C,Mat A,const MatFactorInfo *info)
13: {
14: Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data;
15: IS isrow = b->row,isicol = b->icol;
17: const PetscInt *r,*ic;
18: PetscInt i,j,n = a->mbs,*bi = b->i,*bj = b->j;
19: PetscInt *ajtmpold,*ajtmp,nz,row,bslog,*ai=a->i,*aj=a->j,k,flg;
20: PetscInt *diag_offset=b->diag,diag,bs=A->rmap->bs,bs2 = a->bs2,*pj,*v_pivots;
21: MatScalar *ba = b->a,*aa = a->a,*pv,*v,*rtmp,*multiplier,*v_work,*pc,*w;
24: ISGetIndices(isrow,&r);
25: ISGetIndices(isicol,&ic);
26: PetscMalloc(bs2*(n+1)*sizeof(MatScalar),&rtmp);
27: PetscMemzero(rtmp,(bs2*n+1)*sizeof(MatScalar));
28: /* generate work space needed by dense LU factorization */
29: PetscMalloc3(bs,MatScalar,&v_work,bs2,MatScalar,&multiplier,bs,PetscInt,&v_pivots);
31: /* flops in while loop */
32: bslog = 2*bs*bs2;
34: for (i=0; i<n; i++) {
35: nz = bi[i+1] - bi[i];
36: ajtmp = bj + bi[i];
37: for (j=0; j<nz; j++) {
38: PetscMemzero(rtmp+bs2*ajtmp[j],bs2*sizeof(MatScalar));
39: }
40: /* load in initial (unfactored row) */
41: nz = ai[r[i]+1] - ai[r[i]];
42: ajtmpold = aj + ai[r[i]];
43: v = aa + bs2*ai[r[i]];
44: for (j=0; j<nz; j++) {
45: PetscMemcpy(rtmp+bs2*ic[ajtmpold[j]],v+bs2*j,bs2*sizeof(MatScalar));
46: }
47: row = *ajtmp++;
48: while (row < i) {
49: pc = rtmp + bs2*row;
50: /* if (*pc) { */
51: for (flg=0,k=0; k<bs2; k++) { if (pc[k]!=0.0) { flg = 1; break; }}
52: if (flg) {
53: pv = ba + bs2*diag_offset[row];
54: pj = bj + diag_offset[row] + 1;
55: Kernel_A_gets_A_times_B(bs,pc,pv,multiplier);
56: nz = bi[row+1] - diag_offset[row] - 1;
57: pv += bs2;
58: for (j=0; j<nz; j++) {
59: Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j);
60: }
61: PetscLogFlops(bslog*(nz+1.0)-bs);
62: }
63: row = *ajtmp++;
64: }
65: /* finished row so stick it into b->a */
66: pv = ba + bs2*bi[i];
67: pj = bj + bi[i];
68: nz = bi[i+1] - bi[i];
69: for (j=0; j<nz; j++) {
70: PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));
71: }
72: diag = diag_offset[i] - bi[i];
73: /* invert diagonal block */
74: w = pv + bs2*diag;
75: Kernel_A_gets_inverse_A(bs,w,v_pivots,v_work);
76: }
78: PetscFree(rtmp);
79: PetscFree3(v_work,multiplier,v_pivots);
80: ISRestoreIndices(isicol,&ic);
81: ISRestoreIndices(isrow,&r);
82: C->ops->solve = MatSolve_SeqBAIJ_N_inplace;
83: C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_N_inplace;
84: C->assembled = PETSC_TRUE;
85: PetscLogFlops(1.333333333333*bs*bs2*b->mbs); /* from inverting diagonal blocks */
86: return(0);
87: }