Actual source code: baijfact5.c

petsc-3.10.5 2019-03-28
Report Typos and Errors

  2: /*
  3:     Factorization code for BAIJ format.
  4: */
  5:  #include <../src/mat/impls/baij/seq/baij.h>
  6:  #include <petsc/private/kernels/blockinvert.h>
  7: /*
  8:       Version for when blocks are 7 by 7
  9: */
 10: PetscErrorCode MatLUFactorNumeric_SeqBAIJ_7_inplace(Mat C,Mat A,const MatFactorInfo *info)
 11: {
 12:   Mat_SeqBAIJ    *a    = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ*)C->data;
 13:   IS             isrow = b->row,isicol = b->icol;
 15:   const PetscInt *r,*ic,*bi = b->i,*bj = b->j,*ajtmp,*diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj,*ajtmpold;
 16:   PetscInt       i,j,n = a->mbs,nz,row,idx;
 17:   MatScalar      *pv,*v,*rtmp,*pc,*w,*x;
 18:   MatScalar      p1,p2,p3,p4,m1,m2,m3,m4,m5,m6,m7,m8,m9,x1,x2,x3,x4;
 19:   MatScalar      p5,p6,p7,p8,p9,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16;
 20:   MatScalar      x17,x18,x19,x20,x21,x22,x23,x24,x25,p10,p11,p12,p13,p14;
 21:   MatScalar      p15,p16,p17,p18,p19,p20,p21,p22,p23,p24,p25,m10,m11,m12;
 22:   MatScalar      m13,m14,m15,m16,m17,m18,m19,m20,m21,m22,m23,m24,m25;
 23:   MatScalar      p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36;
 24:   MatScalar      p37,p38,p39,p40,p41,p42,p43,p44,p45,p46,p47,p48,p49;
 25:   MatScalar      x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36;
 26:   MatScalar      x37,x38,x39,x40,x41,x42,x43,x44,x45,x46,x47,x48,x49;
 27:   MatScalar      m26,m27,m28,m29,m30,m31,m32,m33,m34,m35,m36;
 28:   MatScalar      m37,m38,m39,m40,m41,m42,m43,m44,m45,m46,m47,m48,m49;
 29:   MatScalar      *ba   = b->a,*aa = a->a;
 30:   PetscReal      shift = info->shiftamount;
 31:   PetscBool      allowzeropivot,zeropivotdetected;

 34:   allowzeropivot = PetscNot(A->erroriffailure);
 35:   ISGetIndices(isrow,&r);
 36:   ISGetIndices(isicol,&ic);
 37:   PetscMalloc1(49*(n+1),&rtmp);

 39:   for (i=0; i<n; i++) {
 40:     nz    = bi[i+1] - bi[i];
 41:     ajtmp = bj + bi[i];
 42:     for  (j=0; j<nz; j++) {
 43:       x     = rtmp+49*ajtmp[j];
 44:       x[0]  = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0;
 45:       x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0;
 46:       x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0;
 47:       x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0;
 48:       x[34] = x[35] = x[36] = x[37] = x[38] = x[39] = x[40] = x[41] = 0.0;
 49:       x[42] = x[43] = x[44] = x[45] = x[46] = x[47] = x[48] = 0.0;
 50:     }
 51:     /* load in initial (unfactored row) */
 52:     idx      = r[i];
 53:     nz       = ai[idx+1] - ai[idx];
 54:     ajtmpold = aj + ai[idx];
 55:     v        = aa + 49*ai[idx];
 56:     for (j=0; j<nz; j++) {
 57:       x     = rtmp+49*ic[ajtmpold[j]];
 58:       x[0]  =  v[0];  x[1] =  v[1];  x[2] =  v[2];  x[3] =  v[3];
 59:       x[4]  =  v[4];  x[5] =  v[5];  x[6] =  v[6];  x[7] =  v[7];
 60:       x[8]  =  v[8];  x[9] =  v[9];  x[10] = v[10]; x[11] = v[11];
 61:       x[12] = v[12]; x[13] = v[13]; x[14] = v[14]; x[15] = v[15];
 62:       x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; x[19] = v[19];
 63:       x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23];
 64:       x[24] = v[24]; x[25] = v[25]; x[26] = v[26]; x[27] = v[27];
 65:       x[28] = v[28]; x[29] = v[29]; x[30] = v[30]; x[31] = v[31];
 66:       x[32] = v[32]; x[33] = v[33]; x[34] = v[34]; x[35] = v[35];
 67:       x[36] = v[36]; x[37] = v[37]; x[38] = v[38]; x[39] = v[39];
 68:       x[40] = v[40]; x[41] = v[41]; x[42] = v[42]; x[43] = v[43];
 69:       x[44] = v[44]; x[45] = v[45]; x[46] = v[46]; x[47] = v[47];
 70:       x[48] = v[48];
 71:       v    += 49;
 72:     }
 73:     row = *ajtmp++;
 74:     while (row < i) {
 75:       pc  =  rtmp + 49*row;
 76:       p1  = pc[0];  p2  = pc[1];  p3  = pc[2];  p4  = pc[3];
 77:       p5  = pc[4];  p6  = pc[5];  p7  = pc[6];  p8  = pc[7];
 78:       p9  = pc[8];  p10 = pc[9];  p11 = pc[10]; p12 = pc[11];
 79:       p13 = pc[12]; p14 = pc[13]; p15 = pc[14]; p16 = pc[15];
 80:       p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; p20 = pc[19];
 81:       p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23];
 82:       p25 = pc[24]; p26 = pc[25]; p27 = pc[26]; p28 = pc[27];
 83:       p29 = pc[28]; p30 = pc[29]; p31 = pc[30]; p32 = pc[31];
 84:       p33 = pc[32]; p34 = pc[33]; p35 = pc[34]; p36 = pc[35];
 85:       p37 = pc[36]; p38 = pc[37]; p39 = pc[38]; p40 = pc[39];
 86:       p41 = pc[40]; p42 = pc[41]; p43 = pc[42]; p44 = pc[43];
 87:       p45 = pc[44]; p46 = pc[45]; p47 = pc[46]; p48 = pc[47];
 88:       p49 = pc[48];
 89:       if (p1  != 0.0 || p2  != 0.0 || p3  != 0.0 || p4  != 0.0 ||
 90:           p5  != 0.0 || p6  != 0.0 || p7  != 0.0 || p8  != 0.0 ||
 91:           p9  != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 ||
 92:           p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 ||
 93:           p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 ||
 94:           p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 ||
 95:           p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 ||
 96:           p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 ||
 97:           p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0 ||
 98:           p37 != 0.0 || p38 != 0.0 || p39 != 0.0 || p40 != 0.0 ||
 99:           p41 != 0.0 || p42 != 0.0 || p43 != 0.0 || p44 != 0.0 ||
100:           p45 != 0.0 || p46 != 0.0 || p47 != 0.0 || p48 != 0.0 ||
101:           p49 != 0.0) {
102:         pv    = ba + 49*diag_offset[row];
103:         pj    = bj + diag_offset[row] + 1;
104:         x1    = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
105:         x5    = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];
106:         x9    = pv[8];  x10 = pv[9];  x11 = pv[10]; x12 = pv[11];
107:         x13   = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15];
108:         x17   = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19];
109:         x21   = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
110:         x25   = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27];
111:         x29   = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31];
112:         x33   = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35];
113:         x37   = pv[36]; x38 = pv[37]; x39 = pv[38]; x40 = pv[39];
114:         x41   = pv[40]; x42 = pv[41]; x43 = pv[42]; x44 = pv[43];
115:         x45   = pv[44]; x46 = pv[45]; x47 = pv[46]; x48 = pv[47];
116:         x49   = pv[48];
117:         pc[0] = m1  = p1*x1  + p8*x2   + p15*x3  + p22*x4  + p29*x5  + p36*x6 + p43*x7;
118:         pc[1] = m2  = p2*x1  + p9*x2   + p16*x3  + p23*x4  + p30*x5  + p37*x6 + p44*x7;
119:         pc[2] = m3  = p3*x1  + p10*x2  + p17*x3  + p24*x4  + p31*x5  + p38*x6 + p45*x7;
120:         pc[3] = m4  = p4*x1  + p11*x2  + p18*x3  + p25*x4  + p32*x5  + p39*x6 + p46*x7;
121:         pc[4] = m5  = p5*x1  + p12*x2  + p19*x3  + p26*x4  + p33*x5  + p40*x6 + p47*x7;
122:         pc[5] = m6  = p6*x1  + p13*x2  + p20*x3  + p27*x4  + p34*x5  + p41*x6 + p48*x7;
123:         pc[6] = m7  = p7*x1  + p14*x2  + p21*x3  + p28*x4  + p35*x5  + p42*x6 + p49*x7;

