xref: /petsc/src/mat/impls/baij/seq/baijsolvnat15.c (revision 2c733ed45a445b0336611d812c866924feeaee2c)
1*2c733ed4SBarry Smith #include <../src/mat/impls/baij/seq/baij.h>
2*2c733ed4SBarry Smith #include <petsc/private/kernels/blockinvert.h>
3*2c733ed4SBarry Smith 
4*2c733ed4SBarry Smith /* bs = 15 for PFLOTRAN. Block operations are done by accessing all the columns   of the block at once */
5*2c733ed4SBarry Smith 
6*2c733ed4SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_15_NaturalOrdering_ver2(Mat A,Vec bb,Vec xx)
7*2c733ed4SBarry Smith {
8*2c733ed4SBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ*)A->data;
9*2c733ed4SBarry Smith   PetscErrorCode    ierr;
10*2c733ed4SBarry Smith   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*adiag=a->diag,*vi,bs=A->rmap->bs,bs2=a->bs2;
11*2c733ed4SBarry Smith   PetscInt          i,nz,idx,idt,m;
12*2c733ed4SBarry Smith   const MatScalar   *aa=a->a,*v;
13*2c733ed4SBarry Smith   PetscScalar       s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15;
14*2c733ed4SBarry Smith   PetscScalar       x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15;
15*2c733ed4SBarry Smith   PetscScalar       *x;
16*2c733ed4SBarry Smith   const PetscScalar *b;
17*2c733ed4SBarry Smith 
18*2c733ed4SBarry Smith   PetscFunctionBegin;
19*2c733ed4SBarry Smith   ierr = VecGetArrayRead(bb,&b);CHKERRQ(ierr);
20*2c733ed4SBarry Smith   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
21*2c733ed4SBarry Smith 
22*2c733ed4SBarry Smith   /* forward solve the lower triangular */
23*2c733ed4SBarry Smith   idx   = 0;
24*2c733ed4SBarry Smith   x[0]  = b[idx];    x[1]  = b[1+idx];  x[2]  = b[2+idx];  x[3]  = b[3+idx];  x[4]  = b[4+idx];
25*2c733ed4SBarry Smith   x[5]  = b[5+idx];  x[6]  = b[6+idx];  x[7]  = b[7+idx];  x[8]  = b[8+idx];  x[9]  = b[9+idx];
26*2c733ed4SBarry Smith   x[10] = b[10+idx]; x[11] = b[11+idx]; x[12] = b[12+idx]; x[13] = b[13+idx]; x[14] = b[14+idx];
27*2c733ed4SBarry Smith 
28*2c733ed4SBarry Smith   for (i=1; i<n; i++) {
29*2c733ed4SBarry Smith     v   = aa + bs2*ai[i];
30*2c733ed4SBarry Smith     vi  = aj + ai[i];
31*2c733ed4SBarry Smith     nz  = ai[i+1] - ai[i];
32*2c733ed4SBarry Smith     idt = bs*i;
33*2c733ed4SBarry Smith     s1  = b[idt];    s2  = b[1+idt];  s3  = b[2+idt];  s4  = b[3+idt];  s5  = b[4+idt];
34*2c733ed4SBarry Smith     s6  = b[5+idt];  s7  = b[6+idt];  s8  = b[7+idt];  s9  = b[8+idt];  s10 = b[9+idt];
35*2c733ed4SBarry Smith     s11 = b[10+idt]; s12 = b[11+idt]; s13 = b[12+idt]; s14 = b[13+idt]; s15 = b[14+idt];
36*2c733ed4SBarry Smith     for (m=0; m<nz; m++) {
37*2c733ed4SBarry Smith       idx = bs*vi[m];
38*2c733ed4SBarry Smith       x1  = x[idx];     x2  = x[1+idx];  x3  = x[2+idx];  x4  = x[3+idx];  x5  = x[4+idx];
39*2c733ed4SBarry Smith       x6  = x[5+idx];   x7  = x[6+idx];  x8  = x[7+idx];  x9  = x[8+idx];  x10 = x[9+idx];
40*2c733ed4SBarry Smith       x11 = x[10+idx]; x12  = x[11+idx]; x13 = x[12+idx]; x14 = x[13+idx]; x15 = x[14+idx];
41*2c733ed4SBarry Smith 
42*2c733ed4SBarry Smith 
43*2c733ed4SBarry Smith       s1  -= v[0]*x1  + v[15]*x2 + v[30]*x3 + v[45]*x4 + v[60]*x5 + v[75]*x6 + v[90]*x7  + v[105]*x8 + v[120]*x9 + v[135]*x10 + v[150]*x11 + v[165]*x12 + v[180]*x13 + v[195]*x14 + v[210]*x15;
44*2c733ed4SBarry Smith       s2  -= v[1]*x1  + v[16]*x2 + v[31]*x3 + v[46]*x4 + v[61]*x5 + v[76]*x6 + v[91]*x7  + v[106]*x8 + v[121]*x9 + v[136]*x10 + v[151]*x11 + v[166]*x12 + v[181]*x13 + v[196]*x14 + v[211]*x15;
45*2c733ed4SBarry Smith       s3  -= v[2]*x1  + v[17]*x2 + v[32]*x3 + v[47]*x4 + v[62]*x5 + v[77]*x6 + v[92]*x7  + v[107]*x8 + v[122]*x9 + v[137]*x10 + v[152]*x11 + v[167]*x12 + v[182]*x13 + v[197]*x14 + v[212]*x15;
46*2c733ed4SBarry Smith       s4  -= v[3]*x1  + v[18]*x2 + v[33]*x3 + v[48]*x4 + v[63]*x5 + v[78]*x6 + v[93]*x7  + v[108]*x8 + v[123]*x9 + v[138]*x10 + v[153]*x11 + v[168]*x12 + v[183]*x13 + v[198]*x14 + v[213]*x15;
47*2c733ed4SBarry Smith       s5  -= v[4]*x1  + v[19]*x2 + v[34]*x3 + v[49]*x4 + v[64]*x5 + v[79]*x6 + v[94]*x7  + v[109]*x8 + v[124]*x9 + v[139]*x10 + v[154]*x11 + v[169]*x12 + v[184]*x13 + v[199]*x14 + v[214]*x15;
48*2c733ed4SBarry Smith       s6  -= v[5]*x1  + v[20]*x2 + v[35]*x3 + v[50]*x4 + v[65]*x5 + v[80]*x6 + v[95]*x7  + v[110]*x8 + v[125]*x9 + v[140]*x10 + v[155]*x11 + v[170]*x12 + v[185]*x13 + v[200]*x14 + v[215]*x15;
49*2c733ed4SBarry Smith       s7  -= v[6]*x1  + v[21]*x2 + v[36]*x3 + v[51]*x4 + v[66]*x5 + v[81]*x6 + v[96]*x7  + v[111]*x8 + v[126]*x9 + v[141]*x10 + v[156]*x11 + v[171]*x12 + v[186]*x13 + v[201]*x14 + v[216]*x15;
50*2c733ed4SBarry Smith       s8  -= v[7]*x1  + v[22]*x2 + v[37]*x3 + v[52]*x4 + v[67]*x5 + v[82]*x6 + v[97]*x7  + v[112]*x8 + v[127]*x9 + v[142]*x10 + v[157]*x11 + v[172]*x12 + v[187]*x13 + v[202]*x14 + v[217]*x15;
51*2c733ed4SBarry Smith       s9  -= v[8]*x1  + v[23]*x2 + v[38]*x3 + v[53]*x4 + v[68]*x5 + v[83]*x6 + v[98]*x7  + v[113]*x8 + v[128]*x9 + v[143]*x10 + v[158]*x11 + v[173]*x12 + v[188]*x13 + v[203]*x14 + v[218]*x15;
52*2c733ed4SBarry Smith       s10 -= v[9]*x1  + v[24]*x2 + v[39]*x3 + v[54]*x4 + v[69]*x5 + v[84]*x6 + v[99]*x7  + v[114]*x8 + v[129]*x9 + v[144]*x10 + v[159]*x11 + v[174]*x12 + v[189]*x13 + v[204]*x14 + v[219]*x15;
53*2c733ed4SBarry Smith       s11 -= v[10]*x1 + v[25]*x2 + v[40]*x3 + v[55]*x4 + v[70]*x5 + v[85]*x6 + v[100]*x7 + v[115]*x8 + v[130]*x9 + v[145]*x10 + v[160]*x11 + v[175]*x12 + v[190]*x13 + v[205]*x14 + v[220]*x15;
54*2c733ed4SBarry Smith       s12 -= v[11]*x1 + v[26]*x2 + v[41]*x3 + v[56]*x4 + v[71]*x5 + v[86]*x6 + v[101]*x7 + v[116]*x8 + v[131]*x9 + v[146]*x10 + v[161]*x11 + v[176]*x12 + v[191]*x13 + v[206]*x14 + v[221]*x15;
55*2c733ed4SBarry Smith       s13 -= v[12]*x1 + v[27]*x2 + v[42]*x3 + v[57]*x4 + v[72]*x5 + v[87]*x6 + v[102]*x7 + v[117]*x8 + v[132]*x9 + v[147]*x10 + v[162]*x11 + v[177]*x12 + v[192]*x13 + v[207]*x14 + v[222]*x15;
56*2c733ed4SBarry Smith       s14 -= v[13]*x1 + v[28]*x2 + v[43]*x3 + v[58]*x4 + v[73]*x5 + v[88]*x6 + v[103]*x7 + v[118]*x8 + v[133]*x9 + v[148]*x10 + v[163]*x11 + v[178]*x12 + v[193]*x13 + v[208]*x14 + v[223]*x15;
57*2c733ed4SBarry Smith       s15 -= v[14]*x1 + v[29]*x2 + v[44]*x3 + v[59]*x4 + v[74]*x5 + v[89]*x6 + v[104]*x7 + v[119]*x8 + v[134]*x9 + v[149]*x10 + v[164]*x11 + v[179]*x12 + v[194]*x13 + v[209]*x14 + v[224]*x15;
58*2c733ed4SBarry Smith 
59*2c733ed4SBarry Smith       v += bs2;
60*2c733ed4SBarry Smith     }
61*2c733ed4SBarry Smith     x[idt]    = s1;  x[1+idt]  = s2;  x[2+idt]  = s3;  x[3+idt]  = s4;  x[4+idt]  = s5;
62*2c733ed4SBarry Smith     x[5+idt]  = s6;  x[6+idt]  = s7;  x[7+idt]  = s8;  x[8+idt]  = s9;  x[9+idt]  = s10;
63*2c733ed4SBarry Smith     x[10+idt] = s11; x[11+idt] = s12; x[12+idt] = s13; x[13+idt] = s14; x[14+idt] = s15;
64*2c733ed4SBarry Smith 
65*2c733ed4SBarry Smith   }
66*2c733ed4SBarry Smith   /* backward solve the upper triangular */
67*2c733ed4SBarry Smith   for (i=n-1; i>=0; i--) {
68*2c733ed4SBarry Smith     v   = aa + bs2*(adiag[i+1]+1);
69*2c733ed4SBarry Smith     vi  = aj + adiag[i+1]+1;
70*2c733ed4SBarry Smith     nz  = adiag[i] - adiag[i+1] - 1;
71*2c733ed4SBarry Smith     idt = bs*i;
72*2c733ed4SBarry Smith     s1  = x[idt];     s2  = x[1+idt];  s3  = x[2+idt];  s4  = x[3+idt];  s5  = x[4+idt];
73*2c733ed4SBarry Smith     s6  = x[5+idt];   s7  = x[6+idt];  s8  = x[7+idt];  s9  = x[8+idt];  s10 = x[9+idt];
74*2c733ed4SBarry Smith     s11 = x[10+idt]; s12  = x[11+idt]; s13 = x[12+idt]; s14 = x[13+idt]; s15 = x[14+idt];
75*2c733ed4SBarry Smith 
76*2c733ed4SBarry Smith     for (m=0; m<nz; m++) {
77*2c733ed4SBarry Smith       idx = bs*vi[m];
78*2c733ed4SBarry Smith       x1  = x[idx];     x2  = x[1+idx];  x3  = x[2+idx];  x4  = x[3+idx];  x5  = x[4+idx];
79*2c733ed4SBarry Smith       x6  = x[5+idx];   x7  = x[6+idx];  x8  = x[7+idx];  x9  = x[8+idx];  x10 = x[9+idx];
80*2c733ed4SBarry Smith       x11 = x[10+idx]; x12  = x[11+idx]; x13 = x[12+idx]; x14 = x[13+idx]; x15 = x[14+idx];
81*2c733ed4SBarry Smith 
82*2c733ed4SBarry Smith       s1  -= v[0]*x1  + v[15]*x2 + v[30]*x3 + v[45]*x4 + v[60]*x5 + v[75]*x6 + v[90]*x7  + v[105]*x8 + v[120]*x9 + v[135]*x10 + v[150]*x11 + v[165]*x12 + v[180]*x13 + v[195]*x14 + v[210]*x15;
83*2c733ed4SBarry Smith       s2  -= v[1]*x1  + v[16]*x2 + v[31]*x3 + v[46]*x4 + v[61]*x5 + v[76]*x6 + v[91]*x7  + v[106]*x8 + v[121]*x9 + v[136]*x10 + v[151]*x11 + v[166]*x12 + v[181]*x13 + v[196]*x14 + v[211]*x15;
84*2c733ed4SBarry Smith       s3  -= v[2]*x1  + v[17]*x2 + v[32]*x3 + v[47]*x4 + v[62]*x5 + v[77]*x6 + v[92]*x7  + v[107]*x8 + v[122]*x9 + v[137]*x10 + v[152]*x11 + v[167]*x12 + v[182]*x13 + v[197]*x14 + v[212]*x15;
85*2c733ed4SBarry Smith       s4  -= v[3]*x1  + v[18]*x2 + v[33]*x3 + v[48]*x4 + v[63]*x5 + v[78]*x6 + v[93]*x7  + v[108]*x8 + v[123]*x9 + v[138]*x10 + v[153]*x11 + v[168]*x12 + v[183]*x13 + v[198]*x14 + v[213]*x15;
86*2c733ed4SBarry Smith       s5  -= v[4]*x1  + v[19]*x2 + v[34]*x3 + v[49]*x4 + v[64]*x5 + v[79]*x6 + v[94]*x7  + v[109]*x8 + v[124]*x9 + v[139]*x10 + v[154]*x11 + v[169]*x12 + v[184]*x13 + v[199]*x14 + v[214]*x15;
87*2c733ed4SBarry Smith       s6  -= v[5]*x1  + v[20]*x2 + v[35]*x3 + v[50]*x4 + v[65]*x5 + v[80]*x6 + v[95]*x7  + v[110]*x8 + v[125]*x9 + v[140]*x10 + v[155]*x11 + v[170]*x12 + v[185]*x13 + v[200]*x14 + v[215]*x15;
88*2c733ed4SBarry Smith       s7  -= v[6]*x1  + v[21]*x2 + v[36]*x3 + v[51]*x4 + v[66]*x5 + v[81]*x6 + v[96]*x7  + v[111]*x8 + v[126]*x9 + v[141]*x10 + v[156]*x11 + v[171]*x12 + v[186]*x13 + v[201]*x14 + v[216]*x15;
89*2c733ed4SBarry Smith       s8  -= v[7]*x1  + v[22]*x2 + v[37]*x3 + v[52]*x4 + v[67]*x5 + v[82]*x6 + v[97]*x7  + v[112]*x8 + v[127]*x9 + v[142]*x10 + v[157]*x11 + v[172]*x12 + v[187]*x13 + v[202]*x14 + v[217]*x15;
90*2c733ed4SBarry Smith       s9  -= v[8]*x1  + v[23]*x2 + v[38]*x3 + v[53]*x4 + v[68]*x5 + v[83]*x6 + v[98]*x7  + v[113]*x8 + v[128]*x9 + v[143]*x10 + v[158]*x11 + v[173]*x12 + v[188]*x13 + v[203]*x14 + v[218]*x15;
91*2c733ed4SBarry Smith       s10 -= v[9]*x1  + v[24]*x2 + v[39]*x3 + v[54]*x4 + v[69]*x5 + v[84]*x6 + v[99]*x7  + v[114]*x8 + v[129]*x9 + v[144]*x10 + v[159]*x11 + v[174]*x12 + v[189]*x13 + v[204]*x14 + v[219]*x15;
92*2c733ed4SBarry Smith       s11 -= v[10]*x1 + v[25]*x2 + v[40]*x3 + v[55]*x4 + v[70]*x5 + v[85]*x6 + v[100]*x7 + v[115]*x8 + v[130]*x9 + v[145]*x10 + v[160]*x11 + v[175]*x12 + v[190]*x13 + v[205]*x14 + v[220]*x15;
93*2c733ed4SBarry Smith       s12 -= v[11]*x1 + v[26]*x2 + v[41]*x3 + v[56]*x4 + v[71]*x5 + v[86]*x6 + v[101]*x7 + v[116]*x8 + v[131]*x9 + v[146]*x10 + v[161]*x11 + v[176]*x12 + v[191]*x13 + v[206]*x14 + v[221]*x15;
94*2c733ed4SBarry Smith       s13 -= v[12]*x1 + v[27]*x2 + v[42]*x3 + v[57]*x4 + v[72]*x5 + v[87]*x6 + v[102]*x7 + v[117]*x8 + v[132]*x9 + v[147]*x10 + v[162]*x11 + v[177]*x12 + v[192]*x13 + v[207]*x14 + v[222]*x15;
95*2c733ed4SBarry Smith       s14 -= v[13]*x1 + v[28]*x2 + v[43]*x3 + v[58]*x4 + v[73]*x5 + v[88]*x6 + v[103]*x7 + v[118]*x8 + v[133]*x9 + v[148]*x10 + v[163]*x11 + v[178]*x12 + v[193]*x13 + v[208]*x14 + v[223]*x15;
96*2c733ed4SBarry Smith       s15 -= v[14]*x1 + v[29]*x2 + v[44]*x3 + v[59]*x4 + v[74]*x5 + v[89]*x6 + v[104]*x7 + v[119]*x8 + v[134]*x9 + v[149]*x10 + v[164]*x11 + v[179]*x12 + v[194]*x13 + v[209]*x14 + v[224]*x15;
97*2c733ed4SBarry Smith 
98*2c733ed4SBarry Smith       v += bs2;
99*2c733ed4SBarry Smith     }
100*2c733ed4SBarry Smith 
101*2c733ed4SBarry Smith     x[idt]    = v[0]*s1  + v[15]*s2 + v[30]*s3 + v[45]*s4 + v[60]*s5 + v[75]*s6 + v[90]*s7  + v[105]*s8 + v[120]*s9 + v[135]*s10 + v[150]*s11 + v[165]*s12 + v[180]*s13 + v[195]*s14 + v[210]*s15;
102*2c733ed4SBarry Smith     x[1+idt]  = v[1]*s1  + v[16]*s2 + v[31]*s3 + v[46]*s4 + v[61]*s5 + v[76]*s6 + v[91]*s7  + v[106]*s8 + v[121]*s9 + v[136]*s10 + v[151]*s11 + v[166]*s12 + v[181]*s13 + v[196]*s14 + v[211]*s15;
103*2c733ed4SBarry Smith     x[2+idt]  = v[2]*s1  + v[17]*s2 + v[32]*s3 + v[47]*s4 + v[62]*s5 + v[77]*s6 + v[92]*s7  + v[107]*s8 + v[122]*s9 + v[137]*s10 + v[152]*s11 + v[167]*s12 + v[182]*s13 + v[197]*s14 + v[212]*s15;
104*2c733ed4SBarry Smith     x[3+idt]  = v[3]*s1  + v[18]*s2 + v[33]*s3 + v[48]*s4 + v[63]*s5 + v[78]*s6 + v[93]*s7  + v[108]*s8 + v[123]*s9 + v[138]*s10 + v[153]*s11 + v[168]*s12 + v[183]*s13 + v[198]*s14 + v[213]*s15;
105*2c733ed4SBarry Smith     x[4+idt]  = v[4]*s1  + v[19]*s2 + v[34]*s3 + v[49]*s4 + v[64]*s5 + v[79]*s6 + v[94]*s7  + v[109]*s8 + v[124]*s9 + v[139]*s10 + v[154]*s11 + v[169]*s12 + v[184]*s13 + v[199]*s14 + v[214]*s15;
106*2c733ed4SBarry Smith     x[5+idt]  = v[5]*s1  + v[20]*s2 + v[35]*s3 + v[50]*s4 + v[65]*s5 + v[80]*s6 + v[95]*s7  + v[110]*s8 + v[125]*s9 + v[140]*s10 + v[155]*s11 + v[170]*s12 + v[185]*s13 + v[200]*s14 + v[215]*s15;
107*2c733ed4SBarry Smith     x[6+idt]  = v[6]*s1  + v[21]*s2 + v[36]*s3 + v[51]*s4 + v[66]*s5 + v[81]*s6 + v[96]*s7  + v[111]*s8 + v[126]*s9 + v[141]*s10 + v[156]*s11 + v[171]*s12 + v[186]*s13 + v[201]*s14 + v[216]*s15;
108*2c733ed4SBarry Smith     x[7+idt]  = v[7]*s1  + v[22]*s2 + v[37]*s3 + v[52]*s4 + v[67]*s5 + v[82]*s6 + v[97]*s7  + v[112]*s8 + v[127]*s9 + v[142]*s10 + v[157]*s11 + v[172]*s12 + v[187]*s13 + v[202]*s14 + v[217]*s15;
109*2c733ed4SBarry Smith     x[8+idt]  = v[8]*s1  + v[23]*s2 + v[38]*s3 + v[53]*s4 + v[68]*s5 + v[83]*s6 + v[98]*s7  + v[113]*s8 + v[128]*s9 + v[143]*s10 + v[158]*s11 + v[173]*s12 + v[188]*s13 + v[203]*s14 + v[218]*s15;
110*2c733ed4SBarry Smith     x[9+idt]  = v[9]*s1  + v[24]*s2 + v[39]*s3 + v[54]*s4 + v[69]*s5 + v[84]*s6 + v[99]*s7  + v[114]*s8 + v[129]*s9 + v[144]*s10 + v[159]*s11 + v[174]*s12 + v[189]*s13 + v[204]*s14 + v[219]*s15;
111*2c733ed4SBarry Smith     x[10+idt] = v[10]*s1 + v[25]*s2 + v[40]*s3 + v[55]*s4 + v[70]*s5 + v[85]*s6 + v[100]*s7 + v[115]*s8 + v[130]*s9 + v[145]*s10 + v[160]*s11 + v[175]*s12 + v[190]*s13 + v[205]*s14 + v[220]*s15;
112*2c733ed4SBarry Smith     x[11+idt] = v[11]*s1 + v[26]*s2 + v[41]*s3 + v[56]*s4 + v[71]*s5 + v[86]*s6 + v[101]*s7 + v[116]*s8 + v[131]*s9 + v[146]*s10 + v[161]*s11 + v[176]*s12 + v[191]*s13 + v[206]*s14 + v[221]*s15;
113*2c733ed4SBarry Smith     x[12+idt] = v[12]*s1 + v[27]*s2 + v[42]*s3 + v[57]*s4 + v[72]*s5 + v[87]*s6 + v[102]*s7 + v[117]*s8 + v[132]*s9 + v[147]*s10 + v[162]*s11 + v[177]*s12 + v[192]*s13 + v[207]*s14 + v[222]*s15;
114*2c733ed4SBarry Smith     x[13+idt] = v[13]*s1 + v[28]*s2 + v[43]*s3 + v[58]*s4 + v[73]*s5 + v[88]*s6 + v[103]*s7 + v[118]*s8 + v[133]*s9 + v[148]*s10 + v[163]*s11 + v[178]*s12 + v[193]*s13 + v[208]*s14 + v[223]*s15;
115*2c733ed4SBarry Smith     x[14+idt] = v[14]*s1 + v[29]*s2 + v[44]*s3 + v[59]*s4 + v[74]*s5 + v[89]*s6 + v[104]*s7 + v[119]*s8 + v[134]*s9 + v[149]*s10 + v[164]*s11 + v[179]*s12 + v[194]*s13 + v[209]*s14 + v[224]*s15;
116*2c733ed4SBarry Smith 
117*2c733ed4SBarry Smith   }
118*2c733ed4SBarry Smith 
119*2c733ed4SBarry Smith   ierr = VecRestoreArrayRead(bb,&b);CHKERRQ(ierr);
120*2c733ed4SBarry Smith   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
121*2c733ed4SBarry Smith   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
122*2c733ed4SBarry Smith   PetscFunctionReturn(0);
123*2c733ed4SBarry Smith }
124*2c733ed4SBarry Smith 
125*2c733ed4SBarry Smith /* bs = 15 for PFLOTRAN. Block operations are done by accessing one column at at time */
126*2c733ed4SBarry Smith /* Default MatSolve for block size 15 */
127*2c733ed4SBarry Smith 
128*2c733ed4SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_15_NaturalOrdering_ver1(Mat A,Vec bb,Vec xx)
129*2c733ed4SBarry Smith {
130*2c733ed4SBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ*)A->data;
131*2c733ed4SBarry Smith   PetscErrorCode    ierr;
132*2c733ed4SBarry Smith   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*adiag=a->diag,*vi,bs=A->rmap->bs,bs2=a->bs2;
133*2c733ed4SBarry Smith   PetscInt          i,k,nz,idx,idt,m;
134*2c733ed4SBarry Smith   const MatScalar   *aa=a->a,*v;
135*2c733ed4SBarry Smith   PetscScalar       s[15];
136*2c733ed4SBarry Smith   PetscScalar       *x,xv;
137*2c733ed4SBarry Smith   const PetscScalar *b;
138*2c733ed4SBarry Smith 
139*2c733ed4SBarry Smith   PetscFunctionBegin;
140*2c733ed4SBarry Smith   ierr = VecGetArrayRead(bb,&b);CHKERRQ(ierr);
141*2c733ed4SBarry Smith   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
142*2c733ed4SBarry Smith 
143*2c733ed4SBarry Smith   /* forward solve the lower triangular */
144*2c733ed4SBarry Smith   for (i=0; i<n; i++) {
145*2c733ed4SBarry Smith     v         = aa + bs2*ai[i];
146*2c733ed4SBarry Smith     vi        = aj + ai[i];
147*2c733ed4SBarry Smith     nz        = ai[i+1] - ai[i];
148*2c733ed4SBarry Smith     idt       = bs*i;
149*2c733ed4SBarry Smith     x[idt]    = b[idt];    x[1+idt]  = b[1+idt];  x[2+idt]  = b[2+idt];  x[3+idt]  = b[3+idt];  x[4+idt]  = b[4+idt];
150*2c733ed4SBarry Smith     x[5+idt]  = b[5+idt];  x[6+idt]  = b[6+idt];  x[7+idt]  = b[7+idt];  x[8+idt]  = b[8+idt];  x[9+idt] = b[9+idt];
151*2c733ed4SBarry Smith     x[10+idt] = b[10+idt]; x[11+idt] = b[11+idt]; x[12+idt] = b[12+idt]; x[13+idt] = b[13+idt]; x[14+idt] = b[14+idt];
152*2c733ed4SBarry Smith     for (m=0; m<nz; m++) {
153*2c733ed4SBarry Smith       idx = bs*vi[m];
154*2c733ed4SBarry Smith       for (k=0; k<15; k++) {
155*2c733ed4SBarry Smith         xv         = x[k + idx];
156*2c733ed4SBarry Smith         x[idt]    -= v[0]*xv;
157*2c733ed4SBarry Smith         x[1+idt]  -= v[1]*xv;
158*2c733ed4SBarry Smith         x[2+idt]  -= v[2]*xv;
159*2c733ed4SBarry Smith         x[3+idt]  -= v[3]*xv;
160*2c733ed4SBarry Smith         x[4+idt]  -= v[4]*xv;
161*2c733ed4SBarry Smith         x[5+idt]  -= v[5]*xv;
162*2c733ed4SBarry Smith         x[6+idt]  -= v[6]*xv;
163*2c733ed4SBarry Smith         x[7+idt]  -= v[7]*xv;
164*2c733ed4SBarry Smith         x[8+idt]  -= v[8]*xv;
165*2c733ed4SBarry Smith         x[9+idt]  -= v[9]*xv;
166*2c733ed4SBarry Smith         x[10+idt] -= v[10]*xv;
167*2c733ed4SBarry Smith         x[11+idt] -= v[11]*xv;
168*2c733ed4SBarry Smith         x[12+idt] -= v[12]*xv;
169*2c733ed4SBarry Smith         x[13+idt] -= v[13]*xv;
170*2c733ed4SBarry Smith         x[14+idt] -= v[14]*xv;
171*2c733ed4SBarry Smith         v         += 15;
172*2c733ed4SBarry Smith       }
173*2c733ed4SBarry Smith     }
174*2c733ed4SBarry Smith   }
175*2c733ed4SBarry Smith   /* backward solve the upper triangular */
176*2c733ed4SBarry Smith   for (i=n-1; i>=0; i--) {
177*2c733ed4SBarry Smith     v     = aa + bs2*(adiag[i+1]+1);
178*2c733ed4SBarry Smith     vi    = aj + adiag[i+1]+1;
179*2c733ed4SBarry Smith     nz    = adiag[i] - adiag[i+1] - 1;
180*2c733ed4SBarry Smith     idt   = bs*i;
181*2c733ed4SBarry Smith     s[0]  = x[idt];    s[1]  = x[1+idt];  s[2]  = x[2+idt];  s[3]  = x[3+idt];  s[4]  = x[4+idt];
182*2c733ed4SBarry Smith     s[5]  = x[5+idt];  s[6]  = x[6+idt];  s[7]  = x[7+idt];  s[8]  = x[8+idt];  s[9]  = x[9+idt];
183*2c733ed4SBarry Smith     s[10] = x[10+idt]; s[11] = x[11+idt]; s[12] = x[12+idt]; s[13] = x[13+idt]; s[14] = x[14+idt];
184*2c733ed4SBarry Smith 
185*2c733ed4SBarry Smith     for (m=0; m<nz; m++) {
186*2c733ed4SBarry Smith       idx = bs*vi[m];
187*2c733ed4SBarry Smith       for (k=0; k<15; k++) {
188*2c733ed4SBarry Smith         xv     = x[k + idx];
189*2c733ed4SBarry Smith         s[0]  -= v[0]*xv;
190*2c733ed4SBarry Smith         s[1]  -= v[1]*xv;
191*2c733ed4SBarry Smith         s[2]  -= v[2]*xv;
192*2c733ed4SBarry Smith         s[3]  -= v[3]*xv;
193*2c733ed4SBarry Smith         s[4]  -= v[4]*xv;
194*2c733ed4SBarry Smith         s[5]  -= v[5]*xv;
195*2c733ed4SBarry Smith         s[6]  -= v[6]*xv;
196*2c733ed4SBarry Smith         s[7]  -= v[7]*xv;
197*2c733ed4SBarry Smith         s[8]  -= v[8]*xv;
198*2c733ed4SBarry Smith         s[9]  -= v[9]*xv;
199*2c733ed4SBarry Smith         s[10] -= v[10]*xv;
200*2c733ed4SBarry Smith         s[11] -= v[11]*xv;
201*2c733ed4SBarry Smith         s[12] -= v[12]*xv;
202*2c733ed4SBarry Smith         s[13] -= v[13]*xv;
203*2c733ed4SBarry Smith         s[14] -= v[14]*xv;
204*2c733ed4SBarry Smith         v     += 15;
205*2c733ed4SBarry Smith       }
206*2c733ed4SBarry Smith     }
207*2c733ed4SBarry Smith     ierr = PetscMemzero(x+idt,bs*sizeof(MatScalar));CHKERRQ(ierr);
208*2c733ed4SBarry Smith     for (k=0; k<15; k++) {
209*2c733ed4SBarry Smith       x[idt]    += v[0]*s[k];
210*2c733ed4SBarry Smith       x[1+idt]  += v[1]*s[k];
211*2c733ed4SBarry Smith       x[2+idt]  += v[2]*s[k];
212*2c733ed4SBarry Smith       x[3+idt]  += v[3]*s[k];
213*2c733ed4SBarry Smith       x[4+idt]  += v[4]*s[k];
214*2c733ed4SBarry Smith       x[5+idt]  += v[5]*s[k];
215*2c733ed4SBarry Smith       x[6+idt]  += v[6]*s[k];
216*2c733ed4SBarry Smith       x[7+idt]  += v[7]*s[k];
217*2c733ed4SBarry Smith       x[8+idt]  += v[8]*s[k];
218*2c733ed4SBarry Smith       x[9+idt]  += v[9]*s[k];
219*2c733ed4SBarry Smith       x[10+idt] += v[10]*s[k];
220*2c733ed4SBarry Smith       x[11+idt] += v[11]*s[k];
221*2c733ed4SBarry Smith       x[12+idt] += v[12]*s[k];
222*2c733ed4SBarry Smith       x[13+idt] += v[13]*s[k];
223*2c733ed4SBarry Smith       x[14+idt] += v[14]*s[k];
224*2c733ed4SBarry Smith       v         += 15;
225*2c733ed4SBarry Smith     }
226*2c733ed4SBarry Smith   }
227*2c733ed4SBarry Smith   ierr = VecRestoreArrayRead(bb,&b);CHKERRQ(ierr);
228*2c733ed4SBarry Smith   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
229*2c733ed4SBarry Smith   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
230*2c733ed4SBarry Smith   PetscFunctionReturn(0);
231*2c733ed4SBarry Smith }
232