xref: /petsc/src/mat/impls/baij/seq/baijfact9.c (revision 78bb40077513d5120f4c52e0fb25a84efb280004)
1be1d678aSKris Buschelman #define PETSCMAT_DLL
2be1d678aSKris Buschelman 
383287d42SBarry Smith /*
483287d42SBarry Smith     Factorization code for BAIJ format.
583287d42SBarry Smith */
67c4f633dSBarry Smith #include "../src/mat/impls/baij/seq/baij.h"
7c60f0209SBarry Smith #include "../src/mat/blockinvert.h"
883287d42SBarry Smith 
983287d42SBarry Smith /* ------------------------------------------------------------*/
1083287d42SBarry Smith /*
1183287d42SBarry Smith       Version for when blocks are 5 by 5
1283287d42SBarry Smith */
134a2ae208SSatish Balay #undef __FUNCT__
144a2ae208SSatish Balay #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_5"
150481f469SBarry Smith PetscErrorCode MatLUFactorNumeric_SeqBAIJ_5(Mat C,Mat A,const MatFactorInfo *info)
1683287d42SBarry Smith {
1783287d42SBarry Smith   Mat_SeqBAIJ     *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data;
1883287d42SBarry Smith   IS              isrow = b->row,isicol = b->icol;
196849ba73SBarry Smith   PetscErrorCode  ierr;
205d0c19d7SBarry Smith   const PetscInt  *r,*ic,*bi = b->i,*bj = b->j,*ajtmpold,*ajtmp;
215d0c19d7SBarry Smith   PetscInt        i,j,n = a->mbs,nz,row,idx;
225d0c19d7SBarry Smith   const PetscInt  *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj;
238397fe1aSBarry Smith   MatScalar       *w,*pv,*rtmp,*x,*pc;
248397fe1aSBarry Smith   const MatScalar *v,*aa = a->a;
2583287d42SBarry Smith   MatScalar       p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4;
2683287d42SBarry Smith   MatScalar       p5,p6,p7,p8,p9,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16;
2783287d42SBarry Smith   MatScalar       x17,x18,x19,x20,x21,x22,x23,x24,x25,p10,p11,p12,p13,p14;
2883287d42SBarry Smith   MatScalar       p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,m10,m11,m12;
2983287d42SBarry Smith   MatScalar       m13,m14,m15,m16,m17,m18,m19,m20,m21,m22,m23,m24,m25;
308397fe1aSBarry Smith   MatScalar       *ba = b->a;
3162bba022SBarry Smith   PetscReal       shift = info->shiftinblocks;
3283287d42SBarry Smith 
3383287d42SBarry Smith   PetscFunctionBegin;
3483287d42SBarry Smith   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
3583287d42SBarry Smith   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
36b0a32e0cSBarry Smith   ierr = PetscMalloc(25*(n+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr);
3783287d42SBarry Smith 
388397fe1aSBarry Smith #define PETSC_USE_MEMZERO 1
398397fe1aSBarry Smith #define PETSC_USE_MEMCPY 1
408397fe1aSBarry Smith 
4183287d42SBarry Smith   for (i=0; i<n; i++) {
4283287d42SBarry Smith     nz    = bi[i+1] - bi[i];
4383287d42SBarry Smith     ajtmp = bj + bi[i];
4483287d42SBarry Smith     for  (j=0; j<nz; j++) {
458397fe1aSBarry Smith #if defined(PETSC_USE_MEMZERO)
468397fe1aSBarry Smith       ierr = PetscMemzero(rtmp+25*ajtmp[j],25*sizeof(PetscScalar));CHKERRQ(ierr);
478397fe1aSBarry Smith #else
4883287d42SBarry Smith       x = rtmp+25*ajtmp[j];
4983287d42SBarry Smith       x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0;
5083287d42SBarry Smith       x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0;
5183287d42SBarry Smith       x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = 0.0;
528397fe1aSBarry Smith #endif
5383287d42SBarry Smith     }
5483287d42SBarry Smith     /* load in initial (unfactored row) */
5583287d42SBarry Smith     idx      = r[i];
5683287d42SBarry Smith     nz       = ai[idx+1] - ai[idx];
5783287d42SBarry Smith     ajtmpold = aj + ai[idx];
5883287d42SBarry Smith     v        = aa + 25*ai[idx];
5983287d42SBarry Smith     for (j=0; j<nz; j++) {
608397fe1aSBarry Smith #if defined(PETSC_USE_MEMCPY)
618397fe1aSBarry Smith       ierr = PetscMemcpy(rtmp+25*ic[ajtmpold[j]],v,25*sizeof(PetscScalar));CHKERRQ(ierr);
628397fe1aSBarry Smith #else
6383287d42SBarry Smith       x    = rtmp+25*ic[ajtmpold[j]];
6483287d42SBarry Smith       x[0] = v[0]; x[1] = v[1]; x[2] = v[2]; x[3] = v[3];
6583287d42SBarry Smith       x[4] = v[4]; x[5] = v[5]; x[6] = v[6]; x[7] = v[7]; x[8] = v[8];
6683287d42SBarry Smith       x[9] = v[9]; x[10] = v[10]; x[11] = v[11]; x[12] = v[12]; x[13] = v[13];
6783287d42SBarry Smith       x[14] = v[14]; x[15] = v[15]; x[16] = v[16]; x[17] = v[17];
6883287d42SBarry Smith       x[18] = v[18]; x[19] = v[19]; x[20] = v[20]; x[21] = v[21];
6983287d42SBarry Smith       x[22] = v[22]; x[23] = v[23]; x[24] = v[24];
708397fe1aSBarry Smith #endif
7183287d42SBarry Smith       v    += 25;
7283287d42SBarry Smith     }
7383287d42SBarry Smith     row = *ajtmp++;
7483287d42SBarry Smith     while (row < i) {
7583287d42SBarry Smith       pc = rtmp + 25*row;
7683287d42SBarry Smith       p1 = pc[0]; p2 = pc[1]; p3 = pc[2]; p4 = pc[3];
7783287d42SBarry Smith       p5 = pc[4]; p6 = pc[5]; p7 = pc[6]; p8 = pc[7]; p9 = pc[8];
7883287d42SBarry Smith       p10 = pc[9]; p11 = pc[10]; p12 = pc[11]; p13 = pc[12]; p14 = pc[13];
7983287d42SBarry Smith       p15 = pc[14]; p16 = pc[15]; p17 = pc[16]; p18 = pc[17]; p19 = pc[18];
8083287d42SBarry Smith       p20 = pc[19]; p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23];
8183287d42SBarry Smith       p25 = pc[24];
8283287d42SBarry Smith       if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 ||
8383287d42SBarry Smith           p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0 || p10 != 0.0 ||
8483287d42SBarry Smith           p11 != 0.0 || p12 != 0.0 || p13 != 0.0 || p14 != 0.0 || p15 != 0.0
8583287d42SBarry Smith           || p16 != 0.0 || p17 != 0.0 || p18 != 0.0 || p19 != 0.0 ||
8683287d42SBarry Smith           p20 != 0.0 || p21 != 0.0 || p22 != 0.0 || p23 != 0.0 ||
8783287d42SBarry Smith           p24 != 0.0 || p25 != 0.0) {
8883287d42SBarry Smith         pv = ba + 25*diag_offset[row];
8983287d42SBarry Smith         pj = bj + diag_offset[row] + 1;
9083287d42SBarry Smith         x1 = pv[0]; x2 = pv[1]; x3 = pv[2]; x4 = pv[3];
9183287d42SBarry Smith         x5 = pv[4]; x6 = pv[5]; x7 = pv[6]; x8 = pv[7]; x9 = pv[8];
9283287d42SBarry Smith         x10 = pv[9]; x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; x14 = pv[13];
9383287d42SBarry Smith         x15 = pv[14]; x16 = pv[15]; x17 = pv[16]; x18 = pv[17];
9483287d42SBarry Smith         x19 = pv[18]; x20 = pv[19]; x21 = pv[20]; x22 = pv[21];
9583287d42SBarry Smith         x23 = pv[22]; x24 = pv[23]; x25 = pv[24];
9683287d42SBarry Smith         pc[0] = m1 = p1*x1 + p6*x2  + p11*x3 + p16*x4 + p21*x5;
9783287d42SBarry Smith         pc[1] = m2 = p2*x1 + p7*x2  + p12*x3 + p17*x4 + p22*x5;
9883287d42SBarry Smith         pc[2] = m3 = p3*x1 + p8*x2  + p13*x3 + p18*x4 + p23*x5;
9983287d42SBarry Smith         pc[3] = m4 = p4*x1 + p9*x2  + p14*x3 + p19*x4 + p24*x5;
10083287d42SBarry Smith         pc[4] = m5 = p5*x1 + p10*x2 + p15*x3 + p20*x4 + p25*x5;
10183287d42SBarry Smith 
10283287d42SBarry Smith         pc[5] = m6 = p1*x6 + p6*x7  + p11*x8 + p16*x9 + p21*x10;
10383287d42SBarry Smith         pc[6] = m7 = p2*x6 + p7*x7  + p12*x8 + p17*x9 + p22*x10;
10483287d42SBarry Smith         pc[7] = m8 = p3*x6 + p8*x7  + p13*x8 + p18*x9 + p23*x10;
10583287d42SBarry Smith         pc[8] = m9 = p4*x6 + p9*x7  + p14*x8 + p19*x9 + p24*x10;
10683287d42SBarry Smith         pc[9] = m10 = p5*x6 + p10*x7 + p15*x8 + p20*x9 + p25*x10;
10783287d42SBarry Smith 
10883287d42SBarry Smith         pc[10] = m11 = p1*x11 + p6*x12  + p11*x13 + p16*x14 + p21*x15;
10983287d42SBarry Smith         pc[11] = m12 = p2*x11 + p7*x12  + p12*x13 + p17*x14 + p22*x15;
11083287d42SBarry Smith         pc[12] = m13 = p3*x11 + p8*x12  + p13*x13 + p18*x14 + p23*x15;
11183287d42SBarry Smith         pc[13] = m14 = p4*x11 + p9*x12  + p14*x13 + p19*x14 + p24*x15;
11283287d42SBarry Smith         pc[14] = m15 = p5*x11 + p10*x12 + p15*x13 + p20*x14 + p25*x15;
11383287d42SBarry Smith 
11483287d42SBarry Smith         pc[15] = m16 = p1*x16 + p6*x17  + p11*x18 + p16*x19 + p21*x20;
11583287d42SBarry Smith         pc[16] = m17 = p2*x16 + p7*x17  + p12*x18 + p17*x19 + p22*x20;
11683287d42SBarry Smith         pc[17] = m18 = p3*x16 + p8*x17  + p13*x18 + p18*x19 + p23*x20;
11783287d42SBarry Smith         pc[18] = m19 = p4*x16 + p9*x17  + p14*x18 + p19*x19 + p24*x20;
11883287d42SBarry Smith         pc[19] = m20 = p5*x16 + p10*x17 + p15*x18 + p20*x19 + p25*x20;
11983287d42SBarry Smith 
12083287d42SBarry Smith         pc[20] = m21 = p1*x21 + p6*x22  + p11*x23 + p16*x24 + p21*x25;
12183287d42SBarry Smith         pc[21] = m22 = p2*x21 + p7*x22  + p12*x23 + p17*x24 + p22*x25;
12283287d42SBarry Smith         pc[22] = m23 = p3*x21 + p8*x22  + p13*x23 + p18*x24 + p23*x25;
12383287d42SBarry Smith         pc[23] = m24 = p4*x21 + p9*x22  + p14*x23 + p19*x24 + p24*x25;
12483287d42SBarry Smith         pc[24] = m25 = p5*x21 + p10*x22 + p15*x23 + p20*x24 + p25*x25;
12583287d42SBarry Smith 
12683287d42SBarry Smith         nz = bi[row+1] - diag_offset[row] - 1;
12783287d42SBarry Smith         pv += 25;
12883287d42SBarry Smith         for (j=0; j<nz; j++) {
12983287d42SBarry Smith           x1   = pv[0];  x2 = pv[1];   x3  = pv[2];  x4  = pv[3];
13083287d42SBarry Smith           x5   = pv[4];  x6 = pv[5];   x7  = pv[6];  x8  = pv[7]; x9 = pv[8];
13183287d42SBarry Smith           x10  = pv[9];  x11 = pv[10]; x12 = pv[11]; x13 = pv[12];
13283287d42SBarry Smith           x14  = pv[13]; x15 = pv[14]; x16 = pv[15]; x17 = pv[16];
13383287d42SBarry Smith           x18  = pv[17]; x19 = pv[18]; x20 = pv[19]; x21 = pv[20];
13483287d42SBarry Smith           x22  = pv[21]; x23 = pv[22]; x24 = pv[23]; x25 = pv[24];
13583287d42SBarry Smith           x    = rtmp + 25*pj[j];
13683287d42SBarry Smith           x[0] -= m1*x1 + m6*x2  + m11*x3 + m16*x4 + m21*x5;
13783287d42SBarry Smith           x[1] -= m2*x1 + m7*x2  + m12*x3 + m17*x4 + m22*x5;
13883287d42SBarry Smith           x[2] -= m3*x1 + m8*x2  + m13*x3 + m18*x4 + m23*x5;
13983287d42SBarry Smith           x[3] -= m4*x1 + m9*x2  + m14*x3 + m19*x4 + m24*x5;
14083287d42SBarry Smith           x[4] -= m5*x1 + m10*x2 + m15*x3 + m20*x4 + m25*x5;
14183287d42SBarry Smith 
14283287d42SBarry Smith           x[5] -= m1*x6 + m6*x7  + m11*x8 + m16*x9 + m21*x10;
14383287d42SBarry Smith           x[6] -= m2*x6 + m7*x7  + m12*x8 + m17*x9 + m22*x10;
14483287d42SBarry Smith           x[7] -= m3*x6 + m8*x7  + m13*x8 + m18*x9 + m23*x10;
14583287d42SBarry Smith           x[8] -= m4*x6 + m9*x7  + m14*x8 + m19*x9 + m24*x10;
14683287d42SBarry Smith           x[9] -= m5*x6 + m10*x7 + m15*x8 + m20*x9 + m25*x10;
14783287d42SBarry Smith 
14883287d42SBarry Smith           x[10] -= m1*x11 + m6*x12  + m11*x13 + m16*x14 + m21*x15;
14983287d42SBarry Smith           x[11] -= m2*x11 + m7*x12  + m12*x13 + m17*x14 + m22*x15;
15083287d42SBarry Smith           x[12] -= m3*x11 + m8*x12  + m13*x13 + m18*x14 + m23*x15;
15183287d42SBarry Smith           x[13] -= m4*x11 + m9*x12  + m14*x13 + m19*x14 + m24*x15;
15283287d42SBarry Smith           x[14] -= m5*x11 + m10*x12 + m15*x13 + m20*x14 + m25*x15;
15383287d42SBarry Smith 
15483287d42SBarry Smith           x[15] -= m1*x16 + m6*x17  + m11*x18 + m16*x19 + m21*x20;
15583287d42SBarry Smith           x[16] -= m2*x16 + m7*x17  + m12*x18 + m17*x19 + m22*x20;
15683287d42SBarry Smith           x[17] -= m3*x16 + m8*x17  + m13*x18 + m18*x19 + m23*x20;
15783287d42SBarry Smith           x[18] -= m4*x16 + m9*x17  + m14*x18 + m19*x19 + m24*x20;
15883287d42SBarry Smith           x[19] -= m5*x16 + m10*x17 + m15*x18 + m20*x19 + m25*x20;
15983287d42SBarry Smith 
16083287d42SBarry Smith           x[20] -= m1*x21 + m6*x22  + m11*x23 + m16*x24 + m21*x25;
16183287d42SBarry Smith           x[21] -= m2*x21 + m7*x22  + m12*x23 + m17*x24 + m22*x25;
16283287d42SBarry Smith           x[22] -= m3*x21 + m8*x22  + m13*x23 + m18*x24 + m23*x25;
16383287d42SBarry Smith           x[23] -= m4*x21 + m9*x22  + m14*x23 + m19*x24 + m24*x25;
16483287d42SBarry Smith           x[24] -= m5*x21 + m10*x22 + m15*x23 + m20*x24 + m25*x25;
16583287d42SBarry Smith 
16683287d42SBarry Smith           pv   += 25;
16783287d42SBarry Smith         }
168dc0b31edSSatish Balay         ierr = PetscLogFlops(250.0*nz+225.0);CHKERRQ(ierr);
16983287d42SBarry Smith       }
17083287d42SBarry Smith       row = *ajtmp++;
17183287d42SBarry Smith     }
17283287d42SBarry Smith     /* finished row so stick it into b->a */
17383287d42SBarry Smith     pv = ba + 25*bi[i];
17483287d42SBarry Smith     pj = bj + bi[i];
17583287d42SBarry Smith     nz = bi[i+1] - bi[i];
17683287d42SBarry Smith     for (j=0; j<nz; j++) {
1778397fe1aSBarry Smith #if defined(PETSC_USE_MEMCPY)
1788397fe1aSBarry Smith       ierr = PetscMemcpy(pv,rtmp+25*pj[j],25*sizeof(PetscScalar));CHKERRQ(ierr);
1798397fe1aSBarry Smith #else
18083287d42SBarry Smith       x     = rtmp+25*pj[j];
18183287d42SBarry Smith       pv[0] = x[0]; pv[1] = x[1]; pv[2] = x[2]; pv[3] = x[3];
18283287d42SBarry Smith       pv[4] = x[4]; pv[5] = x[5]; pv[6] = x[6]; pv[7] = x[7]; pv[8] = x[8];
18383287d42SBarry Smith       pv[9] = x[9]; pv[10] = x[10]; pv[11] = x[11]; pv[12] = x[12];
18483287d42SBarry Smith       pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; pv[16] = x[16];
18583287d42SBarry Smith       pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19]; pv[20] = x[20];
18683287d42SBarry Smith       pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23]; pv[24] = x[24];
1878397fe1aSBarry Smith #endif
18883287d42SBarry Smith       pv   += 25;
18983287d42SBarry Smith     }
19083287d42SBarry Smith     /* invert diagonal block */
19183287d42SBarry Smith     w = ba + 25*diag_offset[i];
19262bba022SBarry Smith     ierr = Kernel_A_gets_inverse_A_5(w,shift);CHKERRQ(ierr);
19383287d42SBarry Smith   }
19483287d42SBarry Smith 
19583287d42SBarry Smith   ierr = PetscFree(rtmp);CHKERRQ(ierr);
19683287d42SBarry Smith   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
19783287d42SBarry Smith   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
198db4efbfdSBarry Smith   C->ops->solve          = MatSolve_SeqBAIJ_5;
199db4efbfdSBarry Smith   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_5;
20083287d42SBarry Smith   C->assembled = PETSC_TRUE;
201efee365bSSatish Balay   ierr = PetscLogFlops(1.3333*125*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */
20283287d42SBarry Smith   PetscFunctionReturn(0);
20383287d42SBarry Smith }
2040deeaf61SShri Abhyankar 
2050deeaf61SShri Abhyankar /* MatLUFactorNumeric_SeqBAIJ_5_newdatastruct -
2060deeaf61SShri Abhyankar      copied from MatLUFactorNumeric_SeqBAIJ_N_newdatastruct() and manually re-implemented
2070deeaf61SShri Abhyankar        Kernel_A_gets_A_times_B()
2080deeaf61SShri Abhyankar        Kernel_A_gets_A_minus_B_times_C()
2090deeaf61SShri Abhyankar        Kernel_A_gets_inverse_A()
2100deeaf61SShri Abhyankar */
2110deeaf61SShri Abhyankar #undef __FUNCT__
2120deeaf61SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_5_newdatastruct"
2130deeaf61SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_5_newdatastruct(Mat B,Mat A,const MatFactorInfo *info)
2140deeaf61SShri Abhyankar {
2150deeaf61SShri Abhyankar   Mat            C=B;
2160deeaf61SShri Abhyankar   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data;
2170deeaf61SShri Abhyankar   IS             isrow = b->row,isicol = b->icol;
2180deeaf61SShri Abhyankar   PetscErrorCode ierr;
2190deeaf61SShri Abhyankar   const PetscInt *r,*ic,*ics;
2200deeaf61SShri Abhyankar   PetscInt       i,j,k,n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
2210deeaf61SShri Abhyankar   PetscInt       *ajtmp,*bjtmp,nz,nzL,row,*bdiag=b->diag,*pj;
2220deeaf61SShri Abhyankar   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
2230deeaf61SShri Abhyankar   PetscInt       bs2 = a->bs2,flg;
2240deeaf61SShri Abhyankar   PetscReal      shift = info->shiftinblocks;
2250deeaf61SShri Abhyankar 
2260deeaf61SShri Abhyankar   PetscFunctionBegin;
2270deeaf61SShri Abhyankar   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
2280deeaf61SShri Abhyankar   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
2290deeaf61SShri Abhyankar 
2300deeaf61SShri Abhyankar   /* generate work space needed by the factorization */
2310deeaf61SShri Abhyankar   ierr = PetscMalloc((bs2*n+bs2+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr);
2320deeaf61SShri Abhyankar   mwork = rtmp + bs2*n;
2330deeaf61SShri Abhyankar   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
2340deeaf61SShri Abhyankar   ics  = ic;
2350deeaf61SShri Abhyankar 
2360deeaf61SShri Abhyankar   for (i=0; i<n; i++){
2370deeaf61SShri Abhyankar     /* zero rtmp */
2380deeaf61SShri Abhyankar     /* L part */
2390deeaf61SShri Abhyankar     nz    = bi[i+1] - bi[i];
2400deeaf61SShri Abhyankar     bjtmp = bj + bi[i];
2410deeaf61SShri Abhyankar     for  (j=0; j<nz; j++){
2420deeaf61SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
2430deeaf61SShri Abhyankar     }
2440deeaf61SShri Abhyankar 
2450deeaf61SShri Abhyankar     /* U part */
2460deeaf61SShri Abhyankar     nz = bi[2*n-i+1] - bi[2*n-i];
2470deeaf61SShri Abhyankar     bjtmp = bj + bi[2*n-i];
2480deeaf61SShri Abhyankar     for  (j=0; j<nz; j++){
2490deeaf61SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
2500deeaf61SShri Abhyankar     }
2510deeaf61SShri Abhyankar 
2520deeaf61SShri Abhyankar     /* load in initial (unfactored row) */
2530deeaf61SShri Abhyankar     nz    = ai[r[i]+1] - ai[r[i]];
2540deeaf61SShri Abhyankar     ajtmp = aj + ai[r[i]];
2550deeaf61SShri Abhyankar     v     = aa + bs2*ai[r[i]];
2560deeaf61SShri Abhyankar     for (j=0; j<nz; j++) {
2570deeaf61SShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ic[ajtmp[j]],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
2580deeaf61SShri Abhyankar     }
2590deeaf61SShri Abhyankar 
2600deeaf61SShri Abhyankar     /* elimination */
2610deeaf61SShri Abhyankar     bjtmp = bj + bi[i];
2620deeaf61SShri Abhyankar     nzL   = bi[i+1] - bi[i];
263b1646270SShri Abhyankar     for(k=0;k < nzL;k++) {
264b1646270SShri Abhyankar       row = bjtmp[k];
2650deeaf61SShri Abhyankar       pc = rtmp + bs2*row;
2660deeaf61SShri Abhyankar       for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }}
2670deeaf61SShri Abhyankar       if (flg) {
2680deeaf61SShri Abhyankar         pv = b->a + bs2*bdiag[row];
2690deeaf61SShri Abhyankar         /* Kernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */
2700deeaf61SShri Abhyankar         ierr = Kernel_A_gets_A_times_B_5(pc,pv,mwork);CHKERRQ(ierr);
2710deeaf61SShri Abhyankar 
2720deeaf61SShri Abhyankar         pj = b->j + bi[2*n-row]; /* begining of U(row,:) */
2730deeaf61SShri Abhyankar         pv = b->a + bs2*bi[2*n-row];
2740deeaf61SShri Abhyankar         nz = bi[2*n-row+1] - bi[2*n-row] - 1; /* num of entries inU(row,:), excluding diag */
2750deeaf61SShri Abhyankar         for (j=0; j<nz; j++) {
2760deeaf61SShri Abhyankar           /* Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */
2770deeaf61SShri Abhyankar           /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */
2780deeaf61SShri Abhyankar           v    = rtmp + bs2*pj[j];
2790deeaf61SShri Abhyankar           ierr = Kernel_A_gets_A_minus_B_times_C_5(v,pc,pv);CHKERRQ(ierr);
2800deeaf61SShri Abhyankar           pv  += bs2;
2810deeaf61SShri Abhyankar         }
2820deeaf61SShri Abhyankar         ierr = PetscLogFlops(250*nz+225);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
2830deeaf61SShri Abhyankar       }
2840deeaf61SShri Abhyankar     }
2850deeaf61SShri Abhyankar 
2860deeaf61SShri Abhyankar     /* finished row so stick it into b->a */
2870deeaf61SShri Abhyankar     /* L part */
2880deeaf61SShri Abhyankar     pv   = b->a + bs2*bi[i] ;
2890deeaf61SShri Abhyankar     pj   = b->j + bi[i] ;
2900deeaf61SShri Abhyankar     nz   = bi[i+1] - bi[i];
2910deeaf61SShri Abhyankar     for (j=0; j<nz; j++) {
2920deeaf61SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
2930deeaf61SShri Abhyankar     }
2940deeaf61SShri Abhyankar 
2950deeaf61SShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
2960deeaf61SShri Abhyankar     pv   = b->a + bs2*bdiag[i];
2970deeaf61SShri Abhyankar     pj   = b->j + bdiag[i];
2980deeaf61SShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
2990deeaf61SShri Abhyankar     /* ierr = Kernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr); */
3000deeaf61SShri Abhyankar     ierr = Kernel_A_gets_inverse_A_5(pv,shift);CHKERRQ(ierr);
3010deeaf61SShri Abhyankar 
3020deeaf61SShri Abhyankar     /* U part */
3030deeaf61SShri Abhyankar     pv = b->a + bs2*bi[2*n-i];
3040deeaf61SShri Abhyankar     pj = b->j + bi[2*n-i];
3050deeaf61SShri Abhyankar     nz = bi[2*n-i+1] - bi[2*n-i] - 1;
3060deeaf61SShri Abhyankar     for (j=0; j<nz; j++){
3070deeaf61SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
3080deeaf61SShri Abhyankar     }
3090deeaf61SShri Abhyankar   }
3100deeaf61SShri Abhyankar 
3110deeaf61SShri Abhyankar   ierr = PetscFree(rtmp);CHKERRQ(ierr);
3120deeaf61SShri Abhyankar   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
3130deeaf61SShri Abhyankar   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
3140deeaf61SShri Abhyankar 
3150deeaf61SShri Abhyankar   C->assembled = PETSC_TRUE;
3160deeaf61SShri Abhyankar   ierr = PetscLogFlops(1.3333*bs2*n);CHKERRQ(ierr); /* from inverting diagonal blocks */
3170deeaf61SShri Abhyankar   PetscFunctionReturn(0);
3180deeaf61SShri Abhyankar }
3190deeaf61SShri Abhyankar 
320*78bb4007SShri Abhyankar #undef __FUNCT__
321*78bb4007SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_5_newdatastruct_v2"
322*78bb4007SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_5_newdatastruct_v2(Mat B,Mat A,const MatFactorInfo *info)
323*78bb4007SShri Abhyankar {
324*78bb4007SShri Abhyankar   Mat            C=B;
325*78bb4007SShri Abhyankar   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data;
326*78bb4007SShri Abhyankar   IS             isrow = b->row,isicol = b->icol;
327*78bb4007SShri Abhyankar   PetscErrorCode ierr;
328*78bb4007SShri Abhyankar   const PetscInt *r,*ic,*ics;
329*78bb4007SShri Abhyankar   PetscInt       i,j,k,n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
330*78bb4007SShri Abhyankar   PetscInt       *ajtmp,*bjtmp,nz,nzL,row,*bdiag=b->diag,*pj;
331*78bb4007SShri Abhyankar   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
332*78bb4007SShri Abhyankar   PetscInt       bs2 = a->bs2,flg;
333*78bb4007SShri Abhyankar   PetscReal      shift = info->shiftinblocks;
334*78bb4007SShri Abhyankar 
335*78bb4007SShri Abhyankar   PetscFunctionBegin;
336*78bb4007SShri Abhyankar   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
337*78bb4007SShri Abhyankar   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
338*78bb4007SShri Abhyankar 
339*78bb4007SShri Abhyankar   /* generate work space needed by the factorization */
340*78bb4007SShri Abhyankar   ierr = PetscMalloc((bs2*n+bs2+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr);
341*78bb4007SShri Abhyankar   mwork = rtmp + bs2*n;
342*78bb4007SShri Abhyankar   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
343*78bb4007SShri Abhyankar   ics  = ic;
344*78bb4007SShri Abhyankar 
345*78bb4007SShri Abhyankar   for (i=0; i<n; i++){
346*78bb4007SShri Abhyankar     /* zero rtmp */
347*78bb4007SShri Abhyankar     /* L part */
348*78bb4007SShri Abhyankar     nz    = bi[i+1] - bi[i];
349*78bb4007SShri Abhyankar     bjtmp = bj + bi[i];
350*78bb4007SShri Abhyankar     for  (j=0; j<nz; j++){
351*78bb4007SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
352*78bb4007SShri Abhyankar     }
353*78bb4007SShri Abhyankar 
354*78bb4007SShri Abhyankar     /* U part */
355*78bb4007SShri Abhyankar     nz = bdiag[i] - bdiag[i+1];
356*78bb4007SShri Abhyankar     bjtmp = bj + bdiag[i+1]+1;
357*78bb4007SShri Abhyankar     for  (j=0; j<nz; j++){
358*78bb4007SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
359*78bb4007SShri Abhyankar     }
360*78bb4007SShri Abhyankar 
361*78bb4007SShri Abhyankar     /* load in initial (unfactored row) */
362*78bb4007SShri Abhyankar     nz    = ai[r[i]+1] - ai[r[i]];
363*78bb4007SShri Abhyankar     ajtmp = aj + ai[r[i]];
364*78bb4007SShri Abhyankar     v     = aa + bs2*ai[r[i]];
365*78bb4007SShri Abhyankar     for (j=0; j<nz; j++) {
366*78bb4007SShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ic[ajtmp[j]],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
367*78bb4007SShri Abhyankar     }
368*78bb4007SShri Abhyankar 
369*78bb4007SShri Abhyankar     /* elimination */
370*78bb4007SShri Abhyankar     bjtmp = bj + bi[i];
371*78bb4007SShri Abhyankar     nzL   = bi[i+1] - bi[i];
372*78bb4007SShri Abhyankar     for(k=0;k < nzL;k++) {
373*78bb4007SShri Abhyankar       row = bjtmp[k];
374*78bb4007SShri Abhyankar       pc = rtmp + bs2*row;
375*78bb4007SShri Abhyankar       for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }}
376*78bb4007SShri Abhyankar       if (flg) {
377*78bb4007SShri Abhyankar         pv = b->a + bs2*bdiag[row];
378*78bb4007SShri Abhyankar         /* Kernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */
379*78bb4007SShri Abhyankar         ierr = Kernel_A_gets_A_times_B_5(pc,pv,mwork);CHKERRQ(ierr);
380*78bb4007SShri Abhyankar 
381*78bb4007SShri Abhyankar         pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
382*78bb4007SShri Abhyankar         pv = b->a + bs2*(bdiag[row+1]+1);
383*78bb4007SShri Abhyankar         nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
384*78bb4007SShri Abhyankar         for (j=0; j<nz; j++) {
385*78bb4007SShri Abhyankar           /* Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */
386*78bb4007SShri Abhyankar           /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */
387*78bb4007SShri Abhyankar           v    = rtmp + bs2*pj[j];
388*78bb4007SShri Abhyankar           ierr = Kernel_A_gets_A_minus_B_times_C_5(v,pc,pv);CHKERRQ(ierr);
389*78bb4007SShri Abhyankar           pv  += bs2;
390*78bb4007SShri Abhyankar         }
391*78bb4007SShri Abhyankar         ierr = PetscLogFlops(250*nz+225);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
392*78bb4007SShri Abhyankar       }
393*78bb4007SShri Abhyankar     }
394*78bb4007SShri Abhyankar 
395*78bb4007SShri Abhyankar     /* finished row so stick it into b->a */
396*78bb4007SShri Abhyankar     /* L part */
397*78bb4007SShri Abhyankar     pv   = b->a + bs2*bi[i] ;
398*78bb4007SShri Abhyankar     pj   = b->j + bi[i] ;
399*78bb4007SShri Abhyankar     nz   = bi[i+1] - bi[i];
400*78bb4007SShri Abhyankar     for (j=0; j<nz; j++) {
401*78bb4007SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
402*78bb4007SShri Abhyankar     }
403*78bb4007SShri Abhyankar 
404*78bb4007SShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
405*78bb4007SShri Abhyankar     pv   = b->a + bs2*bdiag[i];
406*78bb4007SShri Abhyankar     pj   = b->j + bdiag[i];
407*78bb4007SShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
408*78bb4007SShri Abhyankar     /* ierr = Kernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr); */
409*78bb4007SShri Abhyankar     ierr = Kernel_A_gets_inverse_A_5(pv,shift);CHKERRQ(ierr);
410*78bb4007SShri Abhyankar 
411*78bb4007SShri Abhyankar     /* U part */
412*78bb4007SShri Abhyankar     pv = b->a + bs2*(bdiag[i+1]+1);
413*78bb4007SShri Abhyankar     pj = b->j + bdiag[i+1]+1;
414*78bb4007SShri Abhyankar     nz = bdiag[i] - bdiag[i+1] - 1;
415*78bb4007SShri Abhyankar     for (j=0; j<nz; j++){
416*78bb4007SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
417*78bb4007SShri Abhyankar     }
418*78bb4007SShri Abhyankar   }
419*78bb4007SShri Abhyankar 
420*78bb4007SShri Abhyankar   ierr = PetscFree(rtmp);CHKERRQ(ierr);
421*78bb4007SShri Abhyankar   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
422*78bb4007SShri Abhyankar   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
423*78bb4007SShri Abhyankar 
424*78bb4007SShri Abhyankar   C->assembled = PETSC_TRUE;
425*78bb4007SShri Abhyankar   ierr = PetscLogFlops(1.3333*bs2*n);CHKERRQ(ierr); /* from inverting diagonal blocks */
426*78bb4007SShri Abhyankar   PetscFunctionReturn(0);
427*78bb4007SShri Abhyankar }
428*78bb4007SShri Abhyankar 
4290deeaf61SShri Abhyankar /*
4300deeaf61SShri Abhyankar       Version for when blocks are 5 by 5 Using natural ordering
4310deeaf61SShri Abhyankar */
4320deeaf61SShri Abhyankar #undef __FUNCT__
4330deeaf61SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_5_NaturalOrdering"
4340deeaf61SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_5_NaturalOrdering(Mat C,Mat A,const MatFactorInfo *info)
4350deeaf61SShri Abhyankar {
4360deeaf61SShri Abhyankar   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ *)C->data;
4370deeaf61SShri Abhyankar   PetscErrorCode ierr;
4380deeaf61SShri Abhyankar   PetscInt       i,j,n = a->mbs,*bi = b->i,*bj = b->j;
4390deeaf61SShri Abhyankar   PetscInt       *ajtmpold,*ajtmp,nz,row;
4400deeaf61SShri Abhyankar   PetscInt       *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj;
4410deeaf61SShri Abhyankar   MatScalar      *pv,*v,*rtmp,*pc,*w,*x;
4420deeaf61SShri Abhyankar   MatScalar      x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15;
4430deeaf61SShri Abhyankar   MatScalar      x16,x17,x18,x19,x20,x21,x22,x23,x24,x25;
4440deeaf61SShri Abhyankar   MatScalar      p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15;
4450deeaf61SShri Abhyankar   MatScalar      p16,p17,p18,p19,p20,p21,p22,p23,p24,p25;
4460deeaf61SShri Abhyankar   MatScalar      m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15;
4470deeaf61SShri Abhyankar   MatScalar      m16,m17,m18,m19,m20,m21,m22,m23,m24,m25;
4480deeaf61SShri Abhyankar   MatScalar      *ba = b->a,*aa = a->a;
4490deeaf61SShri Abhyankar   PetscReal      shift = info->shiftinblocks;
4500deeaf61SShri Abhyankar 
4510deeaf61SShri Abhyankar   PetscFunctionBegin;
4520deeaf61SShri Abhyankar   ierr = PetscMalloc(25*(n+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr);
4530deeaf61SShri Abhyankar   for (i=0; i<n; i++) {
4540deeaf61SShri Abhyankar     nz    = bi[i+1] - bi[i];
4550deeaf61SShri Abhyankar     ajtmp = bj + bi[i];
4560deeaf61SShri Abhyankar     for  (j=0; j<nz; j++) {
4570deeaf61SShri Abhyankar       x = rtmp+25*ajtmp[j];
4580deeaf61SShri Abhyankar       x[0]  = x[1]  = x[2]  = x[3]  = x[4]  = x[5]  = x[6] = x[7] = x[8] = x[9] = 0.0;
4590deeaf61SShri Abhyankar       x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = 0.0;
4600deeaf61SShri Abhyankar       x[16] = x[17] = x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = 0.0;
4610deeaf61SShri Abhyankar     }
4620deeaf61SShri Abhyankar     /* load in initial (unfactored row) */
4630deeaf61SShri Abhyankar     nz       = ai[i+1] - ai[i];
4640deeaf61SShri Abhyankar     ajtmpold = aj + ai[i];
4650deeaf61SShri Abhyankar     v        = aa + 25*ai[i];
4660deeaf61SShri Abhyankar     for (j=0; j<nz; j++) {
4670deeaf61SShri Abhyankar       x    = rtmp+25*ajtmpold[j];
4680deeaf61SShri Abhyankar       x[0]  = v[0];  x[1]  = v[1];  x[2]  = v[2];  x[3]  = v[3];
4690deeaf61SShri Abhyankar       x[4]  = v[4];  x[5]  = v[5];  x[6]  = v[6];  x[7]  = v[7];  x[8]  = v[8];
4700deeaf61SShri Abhyankar       x[9]  = v[9];  x[10] = v[10]; x[11] = v[11]; x[12] = v[12]; x[13] = v[13];
4710deeaf61SShri Abhyankar       x[14] = v[14]; x[15] = v[15]; x[16] = v[16]; x[17] = v[17]; x[18] = v[18];
4720deeaf61SShri Abhyankar       x[19] = v[19]; x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23];
4730deeaf61SShri Abhyankar       x[24] = v[24];
4740deeaf61SShri Abhyankar       v    += 25;
4750deeaf61SShri Abhyankar     }
4760deeaf61SShri Abhyankar     row = *ajtmp++;
4770deeaf61SShri Abhyankar     while (row < i) {
4780deeaf61SShri Abhyankar       pc  = rtmp + 25*row;
4790deeaf61SShri Abhyankar       p1  = pc[0];  p2  = pc[1];  p3  = pc[2];  p4  = pc[3];
4800deeaf61SShri Abhyankar       p5  = pc[4];  p6  = pc[5];  p7  = pc[6];  p8  = pc[7];  p9  = pc[8];
4810deeaf61SShri Abhyankar       p10 = pc[9];  p11 = pc[10]; p12 = pc[11]; p13 = pc[12]; p14 = pc[13];
4820deeaf61SShri Abhyankar       p15 = pc[14]; p16 = pc[15]; p17 = pc[16]; p18 = pc[17];
4830deeaf61SShri Abhyankar       p19 = pc[18]; p20 = pc[19]; p21 = pc[20]; p22 = pc[21]; p23 = pc[22];
4840deeaf61SShri Abhyankar       p24 = pc[23]; p25 = pc[24];
4850deeaf61SShri Abhyankar       if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 ||
4860deeaf61SShri Abhyankar           p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0 || p10 != 0.0 ||
4870deeaf61SShri Abhyankar           p11 != 0.0 || p12 != 0.0 || p13 != 0.0 || p14 != 0.0 || p15 != 0.0
4880deeaf61SShri Abhyankar           || p16 != 0.0 || p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0
4890deeaf61SShri Abhyankar           || p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 || p25 != 0.0) {
4900deeaf61SShri Abhyankar         pv = ba + 25*diag_offset[row];
4910deeaf61SShri Abhyankar         pj = bj + diag_offset[row] + 1;
4920deeaf61SShri Abhyankar         x1  = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
4930deeaf61SShri Abhyankar         x5  = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];  x9  = pv[8];
4940deeaf61SShri Abhyankar         x10 = pv[9];  x11 = pv[10]; x12 = pv[11]; x13 = pv[12]; x14 = pv[13];
4950deeaf61SShri Abhyankar         x15 = pv[14]; x16 = pv[15]; x17 = pv[16]; x18 = pv[17]; x19 = pv[18];
4960deeaf61SShri Abhyankar         x20 = pv[19]; x21 = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
4970deeaf61SShri Abhyankar         x25 = pv[24];
4980deeaf61SShri Abhyankar         pc[0] = m1 = p1*x1 + p6*x2  + p11*x3 + p16*x4 + p21*x5;
4990deeaf61SShri Abhyankar         pc[1] = m2 = p2*x1 + p7*x2  + p12*x3 + p17*x4 + p22*x5;
5000deeaf61SShri Abhyankar         pc[2] = m3 = p3*x1 + p8*x2  + p13*x3 + p18*x4 + p23*x5;
5010deeaf61SShri Abhyankar         pc[3] = m4 = p4*x1 + p9*x2  + p14*x3 + p19*x4 + p24*x5;
5020deeaf61SShri Abhyankar         pc[4] = m5 = p5*x1 + p10*x2 + p15*x3 + p20*x4 + p25*x5;
5030deeaf61SShri Abhyankar 
5040deeaf61SShri Abhyankar         pc[5]  = m6  = p1*x6 + p6*x7  + p11*x8 + p16*x9 + p21*x10;
5050deeaf61SShri Abhyankar         pc[6]  = m7  = p2*x6 + p7*x7  + p12*x8 + p17*x9 + p22*x10;
5060deeaf61SShri Abhyankar         pc[7]  = m8  = p3*x6 + p8*x7  + p13*x8 + p18*x9 + p23*x10;
5070deeaf61SShri Abhyankar         pc[8]  = m9  = p4*x6 + p9*x7  + p14*x8 + p19*x9 + p24*x10;
5080deeaf61SShri Abhyankar         pc[9]  = m10 = p5*x6 + p10*x7 + p15*x8 + p20*x9 + p25*x10;
5090deeaf61SShri Abhyankar 
5100deeaf61SShri Abhyankar         pc[10] = m11 = p1*x11 + p6*x12  + p11*x13 + p16*x14 + p21*x15;
5110deeaf61SShri Abhyankar         pc[11] = m12 = p2*x11 + p7*x12  + p12*x13 + p17*x14 + p22*x15;
5120deeaf61SShri Abhyankar         pc[12] = m13 = p3*x11 + p8*x12  + p13*x13 + p18*x14 + p23*x15;
5130deeaf61SShri Abhyankar         pc[13] = m14 = p4*x11 + p9*x12  + p14*x13 + p19*x14 + p24*x15;
5140deeaf61SShri Abhyankar         pc[14] = m15 = p5*x11 + p10*x12 + p15*x13 + p20*x14 + p25*x15;
5150deeaf61SShri Abhyankar 
5160deeaf61SShri Abhyankar         pc[15] = m16 = p1*x16 + p6*x17  + p11*x18 + p16*x19 + p21*x20;
5170deeaf61SShri Abhyankar         pc[16] = m17 = p2*x16 + p7*x17  + p12*x18 + p17*x19 + p22*x20;
5180deeaf61SShri Abhyankar         pc[17] = m18 = p3*x16 + p8*x17  + p13*x18 + p18*x19 + p23*x20;
5190deeaf61SShri Abhyankar         pc[18] = m19 = p4*x16 + p9*x17  + p14*x18 + p19*x19 + p24*x20;
5200deeaf61SShri Abhyankar         pc[19] = m20 = p5*x16 + p10*x17 + p15*x18 + p20*x19 + p25*x20;
5210deeaf61SShri Abhyankar 
5220deeaf61SShri Abhyankar         pc[20] = m21 = p1*x21 + p6*x22  + p11*x23 + p16*x24 + p21*x25;
5230deeaf61SShri Abhyankar         pc[21] = m22 = p2*x21 + p7*x22  + p12*x23 + p17*x24 + p22*x25;
5240deeaf61SShri Abhyankar         pc[22] = m23 = p3*x21 + p8*x22  + p13*x23 + p18*x24 + p23*x25;
5250deeaf61SShri Abhyankar         pc[23] = m24 = p4*x21 + p9*x22  + p14*x23 + p19*x24 + p24*x25;
5260deeaf61SShri Abhyankar         pc[24] = m25 = p5*x21 + p10*x22 + p15*x23 + p20*x24 + p25*x25;
5270deeaf61SShri Abhyankar 
5280deeaf61SShri Abhyankar         nz = bi[row+1] - diag_offset[row] - 1;
5290deeaf61SShri Abhyankar         pv += 25;
5300deeaf61SShri Abhyankar         for (j=0; j<nz; j++) {
5310deeaf61SShri Abhyankar           x1   = pv[0];  x2  = pv[1];   x3 = pv[2];  x4  = pv[3];
5320deeaf61SShri Abhyankar           x5   = pv[4];  x6  = pv[5];   x7 = pv[6];  x8  = pv[7]; x9 = pv[8];
5330deeaf61SShri Abhyankar           x10  = pv[9];  x11 = pv[10]; x12 = pv[11]; x13 = pv[12];
5340deeaf61SShri Abhyankar           x14  = pv[13]; x15 = pv[14]; x16 = pv[15]; x17 = pv[16]; x18 = pv[17];
5350deeaf61SShri Abhyankar           x19 = pv[18];  x20 = pv[19]; x21 = pv[20]; x22 = pv[21]; x23 = pv[22];
5360deeaf61SShri Abhyankar           x24 = pv[23];  x25 = pv[24];
5370deeaf61SShri Abhyankar           x    = rtmp + 25*pj[j];
5380deeaf61SShri Abhyankar           x[0] -= m1*x1 + m6*x2   + m11*x3  + m16*x4 + m21*x5;
5390deeaf61SShri Abhyankar           x[1] -= m2*x1 + m7*x2   + m12*x3  + m17*x4 + m22*x5;
5400deeaf61SShri Abhyankar           x[2] -= m3*x1 + m8*x2   + m13*x3  + m18*x4 + m23*x5;
5410deeaf61SShri Abhyankar           x[3] -= m4*x1 + m9*x2   + m14*x3  + m19*x4 + m24*x5;
5420deeaf61SShri Abhyankar           x[4] -= m5*x1 + m10*x2  + m15*x3  + m20*x4 + m25*x5;
5430deeaf61SShri Abhyankar 
5440deeaf61SShri Abhyankar           x[5] -= m1*x6 + m6*x7   + m11*x8  + m16*x9 + m21*x10;
5450deeaf61SShri Abhyankar           x[6] -= m2*x6 + m7*x7   + m12*x8  + m17*x9 + m22*x10;
5460deeaf61SShri Abhyankar           x[7] -= m3*x6 + m8*x7   + m13*x8  + m18*x9 + m23*x10;
5470deeaf61SShri Abhyankar           x[8] -= m4*x6 + m9*x7   + m14*x8  + m19*x9 + m24*x10;
5480deeaf61SShri Abhyankar           x[9] -= m5*x6 + m10*x7  + m15*x8  + m20*x9 + m25*x10;
5490deeaf61SShri Abhyankar 
5500deeaf61SShri Abhyankar           x[10] -= m1*x11 + m6*x12  + m11*x13 + m16*x14 + m21*x15;
5510deeaf61SShri Abhyankar           x[11] -= m2*x11 + m7*x12  + m12*x13 + m17*x14 + m22*x15;
5520deeaf61SShri Abhyankar           x[12] -= m3*x11 + m8*x12  + m13*x13 + m18*x14 + m23*x15;
5530deeaf61SShri Abhyankar           x[13] -= m4*x11 + m9*x12  + m14*x13 + m19*x14 + m24*x15;
5540deeaf61SShri Abhyankar           x[14] -= m5*x11 + m10*x12 + m15*x13 + m20*x14 + m25*x15;
5550deeaf61SShri Abhyankar 
5560deeaf61SShri Abhyankar           x[15] -= m1*x16 + m6*x17  + m11*x18 + m16*x19 + m21*x20;
5570deeaf61SShri Abhyankar           x[16] -= m2*x16 + m7*x17  + m12*x18 + m17*x19 + m22*x20;
5580deeaf61SShri Abhyankar           x[17] -= m3*x16 + m8*x17  + m13*x18 + m18*x19 + m23*x20;
5590deeaf61SShri Abhyankar           x[18] -= m4*x16 + m9*x17  + m14*x18 + m19*x19 + m24*x20;
5600deeaf61SShri Abhyankar           x[19] -= m5*x16 + m10*x17 + m15*x18 + m20*x19 + m25*x20;
5610deeaf61SShri Abhyankar 
5620deeaf61SShri Abhyankar           x[20] -= m1*x21 + m6*x22  + m11*x23 + m16*x24 + m21*x25;
5630deeaf61SShri Abhyankar           x[21] -= m2*x21 + m7*x22  + m12*x23 + m17*x24 + m22*x25;
5640deeaf61SShri Abhyankar           x[22] -= m3*x21 + m8*x22  + m13*x23 + m18*x24 + m23*x25;
5650deeaf61SShri Abhyankar           x[23] -= m4*x21 + m9*x22  + m14*x23 + m19*x24 + m24*x25;
5660deeaf61SShri Abhyankar           x[24] -= m5*x21 + m10*x22 + m15*x23 + m20*x24 + m25*x25;
5670deeaf61SShri Abhyankar           pv   += 25;
5680deeaf61SShri Abhyankar         }
5690deeaf61SShri Abhyankar         ierr = PetscLogFlops(250.0*nz+225.0);CHKERRQ(ierr);
5700deeaf61SShri Abhyankar       }
5710deeaf61SShri Abhyankar       row = *ajtmp++;
5720deeaf61SShri Abhyankar     }
5730deeaf61SShri Abhyankar     /* finished row so stick it into b->a */
5740deeaf61SShri Abhyankar     pv = ba + 25*bi[i];
5750deeaf61SShri Abhyankar     pj = bj + bi[i];
5760deeaf61SShri Abhyankar     nz = bi[i+1] - bi[i];
5770deeaf61SShri Abhyankar     for (j=0; j<nz; j++) {
5780deeaf61SShri Abhyankar       x      = rtmp+25*pj[j];
5790deeaf61SShri Abhyankar       pv[0]  = x[0];  pv[1]  = x[1];  pv[2]  = x[2];  pv[3]  = x[3];
5800deeaf61SShri Abhyankar       pv[4]  = x[4];  pv[5]  = x[5];  pv[6]  = x[6];  pv[7]  = x[7]; pv[8] = x[8];
5810deeaf61SShri Abhyankar       pv[9]  = x[9];  pv[10] = x[10]; pv[11] = x[11]; pv[12] = x[12];
5820deeaf61SShri Abhyankar       pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15]; pv[16] = x[16]; pv[17] = x[17];
5830deeaf61SShri Abhyankar       pv[18] = x[18]; pv[19] = x[19]; pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22];
5840deeaf61SShri Abhyankar       pv[23] = x[23]; pv[24] = x[24];
5850deeaf61SShri Abhyankar       pv   += 25;
5860deeaf61SShri Abhyankar     }
5870deeaf61SShri Abhyankar     /* invert diagonal block */
5880deeaf61SShri Abhyankar     w = ba + 25*diag_offset[i];
5890deeaf61SShri Abhyankar     ierr = Kernel_A_gets_inverse_A_5(w,shift);CHKERRQ(ierr);
5900deeaf61SShri Abhyankar   }
5910deeaf61SShri Abhyankar 
5920deeaf61SShri Abhyankar   ierr = PetscFree(rtmp);CHKERRQ(ierr);
5930deeaf61SShri Abhyankar   C->ops->solve          = MatSolve_SeqBAIJ_5_NaturalOrdering;
5940deeaf61SShri Abhyankar   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_5_NaturalOrdering;
5950deeaf61SShri Abhyankar   C->assembled = PETSC_TRUE;
5960deeaf61SShri Abhyankar   ierr = PetscLogFlops(1.3333*125*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */
5970deeaf61SShri Abhyankar   PetscFunctionReturn(0);
5980deeaf61SShri Abhyankar }
5990deeaf61SShri Abhyankar 
6000deeaf61SShri Abhyankar #undef __FUNCT__
6010deeaf61SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_5_NaturalOrdering_newdatastruct"
6020deeaf61SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_5_NaturalOrdering_newdatastruct(Mat B,Mat A,const MatFactorInfo *info)
6030deeaf61SShri Abhyankar {
6040deeaf61SShri Abhyankar   Mat            C=B;
6050deeaf61SShri Abhyankar   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data;
6060deeaf61SShri Abhyankar   PetscErrorCode ierr;
6070deeaf61SShri Abhyankar   PetscInt       i,j,k,n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
6080deeaf61SShri Abhyankar   PetscInt       *ajtmp,*bjtmp,nz,nzL,row,*bdiag=b->diag,*pj;
6090deeaf61SShri Abhyankar   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
6100deeaf61SShri Abhyankar   PetscInt       bs2 = a->bs2,flg;
6110deeaf61SShri Abhyankar   PetscReal      shift = info->shiftinblocks;
6120deeaf61SShri Abhyankar 
6130deeaf61SShri Abhyankar   PetscFunctionBegin;
6140deeaf61SShri Abhyankar   /* generate work space needed by the factorization */
6150deeaf61SShri Abhyankar   ierr = PetscMalloc((bs2*n+bs2+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr);
6160deeaf61SShri Abhyankar   mwork = rtmp + bs2*n;
6170deeaf61SShri Abhyankar   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
6180deeaf61SShri Abhyankar 
6190deeaf61SShri Abhyankar   for (i=0; i<n; i++){
6200deeaf61SShri Abhyankar     /* zero rtmp */
6210deeaf61SShri Abhyankar     /* L part */
6220deeaf61SShri Abhyankar     nz    = bi[i+1] - bi[i];
6230deeaf61SShri Abhyankar     bjtmp = bj + bi[i];
6240deeaf61SShri Abhyankar     for  (j=0; j<nz; j++){
6250deeaf61SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
6260deeaf61SShri Abhyankar     }
6270deeaf61SShri Abhyankar 
6280deeaf61SShri Abhyankar     /* U part */
6290deeaf61SShri Abhyankar     nz = bi[2*n-i+1] - bi[2*n-i];
6300deeaf61SShri Abhyankar     bjtmp = bj + bi[2*n-i];
6310deeaf61SShri Abhyankar     for  (j=0; j<nz; j++){
6320deeaf61SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
6330deeaf61SShri Abhyankar     }
6340deeaf61SShri Abhyankar 
6350deeaf61SShri Abhyankar     /* load in initial (unfactored row) */
6360deeaf61SShri Abhyankar     nz    = ai[i+1] - ai[i];
6370deeaf61SShri Abhyankar     ajtmp = aj + ai[i];
6380deeaf61SShri Abhyankar     v     = aa + bs2*ai[i];
6390deeaf61SShri Abhyankar     for (j=0; j<nz; j++) {
6400deeaf61SShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ajtmp[j],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
6410deeaf61SShri Abhyankar     }
6420deeaf61SShri Abhyankar 
6430deeaf61SShri Abhyankar     /* elimination */
6440deeaf61SShri Abhyankar     bjtmp = bj + bi[i];
6450deeaf61SShri Abhyankar     nzL   = bi[i+1] - bi[i];
646b1646270SShri Abhyankar     for(k=0;k < nzL;k++) {
647b1646270SShri Abhyankar       row = bjtmp[k];
6480deeaf61SShri Abhyankar       pc = rtmp + bs2*row;
6490deeaf61SShri Abhyankar       for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }}
6500deeaf61SShri Abhyankar       if (flg) {
6510deeaf61SShri Abhyankar         pv = b->a + bs2*bdiag[row];
6520deeaf61SShri Abhyankar         /* Kernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */
6530deeaf61SShri Abhyankar         ierr = Kernel_A_gets_A_times_B_5(pc,pv,mwork);CHKERRQ(ierr);
6540deeaf61SShri Abhyankar 
6550deeaf61SShri Abhyankar         pj = b->j + bi[2*n-row]; /* begining of U(row,:) */
6560deeaf61SShri Abhyankar         pv = b->a + bs2*bi[2*n-row];
6570deeaf61SShri Abhyankar         nz = bi[2*n-row+1] - bi[2*n-row] - 1; /* num of entries inU(row,:), excluding diag */
6580deeaf61SShri Abhyankar         for (j=0; j<nz; j++) {
6590deeaf61SShri Abhyankar           /* Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */
6600deeaf61SShri Abhyankar           /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */
6610deeaf61SShri Abhyankar           v    = rtmp + bs2*pj[j];
6620deeaf61SShri Abhyankar           ierr = Kernel_A_gets_A_minus_B_times_C_5(v,pc,pv);CHKERRQ(ierr);
6630deeaf61SShri Abhyankar           pv  += bs2;
6640deeaf61SShri Abhyankar         }
6650deeaf61SShri Abhyankar         ierr = PetscLogFlops(250*nz+225);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
6660deeaf61SShri Abhyankar       }
6670deeaf61SShri Abhyankar     }
6680deeaf61SShri Abhyankar 
6690deeaf61SShri Abhyankar     /* finished row so stick it into b->a */
6700deeaf61SShri Abhyankar     /* L part */
6710deeaf61SShri Abhyankar     pv   = b->a + bs2*bi[i] ;
6720deeaf61SShri Abhyankar     pj   = b->j + bi[i] ;
6730deeaf61SShri Abhyankar     nz   = bi[i+1] - bi[i];
6740deeaf61SShri Abhyankar     for (j=0; j<nz; j++) {
6750deeaf61SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
6760deeaf61SShri Abhyankar     }
6770deeaf61SShri Abhyankar 
6780deeaf61SShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
6790deeaf61SShri Abhyankar     pv   = b->a + bs2*bdiag[i];
6800deeaf61SShri Abhyankar     pj   = b->j + bdiag[i];
6810deeaf61SShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
6820deeaf61SShri Abhyankar     /* ierr = Kernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr); */
6830deeaf61SShri Abhyankar     ierr = Kernel_A_gets_inverse_A_5(pv,shift);CHKERRQ(ierr);
6840deeaf61SShri Abhyankar 
6850deeaf61SShri Abhyankar     /* U part */
6860deeaf61SShri Abhyankar     pv = b->a + bs2*bi[2*n-i];
6870deeaf61SShri Abhyankar     pj = b->j + bi[2*n-i];
6880deeaf61SShri Abhyankar     nz = bi[2*n-i+1] - bi[2*n-i] - 1;
6890deeaf61SShri Abhyankar     for (j=0; j<nz; j++){
6900deeaf61SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
6910deeaf61SShri Abhyankar     }
6920deeaf61SShri Abhyankar   }
6930deeaf61SShri Abhyankar 
6940deeaf61SShri Abhyankar   ierr = PetscFree(rtmp);CHKERRQ(ierr);
6950deeaf61SShri Abhyankar   C->assembled = PETSC_TRUE;
6960deeaf61SShri Abhyankar   ierr = PetscLogFlops(1.3333*bs2*n);CHKERRQ(ierr); /* from inverting diagonal blocks */
6970deeaf61SShri Abhyankar   PetscFunctionReturn(0);
6980deeaf61SShri Abhyankar }
69953cca76cSShri Abhyankar 
70053cca76cSShri Abhyankar #undef __FUNCT__
70153cca76cSShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_5_NaturalOrdering_newdatastruct_v2"
70253cca76cSShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_5_NaturalOrdering_newdatastruct_v2(Mat B,Mat A,const MatFactorInfo *info)
70353cca76cSShri Abhyankar {
70453cca76cSShri Abhyankar   Mat            C=B;
70553cca76cSShri Abhyankar   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data;
70653cca76cSShri Abhyankar   PetscErrorCode ierr;
70753cca76cSShri Abhyankar   PetscInt       i,j,k,n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
70853cca76cSShri Abhyankar   PetscInt       *ajtmp,*bjtmp,nz,nzL,row,*bdiag=b->diag,*pj;
70953cca76cSShri Abhyankar   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
71053cca76cSShri Abhyankar   PetscInt       bs2 = a->bs2,flg;
71153cca76cSShri Abhyankar   PetscReal      shift = info->shiftinblocks;
71253cca76cSShri Abhyankar 
71353cca76cSShri Abhyankar   PetscFunctionBegin;
71453cca76cSShri Abhyankar   /* generate work space needed by the factorization */
71553cca76cSShri Abhyankar   ierr = PetscMalloc((bs2*n+bs2+1)*sizeof(MatScalar),&rtmp);CHKERRQ(ierr);
71653cca76cSShri Abhyankar   mwork = rtmp + bs2*n;
71753cca76cSShri Abhyankar   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
71853cca76cSShri Abhyankar 
71953cca76cSShri Abhyankar   for (i=0; i<n; i++){
72053cca76cSShri Abhyankar     /* zero rtmp */
72153cca76cSShri Abhyankar     /* L part */
72253cca76cSShri Abhyankar     nz    = bi[i+1] - bi[i];
72353cca76cSShri Abhyankar     bjtmp = bj + bi[i];
72453cca76cSShri Abhyankar     for  (j=0; j<nz; j++){
72553cca76cSShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
72653cca76cSShri Abhyankar     }
72753cca76cSShri Abhyankar 
72853cca76cSShri Abhyankar     /* U part */
72953cca76cSShri Abhyankar     nz = bdiag[i] - bdiag[i+1];
73053cca76cSShri Abhyankar     bjtmp = bj + bdiag[i+1]+1;
73153cca76cSShri Abhyankar     for  (j=0; j<nz; j++){
73253cca76cSShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
73353cca76cSShri Abhyankar     }
73453cca76cSShri Abhyankar 
73553cca76cSShri Abhyankar     /* load in initial (unfactored row) */
73653cca76cSShri Abhyankar     nz    = ai[i+1] - ai[i];
73753cca76cSShri Abhyankar     ajtmp = aj + ai[i];
73853cca76cSShri Abhyankar     v     = aa + bs2*ai[i];
73953cca76cSShri Abhyankar     for (j=0; j<nz; j++) {
74053cca76cSShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ajtmp[j],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
74153cca76cSShri Abhyankar     }
74253cca76cSShri Abhyankar 
74353cca76cSShri Abhyankar     /* elimination */
74453cca76cSShri Abhyankar     bjtmp = bj + bi[i];
74553cca76cSShri Abhyankar     nzL   = bi[i+1] - bi[i];
74653cca76cSShri Abhyankar     for(k=0;k < nzL;k++) {
74753cca76cSShri Abhyankar       row = bjtmp[k];
74853cca76cSShri Abhyankar       pc = rtmp + bs2*row;
74953cca76cSShri Abhyankar       for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }}
75053cca76cSShri Abhyankar       if (flg) {
75153cca76cSShri Abhyankar         pv = b->a + bs2*bdiag[row];
75253cca76cSShri Abhyankar         /* Kernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */
75353cca76cSShri Abhyankar         ierr = Kernel_A_gets_A_times_B_5(pc,pv,mwork);CHKERRQ(ierr);
75453cca76cSShri Abhyankar 
75553cca76cSShri Abhyankar         pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
75653cca76cSShri Abhyankar         pv = b->a + bs2*(bdiag[row+1]+1);
75753cca76cSShri Abhyankar         nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
75853cca76cSShri Abhyankar         for (j=0; j<nz; j++) {
75953cca76cSShri Abhyankar           /* Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */
76053cca76cSShri Abhyankar           /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */
76153cca76cSShri Abhyankar           v    = rtmp + bs2*pj[j];
76253cca76cSShri Abhyankar           ierr = Kernel_A_gets_A_minus_B_times_C_5(v,pc,pv);CHKERRQ(ierr);
76353cca76cSShri Abhyankar           pv  += bs2;
76453cca76cSShri Abhyankar         }
76553cca76cSShri Abhyankar         ierr = PetscLogFlops(250*nz+225);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
76653cca76cSShri Abhyankar       }
76753cca76cSShri Abhyankar     }
76853cca76cSShri Abhyankar 
76953cca76cSShri Abhyankar     /* finished row so stick it into b->a */
77053cca76cSShri Abhyankar     /* L part */
77153cca76cSShri Abhyankar     pv   = b->a + bs2*bi[i] ;
77253cca76cSShri Abhyankar     pj   = b->j + bi[i] ;
77353cca76cSShri Abhyankar     nz   = bi[i+1] - bi[i];
77453cca76cSShri Abhyankar     for (j=0; j<nz; j++) {
77553cca76cSShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
77653cca76cSShri Abhyankar     }
77753cca76cSShri Abhyankar 
77853cca76cSShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
77953cca76cSShri Abhyankar     pv   = b->a + bs2*bdiag[i];
78053cca76cSShri Abhyankar     pj   = b->j + bdiag[i];
78153cca76cSShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
78253cca76cSShri Abhyankar     /* ierr = Kernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr); */
78353cca76cSShri Abhyankar     ierr = Kernel_A_gets_inverse_A_5(pv,shift);CHKERRQ(ierr);
78453cca76cSShri Abhyankar 
78553cca76cSShri Abhyankar     /* U part */
78653cca76cSShri Abhyankar     pv = b->a + bs2*(bdiag[i+1]+1);
78753cca76cSShri Abhyankar     pj = b->j + bdiag[i+1]+1;
78853cca76cSShri Abhyankar     nz = bdiag[i] - bdiag[i+1] - 1;
78953cca76cSShri Abhyankar     for (j=0; j<nz; j++){
79053cca76cSShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
79153cca76cSShri Abhyankar     }
79253cca76cSShri Abhyankar   }
79353cca76cSShri Abhyankar 
79453cca76cSShri Abhyankar   ierr = PetscFree(rtmp);CHKERRQ(ierr);
79553cca76cSShri Abhyankar   C->assembled = PETSC_TRUE;
79653cca76cSShri Abhyankar   ierr = PetscLogFlops(1.3333*bs2*n);CHKERRQ(ierr); /* from inverting diagonal blocks */
79753cca76cSShri Abhyankar   PetscFunctionReturn(0);
79853cca76cSShri Abhyankar }
799