125:         pc[7]  = m8  = p1*x8  + p8*x9   + p15*x10 + p22*x11 + p29*x12 + p36*x13 + p43*x14;
126:         pc[8]  = m9  = p2*x8  + p9*x9   + p16*x10 + p23*x11 + p30*x12 + p37*x13 + p44*x14;
127:         pc[9]  = m10 = p3*x8  + p10*x9  + p17*x10 + p24*x11 + p31*x12 + p38*x13 + p45*x14;
128:         pc[10] = m11 = p4*x8  + p11*x9  + p18*x10 + p25*x11 + p32*x12 + p39*x13 + p46*x14;
129:         pc[11] = m12 = p5*x8  + p12*x9  + p19*x10 + p26*x11 + p33*x12 + p40*x13 + p47*x14;
130:         pc[12] = m13 = p6*x8  + p13*x9  + p20*x10 + p27*x11 + p34*x12 + p41*x13 + p48*x14;
131:         pc[13] = m14 = p7*x8  + p14*x9  + p21*x10 + p28*x11 + p35*x12 + p42*x13 + p49*x14;

133:         pc[14] = m15 = p1*x15 + p8*x16  + p15*x17 + p22*x18 + p29*x19 + p36*x20 + p43*x21;
134:         pc[15] = m16 = p2*x15 + p9*x16  + p16*x17 + p23*x18 + p30*x19 + p37*x20 + p44*x21;
135:         pc[16] = m17 = p3*x15 + p10*x16 + p17*x17 + p24*x18 + p31*x19 + p38*x20 + p45*x21;
136:         pc[17] = m18 = p4*x15 + p11*x16 + p18*x17 + p25*x18 + p32*x19 + p39*x20 + p46*x21;
137:         pc[18] = m19 = p5*x15 + p12*x16 + p19*x17 + p26*x18 + p33*x19 + p40*x20 + p47*x21;
138:         pc[19] = m20 = p6*x15 + p13*x16 + p20*x17 + p27*x18 + p34*x19 + p41*x20 + p48*x21;
139:         pc[20] = m21 = p7*x15 + p14*x16 + p21*x17 + p28*x18 + p35*x19 + p42*x20 + p49*x21;

141:         pc[21] = m22 = p1*x22 + p8*x23  + p15*x24 + p22*x25 + p29*x26 + p36*x27 + p43*x28;
142:         pc[22] = m23 = p2*x22 + p9*x23  + p16*x24 + p23*x25 + p30*x26 + p37*x27 + p44*x28;
143:         pc[23] = m24 = p3*x22 + p10*x23 + p17*x24 + p24*x25 + p31*x26 + p38*x27 + p45*x28;
144:         pc[24] = m25 = p4*x22 + p11*x23 + p18*x24 + p25*x25 + p32*x26 + p39*x27 + p46*x28;
145:         pc[25] = m26 = p5*x22 + p12*x23 + p19*x24 + p26*x25 + p33*x26 + p40*x27 + p47*x28;
146:         pc[26] = m27 = p6*x22 + p13*x23 + p20*x24 + p27*x25 + p34*x26 + p41*x27 + p48*x28;
147:         pc[27] = m28 = p7*x22 + p14*x23 + p21*x24 + p28*x25 + p35*x26 + p42*x27 + p49*x28;

149:         pc[28] = m29 = p1*x29 + p8*x30  + p15*x31 + p22*x32 + p29*x33 + p36*x34 + p43*x35;
150:         pc[29] = m30 = p2*x29 + p9*x30  + p16*x31 + p23*x32 + p30*x33 + p37*x34 + p44*x35;
151:         pc[30] = m31 = p3*x29 + p10*x30 + p17*x31 + p24*x32 + p31*x33 + p38*x34 + p45*x35;
152:         pc[31] = m32 = p4*x29 + p11*x30 + p18*x31 + p25*x32 + p32*x33 + p39*x34 + p46*x35;
153:         pc[32] = m33 = p5*x29 + p12*x30 + p19*x31 + p26*x32 + p33*x33 + p40*x34 + p47*x35;
154:         pc[33] = m34 = p6*x29 + p13*x30 + p20*x31 + p27*x32 + p34*x33 + p41*x34 + p48*x35;
155:         pc[34] = m35 = p7*x29 + p14*x30 + p21*x31 + p28*x32 + p35*x33 + p42*x34 + p49*x35;

157:         pc[35] = m36 = p1*x36 + p8*x37  + p15*x38 + p22*x39 + p29*x40 + p36*x41 + p43*x42;
158:         pc[36] = m37 = p2*x36 + p9*x37  + p16*x38 + p23*x39 + p30*x40 + p37*x41 + p44*x42;
159:         pc[37] = m38 = p3*x36 + p10*x37 + p17*x38 + p24*x39 + p31*x40 + p38*x41 + p45*x42;
160:         pc[38] = m39 = p4*x36 + p11*x37 + p18*x38 + p25*x39 + p32*x40 + p39*x41 + p46*x42;
161:         pc[39] = m40 = p5*x36 + p12*x37 + p19*x38 + p26*x39 + p33*x40 + p40*x41 + p47*x42;
162:         pc[40] = m41 = p6*x36 + p13*x37 + p20*x38 + p27*x39 + p34*x40 + p41*x41 + p48*x42;
163:         pc[41] = m42 = p7*x36 + p14*x37 + p21*x38 + p28*x39 + p35*x40 + p42*x41 + p49*x42;

165:         pc[42] = m43 = p1*x43 + p8*x44  + p15*x45 + p22*x46 + p29*x47 + p36*x48 + p43*x49;
166:         pc[43] = m44 = p2*x43 + p9*x44  + p16*x45 + p23*x46 + p30*x47 + p37*x48 + p44*x49;
167:         pc[44] = m45 = p3*x43 + p10*x44 + p17*x45 + p24*x46 + p31*x47 + p38*x48 + p45*x49;
168:         pc[45] = m46 = p4*x43 + p11*x44 + p18*x45 + p25*x46 + p32*x47 + p39*x48 + p46*x49;
169:         pc[46] = m47 = p5*x43 + p12*x44 + p19*x45 + p26*x46 + p33*x47 + p40*x48 + p47*x49;
170:         pc[47] = m48 = p6*x43 + p13*x44 + p20*x45 + p27*x46 + p34*x47 + p41*x48 + p48*x49;
171:         pc[48] = m49 = p7*x43 + p14*x44 + p21*x45 + p28*x46 + p35*x47 + p42*x48 + p49*x49;

