12c733ed4SBarry Smith #include <../src/mat/impls/baij/seq/baij.h> 22c733ed4SBarry Smith 32c733ed4SBarry Smith PetscErrorCode MatSolveTranspose_SeqBAIJ_7_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 42c733ed4SBarry Smith { 52c733ed4SBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ*)A->data; 62c733ed4SBarry Smith const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 72c733ed4SBarry Smith PetscInt i,nz,idx,idt,oidx; 82c733ed4SBarry Smith const MatScalar *aa=a->a,*v; 92c733ed4SBarry Smith PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x; 102c733ed4SBarry Smith 112c733ed4SBarry Smith PetscFunctionBegin; 12*9566063dSJacob Faibussowitsch PetscCall(VecCopy(bb,xx)); 13*9566063dSJacob Faibussowitsch PetscCall(VecGetArray(xx,&x)); 142c733ed4SBarry Smith 152c733ed4SBarry Smith /* forward solve the U^T */ 162c733ed4SBarry Smith idx = 0; 172c733ed4SBarry Smith for (i=0; i<n; i++) { 182c733ed4SBarry Smith 192c733ed4SBarry Smith v = aa + 49*diag[i]; 202c733ed4SBarry Smith /* multiply by the inverse of the block diagonal */ 212c733ed4SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx]; 222c733ed4SBarry Smith x6 = x[5+idx]; x7 = x[6+idx]; 232c733ed4SBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6 + v[6]*x7; 242c733ed4SBarry Smith s2 = v[7]*x1 + v[8]*x2 + v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7; 252c733ed4SBarry Smith s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7; 262c733ed4SBarry Smith s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7; 272c733ed4SBarry Smith s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7; 282c733ed4SBarry Smith s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7; 292c733ed4SBarry Smith s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7; 302c733ed4SBarry Smith v += 49; 312c733ed4SBarry Smith 322c733ed4SBarry Smith vi = aj + diag[i] + 1; 332c733ed4SBarry Smith nz = ai[i+1] - diag[i] - 1; 342c733ed4SBarry Smith while (nz--) { 352c733ed4SBarry Smith oidx = 7*(*vi++); 362c733ed4SBarry Smith x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 372c733ed4SBarry Smith x[oidx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 382c733ed4SBarry Smith x[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 392c733ed4SBarry Smith x[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 402c733ed4SBarry Smith x[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 412c733ed4SBarry Smith x[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 422c733ed4SBarry Smith x[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 432c733ed4SBarry Smith v += 49; 442c733ed4SBarry Smith } 452c733ed4SBarry Smith x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4; x[4+idx] = s5; 462c733ed4SBarry Smith x[5+idx] = s6;x[6+idx] = s7; 472c733ed4SBarry Smith idx += 7; 482c733ed4SBarry Smith } 492c733ed4SBarry Smith /* backward solve the L^T */ 502c733ed4SBarry Smith for (i=n-1; i>=0; i--) { 512c733ed4SBarry Smith v = aa + 49*diag[i] - 49; 522c733ed4SBarry Smith vi = aj + diag[i] - 1; 532c733ed4SBarry Smith nz = diag[i] - ai[i]; 542c733ed4SBarry Smith idt = 7*i; 552c733ed4SBarry Smith s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt]; 562c733ed4SBarry Smith s6 = x[5+idt];s7 = x[6+idt]; 572c733ed4SBarry Smith while (nz--) { 582c733ed4SBarry Smith idx = 7*(*vi--); 592c733ed4SBarry Smith x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 602c733ed4SBarry Smith x[idx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 612c733ed4SBarry Smith x[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 622c733ed4SBarry Smith x[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 632c733ed4SBarry Smith x[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 642c733ed4SBarry Smith x[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 652c733ed4SBarry Smith x[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 662c733ed4SBarry Smith v -= 49; 672c733ed4SBarry Smith } 682c733ed4SBarry Smith } 69*9566063dSJacob Faibussowitsch PetscCall(VecRestoreArray(xx,&x)); 70*9566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n)); 712c733ed4SBarry Smith PetscFunctionReturn(0); 722c733ed4SBarry Smith } 732c733ed4SBarry Smith PetscErrorCode MatSolveTranspose_SeqBAIJ_7_NaturalOrdering(Mat A,Vec bb,Vec xx) 742c733ed4SBarry Smith { 752c733ed4SBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ*)A->data; 762c733ed4SBarry Smith const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 772c733ed4SBarry Smith PetscInt nz,idx,idt,j,i,oidx; 782c733ed4SBarry Smith const PetscInt bs =A->rmap->bs,bs2=a->bs2; 792c733ed4SBarry Smith const MatScalar *aa=a->a,*v; 802c733ed4SBarry Smith PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x; 812c733ed4SBarry Smith 822c733ed4SBarry Smith PetscFunctionBegin; 83*9566063dSJacob Faibussowitsch PetscCall(VecCopy(bb,xx)); 84*9566063dSJacob Faibussowitsch PetscCall(VecGetArray(xx,&x)); 852c733ed4SBarry Smith 862c733ed4SBarry Smith /* forward solve the U^T */ 872c733ed4SBarry Smith idx = 0; 882c733ed4SBarry Smith for (i=0; i<n; i++) { 892c733ed4SBarry Smith v = aa + bs2*diag[i]; 902c733ed4SBarry Smith /* multiply by the inverse of the block diagonal */ 912c733ed4SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; 922c733ed4SBarry Smith x5 = x[4+idx]; x6 = x[5+idx]; x7 = x[6+idx]; 932c733ed4SBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6 + v[6]*x7; 942c733ed4SBarry Smith s2 = v[7]*x1 + v[8]*x2 + v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7; 952c733ed4SBarry Smith s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7; 962c733ed4SBarry Smith s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7; 972c733ed4SBarry Smith s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7; 982c733ed4SBarry Smith s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7; 992c733ed4SBarry Smith s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7; 1002c733ed4SBarry Smith v -= bs2; 1012c733ed4SBarry Smith vi = aj + diag[i] - 1; 1022c733ed4SBarry Smith nz = diag[i] - diag[i+1] - 1; 1032c733ed4SBarry Smith for (j=0; j>-nz; j--) { 1042c733ed4SBarry Smith oidx = bs*vi[j]; 1052c733ed4SBarry Smith x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 1062c733ed4SBarry Smith x[oidx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 1072c733ed4SBarry Smith x[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 1082c733ed4SBarry Smith x[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 1092c733ed4SBarry Smith x[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 1102c733ed4SBarry Smith x[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 1112c733ed4SBarry Smith x[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 1122c733ed4SBarry Smith v -= bs2; 1132c733ed4SBarry Smith } 1142c733ed4SBarry Smith x[idx] = s1; x[1+idx] = s2; x[2+idx] = s3; x[3+idx] = s4; x[4+idx] = s5; 1152c733ed4SBarry Smith x[5+idx] = s6; x[6+idx] = s7; 1162c733ed4SBarry Smith idx += bs; 1172c733ed4SBarry Smith } 1182c733ed4SBarry Smith /* backward solve the L^T */ 1192c733ed4SBarry Smith for (i=n-1; i>=0; i--) { 1202c733ed4SBarry Smith v = aa + bs2*ai[i]; 1212c733ed4SBarry Smith vi = aj + ai[i]; 1222c733ed4SBarry Smith nz = ai[i+1] - ai[i]; 1232c733ed4SBarry Smith idt = bs*i; 1242c733ed4SBarry Smith s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt]; s4 = x[3+idt]; s5 = x[4+idt]; 1252c733ed4SBarry Smith s6 = x[5+idt]; s7 = x[6+idt]; 1262c733ed4SBarry Smith for (j=0; j<nz; j++) { 1272c733ed4SBarry Smith idx = bs*vi[j]; 1282c733ed4SBarry Smith x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 1292c733ed4SBarry Smith x[idx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 1302c733ed4SBarry Smith x[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 1312c733ed4SBarry Smith x[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 1322c733ed4SBarry Smith x[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 1332c733ed4SBarry Smith x[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 1342c733ed4SBarry Smith x[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 1352c733ed4SBarry Smith v += bs2; 1362c733ed4SBarry Smith } 1372c733ed4SBarry Smith } 138*9566063dSJacob Faibussowitsch PetscCall(VecRestoreArray(xx,&x)); 139*9566063dSJacob Faibussowitsch PetscCall(PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n)); 1402c733ed4SBarry Smith PetscFunctionReturn(0); 1412c733ed4SBarry Smith } 142