xref: /petsc/src/mat/impls/baij/seq/baijfact7.c (revision 2e92ee13a8395f820cc1e3fd74a7607ed52efa2a)
1be1d678aSKris Buschelman 
283287d42SBarry Smith /*
383287d42SBarry Smith     Factorization code for BAIJ format.
483287d42SBarry Smith */
5c6db04a5SJed Brown #include <../src/mat/impls/baij/seq/baij.h>
6af0996ceSBarry Smith #include <petsc/private/kernels/blockinvert.h>
783287d42SBarry Smith 
883287d42SBarry Smith /* ------------------------------------------------------------*/
983287d42SBarry Smith /*
1083287d42SBarry Smith       Version for when blocks are 6 by 6
1183287d42SBarry Smith */
124a2ae208SSatish Balay #undef __FUNCT__
1306e38f1dSHong Zhang #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_6_inplace"
1406e38f1dSHong Zhang PetscErrorCode MatLUFactorNumeric_SeqBAIJ_6_inplace(Mat C,Mat A,const MatFactorInfo *info)
1583287d42SBarry Smith {
1683287d42SBarry Smith   Mat_SeqBAIJ    *a    = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ*)C->data;
1783287d42SBarry Smith   IS             isrow = b->row,isicol = b->icol;
186849ba73SBarry Smith   PetscErrorCode ierr;
195d0c19d7SBarry Smith   const PetscInt *ajtmpold,*ajtmp,*diag_offset = b->diag,*r,*ic,*bi = b->i,*bj = b->j,*ai=a->i,*aj=a->j,*pj;
205d0c19d7SBarry Smith   PetscInt       nz,row,i,j,n = a->mbs,idx;
2183287d42SBarry Smith   MatScalar      *pv,*v,*rtmp,*pc,*w,*x;
2283287d42SBarry Smith   MatScalar      p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4;
2383287d42SBarry Smith   MatScalar      p5,p6,p7,p8,p9,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16;
2483287d42SBarry Smith   MatScalar      x17,x18,x19,x20,x21,x22,x23,x24,x25,p10,p11,p12,p13,p14;
2583287d42SBarry Smith   MatScalar      p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,m10,m11,m12;
2683287d42SBarry Smith   MatScalar      m13,m14,m15,m16,m17,m18,m19,m20,m21,m22,m23,m24,m25;
2783287d42SBarry Smith   MatScalar      p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36;
2883287d42SBarry Smith   MatScalar      x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36;
2983287d42SBarry Smith   MatScalar      m26,m27,m28,m29,m30,m31,m32,m33,m34,m35,m36;
3083287d42SBarry Smith   MatScalar      *ba   = b->a,*aa = a->a;
31182b8fbaSHong Zhang   PetscReal      shift = info->shiftamount;
32*2e92ee13SHong Zhang   PetscBool      zeropivotdetected;
3383287d42SBarry Smith 
3483287d42SBarry Smith   PetscFunctionBegin;
3583287d42SBarry Smith   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
3683287d42SBarry Smith   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
37785e854fSJed Brown   ierr = PetscMalloc1(36*(n+1),&rtmp);CHKERRQ(ierr);
3883287d42SBarry Smith 
3983287d42SBarry Smith   for (i=0; i<n; i++) {
4083287d42SBarry Smith     nz    = bi[i+1] - bi[i];
4183287d42SBarry Smith     ajtmp = bj + bi[i];
4283287d42SBarry Smith     for  (j=0; j<nz; j++) {
4383287d42SBarry Smith       x     = rtmp+36*ajtmp[j];
4483287d42SBarry Smith       x[0]  = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0;
4583287d42SBarry Smith       x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0;
4683287d42SBarry Smith       x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0;
4783287d42SBarry Smith       x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0;
4883287d42SBarry Smith       x[34] = x[35] = 0.0;
4983287d42SBarry Smith     }
5083287d42SBarry Smith     /* load in initial (unfactored row) */
5183287d42SBarry Smith     idx      = r[i];
5283287d42SBarry Smith     nz       = ai[idx+1] - ai[idx];
5383287d42SBarry Smith     ajtmpold = aj + ai[idx];
5483287d42SBarry Smith     v        = aa + 36*ai[idx];
5583287d42SBarry Smith     for (j=0; j<nz; j++) {
5683287d42SBarry Smith       x     = rtmp+36*ic[ajtmpold[j]];
5783287d42SBarry Smith       x[0]  =  v[0];  x[1] =  v[1];  x[2] =  v[2];  x[3] =  v[3];
5883287d42SBarry Smith       x[4]  =  v[4];  x[5] =  v[5];  x[6] =  v[6];  x[7] =  v[7];
5983287d42SBarry Smith       x[8]  =  v[8];  x[9] =  v[9];  x[10] = v[10]; x[11] = v[11];
6083287d42SBarry Smith       x[12] = v[12]; x[13] = v[13]; x[14] = v[14]; x[15] = v[15];
6183287d42SBarry Smith       x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; x[19] = v[19];
6283287d42SBarry Smith       x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23];
6383287d42SBarry Smith       x[24] = v[24]; x[25] = v[25]; x[26] = v[26]; x[27] = v[27];
6483287d42SBarry Smith       x[28] = v[28]; x[29] = v[29]; x[30] = v[30]; x[31] = v[31];
6583287d42SBarry Smith       x[32] = v[32]; x[33] = v[33]; x[34] = v[34]; x[35] = v[35];
6683287d42SBarry Smith       v    += 36;
6783287d42SBarry Smith     }
6883287d42SBarry Smith     row = *ajtmp++;
6983287d42SBarry Smith     while (row < i) {
7083287d42SBarry Smith       pc  =  rtmp + 36*row;
7183287d42SBarry Smith       p1  = pc[0];  p2  = pc[1];  p3  = pc[2];  p4  = pc[3];
7283287d42SBarry Smith       p5  = pc[4];  p6  = pc[5];  p7  = pc[6];  p8  = pc[7];
7383287d42SBarry Smith       p9  = pc[8];  p10 = pc[9];  p11 = pc[10]; p12 = pc[11];
7483287d42SBarry Smith       p13 = pc[12]; p14 = pc[13]; p15 = pc[14]; p16 = pc[15];
7583287d42SBarry Smith       p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; p20 = pc[19];
7683287d42SBarry Smith       p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23];
7783287d42SBarry Smith       p25 = pc[24]; p26 = pc[25]; p27 = pc[26]; p28 = pc[27];
7883287d42SBarry Smith       p29 = pc[28]; p30 = pc[29]; p31 = pc[30]; p32 = pc[31];
7983287d42SBarry Smith       p33 = pc[32]; p34 = pc[33]; p35 = pc[34]; p36 = pc[35];
8083287d42SBarry Smith       if (p1  != 0.0 || p2  != 0.0 || p3  != 0.0 || p4  != 0.0 ||
8183287d42SBarry Smith           p5  != 0.0 || p6  != 0.0 || p7  != 0.0 || p8  != 0.0 ||
8283287d42SBarry Smith           p9  != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 ||
8383287d42SBarry Smith           p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 ||
8483287d42SBarry Smith           p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 ||
8583287d42SBarry Smith           p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 ||
8683287d42SBarry Smith           p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 ||
8783287d42SBarry Smith           p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 ||
8883287d42SBarry Smith           p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0) {
8983287d42SBarry Smith         pv    = ba + 36*diag_offset[row];
9083287d42SBarry Smith         pj    = bj + diag_offset[row] + 1;
9183287d42SBarry Smith         x1    = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
9283287d42SBarry Smith         x5    = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];
9383287d42SBarry Smith         x9    = pv[8];  x10 = pv[9];  x11 = pv[10]; x12 = pv[11];
9483287d42SBarry Smith         x13   = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15];
9583287d42SBarry Smith         x17   = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19];
9683287d42SBarry Smith         x21   = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
9783287d42SBarry Smith         x25   = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27];
9883287d42SBarry Smith         x29   = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31];
9983287d42SBarry Smith         x33   = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35];
10083287d42SBarry Smith         pc[0] = m1  = p1*x1  + p7*x2   + p13*x3  + p19*x4  + p25*x5  + p31*x6;
10183287d42SBarry Smith         pc[1] = m2  = p2*x1  + p8*x2   + p14*x3  + p20*x4  + p26*x5  + p32*x6;
10283287d42SBarry Smith         pc[2] = m3  = p3*x1  + p9*x2   + p15*x3  + p21*x4  + p27*x5  + p33*x6;
10383287d42SBarry Smith         pc[3] = m4  = p4*x1  + p10*x2  + p16*x3  + p22*x4  + p28*x5  + p34*x6;
10483287d42SBarry Smith         pc[4] = m5  = p5*x1  + p11*x2  + p17*x3  + p23*x4  + p29*x5  + p35*x6;
10583287d42SBarry Smith         pc[5] = m6  = p6*x1  + p12*x2  + p18*x3  + p24*x4  + p30*x5  + p36*x6;
10683287d42SBarry Smith 
10783287d42SBarry Smith         pc[6]  = m7  = p1*x7  + p7*x8   + p13*x9  + p19*x10 + p25*x11 + p31*x12;
10883287d42SBarry Smith         pc[7]  = m8  = p2*x7  + p8*x8   + p14*x9  + p20*x10 + p26*x11 + p32*x12;
10983287d42SBarry Smith         pc[8]  = m9  = p3*x7  + p9*x8   + p15*x9  + p21*x10 + p27*x11 + p33*x12;
11083287d42SBarry Smith         pc[9]  = m10 = p4*x7  + p10*x8  + p16*x9  + p22*x10 + p28*x11 + p34*x12;
11183287d42SBarry Smith         pc[10] = m11 = p5*x7  + p11*x8  + p17*x9  + p23*x10 + p29*x11 + p35*x12;
11283287d42SBarry Smith         pc[11] = m12 = p6*x7  + p12*x8  + p18*x9  + p24*x10 + p30*x11 + p36*x12;
11383287d42SBarry Smith 
11483287d42SBarry Smith         pc[12] = m13 = p1*x13 + p7*x14  + p13*x15 + p19*x16 + p25*x17 + p31*x18;
11583287d42SBarry Smith         pc[13] = m14 = p2*x13 + p8*x14  + p14*x15 + p20*x16 + p26*x17 + p32*x18;
11683287d42SBarry Smith         pc[14] = m15 = p3*x13 + p9*x14  + p15*x15 + p21*x16 + p27*x17 + p33*x18;
11783287d42SBarry Smith         pc[15] = m16 = p4*x13 + p10*x14 + p16*x15 + p22*x16 + p28*x17 + p34*x18;
11883287d42SBarry Smith         pc[16] = m17 = p5*x13 + p11*x14 + p17*x15 + p23*x16 + p29*x17 + p35*x18;
11983287d42SBarry Smith         pc[17] = m18 = p6*x13 + p12*x14 + p18*x15 + p24*x16 + p30*x17 + p36*x18;
12083287d42SBarry Smith 
12183287d42SBarry Smith         pc[18] = m19 = p1*x19 + p7*x20  + p13*x21 + p19*x22 + p25*x23 + p31*x24;
12283287d42SBarry Smith         pc[19] = m20 = p2*x19 + p8*x20  + p14*x21 + p20*x22 + p26*x23 + p32*x24;
12383287d42SBarry Smith         pc[20] = m21 = p3*x19 + p9*x20  + p15*x21 + p21*x22 + p27*x23 + p33*x24;
12483287d42SBarry Smith         pc[21] = m22 = p4*x19 + p10*x20 + p16*x21 + p22*x22 + p28*x23 + p34*x24;
12583287d42SBarry Smith         pc[22] = m23 = p5*x19 + p11*x20 + p17*x21 + p23*x22 + p29*x23 + p35*x24;
12683287d42SBarry Smith         pc[23] = m24 = p6*x19 + p12*x20 + p18*x21 + p24*x22 + p30*x23 + p36*x24;
12783287d42SBarry Smith 
12883287d42SBarry Smith         pc[24] = m25 = p1*x25 + p7*x26  + p13*x27 + p19*x28 + p25*x29 + p31*x30;
12983287d42SBarry Smith         pc[25] = m26 = p2*x25 + p8*x26  + p14*x27 + p20*x28 + p26*x29 + p32*x30;
13083287d42SBarry Smith         pc[26] = m27 = p3*x25 + p9*x26  + p15*x27 + p21*x28 + p27*x29 + p33*x30;
13183287d42SBarry Smith         pc[27] = m28 = p4*x25 + p10*x26 + p16*x27 + p22*x28 + p28*x29 + p34*x30;
13283287d42SBarry Smith         pc[28] = m29 = p5*x25 + p11*x26 + p17*x27 + p23*x28 + p29*x29 + p35*x30;
13383287d42SBarry Smith         pc[29] = m30 = p6*x25 + p12*x26 + p18*x27 + p24*x28 + p30*x29 + p36*x30;
13483287d42SBarry Smith 
13583287d42SBarry Smith         pc[30] = m31 = p1*x31 + p7*x32  + p13*x33 + p19*x34 + p25*x35 + p31*x36;
13683287d42SBarry Smith         pc[31] = m32 = p2*x31 + p8*x32  + p14*x33 + p20*x34 + p26*x35 + p32*x36;
13783287d42SBarry Smith         pc[32] = m33 = p3*x31 + p9*x32  + p15*x33 + p21*x34 + p27*x35 + p33*x36;
13883287d42SBarry Smith         pc[33] = m34 = p4*x31 + p10*x32 + p16*x33 + p22*x34 + p28*x35 + p34*x36;
13983287d42SBarry Smith         pc[34] = m35 = p5*x31 + p11*x32 + p17*x33 + p23*x34 + p29*x35 + p35*x36;
14083287d42SBarry Smith         pc[35] = m36 = p6*x31 + p12*x32 + p18*x33 + p24*x34 + p30*x35 + p36*x36;
14183287d42SBarry Smith 
14283287d42SBarry Smith         nz  = bi[row+1] - diag_offset[row] - 1;
14383287d42SBarry Smith         pv += 36;
14483287d42SBarry Smith         for (j=0; j<nz; j++) {
14583287d42SBarry Smith           x1    = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
14683287d42SBarry Smith           x5    = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];
14783287d42SBarry Smith           x9    = pv[8];  x10 = pv[9];  x11 = pv[10]; x12 = pv[11];
14883287d42SBarry Smith           x13   = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15];
14983287d42SBarry Smith           x17   = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19];
15083287d42SBarry Smith           x21   = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
15183287d42SBarry Smith           x25   = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27];
15283287d42SBarry Smith           x29   = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31];
15383287d42SBarry Smith           x33   = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35];
15483287d42SBarry Smith           x     = rtmp + 36*pj[j];
15583287d42SBarry Smith           x[0] -= m1*x1  + m7*x2   + m13*x3  + m19*x4  + m25*x5  + m31*x6;
15683287d42SBarry Smith           x[1] -= m2*x1  + m8*x2   + m14*x3  + m20*x4  + m26*x5  + m32*x6;
15783287d42SBarry Smith           x[2] -= m3*x1  + m9*x2   + m15*x3  + m21*x4  + m27*x5  + m33*x6;
15883287d42SBarry Smith           x[3] -= m4*x1  + m10*x2  + m16*x3  + m22*x4  + m28*x5  + m34*x6;
15983287d42SBarry Smith           x[4] -= m5*x1  + m11*x2  + m17*x3  + m23*x4  + m29*x5  + m35*x6;
16083287d42SBarry Smith           x[5] -= m6*x1  + m12*x2  + m18*x3  + m24*x4  + m30*x5  + m36*x6;
16183287d42SBarry Smith 
16283287d42SBarry Smith           x[6]  -= m1*x7  + m7*x8   + m13*x9  + m19*x10 + m25*x11 + m31*x12;
16383287d42SBarry Smith           x[7]  -= m2*x7  + m8*x8   + m14*x9  + m20*x10 + m26*x11 + m32*x12;
16483287d42SBarry Smith           x[8]  -= m3*x7  + m9*x8   + m15*x9  + m21*x10 + m27*x11 + m33*x12;
16583287d42SBarry Smith           x[9]  -= m4*x7  + m10*x8  + m16*x9  + m22*x10 + m28*x11 + m34*x12;
16683287d42SBarry Smith           x[10] -= m5*x7  + m11*x8  + m17*x9  + m23*x10 + m29*x11 + m35*x12;
16783287d42SBarry Smith           x[11] -= m6*x7  + m12*x8  + m18*x9  + m24*x10 + m30*x11 + m36*x12;
16883287d42SBarry Smith 
16983287d42SBarry Smith           x[12] -= m1*x13 + m7*x14  + m13*x15 + m19*x16 + m25*x17 + m31*x18;
17083287d42SBarry Smith           x[13] -= m2*x13 + m8*x14  + m14*x15 + m20*x16 + m26*x17 + m32*x18;
17183287d42SBarry Smith           x[14] -= m3*x13 + m9*x14  + m15*x15 + m21*x16 + m27*x17 + m33*x18;
17283287d42SBarry Smith           x[15] -= m4*x13 + m10*x14 + m16*x15 + m22*x16 + m28*x17 + m34*x18;
17383287d42SBarry Smith           x[16] -= m5*x13 + m11*x14 + m17*x15 + m23*x16 + m29*x17 + m35*x18;
17483287d42SBarry Smith           x[17] -= m6*x13 + m12*x14 + m18*x15 + m24*x16 + m30*x17 + m36*x18;
17583287d42SBarry Smith 
17683287d42SBarry Smith           x[18] -= m1*x19 + m7*x20  + m13*x21 + m19*x22 + m25*x23 + m31*x24;
17783287d42SBarry Smith           x[19] -= m2*x19 + m8*x20  + m14*x21 + m20*x22 + m26*x23 + m32*x24;
17883287d42SBarry Smith           x[20] -= m3*x19 + m9*x20  + m15*x21 + m21*x22 + m27*x23 + m33*x24;
17983287d42SBarry Smith           x[21] -= m4*x19 + m10*x20 + m16*x21 + m22*x22 + m28*x23 + m34*x24;
18083287d42SBarry Smith           x[22] -= m5*x19 + m11*x20 + m17*x21 + m23*x22 + m29*x23 + m35*x24;
18183287d42SBarry Smith           x[23] -= m6*x19 + m12*x20 + m18*x21 + m24*x22 + m30*x23 + m36*x24;
18283287d42SBarry Smith 
18383287d42SBarry Smith           x[24] -= m1*x25 + m7*x26  + m13*x27 + m19*x28 + m25*x29 + m31*x30;
18483287d42SBarry Smith           x[25] -= m2*x25 + m8*x26  + m14*x27 + m20*x28 + m26*x29 + m32*x30;
18583287d42SBarry Smith           x[26] -= m3*x25 + m9*x26  + m15*x27 + m21*x28 + m27*x29 + m33*x30;
18683287d42SBarry Smith           x[27] -= m4*x25 + m10*x26 + m16*x27 + m22*x28 + m28*x29 + m34*x30;
18783287d42SBarry Smith           x[28] -= m5*x25 + m11*x26 + m17*x27 + m23*x28 + m29*x29 + m35*x30;
18883287d42SBarry Smith           x[29] -= m6*x25 + m12*x26 + m18*x27 + m24*x28 + m30*x29 + m36*x30;
18983287d42SBarry Smith 
19083287d42SBarry Smith           x[30] -= m1*x31 + m7*x32  + m13*x33 + m19*x34 + m25*x35 + m31*x36;
19183287d42SBarry Smith           x[31] -= m2*x31 + m8*x32  + m14*x33 + m20*x34 + m26*x35 + m32*x36;
19283287d42SBarry Smith           x[32] -= m3*x31 + m9*x32  + m15*x33 + m21*x34 + m27*x35 + m33*x36;
19383287d42SBarry Smith           x[33] -= m4*x31 + m10*x32 + m16*x33 + m22*x34 + m28*x35 + m34*x36;
19483287d42SBarry Smith           x[34] -= m5*x31 + m11*x32 + m17*x33 + m23*x34 + m29*x35 + m35*x36;
19583287d42SBarry Smith           x[35] -= m6*x31 + m12*x32 + m18*x33 + m24*x34 + m30*x35 + m36*x36;
19683287d42SBarry Smith 
19783287d42SBarry Smith           pv += 36;
19883287d42SBarry Smith         }
199dc0b31edSSatish Balay         ierr = PetscLogFlops(432.0*nz+396.0);CHKERRQ(ierr);
20083287d42SBarry Smith       }
20183287d42SBarry Smith       row = *ajtmp++;
20283287d42SBarry Smith     }
20383287d42SBarry Smith     /* finished row so stick it into b->a */
20483287d42SBarry Smith     pv = ba + 36*bi[i];
20583287d42SBarry Smith     pj = bj + bi[i];
20683287d42SBarry Smith     nz = bi[i+1] - bi[i];
20783287d42SBarry Smith     for (j=0; j<nz; j++) {
20883287d42SBarry Smith       x      = rtmp+36*pj[j];
20983287d42SBarry Smith       pv[0]  = x[0];  pv[1]  = x[1];  pv[2]  = x[2];  pv[3]  = x[3];
21083287d42SBarry Smith       pv[4]  = x[4];  pv[5]  = x[5];  pv[6]  = x[6];  pv[7]  = x[7];
21183287d42SBarry Smith       pv[8]  = x[8];  pv[9]  = x[9];  pv[10] = x[10]; pv[11] = x[11];
21283287d42SBarry Smith       pv[12] = x[12]; pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15];
21383287d42SBarry Smith       pv[16] = x[16]; pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19];
21483287d42SBarry Smith       pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23];
21583287d42SBarry Smith       pv[24] = x[24]; pv[25] = x[25]; pv[26] = x[26]; pv[27] = x[27];
21683287d42SBarry Smith       pv[28] = x[28]; pv[29] = x[29]; pv[30] = x[30]; pv[31] = x[31];
21783287d42SBarry Smith       pv[32] = x[32]; pv[33] = x[33]; pv[34] = x[34]; pv[35] = x[35];
21883287d42SBarry Smith       pv    += 36;
21983287d42SBarry Smith     }
22083287d42SBarry Smith     /* invert diagonal block */
22183287d42SBarry Smith     w    = ba + 36*diag_offset[i];
222*2e92ee13SHong Zhang     ierr = PetscKernel_A_gets_inverse_A_6(w,shift,!A->erroriffailure,&zeropivotdetected);CHKERRQ(ierr);
223*2e92ee13SHong Zhang     if (zeropivotdetected) C->errortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
22483287d42SBarry Smith   }
22583287d42SBarry Smith 
22683287d42SBarry Smith   ierr = PetscFree(rtmp);CHKERRQ(ierr);
22783287d42SBarry Smith   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
22883287d42SBarry Smith   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
22926fbe8dcSKarl Rupp 
23006e38f1dSHong Zhang   C->ops->solve          = MatSolve_SeqBAIJ_6_inplace;
23106e38f1dSHong Zhang   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_6_inplace;
23283287d42SBarry Smith   C->assembled           = PETSC_TRUE;
23326fbe8dcSKarl Rupp 
234766f9fbaSBarry Smith   ierr = PetscLogFlops(1.333333333333*6*6*6*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */
23583287d42SBarry Smith   PetscFunctionReturn(0);
23683287d42SBarry Smith }
237bef36659SShri Abhyankar 
238bef36659SShri Abhyankar #undef __FUNCT__
2394dd39f65SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_6"
2404dd39f65SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_6(Mat B,Mat A,const MatFactorInfo *info)
241bef36659SShri Abhyankar {
242bef36659SShri Abhyankar   Mat            C     = B;
243bef36659SShri Abhyankar   Mat_SeqBAIJ    *a    = (Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ*)C->data;
244bef36659SShri Abhyankar   IS             isrow = b->row,isicol = b->icol;
245bef36659SShri Abhyankar   PetscErrorCode ierr;
2465a586d82SBarry Smith   const PetscInt *r,*ic;
247bbd65245SShri Abhyankar   PetscInt       i,j,k,nz,nzL,row;
248bbd65245SShri Abhyankar   const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
249bbd65245SShri Abhyankar   const PetscInt *ajtmp,*bjtmp,*bdiag=b->diag,*pj,bs2=a->bs2;
250bef36659SShri Abhyankar   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
251bbd65245SShri Abhyankar   PetscInt       flg;
252182b8fbaSHong Zhang   PetscReal      shift = info->shiftamount;
253*2e92ee13SHong Zhang   PetscBool      zeropivotdetected;
254bef36659SShri Abhyankar 
255bef36659SShri Abhyankar   PetscFunctionBegin;
256bef36659SShri Abhyankar   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
257bef36659SShri Abhyankar   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
258bef36659SShri Abhyankar 
259bef36659SShri Abhyankar   /* generate work space needed by the factorization */
260dcca6d9dSJed Brown   ierr = PetscMalloc2(bs2*n,&rtmp,bs2,&mwork);CHKERRQ(ierr);
261bef36659SShri Abhyankar   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
262bef36659SShri Abhyankar 
263bef36659SShri Abhyankar   for (i=0; i<n; i++) {
264bef36659SShri Abhyankar     /* zero rtmp */
265bef36659SShri Abhyankar     /* L part */
266bef36659SShri Abhyankar     nz    = bi[i+1] - bi[i];
267bef36659SShri Abhyankar     bjtmp = bj + bi[i];
268bef36659SShri Abhyankar     for  (j=0; j<nz; j++) {
269bef36659SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
270bef36659SShri Abhyankar     }
271bef36659SShri Abhyankar 
272bef36659SShri Abhyankar     /* U part */
2736506fda5SShri Abhyankar     nz    = bdiag[i] - bdiag[i+1];
2746506fda5SShri Abhyankar     bjtmp = bj + bdiag[i+1]+1;
2756506fda5SShri Abhyankar     for  (j=0; j<nz; j++) {
2766506fda5SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
2776506fda5SShri Abhyankar     }
2786506fda5SShri Abhyankar 
2796506fda5SShri Abhyankar     /* load in initial (unfactored row) */
2806506fda5SShri Abhyankar     nz    = ai[r[i]+1] - ai[r[i]];
2816506fda5SShri Abhyankar     ajtmp = aj + ai[r[i]];
2826506fda5SShri Abhyankar     v     = aa + bs2*ai[r[i]];
2836506fda5SShri Abhyankar     for (j=0; j<nz; j++) {
2846506fda5SShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ic[ajtmp[j]],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
2856506fda5SShri Abhyankar     }
2866506fda5SShri Abhyankar 
2876506fda5SShri Abhyankar     /* elimination */
2886506fda5SShri Abhyankar     bjtmp = bj + bi[i];
2896506fda5SShri Abhyankar     nzL   = bi[i+1] - bi[i];
2906506fda5SShri Abhyankar     for (k=0; k < nzL; k++) {
2916506fda5SShri Abhyankar       row = bjtmp[k];
2926506fda5SShri Abhyankar       pc  = rtmp + bs2*row;
293c35f09e5SBarry Smith       for (flg=0,j=0; j<bs2; j++) {
294c35f09e5SBarry Smith         if (pc[j]!=0.0) {
295c35f09e5SBarry Smith           flg = 1;
296c35f09e5SBarry Smith           break;
297c35f09e5SBarry Smith         }
298c35f09e5SBarry Smith       }
2996506fda5SShri Abhyankar       if (flg) {
3006506fda5SShri Abhyankar         pv = b->a + bs2*bdiag[row];
30196b95a6bSBarry Smith         /* PetscKernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */
30296b95a6bSBarry Smith         ierr = PetscKernel_A_gets_A_times_B_6(pc,pv,mwork);CHKERRQ(ierr);
3036506fda5SShri Abhyankar 
3046506fda5SShri Abhyankar         pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
3056506fda5SShri Abhyankar         pv = b->a + bs2*(bdiag[row+1]+1);
3066506fda5SShri Abhyankar         nz = bdiag[row] - bdiag[row+1] -  1; /* num of entries inU(row,:), excluding diag */
3076506fda5SShri Abhyankar         for (j=0; j<nz; j++) {
30896b95a6bSBarry Smith           /* PetscKernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */
3096506fda5SShri Abhyankar           /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */
3106506fda5SShri Abhyankar           v    = rtmp + bs2*pj[j];
31196b95a6bSBarry Smith           ierr = PetscKernel_A_gets_A_minus_B_times_C_6(v,pc,pv);CHKERRQ(ierr);
3126506fda5SShri Abhyankar           pv  += bs2;
3136506fda5SShri Abhyankar         }
3146506fda5SShri Abhyankar         ierr = PetscLogFlops(432*nz+396);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
3156506fda5SShri Abhyankar       }
3166506fda5SShri Abhyankar     }
3176506fda5SShri Abhyankar 
3186506fda5SShri Abhyankar     /* finished row so stick it into b->a */
3196506fda5SShri Abhyankar     /* L part */
3206506fda5SShri Abhyankar     pv = b->a + bs2*bi[i];
3216506fda5SShri Abhyankar     pj = b->j + bi[i];
3226506fda5SShri Abhyankar     nz = bi[i+1] - bi[i];
3236506fda5SShri Abhyankar     for (j=0; j<nz; j++) {
3246506fda5SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
3256506fda5SShri Abhyankar     }
3266506fda5SShri Abhyankar 
3276506fda5SShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
3286506fda5SShri Abhyankar     pv   = b->a + bs2*bdiag[i];
3296506fda5SShri Abhyankar     pj   = b->j + bdiag[i];
3306506fda5SShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
33196b95a6bSBarry Smith     /* ierr = PetscKernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr); */
332*2e92ee13SHong Zhang     ierr = PetscKernel_A_gets_inverse_A_6(pv,shift,!A->erroriffailure,&zeropivotdetected);CHKERRQ(ierr);
333*2e92ee13SHong Zhang     if (zeropivotdetected) C->errortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
3346506fda5SShri Abhyankar 
3356506fda5SShri Abhyankar     /* U part */
3366506fda5SShri Abhyankar     pv = b->a + bs2*(bdiag[i+1]+1);
3376506fda5SShri Abhyankar     pj = b->j + bdiag[i+1]+1;
3386506fda5SShri Abhyankar     nz = bdiag[i] - bdiag[i+1] - 1;
3396506fda5SShri Abhyankar     for (j=0; j<nz; j++) {
3406506fda5SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
3416506fda5SShri Abhyankar     }
3426506fda5SShri Abhyankar   }
3436506fda5SShri Abhyankar 
34474ed9c26SBarry Smith   ierr = PetscFree2(rtmp,mwork);CHKERRQ(ierr);
3456506fda5SShri Abhyankar   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
3466506fda5SShri Abhyankar   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
34726fbe8dcSKarl Rupp 
3484dd39f65SShri Abhyankar   C->ops->solve          = MatSolve_SeqBAIJ_6;
3494dd39f65SShri Abhyankar   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_6;
3506506fda5SShri Abhyankar   C->assembled           = PETSC_TRUE;
35126fbe8dcSKarl Rupp 
352766f9fbaSBarry Smith   ierr = PetscLogFlops(1.333333333333*6*6*6*n);CHKERRQ(ierr); /* from inverting diagonal blocks */
3536506fda5SShri Abhyankar   PetscFunctionReturn(0);
3546506fda5SShri Abhyankar }
3556506fda5SShri Abhyankar 
3566506fda5SShri Abhyankar #undef __FUNCT__
35706e38f1dSHong Zhang #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_6_NaturalOrdering_inplace"
35806e38f1dSHong Zhang PetscErrorCode MatLUFactorNumeric_SeqBAIJ_6_NaturalOrdering_inplace(Mat C,Mat A,const MatFactorInfo *info)
359bef36659SShri Abhyankar {
360bef36659SShri Abhyankar   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ*)C->data;
361bef36659SShri Abhyankar   PetscErrorCode ierr;
362bef36659SShri Abhyankar   PetscInt       i,j,n = a->mbs,*bi = b->i,*bj = b->j;
363bef36659SShri Abhyankar   PetscInt       *ajtmpold,*ajtmp,nz,row;
364bef36659SShri Abhyankar   PetscInt       *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj;
365bef36659SShri Abhyankar   MatScalar      *pv,*v,*rtmp,*pc,*w,*x;
366bef36659SShri Abhyankar   MatScalar      x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15;
367bef36659SShri Abhyankar   MatScalar      x16,x17,x18,x19,x20,x21,x22,x23,x24,x25;
368bef36659SShri Abhyankar   MatScalar      p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15;
369bef36659SShri Abhyankar   MatScalar      p16,p17,p18,p19,p20,p21,p22,p23,p24,p25;
370bef36659SShri Abhyankar   MatScalar      m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15;
371bef36659SShri Abhyankar   MatScalar      m16,m17,m18,m19,m20,m21,m22,m23,m24,m25;
372bef36659SShri Abhyankar   MatScalar      p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36;
373bef36659SShri Abhyankar   MatScalar      x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36;
374bef36659SShri Abhyankar   MatScalar      m26,m27,m28,m29,m30,m31,m32,m33,m34,m35,m36;
375bef36659SShri Abhyankar   MatScalar      *ba   = b->a,*aa = a->a;
376182b8fbaSHong Zhang   PetscReal      shift = info->shiftamount;
377*2e92ee13SHong Zhang   PetscBool      zeropivotdetected;
378bef36659SShri Abhyankar 
379bef36659SShri Abhyankar   PetscFunctionBegin;
380785e854fSJed Brown   ierr = PetscMalloc1(36*(n+1),&rtmp);CHKERRQ(ierr);
381bef36659SShri Abhyankar   for (i=0; i<n; i++) {
382bef36659SShri Abhyankar     nz    = bi[i+1] - bi[i];
383bef36659SShri Abhyankar     ajtmp = bj + bi[i];
384bef36659SShri Abhyankar     for  (j=0; j<nz; j++) {
385bef36659SShri Abhyankar       x     = rtmp+36*ajtmp[j];
386bef36659SShri Abhyankar       x[0]  = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0;
387bef36659SShri Abhyankar       x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0;
388bef36659SShri Abhyankar       x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0;
389bef36659SShri Abhyankar       x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0;
390bef36659SShri Abhyankar       x[34] = x[35] = 0.0;
391bef36659SShri Abhyankar     }
392bef36659SShri Abhyankar     /* load in initial (unfactored row) */
393bef36659SShri Abhyankar     nz       = ai[i+1] - ai[i];
394bef36659SShri Abhyankar     ajtmpold = aj + ai[i];
395bef36659SShri Abhyankar     v        = aa + 36*ai[i];
396bef36659SShri Abhyankar     for (j=0; j<nz; j++) {
397bef36659SShri Abhyankar       x     = rtmp+36*ajtmpold[j];
398bef36659SShri Abhyankar       x[0]  =  v[0];  x[1] =  v[1];  x[2] =  v[2];  x[3] =  v[3];
399bef36659SShri Abhyankar       x[4]  =  v[4];  x[5] =  v[5];  x[6] =  v[6];  x[7] =  v[7];
400bef36659SShri Abhyankar       x[8]  =  v[8];  x[9] =  v[9];  x[10] = v[10]; x[11] = v[11];
401bef36659SShri Abhyankar       x[12] = v[12]; x[13] = v[13]; x[14] = v[14]; x[15] = v[15];
402bef36659SShri Abhyankar       x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; x[19] = v[19];
403bef36659SShri Abhyankar       x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23];
404bef36659SShri Abhyankar       x[24] = v[24]; x[25] = v[25]; x[26] = v[26]; x[27] = v[27];
405bef36659SShri Abhyankar       x[28] = v[28]; x[29] = v[29]; x[30] = v[30]; x[31] = v[31];
406bef36659SShri Abhyankar       x[32] = v[32]; x[33] = v[33]; x[34] = v[34]; x[35] = v[35];
407bef36659SShri Abhyankar       v    += 36;
408bef36659SShri Abhyankar     }
409bef36659SShri Abhyankar     row = *ajtmp++;
410bef36659SShri Abhyankar     while (row < i) {
411bef36659SShri Abhyankar       pc  = rtmp + 36*row;
412bef36659SShri Abhyankar       p1  = pc[0];  p2  = pc[1];  p3  = pc[2];  p4  = pc[3];
413bef36659SShri Abhyankar       p5  = pc[4];  p6  = pc[5];  p7  = pc[6];  p8  = pc[7];
414bef36659SShri Abhyankar       p9  = pc[8];  p10 = pc[9];  p11 = pc[10]; p12 = pc[11];
415bef36659SShri Abhyankar       p13 = pc[12]; p14 = pc[13]; p15 = pc[14]; p16 = pc[15];
416bef36659SShri Abhyankar       p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; p20 = pc[19];
417bef36659SShri Abhyankar       p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23];
418bef36659SShri Abhyankar       p25 = pc[24]; p26 = pc[25]; p27 = pc[26]; p28 = pc[27];
419bef36659SShri Abhyankar       p29 = pc[28]; p30 = pc[29]; p31 = pc[30]; p32 = pc[31];
420bef36659SShri Abhyankar       p33 = pc[32]; p34 = pc[33]; p35 = pc[34]; p36 = pc[35];
421bef36659SShri Abhyankar       if (p1  != 0.0 || p2  != 0.0 || p3  != 0.0 || p4  != 0.0 ||
422bef36659SShri Abhyankar           p5  != 0.0 || p6  != 0.0 || p7  != 0.0 || p8  != 0.0 ||
423bef36659SShri Abhyankar           p9  != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 ||
424bef36659SShri Abhyankar           p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 ||
425bef36659SShri Abhyankar           p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 ||
426bef36659SShri Abhyankar           p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 ||
427bef36659SShri Abhyankar           p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 ||
428bef36659SShri Abhyankar           p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 ||
429bef36659SShri Abhyankar           p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0) {
430bef36659SShri Abhyankar         pv    = ba + 36*diag_offset[row];
431bef36659SShri Abhyankar         pj    = bj + diag_offset[row] + 1;
432bef36659SShri Abhyankar         x1    = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
433bef36659SShri Abhyankar         x5    = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];
434bef36659SShri Abhyankar         x9    = pv[8];  x10 = pv[9];  x11 = pv[10]; x12 = pv[11];
435bef36659SShri Abhyankar         x13   = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15];
436bef36659SShri Abhyankar         x17   = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19];
437bef36659SShri Abhyankar         x21   = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
438bef36659SShri Abhyankar         x25   = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27];
439bef36659SShri Abhyankar         x29   = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31];
440bef36659SShri Abhyankar         x33   = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35];
441bef36659SShri Abhyankar         pc[0] = m1  = p1*x1  + p7*x2   + p13*x3  + p19*x4  + p25*x5  + p31*x6;
442bef36659SShri Abhyankar         pc[1] = m2  = p2*x1  + p8*x2   + p14*x3  + p20*x4  + p26*x5  + p32*x6;
443bef36659SShri Abhyankar         pc[2] = m3  = p3*x1  + p9*x2   + p15*x3  + p21*x4  + p27*x5  + p33*x6;
444bef36659SShri Abhyankar         pc[3] = m4  = p4*x1  + p10*x2  + p16*x3  + p22*x4  + p28*x5  + p34*x6;
445bef36659SShri Abhyankar         pc[4] = m5  = p5*x1  + p11*x2  + p17*x3  + p23*x4  + p29*x5  + p35*x6;
446bef36659SShri Abhyankar         pc[5] = m6  = p6*x1  + p12*x2  + p18*x3  + p24*x4  + p30*x5  + p36*x6;
447bef36659SShri Abhyankar 
448bef36659SShri Abhyankar         pc[6]  = m7  = p1*x7  + p7*x8   + p13*x9  + p19*x10 + p25*x11 + p31*x12;
449bef36659SShri Abhyankar         pc[7]  = m8  = p2*x7  + p8*x8   + p14*x9  + p20*x10 + p26*x11 + p32*x12;
450bef36659SShri Abhyankar         pc[8]  = m9  = p3*x7  + p9*x8   + p15*x9  + p21*x10 + p27*x11 + p33*x12;
451bef36659SShri Abhyankar         pc[9]  = m10 = p4*x7  + p10*x8  + p16*x9  + p22*x10 + p28*x11 + p34*x12;
452bef36659SShri Abhyankar         pc[10] = m11 = p5*x7  + p11*x8  + p17*x9  + p23*x10 + p29*x11 + p35*x12;
453bef36659SShri Abhyankar         pc[11] = m12 = p6*x7  + p12*x8  + p18*x9  + p24*x10 + p30*x11 + p36*x12;
454bef36659SShri Abhyankar 
455bef36659SShri Abhyankar         pc[12] = m13 = p1*x13 + p7*x14  + p13*x15 + p19*x16 + p25*x17 + p31*x18;
456bef36659SShri Abhyankar         pc[13] = m14 = p2*x13 + p8*x14  + p14*x15 + p20*x16 + p26*x17 + p32*x18;
457bef36659SShri Abhyankar         pc[14] = m15 = p3*x13 + p9*x14  + p15*x15 + p21*x16 + p27*x17 + p33*x18;
458bef36659SShri Abhyankar         pc[15] = m16 = p4*x13 + p10*x14 + p16*x15 + p22*x16 + p28*x17 + p34*x18;
459bef36659SShri Abhyankar         pc[16] = m17 = p5*x13 + p11*x14 + p17*x15 + p23*x16 + p29*x17 + p35*x18;
460bef36659SShri Abhyankar         pc[17] = m18 = p6*x13 + p12*x14 + p18*x15 + p24*x16 + p30*x17 + p36*x18;
461bef36659SShri Abhyankar 
462bef36659SShri Abhyankar         pc[18] = m19 = p1*x19 + p7*x20  + p13*x21 + p19*x22 + p25*x23 + p31*x24;
463bef36659SShri Abhyankar         pc[19] = m20 = p2*x19 + p8*x20  + p14*x21 + p20*x22 + p26*x23 + p32*x24;
464bef36659SShri Abhyankar         pc[20] = m21 = p3*x19 + p9*x20  + p15*x21 + p21*x22 + p27*x23 + p33*x24;
465bef36659SShri Abhyankar         pc[21] = m22 = p4*x19 + p10*x20 + p16*x21 + p22*x22 + p28*x23 + p34*x24;
466bef36659SShri Abhyankar         pc[22] = m23 = p5*x19 + p11*x20 + p17*x21 + p23*x22 + p29*x23 + p35*x24;
467bef36659SShri Abhyankar         pc[23] = m24 = p6*x19 + p12*x20 + p18*x21 + p24*x22 + p30*x23 + p36*x24;
468bef36659SShri Abhyankar 
469bef36659SShri Abhyankar         pc[24] = m25 = p1*x25 + p7*x26  + p13*x27 + p19*x28 + p25*x29 + p31*x30;
470bef36659SShri Abhyankar         pc[25] = m26 = p2*x25 + p8*x26  + p14*x27 + p20*x28 + p26*x29 + p32*x30;
471bef36659SShri Abhyankar         pc[26] = m27 = p3*x25 + p9*x26  + p15*x27 + p21*x28 + p27*x29 + p33*x30;
472bef36659SShri Abhyankar         pc[27] = m28 = p4*x25 + p10*x26 + p16*x27 + p22*x28 + p28*x29 + p34*x30;
473bef36659SShri Abhyankar         pc[28] = m29 = p5*x25 + p11*x26 + p17*x27 + p23*x28 + p29*x29 + p35*x30;
474bef36659SShri Abhyankar         pc[29] = m30 = p6*x25 + p12*x26 + p18*x27 + p24*x28 + p30*x29 + p36*x30;
475bef36659SShri Abhyankar 
476bef36659SShri Abhyankar         pc[30] = m31 = p1*x31 + p7*x32  + p13*x33 + p19*x34 + p25*x35 + p31*x36;
477bef36659SShri Abhyankar         pc[31] = m32 = p2*x31 + p8*x32  + p14*x33 + p20*x34 + p26*x35 + p32*x36;
478bef36659SShri Abhyankar         pc[32] = m33 = p3*x31 + p9*x32  + p15*x33 + p21*x34 + p27*x35 + p33*x36;
479bef36659SShri Abhyankar         pc[33] = m34 = p4*x31 + p10*x32 + p16*x33 + p22*x34 + p28*x35 + p34*x36;
480bef36659SShri Abhyankar         pc[34] = m35 = p5*x31 + p11*x32 + p17*x33 + p23*x34 + p29*x35 + p35*x36;
481bef36659SShri Abhyankar         pc[35] = m36 = p6*x31 + p12*x32 + p18*x33 + p24*x34 + p30*x35 + p36*x36;
482bef36659SShri Abhyankar 
483bef36659SShri Abhyankar         nz  = bi[row+1] - diag_offset[row] - 1;
484bef36659SShri Abhyankar         pv += 36;
485bef36659SShri Abhyankar         for (j=0; j<nz; j++) {
486bef36659SShri Abhyankar           x1    = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
487bef36659SShri Abhyankar           x5    = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];
488bef36659SShri Abhyankar           x9    = pv[8];  x10 = pv[9];  x11 = pv[10]; x12 = pv[11];
489bef36659SShri Abhyankar           x13   = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15];
490bef36659SShri Abhyankar           x17   = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19];
491bef36659SShri Abhyankar           x21   = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
492bef36659SShri Abhyankar           x25   = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27];
493bef36659SShri Abhyankar           x29   = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31];
494bef36659SShri Abhyankar           x33   = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35];
495bef36659SShri Abhyankar           x     = rtmp + 36*pj[j];
496bef36659SShri Abhyankar           x[0] -= m1*x1  + m7*x2   + m13*x3  + m19*x4  + m25*x5  + m31*x6;
497bef36659SShri Abhyankar           x[1] -= m2*x1  + m8*x2   + m14*x3  + m20*x4  + m26*x5  + m32*x6;
498bef36659SShri Abhyankar           x[2] -= m3*x1  + m9*x2   + m15*x3  + m21*x4  + m27*x5  + m33*x6;
499bef36659SShri Abhyankar           x[3] -= m4*x1  + m10*x2  + m16*x3  + m22*x4  + m28*x5  + m34*x6;
500bef36659SShri Abhyankar           x[4] -= m5*x1  + m11*x2  + m17*x3  + m23*x4  + m29*x5  + m35*x6;
501bef36659SShri Abhyankar           x[5] -= m6*x1  + m12*x2  + m18*x3  + m24*x4  + m30*x5  + m36*x6;
502bef36659SShri Abhyankar 
503bef36659SShri Abhyankar           x[6]  -= m1*x7  + m7*x8   + m13*x9  + m19*x10 + m25*x11 + m31*x12;
504bef36659SShri Abhyankar           x[7]  -= m2*x7  + m8*x8   + m14*x9  + m20*x10 + m26*x11 + m32*x12;
505bef36659SShri Abhyankar           x[8]  -= m3*x7  + m9*x8   + m15*x9  + m21*x10 + m27*x11 + m33*x12;
506bef36659SShri Abhyankar           x[9]  -= m4*x7  + m10*x8  + m16*x9  + m22*x10 + m28*x11 + m34*x12;
507bef36659SShri Abhyankar           x[10] -= m5*x7  + m11*x8  + m17*x9  + m23*x10 + m29*x11 + m35*x12;
508bef36659SShri Abhyankar           x[11] -= m6*x7  + m12*x8  + m18*x9  + m24*x10 + m30*x11 + m36*x12;
509bef36659SShri Abhyankar 
510bef36659SShri Abhyankar           x[12] -= m1*x13 + m7*x14  + m13*x15 + m19*x16 + m25*x17 + m31*x18;
511bef36659SShri Abhyankar           x[13] -= m2*x13 + m8*x14  + m14*x15 + m20*x16 + m26*x17 + m32*x18;
512bef36659SShri Abhyankar           x[14] -= m3*x13 + m9*x14  + m15*x15 + m21*x16 + m27*x17 + m33*x18;
513bef36659SShri Abhyankar           x[15] -= m4*x13 + m10*x14 + m16*x15 + m22*x16 + m28*x17 + m34*x18;
514bef36659SShri Abhyankar           x[16] -= m5*x13 + m11*x14 + m17*x15 + m23*x16 + m29*x17 + m35*x18;
515bef36659SShri Abhyankar           x[17] -= m6*x13 + m12*x14 + m18*x15 + m24*x16 + m30*x17 + m36*x18;
516bef36659SShri Abhyankar 
517bef36659SShri Abhyankar           x[18] -= m1*x19 + m7*x20  + m13*x21 + m19*x22 + m25*x23 + m31*x24;
518bef36659SShri Abhyankar           x[19] -= m2*x19 + m8*x20  + m14*x21 + m20*x22 + m26*x23 + m32*x24;
519bef36659SShri Abhyankar           x[20] -= m3*x19 + m9*x20  + m15*x21 + m21*x22 + m27*x23 + m33*x24;
520bef36659SShri Abhyankar           x[21] -= m4*x19 + m10*x20 + m16*x21 + m22*x22 + m28*x23 + m34*x24;
521bef36659SShri Abhyankar           x[22] -= m5*x19 + m11*x20 + m17*x21 + m23*x22 + m29*x23 + m35*x24;
522bef36659SShri Abhyankar           x[23] -= m6*x19 + m12*x20 + m18*x21 + m24*x22 + m30*x23 + m36*x24;
523bef36659SShri Abhyankar 
524bef36659SShri Abhyankar           x[24] -= m1*x25 + m7*x26  + m13*x27 + m19*x28 + m25*x29 + m31*x30;
525bef36659SShri Abhyankar           x[25] -= m2*x25 + m8*x26  + m14*x27 + m20*x28 + m26*x29 + m32*x30;
526bef36659SShri Abhyankar           x[26] -= m3*x25 + m9*x26  + m15*x27 + m21*x28 + m27*x29 + m33*x30;
527bef36659SShri Abhyankar           x[27] -= m4*x25 + m10*x26 + m16*x27 + m22*x28 + m28*x29 + m34*x30;
528bef36659SShri Abhyankar           x[28] -= m5*x25 + m11*x26 + m17*x27 + m23*x28 + m29*x29 + m35*x30;
529bef36659SShri Abhyankar           x[29] -= m6*x25 + m12*x26 + m18*x27 + m24*x28 + m30*x29 + m36*x30;
530bef36659SShri Abhyankar 
531bef36659SShri Abhyankar           x[30] -= m1*x31 + m7*x32  + m13*x33 + m19*x34 + m25*x35 + m31*x36;
532bef36659SShri Abhyankar           x[31] -= m2*x31 + m8*x32  + m14*x33 + m20*x34 + m26*x35 + m32*x36;
533bef36659SShri Abhyankar           x[32] -= m3*x31 + m9*x32  + m15*x33 + m21*x34 + m27*x35 + m33*x36;
534bef36659SShri Abhyankar           x[33] -= m4*x31 + m10*x32 + m16*x33 + m22*x34 + m28*x35 + m34*x36;
535bef36659SShri Abhyankar           x[34] -= m5*x31 + m11*x32 + m17*x33 + m23*x34 + m29*x35 + m35*x36;
536bef36659SShri Abhyankar           x[35] -= m6*x31 + m12*x32 + m18*x33 + m24*x34 + m30*x35 + m36*x36;
537bef36659SShri Abhyankar 
538bef36659SShri Abhyankar           pv += 36;
539bef36659SShri Abhyankar         }
540bef36659SShri Abhyankar         ierr = PetscLogFlops(432.0*nz+396.0);CHKERRQ(ierr);
541bef36659SShri Abhyankar       }
542bef36659SShri Abhyankar       row = *ajtmp++;
543bef36659SShri Abhyankar     }
544bef36659SShri Abhyankar     /* finished row so stick it into b->a */
545bef36659SShri Abhyankar     pv = ba + 36*bi[i];
546bef36659SShri Abhyankar     pj = bj + bi[i];
547bef36659SShri Abhyankar     nz = bi[i+1] - bi[i];
548bef36659SShri Abhyankar     for (j=0; j<nz; j++) {
549bef36659SShri Abhyankar       x      = rtmp+36*pj[j];
550bef36659SShri Abhyankar       pv[0]  = x[0];  pv[1]  = x[1];  pv[2]  = x[2];  pv[3]  = x[3];
551bef36659SShri Abhyankar       pv[4]  = x[4];  pv[5]  = x[5];  pv[6]  = x[6];  pv[7]  = x[7];
552bef36659SShri Abhyankar       pv[8]  = x[8];  pv[9]  = x[9];  pv[10] = x[10]; pv[11] = x[11];
553bef36659SShri Abhyankar       pv[12] = x[12]; pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15];
554bef36659SShri Abhyankar       pv[16] = x[16]; pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19];
555bef36659SShri Abhyankar       pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23];
556bef36659SShri Abhyankar       pv[24] = x[24]; pv[25] = x[25]; pv[26] = x[26]; pv[27] = x[27];
557bef36659SShri Abhyankar       pv[28] = x[28]; pv[29] = x[29]; pv[30] = x[30]; pv[31] = x[31];
558bef36659SShri Abhyankar       pv[32] = x[32]; pv[33] = x[33]; pv[34] = x[34]; pv[35] = x[35];
559bef36659SShri Abhyankar       pv    += 36;
560bef36659SShri Abhyankar     }
561bef36659SShri Abhyankar     /* invert diagonal block */
562bef36659SShri Abhyankar     w    = ba + 36*diag_offset[i];
563*2e92ee13SHong Zhang     ierr = PetscKernel_A_gets_inverse_A_6(w,shift,!A->erroriffailure,&zeropivotdetected);CHKERRQ(ierr);
564*2e92ee13SHong Zhang     if (zeropivotdetected) C->errortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
565bef36659SShri Abhyankar   }
566bef36659SShri Abhyankar 
567bef36659SShri Abhyankar   ierr = PetscFree(rtmp);CHKERRQ(ierr);
56826fbe8dcSKarl Rupp 
56906e38f1dSHong Zhang   C->ops->solve          = MatSolve_SeqBAIJ_6_NaturalOrdering_inplace;
57006e38f1dSHong Zhang   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_6_NaturalOrdering_inplace;
571bef36659SShri Abhyankar   C->assembled           = PETSC_TRUE;
57226fbe8dcSKarl Rupp 
573766f9fbaSBarry Smith   ierr = PetscLogFlops(1.333333333333*6*6*6*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */
574bef36659SShri Abhyankar   PetscFunctionReturn(0);
575bef36659SShri Abhyankar }
576bef36659SShri Abhyankar 
577bef36659SShri Abhyankar #undef __FUNCT__
5784dd39f65SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_6_NaturalOrdering"
5794dd39f65SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_6_NaturalOrdering(Mat B,Mat A,const MatFactorInfo *info)
580bef36659SShri Abhyankar {
581bef36659SShri Abhyankar   Mat            C =B;
582bef36659SShri Abhyankar   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ*)C->data;
583bef36659SShri Abhyankar   PetscErrorCode ierr;
584bbd65245SShri Abhyankar   PetscInt       i,j,k,nz,nzL,row;
585bbd65245SShri Abhyankar   const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
586bbd65245SShri Abhyankar   const PetscInt *ajtmp,*bjtmp,*bdiag=b->diag,*pj,bs2=a->bs2;
587bef36659SShri Abhyankar   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
588bbd65245SShri Abhyankar   PetscInt       flg;
589182b8fbaSHong Zhang   PetscReal      shift = info->shiftamount;
590*2e92ee13SHong Zhang   PetscBool      zeropivotdetected;
591bef36659SShri Abhyankar 
592bef36659SShri Abhyankar   PetscFunctionBegin;
593bef36659SShri Abhyankar   /* generate work space needed by the factorization */
594dcca6d9dSJed Brown   ierr = PetscMalloc2(bs2*n,&rtmp,bs2,&mwork);CHKERRQ(ierr);
595bef36659SShri Abhyankar   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
596bef36659SShri Abhyankar 
597bef36659SShri Abhyankar   for (i=0; i<n; i++) {
598bef36659SShri Abhyankar     /* zero rtmp */
599bef36659SShri Abhyankar     /* L part */
600bef36659SShri Abhyankar     nz    = bi[i+1] - bi[i];
601bef36659SShri Abhyankar     bjtmp = bj + bi[i];
602bef36659SShri Abhyankar     for  (j=0; j<nz; j++) {
603bef36659SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
604bef36659SShri Abhyankar     }
605bef36659SShri Abhyankar 
606bef36659SShri Abhyankar     /* U part */
60753cca76cSShri Abhyankar     nz    = bdiag[i] - bdiag[i+1];
60853cca76cSShri Abhyankar     bjtmp = bj + bdiag[i+1]+1;
60953cca76cSShri Abhyankar     for  (j=0; j<nz; j++) {
61053cca76cSShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
61153cca76cSShri Abhyankar     }
61253cca76cSShri Abhyankar 
61353cca76cSShri Abhyankar     /* load in initial (unfactored row) */
61453cca76cSShri Abhyankar     nz    = ai[i+1] - ai[i];
61553cca76cSShri Abhyankar     ajtmp = aj + ai[i];
61653cca76cSShri Abhyankar     v     = aa + bs2*ai[i];
61753cca76cSShri Abhyankar     for (j=0; j<nz; j++) {
61853cca76cSShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ajtmp[j],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
61953cca76cSShri Abhyankar     }
62053cca76cSShri Abhyankar 
62153cca76cSShri Abhyankar     /* elimination */
62253cca76cSShri Abhyankar     bjtmp = bj + bi[i];
62353cca76cSShri Abhyankar     nzL   = bi[i+1] - bi[i];
62453cca76cSShri Abhyankar     for (k=0; k < nzL; k++) {
62553cca76cSShri Abhyankar       row = bjtmp[k];
62653cca76cSShri Abhyankar       pc  = rtmp + bs2*row;
627c35f09e5SBarry Smith       for (flg=0,j=0; j<bs2; j++) {
628c35f09e5SBarry Smith         if (pc[j]!=0.0) {
629c35f09e5SBarry Smith           flg = 1;
630c35f09e5SBarry Smith           break;
631c35f09e5SBarry Smith         }
632c35f09e5SBarry Smith       }
63353cca76cSShri Abhyankar       if (flg) {
63453cca76cSShri Abhyankar         pv = b->a + bs2*bdiag[row];
63596b95a6bSBarry Smith         /* PetscKernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */
63696b95a6bSBarry Smith         ierr = PetscKernel_A_gets_A_times_B_6(pc,pv,mwork);CHKERRQ(ierr);
63753cca76cSShri Abhyankar 
63853cca76cSShri Abhyankar         pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
63953cca76cSShri Abhyankar         pv = b->a + bs2*(bdiag[row+1]+1);
64053cca76cSShri Abhyankar         nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
64153cca76cSShri Abhyankar         for (j=0; j<nz; j++) {
64296b95a6bSBarry Smith           /* PetscKernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */
64353cca76cSShri Abhyankar           /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */
64453cca76cSShri Abhyankar           v    = rtmp + bs2*pj[j];
64596b95a6bSBarry Smith           ierr = PetscKernel_A_gets_A_minus_B_times_C_6(v,pc,pv);CHKERRQ(ierr);
64653cca76cSShri Abhyankar           pv  += bs2;
64753cca76cSShri Abhyankar         }
64853cca76cSShri Abhyankar         ierr = PetscLogFlops(432*nz+396);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
64953cca76cSShri Abhyankar       }
65053cca76cSShri Abhyankar     }
65153cca76cSShri Abhyankar 
65253cca76cSShri Abhyankar     /* finished row so stick it into b->a */
65353cca76cSShri Abhyankar     /* L part */
65453cca76cSShri Abhyankar     pv = b->a + bs2*bi[i];
65553cca76cSShri Abhyankar     pj = b->j + bi[i];
65653cca76cSShri Abhyankar     nz = bi[i+1] - bi[i];
65753cca76cSShri Abhyankar     for (j=0; j<nz; j++) {
65853cca76cSShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
65953cca76cSShri Abhyankar     }
66053cca76cSShri Abhyankar 
66153cca76cSShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
66253cca76cSShri Abhyankar     pv   = b->a + bs2*bdiag[i];
66353cca76cSShri Abhyankar     pj   = b->j + bdiag[i];
66453cca76cSShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
66596b95a6bSBarry Smith     /* ierr = PetscKernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr); */
666*2e92ee13SHong Zhang     ierr = PetscKernel_A_gets_inverse_A_6(pv,shift,!A->erroriffailure,&zeropivotdetected);CHKERRQ(ierr);
667*2e92ee13SHong Zhang     if (zeropivotdetected) C->errortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
66853cca76cSShri Abhyankar 
66953cca76cSShri Abhyankar     /* U part */
67053cca76cSShri Abhyankar     pv = b->a + bs2*(bdiag[i+1]+1);
67153cca76cSShri Abhyankar     pj = b->j + bdiag[i+1]+1;
67253cca76cSShri Abhyankar     nz = bdiag[i] - bdiag[i+1] - 1;
67353cca76cSShri Abhyankar     for (j=0; j<nz; j++) {
67453cca76cSShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
67553cca76cSShri Abhyankar     }
67653cca76cSShri Abhyankar   }
67774ed9c26SBarry Smith   ierr = PetscFree2(rtmp,mwork);CHKERRQ(ierr);
67826fbe8dcSKarl Rupp 
6794dd39f65SShri Abhyankar   C->ops->solve          = MatSolve_SeqBAIJ_6_NaturalOrdering;
6804dd39f65SShri Abhyankar   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_6_NaturalOrdering;
68153cca76cSShri Abhyankar   C->assembled           = PETSC_TRUE;
68226fbe8dcSKarl Rupp 
683766f9fbaSBarry Smith   ierr = PetscLogFlops(1.333333333333*6*6*6*n);CHKERRQ(ierr); /* from inverting diagonal blocks */
68453cca76cSShri Abhyankar   PetscFunctionReturn(0);
68553cca76cSShri Abhyankar }
686