173:         nz  = bi[row+1] - diag_offset[row] - 1;
174:         pv += 49;
175:         for (j=0; j<nz; j++) {
176:           x1    = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
177:           x5    = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];
178:           x9    = pv[8];  x10 = pv[9];  x11 = pv[10]; x12 = pv[11];
179:           x13   = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15];
180:           x17   = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19];
181:           x21   = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
182:           x25   = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27];
183:           x29   = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31];
184:           x33   = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35];
185:           x37   = pv[36]; x38 = pv[37]; x39 = pv[38]; x40 = pv[39];
186:           x41   = pv[40]; x42 = pv[41]; x43 = pv[42]; x44 = pv[43];
187:           x45   = pv[44]; x46 = pv[45]; x47 = pv[46]; x48 = pv[47];
188:           x49   = pv[48];
189:           x     = rtmp + 49*pj[j];
190:           x[0] -= m1*x1  + m8*x2   + m15*x3  + m22*x4  + m29*x5  + m36*x6 + m43*x7;
191:           x[1] -= m2*x1  + m9*x2   + m16*x3  + m23*x4  + m30*x5  + m37*x6 + m44*x7;
192:           x[2] -= m3*x1  + m10*x2  + m17*x3  + m24*x4  + m31*x5  + m38*x6 + m45*x7;
193:           x[3] -= m4*x1  + m11*x2  + m18*x3  + m25*x4  + m32*x5  + m39*x6 + m46*x7;
194:           x[4] -= m5*x1  + m12*x2  + m19*x3  + m26*x4  + m33*x5  + m40*x6 + m47*x7;
195:           x[5] -= m6*x1  + m13*x2  + m20*x3  + m27*x4  + m34*x5  + m41*x6 + m48*x7;
196:           x[6] -= m7*x1  + m14*x2  + m21*x3  + m28*x4  + m35*x5  + m42*x6 + m49*x7;

198:           x[7]  -= m1*x8  + m8*x9   + m15*x10 + m22*x11 + m29*x12 + m36*x13 + m43*x14;
199:           x[8]  -= m2*x8  + m9*x9   + m16*x10 + m23*x11 + m30*x12 + m37*x13 + m44*x14;
200:           x[9]  -= m3*x8  + m10*x9  + m17*x10 + m24*x11 + m31*x12 + m38*x13 + m45*x14;
201:           x[10] -= m4*x8  + m11*x9  + m18*x10 + m25*x11 + m32*x12 + m39*x13 + m46*x14;
202:           x[11] -= m5*x8  + m12*x9  + m19*x10 + m26*x11 + m33*x12 + m40*x13 + m47*x14;
203:           x[12] -= m6*x8  + m13*x9  + m20*x10 + m27*x11 + m34*x12 + m41*x13 + m48*x14;
204:           x[13] -= m7*x8  + m14*x9  + m21*x10 + m28*x11 + m35*x12 + m42*x13 + m49*x14;

206:           x[14] -= m1*x15 + m8*x16  + m15*x17 + m22*x18 + m29*x19 + m36*x20 + m43*x21;
207:           x[15] -= m2*x15 + m9*x16  + m16*x17 + m23*x18 + m30*x19 + m37*x20 + m44*x21;
208:           x[16] -= m3*x15 + m10*x16 + m17*x17 + m24*x18 + m31*x19 + m38*x20 + m45*x21;
209:           x[17] -= m4*x15 + m11*x16 + m18*x17 + m25*x18 + m32*x19 + m39*x20 + m46*x21;
210:           x[18] -= m5*x15 + m12*x16 + m19*x17 + m26*x18 + m33*x19 + m40*x20 + m47*x21;
211:           x[19] -= m6*x15 + m13*x16 + m20*x17 + m27*x18 + m34*x19 + m41*x20 + m48*x21;
212:           x[20] -= m7*x15 + m14*x16 + m21*x17 + m28*x18 + m35*x19 + m42*x20 + m49*x21;

214:           x[21] -= m1*x22 + m8*x23  + m15*x24 + m22*x25 + m29*x26 + m36*x27 + m43*x28;
215:           x[22] -= m2*x22 + m9*x23  + m16*x24 + m23*x25 + m30*x26 + m37*x27 + m44*x28;
216:           x[23] -= m3*x22 + m10*x23 + m17*x24 + m24*x25 + m31*x26 + m38*x27 + m45*x28;
217:           x[24] -= m4*x22 + m11*x23 + m18*x24 + m25*x25 + m32*x26 + m39*x27 + m46*x28;
218:           x[25] -= m5*x22 + m12*x23 + m19*x24 + m26*x25 + m33*x26 + m40*x27 + m47*x28;
219:           x[26] -= m6*x22 + m13*x23 + m20*x24 + m27*x25 + m34*x26 + m41*x27 + m48*x28;
220:           x[27] -= m7*x22 + m14*x23 + m21*x24 + m28*x25 + m35*x26 + m42*x27 + m49*x28;

222:           x[28] -= m1*x29 + m8*x30  + m15*x31 + m22*x32 + m29*x33 + m36*x34 + m43*x35;
223:           x[29] -= m2*x29 + m9*x30  + m16*x31 + m23*x32 + m30*x33 + m37*x34 + m44*x35;
224:           x[30] -= m3*x29 + m10*x30 + m17*x31 + m24*x32 + m31*x33 + m38*x34 + m45*x35;
225:           x[31] -= m4*x29 + m11*x30 + m18*x31 + m25*x32 + m32*x33 + m39*x34 + m46*x35;
226:           x[32] -= m5*x29 + m12*x30 + m19*x31 + m26*x32 + m33*x33 + m40*x34 + m47*x35;
227:           x[33] -= m6*x29 + m13*x30 + m20*x31 + m27*x32 + m34*x33 + m41*x34 + m48*x35;
228:           x[34] -= m7*x29 + m14*x30 + m21*x31 + m28*x32 + m35*x33 + m42*x34 + m49*x35;

230:           x[35] -= m1*x36 + m8*x37  + m15*x38 + m22*x39 + m29*x40 + m36*x41 + m43*x42;
231:           x[36] -= m2*x36 + m9*x37  + m16*x38 + m23*x39 + m30*x40 + m37*x41 + m44*x42;
232:           x[37] -= m3*x36 + m10*x37 + m17*x38 + m24*x39 + m31*x40 + m38*x41 + m45*x42;
233:           x[38] -= m4*x36 + m11*x37 + m18*x38 + m25*x39 + m32*x40 + m39*x41 + m46*x42;
234:           x[39] -= m5*x36 + m12*x37 + m19*x38 + m26*x39 + m33*x40 + m40*x41 + m47*x42;
235:           x[40] -= m6*x36 + m13*x37 + m20*x38 + m27*x39 + m34*x40 + m41*x41 + m48*x42;
236:           x[41] -= m7*x36 + m14*x37 + m21*x38 + m28*x39 + m35*x40 + m42*x41 + m49*x42;

