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 */ 129371c9d4SSatish Balay PetscErrorCode MatLUFactorNumeric_SeqBAIJ_6_inplace(Mat C, Mat A, const MatFactorInfo *info) { 1383287d42SBarry Smith Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data, *b = (Mat_SeqBAIJ *)C->data; 1483287d42SBarry Smith IS isrow = b->row, isicol = b->icol; 155d0c19d7SBarry Smith const PetscInt *ajtmpold, *ajtmp, *diag_offset = b->diag, *r, *ic, *bi = b->i, *bj = b->j, *ai = a->i, *aj = a->j, *pj; 165d0c19d7SBarry Smith PetscInt nz, row, i, j, n = a->mbs, idx; 1783287d42SBarry Smith MatScalar *pv, *v, *rtmp, *pc, *w, *x; 1883287d42SBarry Smith MatScalar p1, p2, p3, p4, m1, m2, m3, m4, m5, m6, m7, m8, m9, x1, x2, x3, x4; 1983287d42SBarry Smith MatScalar p5, p6, p7, p8, p9, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16; 2083287d42SBarry Smith MatScalar x17, x18, x19, x20, x21, x22, x23, x24, x25, p10, p11, p12, p13, p14; 2183287d42SBarry Smith MatScalar p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, m10, m11, m12; 2283287d42SBarry Smith MatScalar m13, m14, m15, m16, m17, m18, m19, m20, m21, m22, m23, m24, m25; 2383287d42SBarry Smith MatScalar p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36; 2483287d42SBarry Smith MatScalar x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, x36; 2583287d42SBarry Smith MatScalar m26, m27, m28, m29, m30, m31, m32, m33, m34, m35, m36; 2683287d42SBarry Smith MatScalar *ba = b->a, *aa = a->a; 27182b8fbaSHong Zhang PetscReal shift = info->shiftamount; 28a455e926SHong Zhang PetscBool allowzeropivot, zeropivotdetected; 2983287d42SBarry Smith 3083287d42SBarry Smith PetscFunctionBegin; 310164db54SHong Zhang allowzeropivot = PetscNot(A->erroriffailure); 329566063dSJacob Faibussowitsch PetscCall(ISGetIndices(isrow, &r)); 339566063dSJacob Faibussowitsch PetscCall(ISGetIndices(isicol, &ic)); 349566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(36 * (n + 1), &rtmp)); 3583287d42SBarry Smith 3683287d42SBarry Smith for (i = 0; i < n; i++) { 3783287d42SBarry Smith nz = bi[i + 1] - bi[i]; 3883287d42SBarry Smith ajtmp = bj + bi[i]; 3983287d42SBarry Smith for (j = 0; j < nz; j++) { 4083287d42SBarry Smith x = rtmp + 36 * ajtmp[j]; 4183287d42SBarry Smith x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 4283287d42SBarry Smith x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0; 4383287d42SBarry Smith x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0; 4483287d42SBarry Smith x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0; 4583287d42SBarry Smith x[34] = x[35] = 0.0; 4683287d42SBarry Smith } 4783287d42SBarry Smith /* load in initial (unfactored row) */ 4883287d42SBarry Smith idx = r[i]; 4983287d42SBarry Smith nz = ai[idx + 1] - ai[idx]; 5083287d42SBarry Smith ajtmpold = aj + ai[idx]; 5183287d42SBarry Smith v = aa + 36 * ai[idx]; 5283287d42SBarry Smith for (j = 0; j < nz; j++) { 5383287d42SBarry Smith x = rtmp + 36 * ic[ajtmpold[j]]; 549371c9d4SSatish Balay x[0] = v[0]; 559371c9d4SSatish Balay x[1] = v[1]; 569371c9d4SSatish Balay x[2] = v[2]; 579371c9d4SSatish Balay x[3] = v[3]; 589371c9d4SSatish Balay x[4] = v[4]; 599371c9d4SSatish Balay x[5] = v[5]; 609371c9d4SSatish Balay x[6] = v[6]; 619371c9d4SSatish Balay x[7] = v[7]; 629371c9d4SSatish Balay x[8] = v[8]; 639371c9d4SSatish Balay x[9] = v[9]; 649371c9d4SSatish Balay x[10] = v[10]; 659371c9d4SSatish Balay x[11] = v[11]; 669371c9d4SSatish Balay x[12] = v[12]; 679371c9d4SSatish Balay x[13] = v[13]; 689371c9d4SSatish Balay x[14] = v[14]; 699371c9d4SSatish Balay x[15] = v[15]; 709371c9d4SSatish Balay x[16] = v[16]; 719371c9d4SSatish Balay x[17] = v[17]; 729371c9d4SSatish Balay x[18] = v[18]; 739371c9d4SSatish Balay x[19] = v[19]; 749371c9d4SSatish Balay x[20] = v[20]; 759371c9d4SSatish Balay x[21] = v[21]; 769371c9d4SSatish Balay x[22] = v[22]; 779371c9d4SSatish Balay x[23] = v[23]; 789371c9d4SSatish Balay x[24] = v[24]; 799371c9d4SSatish Balay x[25] = v[25]; 809371c9d4SSatish Balay x[26] = v[26]; 819371c9d4SSatish Balay x[27] = v[27]; 829371c9d4SSatish Balay x[28] = v[28]; 839371c9d4SSatish Balay x[29] = v[29]; 849371c9d4SSatish Balay x[30] = v[30]; 859371c9d4SSatish Balay x[31] = v[31]; 869371c9d4SSatish Balay x[32] = v[32]; 879371c9d4SSatish Balay x[33] = v[33]; 889371c9d4SSatish Balay x[34] = v[34]; 899371c9d4SSatish Balay x[35] = v[35]; 9083287d42SBarry Smith v += 36; 9183287d42SBarry Smith } 9283287d42SBarry Smith row = *ajtmp++; 9383287d42SBarry Smith while (row < i) { 9483287d42SBarry Smith pc = rtmp + 36 * row; 959371c9d4SSatish Balay p1 = pc[0]; 969371c9d4SSatish Balay p2 = pc[1]; 979371c9d4SSatish Balay p3 = pc[2]; 989371c9d4SSatish Balay p4 = pc[3]; 999371c9d4SSatish Balay p5 = pc[4]; 1009371c9d4SSatish Balay p6 = pc[5]; 1019371c9d4SSatish Balay p7 = pc[6]; 1029371c9d4SSatish Balay p8 = pc[7]; 1039371c9d4SSatish Balay p9 = pc[8]; 1049371c9d4SSatish Balay p10 = pc[9]; 1059371c9d4SSatish Balay p11 = pc[10]; 1069371c9d4SSatish Balay p12 = pc[11]; 1079371c9d4SSatish Balay p13 = pc[12]; 1089371c9d4SSatish Balay p14 = pc[13]; 1099371c9d4SSatish Balay p15 = pc[14]; 1109371c9d4SSatish Balay p16 = pc[15]; 1119371c9d4SSatish Balay p17 = pc[16]; 1129371c9d4SSatish Balay p18 = pc[17]; 1139371c9d4SSatish Balay p19 = pc[18]; 1149371c9d4SSatish Balay p20 = pc[19]; 1159371c9d4SSatish Balay p21 = pc[20]; 1169371c9d4SSatish Balay p22 = pc[21]; 1179371c9d4SSatish Balay p23 = pc[22]; 1189371c9d4SSatish Balay p24 = pc[23]; 1199371c9d4SSatish Balay p25 = pc[24]; 1209371c9d4SSatish Balay p26 = pc[25]; 1219371c9d4SSatish Balay p27 = pc[26]; 1229371c9d4SSatish Balay p28 = pc[27]; 1239371c9d4SSatish Balay p29 = pc[28]; 1249371c9d4SSatish Balay p30 = pc[29]; 1259371c9d4SSatish Balay p31 = pc[30]; 1269371c9d4SSatish Balay p32 = pc[31]; 1279371c9d4SSatish Balay p33 = pc[32]; 1289371c9d4SSatish Balay p34 = pc[33]; 1299371c9d4SSatish Balay p35 = pc[34]; 1309371c9d4SSatish Balay p36 = pc[35]; 1319371c9d4SSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 || p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 || p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 || p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 || p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 || p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 || p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 || p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0) { 13283287d42SBarry Smith pv = ba + 36 * diag_offset[row]; 13383287d42SBarry Smith pj = bj + diag_offset[row] + 1; 1349371c9d4SSatish Balay x1 = pv[0]; 1359371c9d4SSatish Balay x2 = pv[1]; 1369371c9d4SSatish Balay x3 = pv[2]; 1379371c9d4SSatish Balay x4 = pv[3]; 1389371c9d4SSatish Balay x5 = pv[4]; 1399371c9d4SSatish Balay x6 = pv[5]; 1409371c9d4SSatish Balay x7 = pv[6]; 1419371c9d4SSatish Balay x8 = pv[7]; 1429371c9d4SSatish Balay x9 = pv[8]; 1439371c9d4SSatish Balay x10 = pv[9]; 1449371c9d4SSatish Balay x11 = pv[10]; 1459371c9d4SSatish Balay x12 = pv[11]; 1469371c9d4SSatish Balay x13 = pv[12]; 1479371c9d4SSatish Balay x14 = pv[13]; 1489371c9d4SSatish Balay x15 = pv[14]; 1499371c9d4SSatish Balay x16 = pv[15]; 1509371c9d4SSatish Balay x17 = pv[16]; 1519371c9d4SSatish Balay x18 = pv[17]; 1529371c9d4SSatish Balay x19 = pv[18]; 1539371c9d4SSatish Balay x20 = pv[19]; 1549371c9d4SSatish Balay x21 = pv[20]; 1559371c9d4SSatish Balay x22 = pv[21]; 1569371c9d4SSatish Balay x23 = pv[22]; 1579371c9d4SSatish Balay x24 = pv[23]; 1589371c9d4SSatish Balay x25 = pv[24]; 1599371c9d4SSatish Balay x26 = pv[25]; 1609371c9d4SSatish Balay x27 = pv[26]; 1619371c9d4SSatish Balay x28 = pv[27]; 1629371c9d4SSatish Balay x29 = pv[28]; 1639371c9d4SSatish Balay x30 = pv[29]; 1649371c9d4SSatish Balay x31 = pv[30]; 1659371c9d4SSatish Balay x32 = pv[31]; 1669371c9d4SSatish Balay x33 = pv[32]; 1679371c9d4SSatish Balay x34 = pv[33]; 1689371c9d4SSatish Balay x35 = pv[34]; 1699371c9d4SSatish Balay x36 = pv[35]; 17083287d42SBarry Smith pc[0] = m1 = p1 * x1 + p7 * x2 + p13 * x3 + p19 * x4 + p25 * x5 + p31 * x6; 17183287d42SBarry Smith pc[1] = m2 = p2 * x1 + p8 * x2 + p14 * x3 + p20 * x4 + p26 * x5 + p32 * x6; 17283287d42SBarry Smith pc[2] = m3 = p3 * x1 + p9 * x2 + p15 * x3 + p21 * x4 + p27 * x5 + p33 * x6; 17383287d42SBarry Smith pc[3] = m4 = p4 * x1 + p10 * x2 + p16 * x3 + p22 * x4 + p28 * x5 + p34 * x6; 17483287d42SBarry Smith pc[4] = m5 = p5 * x1 + p11 * x2 + p17 * x3 + p23 * x4 + p29 * x5 + p35 * x6; 17583287d42SBarry Smith pc[5] = m6 = p6 * x1 + p12 * x2 + p18 * x3 + p24 * x4 + p30 * x5 + p36 * x6; 17683287d42SBarry Smith 17783287d42SBarry Smith pc[6] = m7 = p1 * x7 + p7 * x8 + p13 * x9 + p19 * x10 + p25 * x11 + p31 * x12; 17883287d42SBarry Smith pc[7] = m8 = p2 * x7 + p8 * x8 + p14 * x9 + p20 * x10 + p26 * x11 + p32 * x12; 17983287d42SBarry Smith pc[8] = m9 = p3 * x7 + p9 * x8 + p15 * x9 + p21 * x10 + p27 * x11 + p33 * x12; 18083287d42SBarry Smith pc[9] = m10 = p4 * x7 + p10 * x8 + p16 * x9 + p22 * x10 + p28 * x11 + p34 * x12; 18183287d42SBarry Smith pc[10] = m11 = p5 * x7 + p11 * x8 + p17 * x9 + p23 * x10 + p29 * x11 + p35 * x12; 18283287d42SBarry Smith pc[11] = m12 = p6 * x7 + p12 * x8 + p18 * x9 + p24 * x10 + p30 * x11 + p36 * x12; 18383287d42SBarry Smith 18483287d42SBarry Smith pc[12] = m13 = p1 * x13 + p7 * x14 + p13 * x15 + p19 * x16 + p25 * x17 + p31 * x18; 18583287d42SBarry Smith pc[13] = m14 = p2 * x13 + p8 * x14 + p14 * x15 + p20 * x16 + p26 * x17 + p32 * x18; 18683287d42SBarry Smith pc[14] = m15 = p3 * x13 + p9 * x14 + p15 * x15 + p21 * x16 + p27 * x17 + p33 * x18; 18783287d42SBarry Smith pc[15] = m16 = p4 * x13 + p10 * x14 + p16 * x15 + p22 * x16 + p28 * x17 + p34 * x18; 18883287d42SBarry Smith pc[16] = m17 = p5 * x13 + p11 * x14 + p17 * x15 + p23 * x16 + p29 * x17 + p35 * x18; 18983287d42SBarry Smith pc[17] = m18 = p6 * x13 + p12 * x14 + p18 * x15 + p24 * x16 + p30 * x17 + p36 * x18; 19083287d42SBarry Smith 19183287d42SBarry Smith pc[18] = m19 = p1 * x19 + p7 * x20 + p13 * x21 + p19 * x22 + p25 * x23 + p31 * x24; 19283287d42SBarry Smith pc[19] = m20 = p2 * x19 + p8 * x20 + p14 * x21 + p20 * x22 + p26 * x23 + p32 * x24; 19383287d42SBarry Smith pc[20] = m21 = p3 * x19 + p9 * x20 + p15 * x21 + p21 * x22 + p27 * x23 + p33 * x24; 19483287d42SBarry Smith pc[21] = m22 = p4 * x19 + p10 * x20 + p16 * x21 + p22 * x22 + p28 * x23 + p34 * x24; 19583287d42SBarry Smith pc[22] = m23 = p5 * x19 + p11 * x20 + p17 * x21 + p23 * x22 + p29 * x23 + p35 * x24; 19683287d42SBarry Smith pc[23] = m24 = p6 * x19 + p12 * x20 + p18 * x21 + p24 * x22 + p30 * x23 + p36 * x24; 19783287d42SBarry Smith 19883287d42SBarry Smith pc[24] = m25 = p1 * x25 + p7 * x26 + p13 * x27 + p19 * x28 + p25 * x29 + p31 * x30; 19983287d42SBarry Smith pc[25] = m26 = p2 * x25 + p8 * x26 + p14 * x27 + p20 * x28 + p26 * x29 + p32 * x30; 20083287d42SBarry Smith pc[26] = m27 = p3 * x25 + p9 * x26 + p15 * x27 + p21 * x28 + p27 * x29 + p33 * x30; 20183287d42SBarry Smith pc[27] = m28 = p4 * x25 + p10 * x26 + p16 * x27 + p22 * x28 + p28 * x29 + p34 * x30; 20283287d42SBarry Smith pc[28] = m29 = p5 * x25 + p11 * x26 + p17 * x27 + p23 * x28 + p29 * x29 + p35 * x30; 20383287d42SBarry Smith pc[29] = m30 = p6 * x25 + p12 * x26 + p18 * x27 + p24 * x28 + p30 * x29 + p36 * x30; 20483287d42SBarry Smith 20583287d42SBarry Smith pc[30] = m31 = p1 * x31 + p7 * x32 + p13 * x33 + p19 * x34 + p25 * x35 + p31 * x36; 20683287d42SBarry Smith pc[31] = m32 = p2 * x31 + p8 * x32 + p14 * x33 + p20 * x34 + p26 * x35 + p32 * x36; 20783287d42SBarry Smith pc[32] = m33 = p3 * x31 + p9 * x32 + p15 * x33 + p21 * x34 + p27 * x35 + p33 * x36; 20883287d42SBarry Smith pc[33] = m34 = p4 * x31 + p10 * x32 + p16 * x33 + p22 * x34 + p28 * x35 + p34 * x36; 20983287d42SBarry Smith pc[34] = m35 = p5 * x31 + p11 * x32 + p17 * x33 + p23 * x34 + p29 * x35 + p35 * x36; 21083287d42SBarry Smith pc[35] = m36 = p6 * x31 + p12 * x32 + p18 * x33 + p24 * x34 + p30 * x35 + p36 * x36; 21183287d42SBarry Smith 21283287d42SBarry Smith nz = bi[row + 1] - diag_offset[row] - 1; 21383287d42SBarry Smith pv += 36; 21483287d42SBarry Smith for (j = 0; j < nz; j++) { 2159371c9d4SSatish Balay x1 = pv[0]; 2169371c9d4SSatish Balay x2 = pv[1]; 2179371c9d4SSatish Balay x3 = pv[2]; 2189371c9d4SSatish Balay x4 = pv[3]; 2199371c9d4SSatish Balay x5 = pv[4]; 2209371c9d4SSatish Balay x6 = pv[5]; 2219371c9d4SSatish Balay x7 = pv[6]; 2229371c9d4SSatish Balay x8 = pv[7]; 2239371c9d4SSatish Balay x9 = pv[8]; 2249371c9d4SSatish Balay x10 = pv[9]; 2259371c9d4SSatish Balay x11 = pv[10]; 2269371c9d4SSatish Balay x12 = pv[11]; 2279371c9d4SSatish Balay x13 = pv[12]; 2289371c9d4SSatish Balay x14 = pv[13]; 2299371c9d4SSatish Balay x15 = pv[14]; 2309371c9d4SSatish Balay x16 = pv[15]; 2319371c9d4SSatish Balay x17 = pv[16]; 2329371c9d4SSatish Balay x18 = pv[17]; 2339371c9d4SSatish Balay x19 = pv[18]; 2349371c9d4SSatish Balay x20 = pv[19]; 2359371c9d4SSatish Balay x21 = pv[20]; 2369371c9d4SSatish Balay x22 = pv[21]; 2379371c9d4SSatish Balay x23 = pv[22]; 2389371c9d4SSatish Balay x24 = pv[23]; 2399371c9d4SSatish Balay x25 = pv[24]; 2409371c9d4SSatish Balay x26 = pv[25]; 2419371c9d4SSatish Balay x27 = pv[26]; 2429371c9d4SSatish Balay x28 = pv[27]; 2439371c9d4SSatish Balay x29 = pv[28]; 2449371c9d4SSatish Balay x30 = pv[29]; 2459371c9d4SSatish Balay x31 = pv[30]; 2469371c9d4SSatish Balay x32 = pv[31]; 2479371c9d4SSatish Balay x33 = pv[32]; 2489371c9d4SSatish Balay x34 = pv[33]; 2499371c9d4SSatish Balay x35 = pv[34]; 2509371c9d4SSatish Balay x36 = pv[35]; 25183287d42SBarry Smith x = rtmp + 36 * pj[j]; 25283287d42SBarry Smith x[0] -= m1 * x1 + m7 * x2 + m13 * x3 + m19 * x4 + m25 * x5 + m31 * x6; 25383287d42SBarry Smith x[1] -= m2 * x1 + m8 * x2 + m14 * x3 + m20 * x4 + m26 * x5 + m32 * x6; 25483287d42SBarry Smith x[2] -= m3 * x1 + m9 * x2 + m15 * x3 + m21 * x4 + m27 * x5 + m33 * x6; 25583287d42SBarry Smith x[3] -= m4 * x1 + m10 * x2 + m16 * x3 + m22 * x4 + m28 * x5 + m34 * x6; 25683287d42SBarry Smith x[4] -= m5 * x1 + m11 * x2 + m17 * x3 + m23 * x4 + m29 * x5 + m35 * x6; 25783287d42SBarry Smith x[5] -= m6 * x1 + m12 * x2 + m18 * x3 + m24 * x4 + m30 * x5 + m36 * x6; 25883287d42SBarry Smith 25983287d42SBarry Smith x[6] -= m1 * x7 + m7 * x8 + m13 * x9 + m19 * x10 + m25 * x11 + m31 * x12; 26083287d42SBarry Smith x[7] -= m2 * x7 + m8 * x8 + m14 * x9 + m20 * x10 + m26 * x11 + m32 * x12; 26183287d42SBarry Smith x[8] -= m3 * x7 + m9 * x8 + m15 * x9 + m21 * x10 + m27 * x11 + m33 * x12; 26283287d42SBarry Smith x[9] -= m4 * x7 + m10 * x8 + m16 * x9 + m22 * x10 + m28 * x11 + m34 * x12; 26383287d42SBarry Smith x[10] -= m5 * x7 + m11 * x8 + m17 * x9 + m23 * x10 + m29 * x11 + m35 * x12; 26483287d42SBarry Smith x[11] -= m6 * x7 + m12 * x8 + m18 * x9 + m24 * x10 + m30 * x11 + m36 * x12; 26583287d42SBarry Smith 26683287d42SBarry Smith x[12] -= m1 * x13 + m7 * x14 + m13 * x15 + m19 * x16 + m25 * x17 + m31 * x18; 26783287d42SBarry Smith x[13] -= m2 * x13 + m8 * x14 + m14 * x15 + m20 * x16 + m26 * x17 + m32 * x18; 26883287d42SBarry Smith x[14] -= m3 * x13 + m9 * x14 + m15 * x15 + m21 * x16 + m27 * x17 + m33 * x18; 26983287d42SBarry Smith x[15] -= m4 * x13 + m10 * x14 + m16 * x15 + m22 * x16 + m28 * x17 + m34 * x18; 27083287d42SBarry Smith x[16] -= m5 * x13 + m11 * x14 + m17 * x15 + m23 * x16 + m29 * x17 + m35 * x18; 27183287d42SBarry Smith x[17] -= m6 * x13 + m12 * x14 + m18 * x15 + m24 * x16 + m30 * x17 + m36 * x18; 27283287d42SBarry Smith 27383287d42SBarry Smith x[18] -= m1 * x19 + m7 * x20 + m13 * x21 + m19 * x22 + m25 * x23 + m31 * x24; 27483287d42SBarry Smith x[19] -= m2 * x19 + m8 * x20 + m14 * x21 + m20 * x22 + m26 * x23 + m32 * x24; 27583287d42SBarry Smith x[20] -= m3 * x19 + m9 * x20 + m15 * x21 + m21 * x22 + m27 * x23 + m33 * x24; 27683287d42SBarry Smith x[21] -= m4 * x19 + m10 * x20 + m16 * x21 + m22 * x22 + m28 * x23 + m34 * x24; 27783287d42SBarry Smith x[22] -= m5 * x19 + m11 * x20 + m17 * x21 + m23 * x22 + m29 * x23 + m35 * x24; 27883287d42SBarry Smith x[23] -= m6 * x19 + m12 * x20 + m18 * x21 + m24 * x22 + m30 * x23 + m36 * x24; 27983287d42SBarry Smith 28083287d42SBarry Smith x[24] -= m1 * x25 + m7 * x26 + m13 * x27 + m19 * x28 + m25 * x29 + m31 * x30; 28183287d42SBarry Smith x[25] -= m2 * x25 + m8 * x26 + m14 * x27 + m20 * x28 + m26 * x29 + m32 * x30; 28283287d42SBarry Smith x[26] -= m3 * x25 + m9 * x26 + m15 * x27 + m21 * x28 + m27 * x29 + m33 * x30; 28383287d42SBarry Smith x[27] -= m4 * x25 + m10 * x26 + m16 * x27 + m22 * x28 + m28 * x29 + m34 * x30; 28483287d42SBarry Smith x[28] -= m5 * x25 + m11 * x26 + m17 * x27 + m23 * x28 + m29 * x29 + m35 * x30; 28583287d42SBarry Smith x[29] -= m6 * x25 + m12 * x26 + m18 * x27 + m24 * x28 + m30 * x29 + m36 * x30; 28683287d42SBarry Smith 28783287d42SBarry Smith x[30] -= m1 * x31 + m7 * x32 + m13 * x33 + m19 * x34 + m25 * x35 + m31 * x36; 28883287d42SBarry Smith x[31] -= m2 * x31 + m8 * x32 + m14 * x33 + m20 * x34 + m26 * x35 + m32 * x36; 28983287d42SBarry Smith x[32] -= m3 * x31 + m9 * x32 + m15 * x33 + m21 * x34 + m27 * x35 + m33 * x36; 29083287d42SBarry Smith x[33] -= m4 * x31 + m10 * x32 + m16 * x33 + m22 * x34 + m28 * x35 + m34 * x36; 29183287d42SBarry Smith x[34] -= m5 * x31 + m11 * x32 + m17 * x33 + m23 * x34 + m29 * x35 + m35 * x36; 29283287d42SBarry Smith x[35] -= m6 * x31 + m12 * x32 + m18 * x33 + m24 * x34 + m30 * x35 + m36 * x36; 29383287d42SBarry Smith 29483287d42SBarry Smith pv += 36; 29583287d42SBarry Smith } 2969566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(432.0 * nz + 396.0)); 29783287d42SBarry Smith } 29883287d42SBarry Smith row = *ajtmp++; 29983287d42SBarry Smith } 30083287d42SBarry Smith /* finished row so stick it into b->a */ 30183287d42SBarry Smith pv = ba + 36 * bi[i]; 30283287d42SBarry Smith pj = bj + bi[i]; 30383287d42SBarry Smith nz = bi[i + 1] - bi[i]; 30483287d42SBarry Smith for (j = 0; j < nz; j++) { 30583287d42SBarry Smith x = rtmp + 36 * pj[j]; 3069371c9d4SSatish Balay pv[0] = x[0]; 3079371c9d4SSatish Balay pv[1] = x[1]; 3089371c9d4SSatish Balay pv[2] = x[2]; 3099371c9d4SSatish Balay pv[3] = x[3]; 3109371c9d4SSatish Balay pv[4] = x[4]; 3119371c9d4SSatish Balay pv[5] = x[5]; 3129371c9d4SSatish Balay pv[6] = x[6]; 3139371c9d4SSatish Balay pv[7] = x[7]; 3149371c9d4SSatish Balay pv[8] = x[8]; 3159371c9d4SSatish Balay pv[9] = x[9]; 3169371c9d4SSatish Balay pv[10] = x[10]; 3179371c9d4SSatish Balay pv[11] = x[11]; 3189371c9d4SSatish Balay pv[12] = x[12]; 3199371c9d4SSatish Balay pv[13] = x[13]; 3209371c9d4SSatish Balay pv[14] = x[14]; 3219371c9d4SSatish Balay pv[15] = x[15]; 3229371c9d4SSatish Balay pv[16] = x[16]; 3239371c9d4SSatish Balay pv[17] = x[17]; 3249371c9d4SSatish Balay pv[18] = x[18]; 3259371c9d4SSatish Balay pv[19] = x[19]; 3269371c9d4SSatish Balay pv[20] = x[20]; 3279371c9d4SSatish Balay pv[21] = x[21]; 3289371c9d4SSatish Balay pv[22] = x[22]; 3299371c9d4SSatish Balay pv[23] = x[23]; 3309371c9d4SSatish Balay pv[24] = x[24]; 3319371c9d4SSatish Balay pv[25] = x[25]; 3329371c9d4SSatish Balay pv[26] = x[26]; 3339371c9d4SSatish Balay pv[27] = x[27]; 3349371c9d4SSatish Balay pv[28] = x[28]; 3359371c9d4SSatish Balay pv[29] = x[29]; 3369371c9d4SSatish Balay pv[30] = x[30]; 3379371c9d4SSatish Balay pv[31] = x[31]; 3389371c9d4SSatish Balay pv[32] = x[32]; 3399371c9d4SSatish Balay pv[33] = x[33]; 3409371c9d4SSatish Balay pv[34] = x[34]; 3419371c9d4SSatish Balay pv[35] = x[35]; 34283287d42SBarry Smith pv += 36; 34383287d42SBarry Smith } 34483287d42SBarry Smith /* invert diagonal block */ 34583287d42SBarry Smith w = ba + 36 * diag_offset[i]; 3469566063dSJacob Faibussowitsch PetscCall(PetscKernel_A_gets_inverse_A_6(w, shift, allowzeropivot, &zeropivotdetected)); 3477b6c816cSBarry Smith if (zeropivotdetected) C->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT; 34883287d42SBarry Smith } 34983287d42SBarry Smith 3509566063dSJacob Faibussowitsch PetscCall(PetscFree(rtmp)); 3519566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(isicol, &ic)); 3529566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(isrow, &r)); 35326fbe8dcSKarl Rupp 35406e38f1dSHong Zhang C->ops->solve = MatSolve_SeqBAIJ_6_inplace; 35506e38f1dSHong Zhang C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_6_inplace; 35683287d42SBarry Smith C->assembled = PETSC_TRUE; 35726fbe8dcSKarl Rupp 3589566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(1.333333333333 * 6 * 6 * 6 * b->mbs)); /* from inverting diagonal blocks */ 35983287d42SBarry Smith PetscFunctionReturn(0); 36083287d42SBarry Smith } 361bef36659SShri Abhyankar 3629371c9d4SSatish Balay PetscErrorCode MatLUFactorNumeric_SeqBAIJ_6(Mat B, Mat A, const MatFactorInfo *info) { 363bef36659SShri Abhyankar Mat C = B; 364bef36659SShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data, *b = (Mat_SeqBAIJ *)C->data; 365bef36659SShri Abhyankar IS isrow = b->row, isicol = b->icol; 3665a586d82SBarry Smith const PetscInt *r, *ic; 367bbd65245SShri Abhyankar PetscInt i, j, k, nz, nzL, row; 368bbd65245SShri Abhyankar const PetscInt n = a->mbs, *ai = a->i, *aj = a->j, *bi = b->i, *bj = b->j; 369bbd65245SShri Abhyankar const PetscInt *ajtmp, *bjtmp, *bdiag = b->diag, *pj, bs2 = a->bs2; 370bef36659SShri Abhyankar MatScalar *rtmp, *pc, *mwork, *v, *pv, *aa = a->a; 371bbd65245SShri Abhyankar PetscInt flg; 372182b8fbaSHong Zhang PetscReal shift = info->shiftamount; 373a455e926SHong Zhang PetscBool allowzeropivot, zeropivotdetected; 374bef36659SShri Abhyankar 375bef36659SShri Abhyankar PetscFunctionBegin; 3760164db54SHong Zhang allowzeropivot = PetscNot(A->erroriffailure); 3779566063dSJacob Faibussowitsch PetscCall(ISGetIndices(isrow, &r)); 3789566063dSJacob Faibussowitsch PetscCall(ISGetIndices(isicol, &ic)); 379bef36659SShri Abhyankar 380bef36659SShri Abhyankar /* generate work space needed by the factorization */ 3819566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(bs2 * n, &rtmp, bs2, &mwork)); 3829566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(rtmp, bs2 * n)); 383bef36659SShri Abhyankar 384bef36659SShri Abhyankar for (i = 0; i < n; i++) { 385bef36659SShri Abhyankar /* zero rtmp */ 386bef36659SShri Abhyankar /* L part */ 387bef36659SShri Abhyankar nz = bi[i + 1] - bi[i]; 388bef36659SShri Abhyankar bjtmp = bj + bi[i]; 389*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArrayzero(rtmp + bs2 * bjtmp[j], bs2)); 390bef36659SShri Abhyankar 391bef36659SShri Abhyankar /* U part */ 3926506fda5SShri Abhyankar nz = bdiag[i] - bdiag[i + 1]; 3936506fda5SShri Abhyankar bjtmp = bj + bdiag[i + 1] + 1; 394*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArrayzero(rtmp + bs2 * bjtmp[j], bs2)); 3956506fda5SShri Abhyankar 3966506fda5SShri Abhyankar /* load in initial (unfactored row) */ 3976506fda5SShri Abhyankar nz = ai[r[i] + 1] - ai[r[i]]; 3986506fda5SShri Abhyankar ajtmp = aj + ai[r[i]]; 3996506fda5SShri Abhyankar v = aa + bs2 * ai[r[i]]; 400*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArraycpy(rtmp + bs2 * ic[ajtmp[j]], v + bs2 * j, bs2)); 4016506fda5SShri Abhyankar 4026506fda5SShri Abhyankar /* elimination */ 4036506fda5SShri Abhyankar bjtmp = bj + bi[i]; 4046506fda5SShri Abhyankar nzL = bi[i + 1] - bi[i]; 4056506fda5SShri Abhyankar for (k = 0; k < nzL; k++) { 4066506fda5SShri Abhyankar row = bjtmp[k]; 4076506fda5SShri Abhyankar pc = rtmp + bs2 * row; 408c35f09e5SBarry Smith for (flg = 0, j = 0; j < bs2; j++) { 409c35f09e5SBarry Smith if (pc[j] != 0.0) { 410c35f09e5SBarry Smith flg = 1; 411c35f09e5SBarry Smith break; 412c35f09e5SBarry Smith } 413c35f09e5SBarry Smith } 4146506fda5SShri Abhyankar if (flg) { 4156506fda5SShri Abhyankar pv = b->a + bs2 * bdiag[row]; 41696b95a6bSBarry Smith /* PetscKernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */ 4179566063dSJacob Faibussowitsch PetscCall(PetscKernel_A_gets_A_times_B_6(pc, pv, mwork)); 4186506fda5SShri Abhyankar 419a5b23f4aSJose E. Roman pj = b->j + bdiag[row + 1] + 1; /* beginning of U(row,:) */ 4206506fda5SShri Abhyankar pv = b->a + bs2 * (bdiag[row + 1] + 1); 4216506fda5SShri Abhyankar nz = bdiag[row] - bdiag[row + 1] - 1; /* num of entries inU(row,:), excluding diag */ 4226506fda5SShri Abhyankar for (j = 0; j < nz; j++) { 42396b95a6bSBarry Smith /* PetscKernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */ 4246506fda5SShri Abhyankar /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */ 4256506fda5SShri Abhyankar v = rtmp + bs2 * pj[j]; 4269566063dSJacob Faibussowitsch PetscCall(PetscKernel_A_gets_A_minus_B_times_C_6(v, pc, pv)); 4276506fda5SShri Abhyankar pv += bs2; 4286506fda5SShri Abhyankar } 4299566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(432.0 * nz + 396)); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */ 4306506fda5SShri Abhyankar } 4316506fda5SShri Abhyankar } 4326506fda5SShri Abhyankar 4336506fda5SShri Abhyankar /* finished row so stick it into b->a */ 4346506fda5SShri Abhyankar /* L part */ 4356506fda5SShri Abhyankar pv = b->a + bs2 * bi[i]; 4366506fda5SShri Abhyankar pj = b->j + bi[i]; 4376506fda5SShri Abhyankar nz = bi[i + 1] - bi[i]; 438*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArraycpy(pv + bs2 * j, rtmp + bs2 * pj[j], bs2)); 4396506fda5SShri Abhyankar 440a5b23f4aSJose E. Roman /* Mark diagonal and invert diagonal for simpler triangular solves */ 4416506fda5SShri Abhyankar pv = b->a + bs2 * bdiag[i]; 4426506fda5SShri Abhyankar pj = b->j + bdiag[i]; 4439566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(pv, rtmp + bs2 * pj[0], bs2)); 4449566063dSJacob Faibussowitsch PetscCall(PetscKernel_A_gets_inverse_A_6(pv, shift, allowzeropivot, &zeropivotdetected)); 4457b6c816cSBarry Smith if (zeropivotdetected) C->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT; 4466506fda5SShri Abhyankar 4476506fda5SShri Abhyankar /* U part */ 4486506fda5SShri Abhyankar pv = b->a + bs2 * (bdiag[i + 1] + 1); 4496506fda5SShri Abhyankar pj = b->j + bdiag[i + 1] + 1; 4506506fda5SShri Abhyankar nz = bdiag[i] - bdiag[i + 1] - 1; 451*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArraycpy(pv + bs2 * j, rtmp + bs2 * pj[j], bs2)); 4526506fda5SShri Abhyankar } 4536506fda5SShri Abhyankar 4549566063dSJacob Faibussowitsch PetscCall(PetscFree2(rtmp, mwork)); 4559566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(isicol, &ic)); 4569566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(isrow, &r)); 45726fbe8dcSKarl Rupp 4584dd39f65SShri Abhyankar C->ops->solve = MatSolve_SeqBAIJ_6; 4594dd39f65SShri Abhyankar C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_6; 4606506fda5SShri Abhyankar C->assembled = PETSC_TRUE; 46126fbe8dcSKarl Rupp 4629566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(1.333333333333 * 6 * 6 * 6 * n)); /* from inverting diagonal blocks */ 4636506fda5SShri Abhyankar PetscFunctionReturn(0); 4646506fda5SShri Abhyankar } 4656506fda5SShri Abhyankar 4669371c9d4SSatish Balay PetscErrorCode MatLUFactorNumeric_SeqBAIJ_6_NaturalOrdering_inplace(Mat C, Mat A, const MatFactorInfo *info) { 467bef36659SShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data, *b = (Mat_SeqBAIJ *)C->data; 468bef36659SShri Abhyankar PetscInt i, j, n = a->mbs, *bi = b->i, *bj = b->j; 469bef36659SShri Abhyankar PetscInt *ajtmpold, *ajtmp, nz, row; 470bef36659SShri Abhyankar PetscInt *diag_offset = b->diag, *ai = a->i, *aj = a->j, *pj; 471bef36659SShri Abhyankar MatScalar *pv, *v, *rtmp, *pc, *w, *x; 472bef36659SShri Abhyankar MatScalar x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; 473bef36659SShri Abhyankar MatScalar x16, x17, x18, x19, x20, x21, x22, x23, x24, x25; 474bef36659SShri Abhyankar MatScalar p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15; 475bef36659SShri Abhyankar MatScalar p16, p17, p18, p19, p20, p21, p22, p23, p24, p25; 476bef36659SShri Abhyankar MatScalar m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15; 477bef36659SShri Abhyankar MatScalar m16, m17, m18, m19, m20, m21, m22, m23, m24, m25; 478bef36659SShri Abhyankar MatScalar p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36; 479bef36659SShri Abhyankar MatScalar x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, x36; 480bef36659SShri Abhyankar MatScalar m26, m27, m28, m29, m30, m31, m32, m33, m34, m35, m36; 481bef36659SShri Abhyankar MatScalar *ba = b->a, *aa = a->a; 482182b8fbaSHong Zhang PetscReal shift = info->shiftamount; 483a455e926SHong Zhang PetscBool allowzeropivot, zeropivotdetected; 484bef36659SShri Abhyankar 485bef36659SShri Abhyankar PetscFunctionBegin; 4860164db54SHong Zhang allowzeropivot = PetscNot(A->erroriffailure); 4879566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(36 * (n + 1), &rtmp)); 488bef36659SShri Abhyankar for (i = 0; i < n; i++) { 489bef36659SShri Abhyankar nz = bi[i + 1] - bi[i]; 490bef36659SShri Abhyankar ajtmp = bj + bi[i]; 491bef36659SShri Abhyankar for (j = 0; j < nz; j++) { 492bef36659SShri Abhyankar x = rtmp + 36 * ajtmp[j]; 493bef36659SShri Abhyankar x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = x[6] = x[7] = x[8] = x[9] = 0.0; 494bef36659SShri Abhyankar x[10] = x[11] = x[12] = x[13] = x[14] = x[15] = x[16] = x[17] = 0.0; 495bef36659SShri Abhyankar x[18] = x[19] = x[20] = x[21] = x[22] = x[23] = x[24] = x[25] = 0.0; 496bef36659SShri Abhyankar x[26] = x[27] = x[28] = x[29] = x[30] = x[31] = x[32] = x[33] = 0.0; 497bef36659SShri Abhyankar x[34] = x[35] = 0.0; 498bef36659SShri Abhyankar } 499bef36659SShri Abhyankar /* load in initial (unfactored row) */ 500bef36659SShri Abhyankar nz = ai[i + 1] - ai[i]; 501bef36659SShri Abhyankar ajtmpold = aj + ai[i]; 502bef36659SShri Abhyankar v = aa + 36 * ai[i]; 503bef36659SShri Abhyankar for (j = 0; j < nz; j++) { 504bef36659SShri Abhyankar x = rtmp + 36 * ajtmpold[j]; 5059371c9d4SSatish Balay x[0] = v[0]; 5069371c9d4SSatish Balay x[1] = v[1]; 5079371c9d4SSatish Balay x[2] = v[2]; 5089371c9d4SSatish Balay x[3] = v[3]; 5099371c9d4SSatish Balay x[4] = v[4]; 5109371c9d4SSatish Balay x[5] = v[5]; 5119371c9d4SSatish Balay x[6] = v[6]; 5129371c9d4SSatish Balay x[7] = v[7]; 5139371c9d4SSatish Balay x[8] = v[8]; 5149371c9d4SSatish Balay x[9] = v[9]; 5159371c9d4SSatish Balay x[10] = v[10]; 5169371c9d4SSatish Balay x[11] = v[11]; 5179371c9d4SSatish Balay x[12] = v[12]; 5189371c9d4SSatish Balay x[13] = v[13]; 5199371c9d4SSatish Balay x[14] = v[14]; 5209371c9d4SSatish Balay x[15] = v[15]; 5219371c9d4SSatish Balay x[16] = v[16]; 5229371c9d4SSatish Balay x[17] = v[17]; 5239371c9d4SSatish Balay x[18] = v[18]; 5249371c9d4SSatish Balay x[19] = v[19]; 5259371c9d4SSatish Balay x[20] = v[20]; 5269371c9d4SSatish Balay x[21] = v[21]; 5279371c9d4SSatish Balay x[22] = v[22]; 5289371c9d4SSatish Balay x[23] = v[23]; 5299371c9d4SSatish Balay x[24] = v[24]; 5309371c9d4SSatish Balay x[25] = v[25]; 5319371c9d4SSatish Balay x[26] = v[26]; 5329371c9d4SSatish Balay x[27] = v[27]; 5339371c9d4SSatish Balay x[28] = v[28]; 5349371c9d4SSatish Balay x[29] = v[29]; 5359371c9d4SSatish Balay x[30] = v[30]; 5369371c9d4SSatish Balay x[31] = v[31]; 5379371c9d4SSatish Balay x[32] = v[32]; 5389371c9d4SSatish Balay x[33] = v[33]; 5399371c9d4SSatish Balay x[34] = v[34]; 5409371c9d4SSatish Balay x[35] = v[35]; 541bef36659SShri Abhyankar v += 36; 542bef36659SShri Abhyankar } 543bef36659SShri Abhyankar row = *ajtmp++; 544bef36659SShri Abhyankar while (row < i) { 545bef36659SShri Abhyankar pc = rtmp + 36 * row; 5469371c9d4SSatish Balay p1 = pc[0]; 5479371c9d4SSatish Balay p2 = pc[1]; 5489371c9d4SSatish Balay p3 = pc[2]; 5499371c9d4SSatish Balay p4 = pc[3]; 5509371c9d4SSatish Balay p5 = pc[4]; 5519371c9d4SSatish Balay p6 = pc[5]; 5529371c9d4SSatish Balay p7 = pc[6]; 5539371c9d4SSatish Balay p8 = pc[7]; 5549371c9d4SSatish Balay p9 = pc[8]; 5559371c9d4SSatish Balay p10 = pc[9]; 5569371c9d4SSatish Balay p11 = pc[10]; 5579371c9d4SSatish Balay p12 = pc[11]; 5589371c9d4SSatish Balay p13 = pc[12]; 5599371c9d4SSatish Balay p14 = pc[13]; 5609371c9d4SSatish Balay p15 = pc[14]; 5619371c9d4SSatish Balay p16 = pc[15]; 5629371c9d4SSatish Balay p17 = pc[16]; 5639371c9d4SSatish Balay p18 = pc[17]; 5649371c9d4SSatish Balay p19 = pc[18]; 5659371c9d4SSatish Balay p20 = pc[19]; 5669371c9d4SSatish Balay p21 = pc[20]; 5679371c9d4SSatish Balay p22 = pc[21]; 5689371c9d4SSatish Balay p23 = pc[22]; 5699371c9d4SSatish Balay p24 = pc[23]; 5709371c9d4SSatish Balay p25 = pc[24]; 5719371c9d4SSatish Balay p26 = pc[25]; 5729371c9d4SSatish Balay p27 = pc[26]; 5739371c9d4SSatish Balay p28 = pc[27]; 5749371c9d4SSatish Balay p29 = pc[28]; 5759371c9d4SSatish Balay p30 = pc[29]; 5769371c9d4SSatish Balay p31 = pc[30]; 5779371c9d4SSatish Balay p32 = pc[31]; 5789371c9d4SSatish Balay p33 = pc[32]; 5799371c9d4SSatish Balay p34 = pc[33]; 5809371c9d4SSatish Balay p35 = pc[34]; 5819371c9d4SSatish Balay p36 = pc[35]; 5829371c9d4SSatish Balay if (p1 != 0.0 || p2 != 0.0 || p3 != 0.0 || p4 != 0.0 || p5 != 0.0 || p6 != 0.0 || p7 != 0.0 || p8 != 0.0 || p9 != 0.0 || p10 != 0.0 || p11 != 0.0 || p12 != 0.0 || p13 != 0.0 || p14 != 0.0 || p15 != 0.0 || p16 != 0.0 || p17 != 0.0 || p18 != 0.0 || p19 != 0.0 || p20 != 0.0 || p21 != 0.0 || p22 != 0.0 || p23 != 0.0 || p24 != 0.0 || p25 != 0.0 || p26 != 0.0 || p27 != 0.0 || p28 != 0.0 || p29 != 0.0 || p30 != 0.0 || p31 != 0.0 || p32 != 0.0 || p33 != 0.0 || p34 != 0.0 || p35 != 0.0 || p36 != 0.0) { 583bef36659SShri Abhyankar pv = ba + 36 * diag_offset[row]; 584bef36659SShri Abhyankar pj = bj + diag_offset[row] + 1; 5859371c9d4SSatish Balay x1 = pv[0]; 5869371c9d4SSatish Balay x2 = pv[1]; 5879371c9d4SSatish Balay x3 = pv[2]; 5889371c9d4SSatish Balay x4 = pv[3]; 5899371c9d4SSatish Balay x5 = pv[4]; 5909371c9d4SSatish Balay x6 = pv[5]; 5919371c9d4SSatish Balay x7 = pv[6]; 5929371c9d4SSatish Balay x8 = pv[7]; 5939371c9d4SSatish Balay x9 = pv[8]; 5949371c9d4SSatish Balay x10 = pv[9]; 5959371c9d4SSatish Balay x11 = pv[10]; 5969371c9d4SSatish Balay x12 = pv[11]; 5979371c9d4SSatish Balay x13 = pv[12]; 5989371c9d4SSatish Balay x14 = pv[13]; 5999371c9d4SSatish Balay x15 = pv[14]; 6009371c9d4SSatish Balay x16 = pv[15]; 6019371c9d4SSatish Balay x17 = pv[16]; 6029371c9d4SSatish Balay x18 = pv[17]; 6039371c9d4SSatish Balay x19 = pv[18]; 6049371c9d4SSatish Balay x20 = pv[19]; 6059371c9d4SSatish Balay x21 = pv[20]; 6069371c9d4SSatish Balay x22 = pv[21]; 6079371c9d4SSatish Balay x23 = pv[22]; 6089371c9d4SSatish Balay x24 = pv[23]; 6099371c9d4SSatish Balay x25 = pv[24]; 6109371c9d4SSatish Balay x26 = pv[25]; 6119371c9d4SSatish Balay x27 = pv[26]; 6129371c9d4SSatish Balay x28 = pv[27]; 6139371c9d4SSatish Balay x29 = pv[28]; 6149371c9d4SSatish Balay x30 = pv[29]; 6159371c9d4SSatish Balay x31 = pv[30]; 6169371c9d4SSatish Balay x32 = pv[31]; 6179371c9d4SSatish Balay x33 = pv[32]; 6189371c9d4SSatish Balay x34 = pv[33]; 6199371c9d4SSatish Balay x35 = pv[34]; 6209371c9d4SSatish Balay x36 = pv[35]; 621bef36659SShri Abhyankar pc[0] = m1 = p1 * x1 + p7 * x2 + p13 * x3 + p19 * x4 + p25 * x5 + p31 * x6; 622bef36659SShri Abhyankar pc[1] = m2 = p2 * x1 + p8 * x2 + p14 * x3 + p20 * x4 + p26 * x5 + p32 * x6; 623bef36659SShri Abhyankar pc[2] = m3 = p3 * x1 + p9 * x2 + p15 * x3 + p21 * x4 + p27 * x5 + p33 * x6; 624bef36659SShri Abhyankar pc[3] = m4 = p4 * x1 + p10 * x2 + p16 * x3 + p22 * x4 + p28 * x5 + p34 * x6; 625bef36659SShri Abhyankar pc[4] = m5 = p5 * x1 + p11 * x2 + p17 * x3 + p23 * x4 + p29 * x5 + p35 * x6; 626bef36659SShri Abhyankar pc[5] = m6 = p6 * x1 + p12 * x2 + p18 * x3 + p24 * x4 + p30 * x5 + p36 * x6; 627bef36659SShri Abhyankar 628bef36659SShri Abhyankar pc[6] = m7 = p1 * x7 + p7 * x8 + p13 * x9 + p19 * x10 + p25 * x11 + p31 * x12; 629bef36659SShri Abhyankar pc[7] = m8 = p2 * x7 + p8 * x8 + p14 * x9 + p20 * x10 + p26 * x11 + p32 * x12; 630bef36659SShri Abhyankar pc[8] = m9 = p3 * x7 + p9 * x8 + p15 * x9 + p21 * x10 + p27 * x11 + p33 * x12; 631bef36659SShri Abhyankar pc[9] = m10 = p4 * x7 + p10 * x8 + p16 * x9 + p22 * x10 + p28 * x11 + p34 * x12; 632bef36659SShri Abhyankar pc[10] = m11 = p5 * x7 + p11 * x8 + p17 * x9 + p23 * x10 + p29 * x11 + p35 * x12; 633bef36659SShri Abhyankar pc[11] = m12 = p6 * x7 + p12 * x8 + p18 * x9 + p24 * x10 + p30 * x11 + p36 * x12; 634bef36659SShri Abhyankar 635bef36659SShri Abhyankar pc[12] = m13 = p1 * x13 + p7 * x14 + p13 * x15 + p19 * x16 + p25 * x17 + p31 * x18; 636bef36659SShri Abhyankar pc[13] = m14 = p2 * x13 + p8 * x14 + p14 * x15 + p20 * x16 + p26 * x17 + p32 * x18; 637bef36659SShri Abhyankar pc[14] = m15 = p3 * x13 + p9 * x14 + p15 * x15 + p21 * x16 + p27 * x17 + p33 * x18; 638bef36659SShri Abhyankar pc[15] = m16 = p4 * x13 + p10 * x14 + p16 * x15 + p22 * x16 + p28 * x17 + p34 * x18; 639bef36659SShri Abhyankar pc[16] = m17 = p5 * x13 + p11 * x14 + p17 * x15 + p23 * x16 + p29 * x17 + p35 * x18; 640bef36659SShri Abhyankar pc[17] = m18 = p6 * x13 + p12 * x14 + p18 * x15 + p24 * x16 + p30 * x17 + p36 * x18; 641bef36659SShri Abhyankar 642bef36659SShri Abhyankar pc[18] = m19 = p1 * x19 + p7 * x20 + p13 * x21 + p19 * x22 + p25 * x23 + p31 * x24; 643bef36659SShri Abhyankar pc[19] = m20 = p2 * x19 + p8 * x20 + p14 * x21 + p20 * x22 + p26 * x23 + p32 * x24; 644bef36659SShri Abhyankar pc[20] = m21 = p3 * x19 + p9 * x20 + p15 * x21 + p21 * x22 + p27 * x23 + p33 * x24; 645bef36659SShri Abhyankar pc[21] = m22 = p4 * x19 + p10 * x20 + p16 * x21 + p22 * x22 + p28 * x23 + p34 * x24; 646bef36659SShri Abhyankar pc[22] = m23 = p5 * x19 + p11 * x20 + p17 * x21 + p23 * x22 + p29 * x23 + p35 * x24; 647bef36659SShri Abhyankar pc[23] = m24 = p6 * x19 + p12 * x20 + p18 * x21 + p24 * x22 + p30 * x23 + p36 * x24; 648bef36659SShri Abhyankar 649bef36659SShri Abhyankar pc[24] = m25 = p1 * x25 + p7 * x26 + p13 * x27 + p19 * x28 + p25 * x29 + p31 * x30; 650bef36659SShri Abhyankar pc[25] = m26 = p2 * x25 + p8 * x26 + p14 * x27 + p20 * x28 + p26 * x29 + p32 * x30; 651bef36659SShri Abhyankar pc[26] = m27 = p3 * x25 + p9 * x26 + p15 * x27 + p21 * x28 + p27 * x29 + p33 * x30; 652bef36659SShri Abhyankar pc[27] = m28 = p4 * x25 + p10 * x26 + p16 * x27 + p22 * x28 + p28 * x29 + p34 * x30; 653bef36659SShri Abhyankar pc[28] = m29 = p5 * x25 + p11 * x26 + p17 * x27 + p23 * x28 + p29 * x29 + p35 * x30; 654bef36659SShri Abhyankar pc[29] = m30 = p6 * x25 + p12 * x26 + p18 * x27 + p24 * x28 + p30 * x29 + p36 * x30; 655bef36659SShri Abhyankar 656bef36659SShri Abhyankar pc[30] = m31 = p1 * x31 + p7 * x32 + p13 * x33 + p19 * x34 + p25 * x35 + p31 * x36; 657bef36659SShri Abhyankar pc[31] = m32 = p2 * x31 + p8 * x32 + p14 * x33 + p20 * x34 + p26 * x35 + p32 * x36; 658bef36659SShri Abhyankar pc[32] = m33 = p3 * x31 + p9 * x32 + p15 * x33 + p21 * x34 + p27 * x35 + p33 * x36; 659bef36659SShri Abhyankar pc[33] = m34 = p4 * x31 + p10 * x32 + p16 * x33 + p22 * x34 + p28 * x35 + p34 * x36; 660bef36659SShri Abhyankar pc[34] = m35 = p5 * x31 + p11 * x32 + p17 * x33 + p23 * x34 + p29 * x35 + p35 * x36; 661bef36659SShri Abhyankar pc[35] = m36 = p6 * x31 + p12 * x32 + p18 * x33 + p24 * x34 + p30 * x35 + p36 * x36; 662bef36659SShri Abhyankar 663bef36659SShri Abhyankar nz = bi[row + 1] - diag_offset[row] - 1; 664bef36659SShri Abhyankar pv += 36; 665bef36659SShri Abhyankar for (j = 0; j < nz; j++) { 6669371c9d4SSatish Balay x1 = pv[0]; 6679371c9d4SSatish Balay x2 = pv[1]; 6689371c9d4SSatish Balay x3 = pv[2]; 6699371c9d4SSatish Balay x4 = pv[3]; 6709371c9d4SSatish Balay x5 = pv[4]; 6719371c9d4SSatish Balay x6 = pv[5]; 6729371c9d4SSatish Balay x7 = pv[6]; 6739371c9d4SSatish Balay x8 = pv[7]; 6749371c9d4SSatish Balay x9 = pv[8]; 6759371c9d4SSatish Balay x10 = pv[9]; 6769371c9d4SSatish Balay x11 = pv[10]; 6779371c9d4SSatish Balay x12 = pv[11]; 6789371c9d4SSatish Balay x13 = pv[12]; 6799371c9d4SSatish Balay x14 = pv[13]; 6809371c9d4SSatish Balay x15 = pv[14]; 6819371c9d4SSatish Balay x16 = pv[15]; 6829371c9d4SSatish Balay x17 = pv[16]; 6839371c9d4SSatish Balay x18 = pv[17]; 6849371c9d4SSatish Balay x19 = pv[18]; 6859371c9d4SSatish Balay x20 = pv[19]; 6869371c9d4SSatish Balay x21 = pv[20]; 6879371c9d4SSatish Balay x22 = pv[21]; 6889371c9d4SSatish Balay x23 = pv[22]; 6899371c9d4SSatish Balay x24 = pv[23]; 6909371c9d4SSatish Balay x25 = pv[24]; 6919371c9d4SSatish Balay x26 = pv[25]; 6929371c9d4SSatish Balay x27 = pv[26]; 6939371c9d4SSatish Balay x28 = pv[27]; 6949371c9d4SSatish Balay x29 = pv[28]; 6959371c9d4SSatish Balay x30 = pv[29]; 6969371c9d4SSatish Balay x31 = pv[30]; 6979371c9d4SSatish Balay x32 = pv[31]; 6989371c9d4SSatish Balay x33 = pv[32]; 6999371c9d4SSatish Balay x34 = pv[33]; 7009371c9d4SSatish Balay x35 = pv[34]; 7019371c9d4SSatish Balay x36 = pv[35]; 702bef36659SShri Abhyankar x = rtmp + 36 * pj[j]; 703bef36659SShri Abhyankar x[0] -= m1 * x1 + m7 * x2 + m13 * x3 + m19 * x4 + m25 * x5 + m31 * x6; 704bef36659SShri Abhyankar x[1] -= m2 * x1 + m8 * x2 + m14 * x3 + m20 * x4 + m26 * x5 + m32 * x6; 705bef36659SShri Abhyankar x[2] -= m3 * x1 + m9 * x2 + m15 * x3 + m21 * x4 + m27 * x5 + m33 * x6; 706bef36659SShri Abhyankar x[3] -= m4 * x1 + m10 * x2 + m16 * x3 + m22 * x4 + m28 * x5 + m34 * x6; 707bef36659SShri Abhyankar x[4] -= m5 * x1 + m11 * x2 + m17 * x3 + m23 * x4 + m29 * x5 + m35 * x6; 708bef36659SShri Abhyankar x[5] -= m6 * x1 + m12 * x2 + m18 * x3 + m24 * x4 + m30 * x5 + m36 * x6; 709bef36659SShri Abhyankar 710bef36659SShri Abhyankar x[6] -= m1 * x7 + m7 * x8 + m13 * x9 + m19 * x10 + m25 * x11 + m31 * x12; 711bef36659SShri Abhyankar x[7] -= m2 * x7 + m8 * x8 + m14 * x9 + m20 * x10 + m26 * x11 + m32 * x12; 712bef36659SShri Abhyankar x[8] -= m3 * x7 + m9 * x8 + m15 * x9 + m21 * x10 + m27 * x11 + m33 * x12; 713bef36659SShri Abhyankar x[9] -= m4 * x7 + m10 * x8 + m16 * x9 + m22 * x10 + m28 * x11 + m34 * x12; 714bef36659SShri Abhyankar x[10] -= m5 * x7 + m11 * x8 + m17 * x9 + m23 * x10 + m29 * x11 + m35 * x12; 715bef36659SShri Abhyankar x[11] -= m6 * x7 + m12 * x8 + m18 * x9 + m24 * x10 + m30 * x11 + m36 * x12; 716bef36659SShri Abhyankar 717bef36659SShri Abhyankar x[12] -= m1 * x13 + m7 * x14 + m13 * x15 + m19 * x16 + m25 * x17 + m31 * x18; 718bef36659SShri Abhyankar x[13] -= m2 * x13 + m8 * x14 + m14 * x15 + m20 * x16 + m26 * x17 + m32 * x18; 719bef36659SShri Abhyankar x[14] -= m3 * x13 + m9 * x14 + m15 * x15 + m21 * x16 + m27 * x17 + m33 * x18; 720bef36659SShri Abhyankar x[15] -= m4 * x13 + m10 * x14 + m16 * x15 + m22 * x16 + m28 * x17 + m34 * x18; 721bef36659SShri Abhyankar x[16] -= m5 * x13 + m11 * x14 + m17 * x15 + m23 * x16 + m29 * x17 + m35 * x18; 722bef36659SShri Abhyankar x[17] -= m6 * x13 + m12 * x14 + m18 * x15 + m24 * x16 + m30 * x17 + m36 * x18; 723bef36659SShri Abhyankar 724bef36659SShri Abhyankar x[18] -= m1 * x19 + m7 * x20 + m13 * x21 + m19 * x22 + m25 * x23 + m31 * x24; 725bef36659SShri Abhyankar x[19] -= m2 * x19 + m8 * x20 + m14 * x21 + m20 * x22 + m26 * x23 + m32 * x24; 726bef36659SShri Abhyankar x[20] -= m3 * x19 + m9 * x20 + m15 * x21 + m21 * x22 + m27 * x23 + m33 * x24; 727bef36659SShri Abhyankar x[21] -= m4 * x19 + m10 * x20 + m16 * x21 + m22 * x22 + m28 * x23 + m34 * x24; 728bef36659SShri Abhyankar x[22] -= m5 * x19 + m11 * x20 + m17 * x21 + m23 * x22 + m29 * x23 + m35 * x24; 729bef36659SShri Abhyankar x[23] -= m6 * x19 + m12 * x20 + m18 * x21 + m24 * x22 + m30 * x23 + m36 * x24; 730bef36659SShri Abhyankar 731bef36659SShri Abhyankar x[24] -= m1 * x25 + m7 * x26 + m13 * x27 + m19 * x28 + m25 * x29 + m31 * x30; 732bef36659SShri Abhyankar x[25] -= m2 * x25 + m8 * x26 + m14 * x27 + m20 * x28 + m26 * x29 + m32 * x30; 733bef36659SShri Abhyankar x[26] -= m3 * x25 + m9 * x26 + m15 * x27 + m21 * x28 + m27 * x29 + m33 * x30; 734bef36659SShri Abhyankar x[27] -= m4 * x25 + m10 * x26 + m16 * x27 + m22 * x28 + m28 * x29 + m34 * x30; 735bef36659SShri Abhyankar x[28] -= m5 * x25 + m11 * x26 + m17 * x27 + m23 * x28 + m29 * x29 + m35 * x30; 736bef36659SShri Abhyankar x[29] -= m6 * x25 + m12 * x26 + m18 * x27 + m24 * x28 + m30 * x29 + m36 * x30; 737bef36659SShri Abhyankar 738bef36659SShri Abhyankar x[30] -= m1 * x31 + m7 * x32 + m13 * x33 + m19 * x34 + m25 * x35 + m31 * x36; 739bef36659SShri Abhyankar x[31] -= m2 * x31 + m8 * x32 + m14 * x33 + m20 * x34 + m26 * x35 + m32 * x36; 740bef36659SShri Abhyankar x[32] -= m3 * x31 + m9 * x32 + m15 * x33 + m21 * x34 + m27 * x35 + m33 * x36; 741bef36659SShri Abhyankar x[33] -= m4 * x31 + m10 * x32 + m16 * x33 + m22 * x34 + m28 * x35 + m34 * x36; 742bef36659SShri Abhyankar x[34] -= m5 * x31 + m11 * x32 + m17 * x33 + m23 * x34 + m29 * x35 + m35 * x36; 743bef36659SShri Abhyankar x[35] -= m6 * x31 + m12 * x32 + m18 * x33 + m24 * x34 + m30 * x35 + m36 * x36; 744bef36659SShri Abhyankar 745bef36659SShri Abhyankar pv += 36; 746bef36659SShri Abhyankar } 7479566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(432.0 * nz + 396.0)); 748bef36659SShri Abhyankar } 749bef36659SShri Abhyankar row = *ajtmp++; 750bef36659SShri Abhyankar } 751bef36659SShri Abhyankar /* finished row so stick it into b->a */ 752bef36659SShri Abhyankar pv = ba + 36 * bi[i]; 753bef36659SShri Abhyankar pj = bj + bi[i]; 754bef36659SShri Abhyankar nz = bi[i + 1] - bi[i]; 755bef36659SShri Abhyankar for (j = 0; j < nz; j++) { 756bef36659SShri Abhyankar x = rtmp + 36 * pj[j]; 7579371c9d4SSatish Balay pv[0] = x[0]; 7589371c9d4SSatish Balay pv[1] = x[1]; 7599371c9d4SSatish Balay pv[2] = x[2]; 7609371c9d4SSatish Balay pv[3] = x[3]; 7619371c9d4SSatish Balay pv[4] = x[4]; 7629371c9d4SSatish Balay pv[5] = x[5]; 7639371c9d4SSatish Balay pv[6] = x[6]; 7649371c9d4SSatish Balay pv[7] = x[7]; 7659371c9d4SSatish Balay pv[8] = x[8]; 7669371c9d4SSatish Balay pv[9] = x[9]; 7679371c9d4SSatish Balay pv[10] = x[10]; 7689371c9d4SSatish Balay pv[11] = x[11]; 7699371c9d4SSatish Balay pv[12] = x[12]; 7709371c9d4SSatish Balay pv[13] = x[13]; 7719371c9d4SSatish Balay pv[14] = x[14]; 7729371c9d4SSatish Balay pv[15] = x[15]; 7739371c9d4SSatish Balay pv[16] = x[16]; 7749371c9d4SSatish Balay pv[17] = x[17]; 7759371c9d4SSatish Balay pv[18] = x[18]; 7769371c9d4SSatish Balay pv[19] = x[19]; 7779371c9d4SSatish Balay pv[20] = x[20]; 7789371c9d4SSatish Balay pv[21] = x[21]; 7799371c9d4SSatish Balay pv[22] = x[22]; 7809371c9d4SSatish Balay pv[23] = x[23]; 7819371c9d4SSatish Balay pv[24] = x[24]; 7829371c9d4SSatish Balay pv[25] = x[25]; 7839371c9d4SSatish Balay pv[26] = x[26]; 7849371c9d4SSatish Balay pv[27] = x[27]; 7859371c9d4SSatish Balay pv[28] = x[28]; 7869371c9d4SSatish Balay pv[29] = x[29]; 7879371c9d4SSatish Balay pv[30] = x[30]; 7889371c9d4SSatish Balay pv[31] = x[31]; 7899371c9d4SSatish Balay pv[32] = x[32]; 7909371c9d4SSatish Balay pv[33] = x[33]; 7919371c9d4SSatish Balay pv[34] = x[34]; 7929371c9d4SSatish Balay pv[35] = x[35]; 793bef36659SShri Abhyankar pv += 36; 794bef36659SShri Abhyankar } 795bef36659SShri Abhyankar /* invert diagonal block */ 796bef36659SShri Abhyankar w = ba + 36 * diag_offset[i]; 7979566063dSJacob Faibussowitsch PetscCall(PetscKernel_A_gets_inverse_A_6(w, shift, allowzeropivot, &zeropivotdetected)); 7987b6c816cSBarry Smith if (zeropivotdetected) C->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT; 799bef36659SShri Abhyankar } 800bef36659SShri Abhyankar 8019566063dSJacob Faibussowitsch PetscCall(PetscFree(rtmp)); 80226fbe8dcSKarl Rupp 80306e38f1dSHong Zhang C->ops->solve = MatSolve_SeqBAIJ_6_NaturalOrdering_inplace; 80406e38f1dSHong Zhang C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_6_NaturalOrdering_inplace; 805bef36659SShri Abhyankar C->assembled = PETSC_TRUE; 80626fbe8dcSKarl Rupp 8079566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(1.333333333333 * 6 * 6 * 6 * b->mbs)); /* from inverting diagonal blocks */ 808bef36659SShri Abhyankar PetscFunctionReturn(0); 809bef36659SShri Abhyankar } 810bef36659SShri Abhyankar 8119371c9d4SSatish Balay PetscErrorCode MatLUFactorNumeric_SeqBAIJ_6_NaturalOrdering(Mat B, Mat A, const MatFactorInfo *info) { 812bef36659SShri Abhyankar Mat C = B; 813bef36659SShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data, *b = (Mat_SeqBAIJ *)C->data; 814bbd65245SShri Abhyankar PetscInt i, j, k, nz, nzL, row; 815bbd65245SShri Abhyankar const PetscInt n = a->mbs, *ai = a->i, *aj = a->j, *bi = b->i, *bj = b->j; 816bbd65245SShri Abhyankar const PetscInt *ajtmp, *bjtmp, *bdiag = b->diag, *pj, bs2 = a->bs2; 817bef36659SShri Abhyankar MatScalar *rtmp, *pc, *mwork, *v, *pv, *aa = a->a; 818bbd65245SShri Abhyankar PetscInt flg; 819182b8fbaSHong Zhang PetscReal shift = info->shiftamount; 820a455e926SHong Zhang PetscBool allowzeropivot, zeropivotdetected; 821bef36659SShri Abhyankar 822bef36659SShri Abhyankar PetscFunctionBegin; 8230164db54SHong Zhang allowzeropivot = PetscNot(A->erroriffailure); 8240164db54SHong Zhang 825bef36659SShri Abhyankar /* generate work space needed by the factorization */ 8269566063dSJacob Faibussowitsch PetscCall(PetscMalloc2(bs2 * n, &rtmp, bs2, &mwork)); 8279566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(rtmp, bs2 * n)); 828bef36659SShri Abhyankar 829bef36659SShri Abhyankar for (i = 0; i < n; i++) { 830bef36659SShri Abhyankar /* zero rtmp */ 831bef36659SShri Abhyankar /* L part */ 832bef36659SShri Abhyankar nz = bi[i + 1] - bi[i]; 833bef36659SShri Abhyankar bjtmp = bj + bi[i]; 834*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArrayzero(rtmp + bs2 * bjtmp[j], bs2)); 835bef36659SShri Abhyankar 836bef36659SShri Abhyankar /* U part */ 83753cca76cSShri Abhyankar nz = bdiag[i] - bdiag[i + 1]; 83853cca76cSShri Abhyankar bjtmp = bj + bdiag[i + 1] + 1; 839*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArrayzero(rtmp + bs2 * bjtmp[j], bs2)); 84053cca76cSShri Abhyankar 84153cca76cSShri Abhyankar /* load in initial (unfactored row) */ 84253cca76cSShri Abhyankar nz = ai[i + 1] - ai[i]; 84353cca76cSShri Abhyankar ajtmp = aj + ai[i]; 84453cca76cSShri Abhyankar v = aa + bs2 * ai[i]; 845*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArraycpy(rtmp + bs2 * ajtmp[j], v + bs2 * j, bs2)); 84653cca76cSShri Abhyankar 84753cca76cSShri Abhyankar /* elimination */ 84853cca76cSShri Abhyankar bjtmp = bj + bi[i]; 84953cca76cSShri Abhyankar nzL = bi[i + 1] - bi[i]; 85053cca76cSShri Abhyankar for (k = 0; k < nzL; k++) { 85153cca76cSShri Abhyankar row = bjtmp[k]; 85253cca76cSShri Abhyankar pc = rtmp + bs2 * row; 853c35f09e5SBarry Smith for (flg = 0, j = 0; j < bs2; j++) { 854c35f09e5SBarry Smith if (pc[j] != 0.0) { 855c35f09e5SBarry Smith flg = 1; 856c35f09e5SBarry Smith break; 857c35f09e5SBarry Smith } 858c35f09e5SBarry Smith } 85953cca76cSShri Abhyankar if (flg) { 86053cca76cSShri Abhyankar pv = b->a + bs2 * bdiag[row]; 86196b95a6bSBarry Smith /* PetscKernel_A_gets_A_times_B(bs,pc,pv,mwork); *pc = *pc * (*pv); */ 8629566063dSJacob Faibussowitsch PetscCall(PetscKernel_A_gets_A_times_B_6(pc, pv, mwork)); 86353cca76cSShri Abhyankar 864a5b23f4aSJose E. Roman pj = b->j + bdiag[row + 1] + 1; /* beginning of U(row,:) */ 86553cca76cSShri Abhyankar pv = b->a + bs2 * (bdiag[row + 1] + 1); 86653cca76cSShri Abhyankar nz = bdiag[row] - bdiag[row + 1] - 1; /* num of entries inU(row,:), excluding diag */ 86753cca76cSShri Abhyankar for (j = 0; j < nz; j++) { 86896b95a6bSBarry Smith /* PetscKernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); */ 86953cca76cSShri Abhyankar /* rtmp+bs2*pj[j] = rtmp+bs2*pj[j] - (*pc)*(pv+bs2*j) */ 87053cca76cSShri Abhyankar v = rtmp + bs2 * pj[j]; 8719566063dSJacob Faibussowitsch PetscCall(PetscKernel_A_gets_A_minus_B_times_C_6(v, pc, pv)); 87253cca76cSShri Abhyankar pv += bs2; 87353cca76cSShri Abhyankar } 8749566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(432.0 * nz + 396)); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */ 87553cca76cSShri Abhyankar } 87653cca76cSShri Abhyankar } 87753cca76cSShri Abhyankar 87853cca76cSShri Abhyankar /* finished row so stick it into b->a */ 87953cca76cSShri Abhyankar /* L part */ 88053cca76cSShri Abhyankar pv = b->a + bs2 * bi[i]; 88153cca76cSShri Abhyankar pj = b->j + bi[i]; 88253cca76cSShri Abhyankar nz = bi[i + 1] - bi[i]; 883*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArraycpy(pv + bs2 * j, rtmp + bs2 * pj[j], bs2)); 88453cca76cSShri Abhyankar 885a5b23f4aSJose E. Roman /* Mark diagonal and invert diagonal for simpler triangular solves */ 88653cca76cSShri Abhyankar pv = b->a + bs2 * bdiag[i]; 88753cca76cSShri Abhyankar pj = b->j + bdiag[i]; 8889566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(pv, rtmp + bs2 * pj[0], bs2)); 8899566063dSJacob Faibussowitsch PetscCall(PetscKernel_A_gets_inverse_A_6(pv, shift, allowzeropivot, &zeropivotdetected)); 8907b6c816cSBarry Smith if (zeropivotdetected) C->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT; 89153cca76cSShri Abhyankar 89253cca76cSShri Abhyankar /* U part */ 89353cca76cSShri Abhyankar pv = b->a + bs2 * (bdiag[i + 1] + 1); 89453cca76cSShri Abhyankar pj = b->j + bdiag[i + 1] + 1; 89553cca76cSShri Abhyankar nz = bdiag[i] - bdiag[i + 1] - 1; 896*48a46eb9SPierre Jolivet for (j = 0; j < nz; j++) PetscCall(PetscArraycpy(pv + bs2 * j, rtmp + bs2 * pj[j], bs2)); 89753cca76cSShri Abhyankar } 8989566063dSJacob Faibussowitsch PetscCall(PetscFree2(rtmp, mwork)); 89926fbe8dcSKarl Rupp 9004dd39f65SShri Abhyankar C->ops->solve = MatSolve_SeqBAIJ_6_NaturalOrdering; 9014dd39f65SShri Abhyankar C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_6_NaturalOrdering; 90253cca76cSShri Abhyankar C->assembled = PETSC_TRUE; 90326fbe8dcSKarl Rupp 9049566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(1.333333333333 * 6 * 6 * 6 * n)); /* from inverting diagonal blocks */ 90553cca76cSShri Abhyankar PetscFunctionReturn(0); 90653cca76cSShri Abhyankar } 907