238:           x[42] -= m1*x43 + m8*x44  + m15*x45 + m22*x46 + m29*x47 + m36*x48 + m43*x49;
239:           x[43] -= m2*x43 + m9*x44  + m16*x45 + m23*x46 + m30*x47 + m37*x48 + m44*x49;
240:           x[44] -= m3*x43 + m10*x44 + m17*x45 + m24*x46 + m31*x47 + m38*x48 + m45*x49;
241:           x[45] -= m4*x43 + m11*x44 + m18*x45 + m25*x46 + m32*x47 + m39*x48 + m46*x49;
242:           x[46] -= m5*x43 + m12*x44 + m19*x45 + m26*x46 + m33*x47 + m40*x48 + m47*x49;
243:           x[47] -= m6*x43 + m13*x44 + m20*x45 + m27*x46 + m34*x47 + m41*x48 + m48*x49;
244:           x[48] -= m7*x43 + m14*x44 + m21*x45 + m28*x46 + m35*x47 + m42*x48 + m49*x49;
245:           pv    += 49;
246:         }
247:         PetscLogFlops(686.0*nz+637.0);
248:       }
249:       row = *ajtmp++;
250:     }
251:     /* finished row so stick it into b->a */
252:     pv = ba + 49*bi[i];
253:     pj = bj + bi[i];
254:     nz = bi[i+1] - bi[i];
255:     for (j=0; j<nz; j++) {
256:       x      = rtmp+49*pj[j];
257:       pv[0]  = x[0];  pv[1]  = x[1];  pv[2]  = x[2];  pv[3]  = x[3];
258:       pv[4]  = x[4];  pv[5]  = x[5];  pv[6]  = x[6];  pv[7]  = x[7];
259:       pv[8]  = x[8];  pv[9]  = x[9];  pv[10] = x[10]; pv[11] = x[11];
260:       pv[12] = x[12]; pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15];
261:       pv[16] = x[16]; pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19];
262:       pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23];
263:       pv[24] = x[24]; pv[25] = x[25]; pv[26] = x[26]; pv[27] = x[27];
264:       pv[28] = x[28]; pv[29] = x[29]; pv[30] = x[30]; pv[31] = x[31];
265:       pv[32] = x[32]; pv[33] = x[33]; pv[34] = x[34]; pv[35] = x[35];
266:       pv[36] = x[36]; pv[37] = x[37]; pv[38] = x[38]; pv[39] = x[39];
267:       pv[40] = x[40]; pv[41] = x[41]; pv[42] = x[42]; pv[43] = x[43];
268:       pv[44] = x[44]; pv[45] = x[45]; pv[46] = x[46]; pv[47] = x[47];
269:       pv[48] = x[48];
270:       pv    += 49;
271:     }
272:     /* invert diagonal block */
273:     w    = ba + 49*diag_offset[i];
274:     PetscKernel_A_gets_inverse_A_7(w,shift,allowzeropivot,&zeropivotdetected);
275:     if (zeropivotdetected) C->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
276:   }

278:   PetscFree(rtmp);
279:   ISRestoreIndices(isicol,&ic);
280:   ISRestoreIndices(isrow,&r);

282:   C->ops->solve          = MatSolve_SeqBAIJ_7_inplace;
283:   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_7_inplace;
284:   C->assembled           = PETSC_TRUE;

286:   PetscLogFlops(1.333333333333*7*7*7*b->mbs); /* from inverting diagonal blocks */
287:   return(0);
288: }


291: PetscErrorCode MatLUFactorNumeric_SeqBAIJ_7(Mat B,Mat A,const MatFactorInfo *info)
292: {
293:   Mat            C     =B;
294:   Mat_SeqBAIJ    *a    =(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ*)C->data;
295:   IS             isrow = b->row,isicol = b->icol;
297:   const PetscInt *r,*ic;
298:   PetscInt       i,j,k,nz,nzL,row;
299:   const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
300:   const PetscInt *ajtmp,*bjtmp,*bdiag=b->diag,*pj,bs2=a->bs2;
301:   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
302:   PetscInt       flg;
303:   PetscReal      shift = info->shiftamount;
304:   PetscBool      allowzeropivot,zeropivotdetected;

307:   allowzeropivot = PetscNot(A->erroriffailure);
308:   ISGetIndices(isrow,&r);
309:   ISGetIndices(isicol,&ic);

311:   /* generate work space needed by the factorization */
312:   PetscMalloc2(bs2*n,&rtmp,bs2,&mwork);
313:   PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));

315:   for (i=0; i<n; i++) {
316:     /* zero rtmp */
317:     /* L part */
318:     nz    = bi[i+1] - bi[i];
319:     bjtmp = bj + bi[i];
320:     for  (j=0; j<nz; j++) {
321:       PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));
322:     }

324:     /* U part */
325:     nz    = bdiag[i] - bdiag[i+1];
326:     bjtmp = bj + bdiag[i+1]+1;
327:     for  (j=0; j<nz; j++) {
328:       PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));
329:     }

331:     /* load in initial (unfactored row) */
332:     nz    = ai[r[i]+1] - ai[r[i]];
333:     ajtmp = aj + ai[r[i]];
334:     v     = aa + bs2*ai[r[i]];
335:     for (j=0; j<nz; j++) {
336:       PetscMemcpy(rtmp+bs2*ic[ajtmp[j]],v+bs2*j,bs2*sizeof(MatScalar));
337:     }

339:     /* elimination */
340:     bjtmp = bj + bi[i];
341:     nzL   = bi[i+1] - bi[i];
342:     for (k=0; k < nzL; k++) {
343:       row = bjtmp[k];
344:       pc  = rtmp + bs2*row;
345:       for (flg=0,j=0; j<bs2; j++) {
346:         if (pc[j]!=0.0) {
347:           flg = 1;
348:           break;
349:         }
350:       }
351:       if (flg) {
352:         pv = b->a + bs2*bdiag[row];
353:         /* PetscKernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */
354:         PetscKernel_A_gets_A_times_B_7(pc,pv,mwork);

356:         pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
357:         pv = b->a + bs2*(bdiag[row+1]+1);
358:         nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
359:         for (j=0; j<nz; j++) {
360:           /* PetscKernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */
361:           /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */
362:           v    = rtmp + bs2*pj[j];
363:           PetscKernel_A_gets_A_minus_B_times_C_7(v,pc,pv);
364:           pv  += bs2;
365:         }
366:         PetscLogFlops(686*nz+637); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
367:       }
368:     }

370:     /* finished row so stick it into b->a */
371:     /* L part */
372:     pv = b->a + bs2*bi[i];
373:     pj = b->j + bi[i];
374:     nz = bi[i+1] - bi[i];
375:     for (j=0; j<nz; j++) {
376:       PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));
377:     }

379:     /* Mark diagonal and invert diagonal for simplier triangular solves */
380:     pv   = b->a + bs2*bdiag[i];
381:     pj   = b->j + bdiag[i];
382:     PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));
383:     PetscKernel_A_gets_inverse_A_7(pv,shift,allowzeropivot,&zeropivotdetected);
384:     if (zeropivotdetected) C->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;

386:     /* U part */
387:     pv = b->a + bs2*(bdiag[i+1]+1);
388:     pj = b->j + bdiag[i+1]+1;
389:     nz = bdiag[i] - bdiag[i+1] - 1;
390:     for (j=0; j<nz; j++) {
391:       PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));
392:     }
393:   }

395:   PetscFree2(rtmp,mwork);
396:   ISRestoreIndices(isicol,&ic);
397:   ISRestoreIndices(isrow,&r);

399:   C->ops->solve          = MatSolve_SeqBAIJ_7;
400:   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_7;
401:   C->assembled           = PETSC_TRUE;

403:   PetscLogFlops(1.333333333333*7*7*7*n); /* from inverting diagonal blocks */
404:   return(0);
405: }

407: PetscErrorCode MatLUFactorNumeric_SeqBAIJ_7_NaturalOrdering_inplace(Mat C,Mat A,const MatFactorInfo *info)
408: {
409:   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ*)A->data,*b = (Mat_SeqBAIJ*)C->data;
411:   PetscInt       i,j,n = a->mbs,*bi = b->i,*bj = b->j;
412:   PetscInt       *ajtmpold,*ajtmp,nz,row;
413:   PetscInt       *diag_offset = b->diag,*ai=a->i,*aj=a->j,*pj;
414:   MatScalar      *pv,*v,*rtmp,*pc,*w,*x;
415:   MatScalar      x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15;
416:   MatScalar      x16,x17,x18,x19,x20,x21,x22,x23,x24,x25;
417:   MatScalar      p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15;
418:   MatScalar      p16,p17,p18,p19,p20,p21,p22,p23,p24,p25;
419:   MatScalar      m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15;
420:   MatScalar      m16,m17,m18,m19,m20,m21,m22,m23,m24,m25;
421:   MatScalar      p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36;
422:   MatScalar      p37,p38,p39,p40,p41,p42,p43,p44,p45,p46,p47,p48,p49;
423:   MatScalar      x26,x27,x28,x29,x30,x31,x32,x33,x34,x35,x36;
424:   MatScalar      x37,x38,x39,x40,x41,x42,x43,x44,x45,x46,x47,x48,x49;
425:   MatScalar      m26,m27,m28,m29,m30,m31,m32,m33,m34,m35,m36;
426:   MatScalar      m37,m38,m39,m40,m41,m42,m43,m44,m45,m46,m47,m48,m49;
427:   MatScalar      *ba   = b->a,*aa = a->a;
428:   PetscReal      shift = info->shiftamount;
429:   PetscBool      allowzeropivot,zeropivotdetected;

432:   allowzeropivot = PetscNot(A->erroriffailure);
433:   PetscMalloc1(49*(n+1),&rtmp);
434:   for (i=0; i<n; i++) {
435:     nz    = bi[i+1] - bi[i];
436:     ajtmp = bj + bi[i];
437:     for  (j=0; j<nz; j++) {
438:       x     = rtmp+49*ajtmp[j];
439:       x[0]  = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0;
440:       x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0;
441:       x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0;
442:       x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0;
443:       x[34] = x[35] = x[36] = x[37] = x[38] = x[39] = x[40] = x[41] = 0.0;
444:       x[42] = x[43] = x[44] = x[45] = x[46] = x[47] = x[48] = 0.0;
445:     }
446:     /* load in initial (unfactored row) */
447:     nz       = ai[i+1] - ai[i];
448:     ajtmpold = aj + ai[i];
449:     v        = aa + 49*ai[i];
450:     for (j=0; j<nz; j++) {
451:       x     = rtmp+49*ajtmpold[j];
452:       x[0]  =  v[0];  x[1] =  v[1];  x[2] =  v[2];  x[3] =  v[3];
453:       x[4]  =  v[4];  x[5] =  v[5];  x[6] =  v[6];  x[7] =  v[7];
454:       x[8]  =  v[8];  x[9] =  v[9];  x[10] = v[10]; x[11] = v[11];
455:       x[12] = v[12]; x[13] = v[13]; x[14] = v[14]; x[15] = v[15];
456:       x[16] = v[16]; x[17] = v[17]; x[18] = v[18]; x[19] = v[19];
457:       x[20] = v[20]; x[21] = v[21]; x[22] = v[22]; x[23] = v[23];
458:       x[24] = v[24]; x[25] = v[25]; x[26] = v[26]; x[27] = v[27];
459:       x[28] = v[28]; x[29] = v[29]; x[30] = v[30]; x[31] = v[31];
460:       x[32] = v[32]; x[33] = v[33]; x[34] = v[34]; x[35] = v[35];
461:       x[36] = v[36]; x[37] = v[37]; x[38] = v[38]; x[39] = v[39];
462:       x[40] = v[40]; x[41] = v[41]; x[42] = v[42]; x[43] = v[43];
463:       x[44] = v[44]; x[45] = v[45]; x[46] = v[46]; x[47] = v[47];
464:       x[48] = v[48];
465:       v    += 49;
466:     }
467:     row = *ajtmp++;
468:     while (row < i) {
469:       pc  = rtmp + 49*row;
470:       p1  = pc[0];  p2  = pc[1];  p3  = pc[2];  p4  = pc[3];
471:       p5  = pc[4];  p6  = pc[5];  p7  = pc[6];  p8  = pc[7];
472:       p9  = pc[8];  p10 = pc[9];  p11 = pc[10]; p12 = pc[11];
473:       p13 = pc[12]; p14 = pc[13]; p15 = pc[14]; p16 = pc[15];
474:       p17 = pc[16]; p18 = pc[17]; p19 = pc[18]; p20 = pc[19];
475:       p21 = pc[20]; p22 = pc[21]; p23 = pc[22]; p24 = pc[23];
476:       p25 = pc[24]; p26 = pc[25]; p27 = pc[26]; p28 = pc[27];
477:       p29 = pc[28]; p30 = pc[29]; p31 = pc[30]; p32 = pc[31];
478:       p33 = pc[32]; p34 = pc[33]; p35 = pc[34]; p36 = pc[35];
479:       p37 = pc[36]; p38 = pc[37]; p39 = pc[38]; p40 = pc[39];
480:       p41 = pc[40]; p42 = pc[41]; p43 = pc[42]; p44 = pc[43];
481:       p45 = pc[44]; p46 = pc[45]; p47 = pc[46]; p48 = pc[47];
482:       p49 = pc[48];
483:       if (p1  != 0.0 || p2  != 0.0 || p3  != 0.0 || p4  != 0.0 ||
484:           p5  != 0.0 || p6  != 0.0 || p7  != 0.0 || p8  != 0.0 ||
485:           p9  != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 ||
486:           p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 ||
487:           p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 ||
488:           p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 ||
489:           p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 ||
490:           p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 ||
491:           p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0 ||
492:           p37 != 0.0 || p38 != 0.0 || p39 != 0.0 || p40 != 0.0 ||
493:           p41 != 0.0 || p42 != 0.0 || p43 != 0.0 || p44 != 0.0 ||
494:           p45 != 0.0 || p46 != 0.0 || p47 != 0.0 || p48 != 0.0 ||
495:           p49 != 0.0) {
496:         pv    = ba + 49*diag_offset[row];
497:         pj    = bj + diag_offset[row] + 1;
498:         x1    = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
499:         x5    = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];
500:         x9    = pv[8];  x10 = pv[9];  x11 = pv[10]; x12 = pv[11];
501:         x13   = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15];
502:         x17   = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19];
503:         x21   = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
504:         x25   = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27];
505:         x29   = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31];
506:         x33   = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35];
507:         x37   = pv[36]; x38 = pv[37]; x39 = pv[38]; x40 = pv[39];
508:         x41   = pv[40]; x42 = pv[41]; x43 = pv[42]; x44 = pv[43];
509:         x45   = pv[44]; x46 = pv[45]; x47 = pv[46]; x48 = pv[47];
510:         x49   = pv[48];
511:         pc[0] = m1  = p1*x1  + p8*x2   + p15*x3  + p22*x4  + p29*x5  + p36*x6 + p43*x7;
512:         pc[1] = m2  = p2*x1  + p9*x2   + p16*x3  + p23*x4  + p30*x5  + p37*x6 + p44*x7;
513:         pc[2] = m3  = p3*x1  + p10*x2  + p17*x3  + p24*x4  + p31*x5  + p38*x6 + p45*x7;
514:         pc[3] = m4  = p4*x1  + p11*x2  + p18*x3  + p25*x4  + p32*x5  + p39*x6 + p46*x7;
515:         pc[4] = m5  = p5*x1  + p12*x2  + p19*x3  + p26*x4  + p33*x5  + p40*x6 + p47*x7;
516:         pc[5] = m6  = p6*x1  + p13*x2  + p20*x3  + p27*x4  + p34*x5  + p41*x6 + p48*x7;
517:         pc[6] = m7  = p7*x1  + p14*x2  + p21*x3  + p28*x4  + p35*x5  + p42*x6 + p49*x7;

519:         pc[7]  = m8  = p1*x8  + p8*x9   + p15*x10 + p22*x11 + p29*x12 + p36*x13 + p43*x14;
520:         pc[8]  = m9  = p2*x8  + p9*x9   + p16*x10 + p23*x11 + p30*x12 + p37*x13 + p44*x14;
521:         pc[9]  = m10 = p3*x8  + p10*x9  + p17*x10 + p24*x11 + p31*x12 + p38*x13 + p45*x14;
522:         pc[10] = m11 = p4*x8  + p11*x9  + p18*x10 + p25*x11 + p32*x12 + p39*x13 + p46*x14;
523:         pc[11] = m12 = p5*x8  + p12*x9  + p19*x10 + p26*x11 + p33*x12 + p40*x13 + p47*x14;
524:         pc[12] = m13 = p6*x8  + p13*x9  + p20*x10 + p27*x11 + p34*x12 + p41*x13 + p48*x14;
525:         pc[13] = m14 = p7*x8  + p14*x9  + p21*x10 + p28*x11 + p35*x12 + p42*x13 + p49*x14;

527:         pc[14] = m15 = p1*x15 + p8*x16  + p15*x17 + p22*x18 + p29*x19 + p36*x20 + p43*x21;
528:         pc[15] = m16 = p2*x15 + p9*x16  + p16*x17 + p23*x18 + p30*x19 + p37*x20 + p44*x21;
529:         pc[16] = m17 = p3*x15 + p10*x16 + p17*x17 + p24*x18 + p31*x19 + p38*x20 + p45*x21;
530:         pc[17] = m18 = p4*x15 + p11*x16 + p18*x17 + p25*x18 + p32*x19 + p39*x20 + p46*x21;
531:         pc[18] = m19 = p5*x15 + p12*x16 + p19*x17 + p26*x18 + p33*x19 + p40*x20 + p47*x21;
532:         pc[19] = m20 = p6*x15 + p13*x16 + p20*x17 + p27*x18 + p34*x19 + p41*x20 + p48*x21;
533:         pc[20] = m21 = p7*x15 + p14*x16 + p21*x17 + p28*x18 + p35*x19 + p42*x20 + p49*x21;

535:         pc[21] = m22 = p1*x22 + p8*x23  + p15*x24 + p22*x25 + p29*x26 + p36*x27 + p43*x28;
536:         pc[22] = m23 = p2*x22 + p9*x23  + p16*x24 + p23*x25 + p30*x26 + p37*x27 + p44*x28;
537:         pc[23] = m24 = p3*x22 + p10*x23 + p17*x24 + p24*x25 + p31*x26 + p38*x27 + p45*x28;
538:         pc[24] = m25 = p4*x22 + p11*x23 + p18*x24 + p25*x25 + p32*x26 + p39*x27 + p46*x28;
539:         pc[25] = m26 = p5*x22 + p12*x23 + p19*x24 + p26*x25 + p33*x26 + p40*x27 + p47*x28;
540:         pc[26] = m27 = p6*x22 + p13*x23 + p20*x24 + p27*x25 + p34*x26 + p41*x27 + p48*x28;
541:         pc[27] = m28 = p7*x22 + p14*x23 + p21*x24 + p28*x25 + p35*x26 + p42*x27 + p49*x28;

543:         pc[28] = m29 = p1*x29 + p8*x30  + p15*x31 + p22*x32 + p29*x33 + p36*x34 + p43*x35;
544:         pc[29] = m30 = p2*x29 + p9*x30  + p16*x31 + p23*x32 + p30*x33 + p37*x34 + p44*x35;
545:         pc[30] = m31 = p3*x29 + p10*x30 + p17*x31 + p24*x32 + p31*x33 + p38*x34 + p45*x35;
546:         pc[31] = m32 = p4*x29 + p11*x30 + p18*x31 + p25*x32 + p32*x33 + p39*x34 + p46*x35;
547:         pc[32] = m33 = p5*x29 + p12*x30 + p19*x31 + p26*x32 + p33*x33 + p40*x34 + p47*x35;
548:         pc[33] = m34 = p6*x29 + p13*x30 + p20*x31 + p27*x32 + p34*x33 + p41*x34 + p48*x35;
549:         pc[34] = m35 = p7*x29 + p14*x30 + p21*x31 + p28*x32 + p35*x33 + p42*x34 + p49*x35;

551:         pc[35] = m36 = p1*x36 + p8*x37  + p15*x38 + p22*x39 + p29*x40 + p36*x41 + p43*x42;
552:         pc[36] = m37 = p2*x36 + p9*x37  + p16*x38 + p23*x39 + p30*x40 + p37*x41 + p44*x42;
553:         pc[37] = m38 = p3*x36 + p10*x37 + p17*x38 + p24*x39 + p31*x40 + p38*x41 + p45*x42;
554:         pc[38] = m39 = p4*x36 + p11*x37 + p18*x38 + p25*x39 + p32*x40 + p39*x41 + p46*x42;
555:         pc[39] = m40 = p5*x36 + p12*x37 + p19*x38 + p26*x39 + p33*x40 + p40*x41 + p47*x42;
556:         pc[40] = m41 = p6*x36 + p13*x37 + p20*x38 + p27*x39 + p34*x40 + p41*x41 + p48*x42;
557:         pc[41] = m42 = p7*x36 + p14*x37 + p21*x38 + p28*x39 + p35*x40 + p42*x41 + p49*x42;

559:         pc[42] = m43 = p1*x43 + p8*x44  + p15*x45 + p22*x46 + p29*x47 + p36*x48 + p43*x49;
560:         pc[43] = m44 = p2*x43 + p9*x44  + p16*x45 + p23*x46 + p30*x47 + p37*x48 + p44*x49;
561:         pc[44] = m45 = p3*x43 + p10*x44 + p17*x45 + p24*x46 + p31*x47 + p38*x48 + p45*x49;
562:         pc[45] = m46 = p4*x43 + p11*x44 + p18*x45 + p25*x46 + p32*x47 + p39*x48 + p46*x49;
563:         pc[46] = m47 = p5*x43 + p12*x44 + p19*x45 + p26*x46 + p33*x47 + p40*x48 + p47*x49;
564:         pc[47] = m48 = p6*x43 + p13*x44 + p20*x45 + p27*x46 + p34*x47 + p41*x48 + p48*x49;
565:         pc[48] = m49 = p7*x43 + p14*x44 + p21*x45 + p28*x46 + p35*x47 + p42*x48 + p49*x49;

567:         nz  = bi[row+1] - diag_offset[row] - 1;
568:         pv += 49;
569:         for (j=0; j<nz; j++) {
570:           x1    = pv[0];  x2  = pv[1];  x3  = pv[2];  x4  = pv[3];
571:           x5    = pv[4];  x6  = pv[5];  x7  = pv[6];  x8  = pv[7];
572:           x9    = pv[8];  x10 = pv[9];  x11 = pv[10]; x12 = pv[11];
573:           x13   = pv[12]; x14 = pv[13]; x15 = pv[14]; x16 = pv[15];
574:           x17   = pv[16]; x18 = pv[17]; x19 = pv[18]; x20 = pv[19];
575:           x21   = pv[20]; x22 = pv[21]; x23 = pv[22]; x24 = pv[23];
576:           x25   = pv[24]; x26 = pv[25]; x27 = pv[26]; x28 = pv[27];
577:           x29   = pv[28]; x30 = pv[29]; x31 = pv[30]; x32 = pv[31];
578:           x33   = pv[32]; x34 = pv[33]; x35 = pv[34]; x36 = pv[35];
579:           x37   = pv[36]; x38 = pv[37]; x39 = pv[38]; x40 = pv[39];
580:           x41   = pv[40]; x42 = pv[41]; x43 = pv[42]; x44 = pv[43];
581:           x45   = pv[44]; x46 = pv[45]; x47 = pv[46]; x48 = pv[47];
582:           x49   = pv[48];
583:           x     = rtmp + 49*pj[j];
584:           x[0] -= m1*x1  + m8*x2   + m15*x3  + m22*x4  + m29*x5  + m36*x6 + m43*x7;
585:           x[1] -= m2*x1  + m9*x2   + m16*x3  + m23*x4  + m30*x5  + m37*x6 + m44*x7;
586:           x[2] -= m3*x1  + m10*x2  + m17*x3  + m24*x4  + m31*x5  + m38*x6 + m45*x7;
587:           x[3] -= m4*x1  + m11*x2  + m18*x3  + m25*x4  + m32*x5  + m39*x6 + m46*x7;
588:           x[4] -= m5*x1  + m12*x2  + m19*x3  + m26*x4  + m33*x5  + m40*x6 + m47*x7;
589:           x[5] -= m6*x1  + m13*x2  + m20*x3  + m27*x4  + m34*x5  + m41*x6 + m48*x7;
590:           x[6] -= m7*x1  + m14*x2  + m21*x3  + m28*x4  + m35*x5  + m42*x6 + m49*x7;

592:           x[7]  -= m1*x8  + m8*x9   + m15*x10 + m22*x11 + m29*x12 + m36*x13 + m43*x14;
593:           x[8]  -= m2*x8  + m9*x9   + m16*x10 + m23*x11 + m30*x12 + m37*x13 + m44*x14;
594:           x[9]  -= m3*x8  + m10*x9  + m17*x10 + m24*x11 + m31*x12 + m38*x13 + m45*x14;
595:           x[10] -= m4*x8  + m11*x9  + m18*x10 + m25*x11 + m32*x12 + m39*x13 + m46*x14;
596:           x[11] -= m5*x8  + m12*x9  + m19*x10 + m26*x11 + m33*x12 + m40*x13 + m47*x14;
597:           x[12] -= m6*x8  + m13*x9  + m20*x10 + m27*x11 + m34*x12 + m41*x13 + m48*x14;
598:           x[13] -= m7*x8  + m14*x9  + m21*x10 + m28*x11 + m35*x12 + m42*x13 + m49*x14;

600:           x[14] -= m1*x15 + m8*x16  + m15*x17 + m22*x18 + m29*x19 + m36*x20 + m43*x21;
601:           x[15] -= m2*x15 + m9*x16  + m16*x17 + m23*x18 + m30*x19 + m37*x20 + m44*x21;
602:           x[16] -= m3*x15 + m10*x16 + m17*x17 + m24*x18 + m31*x19 + m38*x20 + m45*x21;
603:           x[17] -= m4*x15 + m11*x16 + m18*x17 + m25*x18 + m32*x19 + m39*x20 + m46*x21;
604:           x[18] -= m5*x15 + m12*x16 + m19*x17 + m26*x18 + m33*x19 + m40*x20 + m47*x21;
605:           x[19] -= m6*x15 + m13*x16 + m20*x17 + m27*x18 + m34*x19 + m41*x20 + m48*x21;
606:           x[20] -= m7*x15 + m14*x16 + m21*x17 + m28*x18 + m35*x19 + m42*x20 + m49*x21;

608:           x[21] -= m1*x22 + m8*x23  + m15*x24 + m22*x25 + m29*x26 + m36*x27 + m43*x28;
609:           x[22] -= m2*x22 + m9*x23  + m16*x24 + m23*x25 + m30*x26 + m37*x27 + m44*x28;
610:           x[23] -= m3*x22 + m10*x23 + m17*x24 + m24*x25 + m31*x26 + m38*x27 + m45*x28;
611:           x[24] -= m4*x22 + m11*x23 + m18*x24 + m25*x25 + m32*x26 + m39*x27 + m46*x28;
612:           x[25] -= m5*x22 + m12*x23 + m19*x24 + m26*x25 + m33*x26 + m40*x27 + m47*x28;
613:           x[26] -= m6*x22 + m13*x23 + m20*x24 + m27*x25 + m34*x26 + m41*x27 + m48*x28;
614:           x[27] -= m7*x22 + m14*x23 + m21*x24 + m28*x25 + m35*x26 + m42*x27 + m49*x28;

616:           x[28] -= m1*x29 + m8*x30  + m15*x31 + m22*x32 + m29*x33 + m36*x34 + m43*x35;
617:           x[29] -= m2*x29 + m9*x30  + m16*x31 + m23*x32 + m30*x33 + m37*x34 + m44*x35;
618:           x[30] -= m3*x29 + m10*x30 + m17*x31 + m24*x32 + m31*x33 + m38*x34 + m45*x35;
619:           x[31] -= m4*x29 + m11*x30 + m18*x31 + m25*x32 + m32*x33 + m39*x34 + m46*x35;
620:           x[32] -= m5*x29 + m12*x30 + m19*x31 + m26*x32 + m33*x33 + m40*x34 + m47*x35;
621:           x[33] -= m6*x29 + m13*x30 + m20*x31 + m27*x32 + m34*x33 + m41*x34 + m48*x35;
622:           x[34] -= m7*x29 + m14*x30 + m21*x31 + m28*x32 + m35*x33 + m42*x34 + m49*x35;

624:           x[35] -= m1*x36 + m8*x37  + m15*x38 + m22*x39 + m29*x40 + m36*x41 + m43*x42;
625:           x[36] -= m2*x36 + m9*x37  + m16*x38 + m23*x39 + m30*x40 + m37*x41 + m44*x42;
626:           x[37] -= m3*x36 + m10*x37 + m17*x38 + m24*x39 + m31*x40 + m38*x41 + m45*x42;
627:           x[38] -= m4*x36 + m11*x37 + m18*x38 + m25*x39 + m32*x40 + m39*x41 + m46*x42;
628:           x[39] -= m5*x36 + m12*x37 + m19*x38 + m26*x39 + m33*x40 + m40*x41 + m47*x42;
629:           x[40] -= m6*x36 + m13*x37 + m20*x38 + m27*x39 + m34*x40 + m41*x41 + m48*x42;
630:           x[41] -= m7*x36 + m14*x37 + m21*x38 + m28*x39 + m35*x40 + m42*x41 + m49*x42;

632:           x[42] -= m1*x43 + m8*x44  + m15*x45 + m22*x46 + m29*x47 + m36*x48 + m43*x49;
633:           x[43] -= m2*x43 + m9*x44  + m16*x45 + m23*x46 + m30*x47 + m37*x48 + m44*x49;
634:           x[44] -= m3*x43 + m10*x44 + m17*x45 + m24*x46 + m31*x47 + m38*x48 + m45*x49;
635:           x[45] -= m4*x43 + m11*x44 + m18*x45 + m25*x46 + m32*x47 + m39*x48 + m46*x49;
636:           x[46] -= m5*x43 + m12*x44 + m19*x45 + m26*x46 + m33*x47 + m40*x48 + m47*x49;
637:           x[47] -= m6*x43 + m13*x44 + m20*x45 + m27*x46 + m34*x47 + m41*x48 + m48*x49;
638:           x[48] -= m7*x43 + m14*x44 + m21*x45 + m28*x46 + m35*x47 + m42*x48 + m49*x49;
639:           pv    += 49;
640:         }
641:         PetscLogFlops(686.0*nz+637.0);
642:       }
643:       row = *ajtmp++;
644:     }
645:     /* finished row so stick it into b->a */
646:     pv = ba + 49*bi[i];
647:     pj = bj + bi[i];
648:     nz = bi[i+1] - bi[i];
649:     for (j=0; j<nz; j++) {
650:       x      = rtmp+49*pj[j];
651:       pv[0]  = x[0];  pv[1]  = x[1];  pv[2]  = x[2];  pv[3]  = x[3];
652:       pv[4]  = x[4];  pv[5]  = x[5];  pv[6]  = x[6];  pv[7]  = x[7];
653:       pv[8]  = x[8];  pv[9]  = x[9];  pv[10] = x[10]; pv[11] = x[11];
654:       pv[12] = x[12]; pv[13] = x[13]; pv[14] = x[14]; pv[15] = x[15];
655:       pv[16] = x[16]; pv[17] = x[17]; pv[18] = x[18]; pv[19] = x[19];
656:       pv[20] = x[20]; pv[21] = x[21]; pv[22] = x[22]; pv[23] = x[23];
657:       pv[24] = x[24]; pv[25] = x[25]; pv[26] = x[26]; pv[27] = x[27];
658:       pv[28] = x[28]; pv[29] = x[29]; pv[30] = x[30]; pv[31] = x[31];
659:       pv[32] = x[32]; pv[33] = x[33]; pv[34] = x[34]; pv[35] = x[35];
660:       pv[36] = x[36]; pv[37] = x[37]; pv[38] = x[38]; pv[39] = x[39];
661:       pv[40] = x[40]; pv[41] = x[41]; pv[42] = x[42]; pv[43] = x[43];
662:       pv[44] = x[44]; pv[45] = x[45]; pv[46] = x[46]; pv[47] = x[47];
663:       pv[48] = x[48];
664:       pv    += 49;
665:     }
666:     /* invert diagonal block */
667:     w    = ba + 49*diag_offset[i];
668:     PetscKernel_A_gets_inverse_A_7(w,shift,allowzeropivot,&zeropivotdetected);
669:     if (zeropivotdetected) C->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
670:   }

672:   PetscFree(rtmp);

674:   C->ops->solve          = MatSolve_SeqBAIJ_7_NaturalOrdering_inplace;
675:   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_7_NaturalOrdering_inplace;
676:   C->assembled           = PETSC_TRUE;

678:   PetscLogFlops(1.333333333333*7*7*7*b->mbs); /* from inverting diagonal blocks */
679:   return(0);
680: }

682: PetscErrorCode MatLUFactorNumeric_SeqBAIJ_7_NaturalOrdering(Mat B,Mat A,const MatFactorInfo *info)
683: {
684:   Mat            C =B;
685:   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ*)C->data;
687:   PetscInt       i,j,k,nz,nzL,row;
688:   const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
689:   const PetscInt *ajtmp,*bjtmp,*bdiag=b->diag,*pj,bs2=a->bs2;
690:   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
691:   PetscInt       flg;
692:   PetscReal      shift = info->shiftamount;
693:   PetscBool      allowzeropivot,zeropivotdetected;

696:   allowzeropivot = PetscNot(A->erroriffailure);

698:   /* generate work space needed by the factorization */
699:   PetscMalloc2(bs2*n,&rtmp,bs2,&mwork);
700:   PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));

702:   for (i=0; i<n; i++) {
703:     /* zero rtmp */
704:     /* L part */
705:     nz    = bi[i+1] - bi[i];
706:     bjtmp = bj + bi[i];
707:     for  (j=0; j<nz; j++) {
708:       PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));
709:     }

711:     /* U part */
712:     nz    = bdiag[i] - bdiag[i+1];
713:     bjtmp = bj + bdiag[i+1]+1;
714:     for  (j=0; j<nz; j++) {
715:       PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));
716:     }

718:     /* load in initial (unfactored row) */
719:     nz    = ai[i+1] - ai[i];
720:     ajtmp = aj + ai[i];
721:     v     = aa + bs2*ai[i];
722:     for (j=0; j<nz; j++) {
723:       PetscMemcpy(rtmp+bs2*ajtmp[j],v+bs2*j,bs2*sizeof(MatScalar));
724:     }

726:     /* elimination */
727:     bjtmp = bj + bi[i];
728:     nzL   = bi[i+1] - bi[i];
729:     for (k=0; k < nzL; k++) {
730:       row = bjtmp[k];
731:       pc  = rtmp + bs2*row;
732:       for (flg=0,j=0; j<bs2; j++) {
733:         if (pc[j]!=0.0) {
734:           flg = 1;
735:           break;
736:         }
737:       }
738:       if (flg) {
739:         pv = b->a + bs2*bdiag[row];
740:         /* PetscKernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */
741:         PetscKernel_A_gets_A_times_B_7(pc,pv,mwork);

743:         pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
744:         pv = b->a + bs2*(bdiag[row+1]+1);
745:         nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
746:         for (j=0; j<nz; j++) {
747:           /* PetscKernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */
748:           /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */
749:           v    = rtmp + bs2*pj[j];
750:           PetscKernel_A_gets_A_minus_B_times_C_7(v,pc,pv);
751:           pv  += bs2;
752:         }
753:         PetscLogFlops(686*nz+637); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
754:       }
755:     }

757:     /* finished row so stick it into b->a */
758:     /* L part */
759:     pv = b->a + bs2*bi[i];
760:     pj = b->j + bi[i];
761:     nz = bi[i+1] - bi[i];
762:     for (j=0; j<nz; j++) {
763:       PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));
764:     }

766:     /* Mark diagonal and invert diagonal for simplier triangular solves */
767:     pv   = b->a + bs2*bdiag[i];
768:     pj   = b->j + bdiag[i];
769:     PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));
770:     PetscKernel_A_gets_inverse_A_7(pv,shift,allowzeropivot,&zeropivotdetected);
771:     if (zeropivotdetected) C->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;

773:     /* U part */
774:     pv = b->a + bs2*(bdiag[i+1]+1);
775:     pj = b->j + bdiag[i+1]+1;
776:     nz = bdiag[i] - bdiag[i+1] - 1;
777:     for (j=0; j<nz; j++) {
778:       PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));
779:     }
780:   }
781:   PetscFree2(rtmp,mwork);

783:   C->ops->solve          = MatSolve_SeqBAIJ_7_NaturalOrdering;
784:   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_7_NaturalOrdering;
785:   C->assembled           = PETSC_TRUE;

787:   PetscLogFlops(1.333333333333*7*7*7*n); /* from inverting diagonal blocks */
788:   return(0);
789: }