1be1d678aSKris Buschelman #define PETSCMAT_DLL 2be1d678aSKris Buschelman 34e2b4712SSatish Balay /* 44e2b4712SSatish Balay Factorization code for BAIJ format. 54e2b4712SSatish Balay */ 64e2b4712SSatish Balay 77c4f633dSBarry Smith #include "../src/mat/impls/baij/seq/baij.h" 8c60f0209SBarry Smith #include "../src/mat/blockinvert.h" 916a2bf60SHong Zhang #include "petscbt.h" 1016a2bf60SHong Zhang #include "../src/mat/utils/freespace.h" 114e2b4712SSatish Balay 124a2ae208SSatish Balay #undef __FUNCT__ 1306e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_1_NaturalOrdering_inplace" 1406e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_1_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 15f1af5d2fSBarry Smith { 16f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 17dfbe8321SBarry Smith PetscErrorCode ierr; 180b68f018SBarry Smith PetscInt i,nz; 190b68f018SBarry Smith const PetscInt *diag = a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 200b68f018SBarry Smith const MatScalar *aa=a->a,*v; 210b68f018SBarry Smith PetscScalar s1,*x; 220b68f018SBarry Smith const PetscScalar *b; 23f1af5d2fSBarry Smith 24f1af5d2fSBarry Smith PetscFunctionBegin; 25ef66eb69SBarry Smith ierr = VecCopy(bb,xx);CHKERRQ(ierr); 260b68f018SBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 271ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 28f1af5d2fSBarry Smith 29f1af5d2fSBarry Smith /* forward solve the U^T */ 30f1af5d2fSBarry Smith for (i=0; i<n; i++) { 31f1af5d2fSBarry Smith 32f1af5d2fSBarry Smith v = aa + diag[i]; 33f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 34ef66eb69SBarry Smith s1 = (*v++)*x[i]; 35f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 36f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 37f1af5d2fSBarry Smith while (nz--) { 38f1af5d2fSBarry Smith x[*vi++] -= (*v++)*s1; 39f1af5d2fSBarry Smith } 40f1af5d2fSBarry Smith x[i] = s1; 41f1af5d2fSBarry Smith } 42f1af5d2fSBarry Smith /* backward solve the L^T */ 43f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 44f1af5d2fSBarry Smith v = aa + diag[i] - 1; 45f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 46f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 47f1af5d2fSBarry Smith s1 = x[i]; 48f1af5d2fSBarry Smith while (nz--) { 49f1af5d2fSBarry Smith x[*vi--] -= (*v--)*s1; 50f1af5d2fSBarry Smith } 51f1af5d2fSBarry Smith } 520b68f018SBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 531ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 54dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*(a->nz) - A->cmap->n);CHKERRQ(ierr); 55f1af5d2fSBarry Smith PetscFunctionReturn(0); 56f1af5d2fSBarry Smith } 57f1af5d2fSBarry Smith 584a2ae208SSatish Balay #undef __FUNCT__ 5906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_2_NaturalOrdering_inplace" 6006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_2_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 61f1af5d2fSBarry Smith { 62f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 63dfbe8321SBarry Smith PetscErrorCode ierr; 64b3260449SShri Abhyankar PetscInt i,nz,idx,idt,oidx; 65b3260449SShri Abhyankar const PetscInt *diag = a->diag,*vi,n=a->mbs,*ai=a->i,*aj=a->j; 66b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 67b3260449SShri Abhyankar PetscScalar s1,s2,x1,x2,*x; 68b3260449SShri Abhyankar const PetscScalar *b; 69f1af5d2fSBarry Smith 70f1af5d2fSBarry Smith PetscFunctionBegin; 71ef66eb69SBarry Smith ierr = VecCopy(bb,xx);CHKERRQ(ierr); 72b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 731ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 74f1af5d2fSBarry Smith 75f1af5d2fSBarry Smith /* forward solve the U^T */ 76f1af5d2fSBarry Smith idx = 0; 77f1af5d2fSBarry Smith for (i=0; i<n; i++) { 78f1af5d2fSBarry Smith 79f1af5d2fSBarry Smith v = aa + 4*diag[i]; 80f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 81ef66eb69SBarry Smith x1 = x[idx]; x2 = x[1+idx]; 82f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2; 83f1af5d2fSBarry Smith s2 = v[2]*x1 + v[3]*x2; 84f1af5d2fSBarry Smith v += 4; 85f1af5d2fSBarry Smith 86f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 87f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 88f1af5d2fSBarry Smith while (nz--) { 89f1af5d2fSBarry Smith oidx = 2*(*vi++); 90f1af5d2fSBarry Smith x[oidx] -= v[0]*s1 + v[1]*s2; 91f1af5d2fSBarry Smith x[oidx+1] -= v[2]*s1 + v[3]*s2; 92f1af5d2fSBarry Smith v += 4; 93f1af5d2fSBarry Smith } 94f1af5d2fSBarry Smith x[idx] = s1;x[1+idx] = s2; 95f1af5d2fSBarry Smith idx += 2; 96f1af5d2fSBarry Smith } 97f1af5d2fSBarry Smith /* backward solve the L^T */ 98f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 99f1af5d2fSBarry Smith v = aa + 4*diag[i] - 4; 100f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 101f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 102f1af5d2fSBarry Smith idt = 2*i; 103f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; 104f1af5d2fSBarry Smith while (nz--) { 105f1af5d2fSBarry Smith idx = 2*(*vi--); 106f1af5d2fSBarry Smith x[idx] -= v[0]*s1 + v[1]*s2; 107f1af5d2fSBarry Smith x[idx+1] -= v[2]*s1 + v[3]*s2; 108f1af5d2fSBarry Smith v -= 4; 109f1af5d2fSBarry Smith } 110f1af5d2fSBarry Smith } 111b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 1121ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 113dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*4.0*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr); 114f1af5d2fSBarry Smith PetscFunctionReturn(0); 115f1af5d2fSBarry Smith } 116f1af5d2fSBarry Smith 1174a2ae208SSatish Balay #undef __FUNCT__ 1184dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_2_NaturalOrdering" 1194dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_2_NaturalOrdering(Mat A,Vec bb,Vec xx) 1206929473cSShri Abhyankar { 1216929473cSShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 1226929473cSShri Abhyankar PetscErrorCode ierr; 123b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 1246929473cSShri Abhyankar PetscInt nz,idx,idt,j,i,oidx; 125b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 126b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 127b3260449SShri Abhyankar PetscScalar s1,s2,x1,x2,*x; 128b3260449SShri Abhyankar const PetscScalar *b; 1296929473cSShri Abhyankar 1306929473cSShri Abhyankar PetscFunctionBegin; 1316929473cSShri Abhyankar ierr = VecCopy(bb,xx);CHKERRQ(ierr); 132b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 1336929473cSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 1346929473cSShri Abhyankar 1356929473cSShri Abhyankar /* forward solve the U^T */ 1366929473cSShri Abhyankar idx = 0; 1376929473cSShri Abhyankar for (i=0; i<n; i++) { 1386929473cSShri Abhyankar v = aa + bs2*diag[i]; 1396929473cSShri Abhyankar /* multiply by the inverse of the block diagonal */ 1406929473cSShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; 1416929473cSShri Abhyankar s1 = v[0]*x1 + v[1]*x2; 1426929473cSShri Abhyankar s2 = v[2]*x1 + v[3]*x2; 1436929473cSShri Abhyankar v -= bs2; 1446929473cSShri Abhyankar 1456929473cSShri Abhyankar vi = aj + diag[i] - 1; 1466929473cSShri Abhyankar nz = diag[i] - diag[i+1] - 1; 1476929473cSShri Abhyankar for(j=0;j>-nz;j--){ 1486929473cSShri Abhyankar oidx = bs*vi[j]; 1496929473cSShri Abhyankar x[oidx] -= v[0]*s1 + v[1]*s2; 1506929473cSShri Abhyankar x[oidx+1] -= v[2]*s1 + v[3]*s2; 1516929473cSShri Abhyankar v -= bs2; 1526929473cSShri Abhyankar } 1536929473cSShri Abhyankar x[idx] = s1;x[1+idx] = s2; 1546929473cSShri Abhyankar idx += bs; 1556929473cSShri Abhyankar } 1566929473cSShri Abhyankar /* backward solve the L^T */ 1576929473cSShri Abhyankar for (i=n-1; i>=0; i--){ 1586929473cSShri Abhyankar v = aa + bs2*ai[i]; 1596929473cSShri Abhyankar vi = aj + ai[i]; 1606929473cSShri Abhyankar nz = ai[i+1] - ai[i]; 1616929473cSShri Abhyankar idt = bs*i; 1626929473cSShri Abhyankar s1 = x[idt]; s2 = x[1+idt]; 1636929473cSShri Abhyankar for(j=0;j<nz;j++){ 1646929473cSShri Abhyankar idx = bs*vi[j]; 1656929473cSShri Abhyankar x[idx] -= v[0]*s1 + v[1]*s2; 1666929473cSShri Abhyankar x[idx+1] -= v[2]*s1 + v[3]*s2; 1676929473cSShri Abhyankar v += bs2; 1686929473cSShri Abhyankar } 1696929473cSShri Abhyankar } 170b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 1716929473cSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 1726929473cSShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 1736929473cSShri Abhyankar PetscFunctionReturn(0); 1746929473cSShri Abhyankar } 1756929473cSShri Abhyankar 1766929473cSShri Abhyankar #undef __FUNCT__ 17706e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_3_NaturalOrdering_inplace" 17806e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_3_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 179f1af5d2fSBarry Smith { 180f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 181dfbe8321SBarry Smith PetscErrorCode ierr; 182b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 183b3260449SShri Abhyankar PetscInt i,nz,idx,idt,oidx; 184b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 185b3260449SShri Abhyankar PetscScalar s1,s2,s3,x1,x2,x3,*x; 186b3260449SShri Abhyankar const PetscScalar *b; 187f1af5d2fSBarry Smith 188f1af5d2fSBarry Smith PetscFunctionBegin; 189ef66eb69SBarry Smith ierr = VecCopy(bb,xx);CHKERRQ(ierr); 190b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 1911ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 192f1af5d2fSBarry Smith 193f1af5d2fSBarry Smith /* forward solve the U^T */ 194f1af5d2fSBarry Smith idx = 0; 195f1af5d2fSBarry Smith for (i=0; i<n; i++) { 196f1af5d2fSBarry Smith 197f1af5d2fSBarry Smith v = aa + 9*diag[i]; 198f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 199ef66eb69SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; 200f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3; 201f1af5d2fSBarry Smith s2 = v[3]*x1 + v[4]*x2 + v[5]*x3; 202f1af5d2fSBarry Smith s3 = v[6]*x1 + v[7]*x2 + v[8]*x3; 203f1af5d2fSBarry Smith v += 9; 204f1af5d2fSBarry Smith 205f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 206f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 207f1af5d2fSBarry Smith while (nz--) { 208f1af5d2fSBarry Smith oidx = 3*(*vi++); 209f1af5d2fSBarry Smith x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3; 210f1af5d2fSBarry Smith x[oidx+1] -= v[3]*s1 + v[4]*s2 + v[5]*s3; 211f1af5d2fSBarry Smith x[oidx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3; 212f1af5d2fSBarry Smith v += 9; 213f1af5d2fSBarry Smith } 214f1af5d2fSBarry Smith x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3; 215f1af5d2fSBarry Smith idx += 3; 216f1af5d2fSBarry Smith } 217f1af5d2fSBarry Smith /* backward solve the L^T */ 218f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 219f1af5d2fSBarry Smith v = aa + 9*diag[i] - 9; 220f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 221f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 222f1af5d2fSBarry Smith idt = 3*i; 223f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt]; 224f1af5d2fSBarry Smith while (nz--) { 225f1af5d2fSBarry Smith idx = 3*(*vi--); 226f1af5d2fSBarry Smith x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3; 227f1af5d2fSBarry Smith x[idx+1] -= v[3]*s1 + v[4]*s2 + v[5]*s3; 228f1af5d2fSBarry Smith x[idx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3; 229f1af5d2fSBarry Smith v -= 9; 230f1af5d2fSBarry Smith } 231f1af5d2fSBarry Smith } 232b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 2331ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 234dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*9.0*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr); 235f1af5d2fSBarry Smith PetscFunctionReturn(0); 236f1af5d2fSBarry Smith } 237f1af5d2fSBarry Smith 2384a2ae208SSatish Balay #undef __FUNCT__ 2394dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_3_NaturalOrdering" 2404dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_3_NaturalOrdering(Mat A,Vec bb,Vec xx) 2418499736aSShri Abhyankar { 2428499736aSShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 2438499736aSShri Abhyankar PetscErrorCode ierr; 244b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 2458499736aSShri Abhyankar PetscInt nz,idx,idt,j,i,oidx; 246b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 247b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 248b3260449SShri Abhyankar PetscScalar s1,s2,s3,x1,x2,x3,*x; 249b3260449SShri Abhyankar const PetscScalar *b; 2508499736aSShri Abhyankar 2518499736aSShri Abhyankar PetscFunctionBegin; 2528499736aSShri Abhyankar ierr = VecCopy(bb,xx);CHKERRQ(ierr); 253b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 2548499736aSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 2558499736aSShri Abhyankar 2568499736aSShri Abhyankar /* forward solve the U^T */ 2578499736aSShri Abhyankar idx = 0; 2588499736aSShri Abhyankar for (i=0; i<n; i++) { 2598499736aSShri Abhyankar v = aa + bs2*diag[i]; 2608499736aSShri Abhyankar /* multiply by the inverse of the block diagonal */ 2618499736aSShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; 2628499736aSShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3; 2638499736aSShri Abhyankar s2 = v[3]*x1 + v[4]*x2 + v[5]*x3; 2648499736aSShri Abhyankar s3 = v[6]*x1 + v[7]*x2 + v[8]*x3; 2658499736aSShri Abhyankar v -= bs2; 2668499736aSShri Abhyankar 2678499736aSShri Abhyankar vi = aj + diag[i] - 1; 2688499736aSShri Abhyankar nz = diag[i] - diag[i+1] - 1; 2698499736aSShri Abhyankar for(j=0;j>-nz;j--){ 2708499736aSShri Abhyankar oidx = bs*vi[j]; 2718499736aSShri Abhyankar x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3; 2728499736aSShri Abhyankar x[oidx+1] -= v[3]*s1 + v[4]*s2 + v[5]*s3; 2738499736aSShri Abhyankar x[oidx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3; 2748499736aSShri Abhyankar v -= bs2; 2758499736aSShri Abhyankar } 2768499736aSShri Abhyankar x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3; 2778499736aSShri Abhyankar idx += bs; 2788499736aSShri Abhyankar } 2798499736aSShri Abhyankar /* backward solve the L^T */ 2808499736aSShri Abhyankar for (i=n-1; i>=0; i--){ 2818499736aSShri Abhyankar v = aa + bs2*ai[i]; 2828499736aSShri Abhyankar vi = aj + ai[i]; 2838499736aSShri Abhyankar nz = ai[i+1] - ai[i]; 2848499736aSShri Abhyankar idt = bs*i; 2858499736aSShri Abhyankar s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt]; 2868499736aSShri Abhyankar for(j=0;j<nz;j++){ 2878499736aSShri Abhyankar idx = bs*vi[j]; 2888499736aSShri Abhyankar x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3; 2898499736aSShri Abhyankar x[idx+1] -= v[3]*s1 + v[4]*s2 + v[5]*s3; 2908499736aSShri Abhyankar x[idx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3; 2918499736aSShri Abhyankar v += bs2; 2928499736aSShri Abhyankar } 2938499736aSShri Abhyankar } 294b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 2958499736aSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 2968499736aSShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 2978499736aSShri Abhyankar PetscFunctionReturn(0); 2988499736aSShri Abhyankar } 2998499736aSShri Abhyankar 3008499736aSShri Abhyankar #undef __FUNCT__ 30106e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_4_NaturalOrdering_inplace" 30206e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_4_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 303f1af5d2fSBarry Smith { 304f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 305dfbe8321SBarry Smith PetscErrorCode ierr; 306b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 307b3260449SShri Abhyankar PetscInt i,nz,idx,idt,oidx; 308b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 309b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,x1,x2,x3,x4,*x; 310b3260449SShri Abhyankar const PetscScalar *b; 311f1af5d2fSBarry Smith 312f1af5d2fSBarry Smith PetscFunctionBegin; 313ef66eb69SBarry Smith ierr = VecCopy(bb,xx);CHKERRQ(ierr); 314b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 3151ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 316f1af5d2fSBarry Smith 317f1af5d2fSBarry Smith /* forward solve the U^T */ 318f1af5d2fSBarry Smith idx = 0; 319f1af5d2fSBarry Smith for (i=0; i<n; i++) { 320f1af5d2fSBarry Smith 321f1af5d2fSBarry Smith v = aa + 16*diag[i]; 322f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 323ef66eb69SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; 324f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4; 325f1af5d2fSBarry Smith s2 = v[4]*x1 + v[5]*x2 + v[6]*x3 + v[7]*x4; 326f1af5d2fSBarry Smith s3 = v[8]*x1 + v[9]*x2 + v[10]*x3 + v[11]*x4; 327f1af5d2fSBarry Smith s4 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4; 328f1af5d2fSBarry Smith v += 16; 329f1af5d2fSBarry Smith 330f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 331f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 332f1af5d2fSBarry Smith while (nz--) { 333f1af5d2fSBarry Smith oidx = 4*(*vi++); 334f1af5d2fSBarry Smith x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4; 335f1af5d2fSBarry Smith x[oidx+1] -= v[4]*s1 + v[5]*s2 + v[6]*s3 + v[7]*s4; 336f1af5d2fSBarry Smith x[oidx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4; 337f1af5d2fSBarry Smith x[oidx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4; 338f1af5d2fSBarry Smith v += 16; 339f1af5d2fSBarry Smith } 340f1af5d2fSBarry Smith x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4; 341f1af5d2fSBarry Smith idx += 4; 342f1af5d2fSBarry Smith } 343f1af5d2fSBarry Smith /* backward solve the L^T */ 344f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 345f1af5d2fSBarry Smith v = aa + 16*diag[i] - 16; 346f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 347f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 348f1af5d2fSBarry Smith idt = 4*i; 349f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt]; 350f1af5d2fSBarry Smith while (nz--) { 351f1af5d2fSBarry Smith idx = 4*(*vi--); 352f1af5d2fSBarry Smith x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4; 353f1af5d2fSBarry Smith x[idx+1] -= v[4]*s1 + v[5]*s2 + v[6]*s3 + v[7]*s4; 354f1af5d2fSBarry Smith x[idx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4; 355f1af5d2fSBarry Smith x[idx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4; 356f1af5d2fSBarry Smith v -= 16; 357f1af5d2fSBarry Smith } 358f1af5d2fSBarry Smith } 359b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 3601ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 361dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 362f1af5d2fSBarry Smith PetscFunctionReturn(0); 363f1af5d2fSBarry Smith } 364f1af5d2fSBarry Smith 3654a2ae208SSatish Balay #undef __FUNCT__ 3664dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_4_NaturalOrdering" 3674dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_4_NaturalOrdering(Mat A,Vec bb,Vec xx) 3688499736aSShri Abhyankar { 3698499736aSShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 3708499736aSShri Abhyankar PetscErrorCode ierr; 371b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 3728499736aSShri Abhyankar PetscInt nz,idx,idt,j,i,oidx; 373b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 374b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 375b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,x1,x2,x3,x4,*x; 376b3260449SShri Abhyankar const PetscScalar *b; 3778499736aSShri Abhyankar 3788499736aSShri Abhyankar PetscFunctionBegin; 3798499736aSShri Abhyankar ierr = VecCopy(bb,xx);CHKERRQ(ierr); 380b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 3818499736aSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 3828499736aSShri Abhyankar 3838499736aSShri Abhyankar /* forward solve the U^T */ 3848499736aSShri Abhyankar idx = 0; 3858499736aSShri Abhyankar for (i=0; i<n; i++) { 3868499736aSShri Abhyankar v = aa + bs2*diag[i]; 3878499736aSShri Abhyankar /* multiply by the inverse of the block diagonal */ 3888499736aSShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; 3898499736aSShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4; 3908499736aSShri Abhyankar s2 = v[4]*x1 + v[5]*x2 + v[6]*x3 + v[7]*x4; 3918499736aSShri Abhyankar s3 = v[8]*x1 + v[9]*x2 + v[10]*x3 + v[11]*x4; 3928499736aSShri Abhyankar s4 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4; 3938499736aSShri Abhyankar v -= bs2; 3948499736aSShri Abhyankar 3958499736aSShri Abhyankar vi = aj + diag[i] - 1; 3968499736aSShri Abhyankar nz = diag[i] - diag[i+1] - 1; 3978499736aSShri Abhyankar for(j=0;j>-nz;j--){ 3988499736aSShri Abhyankar oidx = bs*vi[j]; 3998499736aSShri Abhyankar x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4; 4008499736aSShri Abhyankar x[oidx+1] -= v[4]*s1 + v[5]*s2 + v[6]*s3 + v[7]*s4; 4018499736aSShri Abhyankar x[oidx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4; 4028499736aSShri Abhyankar x[oidx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4; 4038499736aSShri Abhyankar v -= bs2; 4048499736aSShri Abhyankar } 4058499736aSShri Abhyankar x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3; x[3+idx] = s4; 4068499736aSShri Abhyankar idx += bs; 4078499736aSShri Abhyankar } 4088499736aSShri Abhyankar /* backward solve the L^T */ 4098499736aSShri Abhyankar for (i=n-1; i>=0; i--){ 4108499736aSShri Abhyankar v = aa + bs2*ai[i]; 4118499736aSShri Abhyankar vi = aj + ai[i]; 4128499736aSShri Abhyankar nz = ai[i+1] - ai[i]; 4138499736aSShri Abhyankar idt = bs*i; 4148499736aSShri Abhyankar s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt]; s4 = x[3+idt]; 4158499736aSShri Abhyankar for(j=0;j<nz;j++){ 4168499736aSShri Abhyankar idx = bs*vi[j]; 4178499736aSShri Abhyankar x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4; 4188499736aSShri Abhyankar x[idx+1] -= v[4]*s1 + v[5]*s2 + v[6]*s3 + v[7]*s4; 4198499736aSShri Abhyankar x[idx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4; 4208499736aSShri Abhyankar x[idx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4; 4218499736aSShri Abhyankar v += bs2; 4228499736aSShri Abhyankar } 4238499736aSShri Abhyankar } 424b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 4258499736aSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4268499736aSShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 4278499736aSShri Abhyankar PetscFunctionReturn(0); 4288499736aSShri Abhyankar } 4298499736aSShri Abhyankar 4308499736aSShri Abhyankar #undef __FUNCT__ 43106e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_5_NaturalOrdering_inplace" 43206e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_5_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 433f1af5d2fSBarry Smith { 434f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 435dfbe8321SBarry Smith PetscErrorCode ierr; 436b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 437b3260449SShri Abhyankar PetscInt i,nz,idx,idt,oidx; 438b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 439b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x; 440b3260449SShri Abhyankar const PetscScalar *b; 441f1af5d2fSBarry Smith 442f1af5d2fSBarry Smith PetscFunctionBegin; 443ef66eb69SBarry Smith ierr = VecCopy(bb,xx);CHKERRQ(ierr); 444b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 4451ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 446f1af5d2fSBarry Smith 447f1af5d2fSBarry Smith /* forward solve the U^T */ 448f1af5d2fSBarry Smith idx = 0; 449f1af5d2fSBarry Smith for (i=0; i<n; i++) { 450f1af5d2fSBarry Smith 451f1af5d2fSBarry Smith v = aa + 25*diag[i]; 452f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 453ef66eb69SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx]; 454f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5; 455f1af5d2fSBarry Smith s2 = v[5]*x1 + v[6]*x2 + v[7]*x3 + v[8]*x4 + v[9]*x5; 456f1af5d2fSBarry Smith s3 = v[10]*x1 + v[11]*x2 + v[12]*x3 + v[13]*x4 + v[14]*x5; 457f1af5d2fSBarry Smith s4 = v[15]*x1 + v[16]*x2 + v[17]*x3 + v[18]*x4 + v[19]*x5; 458f1af5d2fSBarry Smith s5 = v[20]*x1 + v[21]*x2 + v[22]*x3 + v[23]*x4 + v[24]*x5; 459f1af5d2fSBarry Smith v += 25; 460f1af5d2fSBarry Smith 461f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 462f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 463f1af5d2fSBarry Smith while (nz--) { 464f1af5d2fSBarry Smith oidx = 5*(*vi++); 465f1af5d2fSBarry Smith x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5; 466f1af5d2fSBarry Smith x[oidx+1] -= v[5]*s1 + v[6]*s2 + v[7]*s3 + v[8]*s4 + v[9]*s5; 467f1af5d2fSBarry Smith x[oidx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5; 468f1af5d2fSBarry Smith x[oidx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5; 469f1af5d2fSBarry Smith x[oidx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5; 470f1af5d2fSBarry Smith v += 25; 471f1af5d2fSBarry Smith } 472f1af5d2fSBarry Smith x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4; x[4+idx] = s5; 473f1af5d2fSBarry Smith idx += 5; 474f1af5d2fSBarry Smith } 475f1af5d2fSBarry Smith /* backward solve the L^T */ 476f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 477f1af5d2fSBarry Smith v = aa + 25*diag[i] - 25; 478f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 479f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 480f1af5d2fSBarry Smith idt = 5*i; 481f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt]; 482f1af5d2fSBarry Smith while (nz--) { 483f1af5d2fSBarry Smith idx = 5*(*vi--); 484f1af5d2fSBarry Smith x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5; 485f1af5d2fSBarry Smith x[idx+1] -= v[5]*s1 + v[6]*s2 + v[7]*s3 + v[8]*s4 + v[9]*s5; 486f1af5d2fSBarry Smith x[idx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5; 487f1af5d2fSBarry Smith x[idx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5; 488f1af5d2fSBarry Smith x[idx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5; 489f1af5d2fSBarry Smith v -= 25; 490f1af5d2fSBarry Smith } 491f1af5d2fSBarry Smith } 492b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 4931ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 494dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr); 495f1af5d2fSBarry Smith PetscFunctionReturn(0); 496f1af5d2fSBarry Smith } 497f1af5d2fSBarry Smith 4984a2ae208SSatish Balay #undef __FUNCT__ 4994dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_5_NaturalOrdering" 5004dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_5_NaturalOrdering(Mat A,Vec bb,Vec xx) 5018499736aSShri Abhyankar { 5028499736aSShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 5038499736aSShri Abhyankar PetscErrorCode ierr; 504b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 5058499736aSShri Abhyankar PetscInt nz,idx,idt,j,i,oidx; 506b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 507b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 508b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x; 509b3260449SShri Abhyankar const PetscScalar *b; 5108499736aSShri Abhyankar 5118499736aSShri Abhyankar PetscFunctionBegin; 5128499736aSShri Abhyankar ierr = VecCopy(bb,xx);CHKERRQ(ierr); 513b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 5148499736aSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 5158499736aSShri Abhyankar 5168499736aSShri Abhyankar /* forward solve the U^T */ 5178499736aSShri Abhyankar idx = 0; 5188499736aSShri Abhyankar for (i=0; i<n; i++) { 5198499736aSShri Abhyankar v = aa + bs2*diag[i]; 5208499736aSShri Abhyankar /* multiply by the inverse of the block diagonal */ 5218499736aSShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; 5228499736aSShri Abhyankar x5 = x[4+idx]; 5238499736aSShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5; 5248499736aSShri Abhyankar s2 = v[5]*x1 + v[6]*x2 + v[7]*x3 + v[8]*x4 + v[9]*x5; 5258499736aSShri Abhyankar s3 = v[10]*x1 + v[11]*x2 + v[12]*x3 + v[13]*x4 + v[14]*x5; 5268499736aSShri Abhyankar s4 = v[15]*x1 + v[16]*x2 + v[17]*x3 + v[18]*x4 + v[19]*x5; 5278499736aSShri Abhyankar s5 = v[20]*x1 + v[21]*x2 + v[22]*x3 + v[23]*x4 + v[24]*x5; 5288499736aSShri Abhyankar v -= bs2; 5298499736aSShri Abhyankar 5308499736aSShri Abhyankar vi = aj + diag[i] - 1; 5318499736aSShri Abhyankar nz = diag[i] - diag[i+1] - 1; 5328499736aSShri Abhyankar for(j=0;j>-nz;j--){ 5338499736aSShri Abhyankar oidx = bs*vi[j]; 5348499736aSShri Abhyankar x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5; 5358499736aSShri Abhyankar x[oidx+1] -= v[5]*s1 + v[6]*s2 + v[7]*s3 + v[8]*s4 + v[9]*s5; 5368499736aSShri Abhyankar x[oidx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5; 5378499736aSShri Abhyankar x[oidx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5; 5388499736aSShri Abhyankar x[oidx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5; 5398499736aSShri Abhyankar v -= bs2; 5408499736aSShri Abhyankar } 5418499736aSShri Abhyankar x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3; x[3+idx] = s4; x[4+idx] = s5; 5428499736aSShri Abhyankar idx += bs; 5438499736aSShri Abhyankar } 5448499736aSShri Abhyankar /* backward solve the L^T */ 5458499736aSShri Abhyankar for (i=n-1; i>=0; i--){ 5468499736aSShri Abhyankar v = aa + bs2*ai[i]; 5478499736aSShri Abhyankar vi = aj + ai[i]; 5488499736aSShri Abhyankar nz = ai[i+1] - ai[i]; 5498499736aSShri Abhyankar idt = bs*i; 5508499736aSShri Abhyankar s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt]; s4 = x[3+idt]; s5 = x[4+idt]; 5518499736aSShri Abhyankar for(j=0;j<nz;j++){ 5528499736aSShri Abhyankar idx = bs*vi[j]; 5538499736aSShri Abhyankar x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5; 5548499736aSShri Abhyankar x[idx+1] -= v[5]*s1 + v[6]*s2 + v[7]*s3 + v[8]*s4 + v[9]*s5; 5558499736aSShri Abhyankar x[idx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5; 5568499736aSShri Abhyankar x[idx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5; 5578499736aSShri Abhyankar x[idx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5; 5588499736aSShri Abhyankar v += bs2; 5598499736aSShri Abhyankar } 5608499736aSShri Abhyankar } 561b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 5628499736aSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 5638499736aSShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 5648499736aSShri Abhyankar PetscFunctionReturn(0); 5658499736aSShri Abhyankar } 5668499736aSShri Abhyankar 5678499736aSShri Abhyankar #undef __FUNCT__ 56806e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_6_NaturalOrdering_inplace" 56906e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_6_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 570f1af5d2fSBarry Smith { 571f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 572dfbe8321SBarry Smith PetscErrorCode ierr; 573b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 574b3260449SShri Abhyankar PetscInt i,nz,idx,idt,oidx; 575b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 576b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x; 577b3260449SShri Abhyankar const PetscScalar *b; 578f1af5d2fSBarry Smith 579f1af5d2fSBarry Smith PetscFunctionBegin; 580ef66eb69SBarry Smith ierr = VecCopy(bb,xx);CHKERRQ(ierr); 581b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 5821ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 583f1af5d2fSBarry Smith 584f1af5d2fSBarry Smith /* forward solve the U^T */ 585f1af5d2fSBarry Smith idx = 0; 586f1af5d2fSBarry Smith for (i=0; i<n; i++) { 587f1af5d2fSBarry Smith 588f1af5d2fSBarry Smith v = aa + 36*diag[i]; 589f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 590ef66eb69SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx]; 591ef66eb69SBarry Smith x6 = x[5+idx]; 592f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6; 593f1af5d2fSBarry Smith s2 = v[6]*x1 + v[7]*x2 + v[8]*x3 + v[9]*x4 + v[10]*x5 + v[11]*x6; 594f1af5d2fSBarry Smith s3 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4 + v[16]*x5 + v[17]*x6; 595f1af5d2fSBarry Smith s4 = v[18]*x1 + v[19]*x2 + v[20]*x3 + v[21]*x4 + v[22]*x5 + v[23]*x6; 596f1af5d2fSBarry Smith s5 = v[24]*x1 + v[25]*x2 + v[26]*x3 + v[27]*x4 + v[28]*x5 + v[29]*x6; 597f1af5d2fSBarry Smith s6 = v[30]*x1 + v[31]*x2 + v[32]*x3 + v[33]*x4 + v[34]*x5 + v[35]*x6; 598f1af5d2fSBarry Smith v += 36; 599f1af5d2fSBarry Smith 600f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 601f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 602f1af5d2fSBarry Smith while (nz--) { 603f1af5d2fSBarry Smith oidx = 6*(*vi++); 604f1af5d2fSBarry Smith x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6; 605f1af5d2fSBarry Smith x[oidx+1] -= v[6]*s1 + v[7]*s2 + v[8]*s3 + v[9]*s4 + v[10]*s5 + v[11]*s6; 606f1af5d2fSBarry Smith x[oidx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6; 607f1af5d2fSBarry Smith x[oidx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6; 608f1af5d2fSBarry Smith x[oidx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6; 609f1af5d2fSBarry Smith x[oidx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6; 610f1af5d2fSBarry Smith v += 36; 611f1af5d2fSBarry Smith } 612f1af5d2fSBarry Smith x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4; x[4+idx] = s5; 613f1af5d2fSBarry Smith x[5+idx] = s6; 614f1af5d2fSBarry Smith idx += 6; 615f1af5d2fSBarry Smith } 616f1af5d2fSBarry Smith /* backward solve the L^T */ 617f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 618f1af5d2fSBarry Smith v = aa + 36*diag[i] - 36; 619f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 620f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 621f1af5d2fSBarry Smith idt = 6*i; 622f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt]; 623f1af5d2fSBarry Smith s6 = x[5+idt]; 624f1af5d2fSBarry Smith while (nz--) { 625f1af5d2fSBarry Smith idx = 6*(*vi--); 626f1af5d2fSBarry Smith x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6; 627f1af5d2fSBarry Smith x[idx+1] -= v[6]*s1 + v[7]*s2 + v[8]*s3 + v[9]*s4 + v[10]*s5 + v[11]*s6; 628f1af5d2fSBarry Smith x[idx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6; 629f1af5d2fSBarry Smith x[idx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6; 630f1af5d2fSBarry Smith x[idx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6; 631f1af5d2fSBarry Smith x[idx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6; 632f1af5d2fSBarry Smith v -= 36; 633f1af5d2fSBarry Smith } 634f1af5d2fSBarry Smith } 635b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 6361ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 637dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr); 638f1af5d2fSBarry Smith PetscFunctionReturn(0); 639f1af5d2fSBarry Smith } 640f1af5d2fSBarry Smith 6414a2ae208SSatish Balay #undef __FUNCT__ 6424dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_6_NaturalOrdering" 6434dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_6_NaturalOrdering(Mat A,Vec bb,Vec xx) 6448499736aSShri Abhyankar { 6458499736aSShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 6468499736aSShri Abhyankar PetscErrorCode ierr; 647b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 6488499736aSShri Abhyankar PetscInt nz,idx,idt,j,i,oidx; 649b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 650b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 651b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x; 652b3260449SShri Abhyankar const PetscScalar *b; 6538499736aSShri Abhyankar 6548499736aSShri Abhyankar PetscFunctionBegin; 6558499736aSShri Abhyankar ierr = VecCopy(bb,xx);CHKERRQ(ierr); 656b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 6578499736aSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 6588499736aSShri Abhyankar 6598499736aSShri Abhyankar /* forward solve the U^T */ 6608499736aSShri Abhyankar idx = 0; 6618499736aSShri Abhyankar for (i=0; i<n; i++) { 6628499736aSShri Abhyankar v = aa + bs2*diag[i]; 6638499736aSShri Abhyankar /* multiply by the inverse of the block diagonal */ 6648499736aSShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; 6658499736aSShri Abhyankar x5 = x[4+idx]; x6 = x[5+idx]; 6668499736aSShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6; 6678499736aSShri Abhyankar s2 = v[6]*x1 + v[7]*x2 + v[8]*x3 + v[9]*x4 + v[10]*x5 + v[11]*x6; 6688499736aSShri Abhyankar s3 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4 + v[16]*x5 + v[17]*x6; 6698499736aSShri Abhyankar s4 = v[18]*x1 + v[19]*x2 + v[20]*x3 + v[21]*x4 + v[22]*x5 + v[23]*x6; 6708499736aSShri Abhyankar s5 = v[24]*x1 + v[25]*x2 + v[26]*x3 + v[27]*x4 + v[28]*x5 + v[29]*x6; 6718499736aSShri Abhyankar s6 = v[30]*x1 + v[31]*x2 + v[32]*x3 + v[33]*x4 + v[34]*x5 + v[35]*x6; 6728499736aSShri Abhyankar v -= bs2; 6738499736aSShri Abhyankar 6748499736aSShri Abhyankar vi = aj + diag[i] - 1; 6758499736aSShri Abhyankar nz = diag[i] - diag[i+1] - 1; 6768499736aSShri Abhyankar for(j=0;j>-nz;j--){ 6778499736aSShri Abhyankar oidx = bs*vi[j]; 6788499736aSShri Abhyankar x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6; 6798499736aSShri Abhyankar x[oidx+1] -= v[6]*s1 + v[7]*s2 + v[8]*s3 + v[9]*s4 + v[10]*s5 + v[11]*s6; 6808499736aSShri Abhyankar x[oidx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6; 6818499736aSShri Abhyankar x[oidx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6; 6828499736aSShri Abhyankar x[oidx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6; 6838499736aSShri Abhyankar x[oidx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6; 6848499736aSShri Abhyankar v -= bs2; 6858499736aSShri Abhyankar } 6868499736aSShri Abhyankar x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3; x[3+idx] = s4; x[4+idx] = s5; 6878499736aSShri Abhyankar x[5+idx] = s6; 6888499736aSShri Abhyankar idx += bs; 6898499736aSShri Abhyankar } 6908499736aSShri Abhyankar /* backward solve the L^T */ 6918499736aSShri Abhyankar for (i=n-1; i>=0; i--){ 6928499736aSShri Abhyankar v = aa + bs2*ai[i]; 6938499736aSShri Abhyankar vi = aj + ai[i]; 6948499736aSShri Abhyankar nz = ai[i+1] - ai[i]; 6958499736aSShri Abhyankar idt = bs*i; 6968499736aSShri Abhyankar s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt]; s4 = x[3+idt]; s5 = x[4+idt]; 6978499736aSShri Abhyankar s6 = x[5+idt]; 6988499736aSShri Abhyankar for(j=0;j<nz;j++){ 6998499736aSShri Abhyankar idx = bs*vi[j]; 7008499736aSShri Abhyankar x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6; 7018499736aSShri Abhyankar x[idx+1] -= v[6]*s1 + v[7]*s2 + v[8]*s3 + v[9]*s4 + v[10]*s5 + v[11]*s6; 7028499736aSShri Abhyankar x[idx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6; 7038499736aSShri Abhyankar x[idx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6; 7048499736aSShri Abhyankar x[idx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6; 7058499736aSShri Abhyankar x[idx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6; 7068499736aSShri Abhyankar v += bs2; 7078499736aSShri Abhyankar } 7088499736aSShri Abhyankar } 709b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 7108499736aSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 7118499736aSShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 7128499736aSShri Abhyankar PetscFunctionReturn(0); 7138499736aSShri Abhyankar } 7148499736aSShri Abhyankar 7158499736aSShri Abhyankar #undef __FUNCT__ 71606e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_7_NaturalOrdering_inplace" 71706e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_7_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 718f1af5d2fSBarry Smith { 719f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 720dfbe8321SBarry Smith PetscErrorCode ierr; 721b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 722b3260449SShri Abhyankar PetscInt i,nz,idx,idt,oidx; 723b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 724b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x; 725b3260449SShri Abhyankar const PetscScalar *b; 726f1af5d2fSBarry Smith 727f1af5d2fSBarry Smith PetscFunctionBegin; 728ef66eb69SBarry Smith ierr = VecCopy(bb,xx);CHKERRQ(ierr); 729b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 7301ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 731f1af5d2fSBarry Smith 732f1af5d2fSBarry Smith /* forward solve the U^T */ 733f1af5d2fSBarry Smith idx = 0; 734f1af5d2fSBarry Smith for (i=0; i<n; i++) { 735f1af5d2fSBarry Smith 736f1af5d2fSBarry Smith v = aa + 49*diag[i]; 737f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 738ef66eb69SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx]; 739ef66eb69SBarry Smith x6 = x[5+idx]; x7 = x[6+idx]; 740f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6 + v[6]*x7; 741f1af5d2fSBarry Smith s2 = v[7]*x1 + v[8]*x2 + v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7; 742f1af5d2fSBarry Smith s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7; 743f1af5d2fSBarry Smith s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7; 744f1af5d2fSBarry Smith s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7; 745f1af5d2fSBarry Smith s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7; 746f1af5d2fSBarry Smith s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7; 747f1af5d2fSBarry Smith v += 49; 748f1af5d2fSBarry Smith 749f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 750f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 751f1af5d2fSBarry Smith while (nz--) { 752f1af5d2fSBarry Smith oidx = 7*(*vi++); 753f1af5d2fSBarry Smith x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 754f1af5d2fSBarry 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; 755f1af5d2fSBarry 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; 756f1af5d2fSBarry 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; 757f1af5d2fSBarry 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; 758f1af5d2fSBarry 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; 759f1af5d2fSBarry 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; 760f1af5d2fSBarry Smith v += 49; 761f1af5d2fSBarry Smith } 762f1af5d2fSBarry Smith x[idx] = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4; x[4+idx] = s5; 763f1af5d2fSBarry Smith x[5+idx] = s6;x[6+idx] = s7; 764f1af5d2fSBarry Smith idx += 7; 765f1af5d2fSBarry Smith } 766f1af5d2fSBarry Smith /* backward solve the L^T */ 767f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 768f1af5d2fSBarry Smith v = aa + 49*diag[i] - 49; 769f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 770f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 771f1af5d2fSBarry Smith idt = 7*i; 772f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt]; 773f1af5d2fSBarry Smith s6 = x[5+idt];s7 = x[6+idt]; 774f1af5d2fSBarry Smith while (nz--) { 775f1af5d2fSBarry Smith idx = 7*(*vi--); 776f1af5d2fSBarry Smith x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 777f1af5d2fSBarry 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; 778f1af5d2fSBarry 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; 779f1af5d2fSBarry 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; 780f1af5d2fSBarry 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; 781f1af5d2fSBarry 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; 782f1af5d2fSBarry 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; 783f1af5d2fSBarry Smith v -= 49; 784f1af5d2fSBarry Smith } 785f1af5d2fSBarry Smith } 786b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 7871ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 788dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr); 789f1af5d2fSBarry Smith PetscFunctionReturn(0); 790f1af5d2fSBarry Smith } 7918499736aSShri Abhyankar #undef __FUNCT__ 7924dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_7_NaturalOrdering" 7934dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_7_NaturalOrdering(Mat A,Vec bb,Vec xx) 7948499736aSShri Abhyankar { 7958499736aSShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 7968499736aSShri Abhyankar PetscErrorCode ierr; 797b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 7988499736aSShri Abhyankar PetscInt nz,idx,idt,j,i,oidx; 799b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 800b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 801b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x; 802b3260449SShri Abhyankar const PetscScalar *b; 8038499736aSShri Abhyankar 8048499736aSShri Abhyankar PetscFunctionBegin; 8058499736aSShri Abhyankar ierr = VecCopy(bb,xx);CHKERRQ(ierr); 806b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 8078499736aSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 8088499736aSShri Abhyankar 8098499736aSShri Abhyankar /* forward solve the U^T */ 8108499736aSShri Abhyankar idx = 0; 8118499736aSShri Abhyankar for (i=0; i<n; i++) { 8128499736aSShri Abhyankar v = aa + bs2*diag[i]; 8138499736aSShri Abhyankar /* multiply by the inverse of the block diagonal */ 8148499736aSShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; x4 = x[3+idx]; 8158499736aSShri Abhyankar x5 = x[4+idx]; x6 = x[5+idx]; x7 = x[6+idx]; 8168499736aSShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6 + v[6]*x7; 8178499736aSShri Abhyankar s2 = v[7]*x1 + v[8]*x2 + v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7; 8188499736aSShri Abhyankar s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7; 8198499736aSShri Abhyankar s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7; 8208499736aSShri Abhyankar s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7; 8218499736aSShri Abhyankar s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7; 8228499736aSShri Abhyankar s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7; 8238499736aSShri Abhyankar v -= bs2; 8248499736aSShri Abhyankar vi = aj + diag[i] - 1; 8258499736aSShri Abhyankar nz = diag[i] - diag[i+1] - 1; 8268499736aSShri Abhyankar for(j=0;j>-nz;j--){ 8278499736aSShri Abhyankar oidx = bs*vi[j]; 8288499736aSShri Abhyankar x[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 8298499736aSShri Abhyankar x[oidx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 8308499736aSShri Abhyankar x[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 8318499736aSShri Abhyankar x[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 8328499736aSShri Abhyankar x[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 8338499736aSShri Abhyankar x[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 8348499736aSShri Abhyankar x[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 8358499736aSShri Abhyankar v -= bs2; 8368499736aSShri Abhyankar } 8378499736aSShri Abhyankar x[idx] = s1; x[1+idx] = s2; x[2+idx] = s3; x[3+idx] = s4; x[4+idx] = s5; 8388499736aSShri Abhyankar x[5+idx] = s6; x[6+idx] = s7; 8398499736aSShri Abhyankar idx += bs; 8408499736aSShri Abhyankar } 8418499736aSShri Abhyankar /* backward solve the L^T */ 8428499736aSShri Abhyankar for (i=n-1; i>=0; i--){ 8438499736aSShri Abhyankar v = aa + bs2*ai[i]; 8448499736aSShri Abhyankar vi = aj + ai[i]; 8458499736aSShri Abhyankar nz = ai[i+1] - ai[i]; 8468499736aSShri Abhyankar idt = bs*i; 8478499736aSShri Abhyankar s1 = x[idt]; s2 = x[1+idt]; s3 = x[2+idt]; s4 = x[3+idt]; s5 = x[4+idt]; 8488499736aSShri Abhyankar s6 = x[5+idt]; s7 = x[6+idt]; 8498499736aSShri Abhyankar for(j=0;j<nz;j++){ 8508499736aSShri Abhyankar idx = bs*vi[j]; 8518499736aSShri Abhyankar x[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 8528499736aSShri Abhyankar x[idx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 8538499736aSShri Abhyankar x[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 8548499736aSShri Abhyankar x[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 8558499736aSShri Abhyankar x[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 8568499736aSShri Abhyankar x[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 8578499736aSShri Abhyankar x[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 8588499736aSShri Abhyankar v += bs2; 8598499736aSShri Abhyankar } 8608499736aSShri Abhyankar } 861b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 8628499736aSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 8638499736aSShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 8648499736aSShri Abhyankar PetscFunctionReturn(0); 8658499736aSShri Abhyankar } 866f1af5d2fSBarry Smith 867f1af5d2fSBarry Smith /*---------------------------------------------------------------------------------------------*/ 8684a2ae208SSatish Balay #undef __FUNCT__ 86906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_1_inplace" 87006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_1_inplace(Mat A,Vec bb,Vec xx) 871f1af5d2fSBarry Smith { 872f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 873f1af5d2fSBarry Smith IS iscol=a->col,isrow=a->row; 8746849ba73SBarry Smith PetscErrorCode ierr; 8755d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout; 876b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 877b3260449SShri Abhyankar PetscInt i,nz; 878b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 879b3260449SShri Abhyankar PetscScalar s1,*x,*t; 880b3260449SShri Abhyankar const PetscScalar *b; 881f1af5d2fSBarry Smith 882f1af5d2fSBarry Smith PetscFunctionBegin; 883b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 8841ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 885f1af5d2fSBarry Smith t = a->solve_work; 886f1af5d2fSBarry Smith 887f1af5d2fSBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 888f1af5d2fSBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 889f1af5d2fSBarry Smith 890f1af5d2fSBarry Smith /* copy the b into temp work space according to permutation */ 891f1af5d2fSBarry Smith for (i=0; i<n; i++) { 892f1af5d2fSBarry Smith t[i] = b[c[i]]; 893f1af5d2fSBarry Smith } 894f1af5d2fSBarry Smith 895f1af5d2fSBarry Smith /* forward solve the U^T */ 896f1af5d2fSBarry Smith for (i=0; i<n; i++) { 897f1af5d2fSBarry Smith 898f1af5d2fSBarry Smith v = aa + diag[i]; 899f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 900f1af5d2fSBarry Smith s1 = (*v++)*t[i]; 901f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 902f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 903f1af5d2fSBarry Smith while (nz--) { 904f1af5d2fSBarry Smith t[*vi++] -= (*v++)*s1; 905f1af5d2fSBarry Smith } 906f1af5d2fSBarry Smith t[i] = s1; 907f1af5d2fSBarry Smith } 908f1af5d2fSBarry Smith /* backward solve the L^T */ 909f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 910f1af5d2fSBarry Smith v = aa + diag[i] - 1; 911f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 912f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 913f1af5d2fSBarry Smith s1 = t[i]; 914f1af5d2fSBarry Smith while (nz--) { 915f1af5d2fSBarry Smith t[*vi--] -= (*v--)*s1; 916f1af5d2fSBarry Smith } 917f1af5d2fSBarry Smith } 918f1af5d2fSBarry Smith 919f1af5d2fSBarry Smith /* copy t into x according to permutation */ 920f1af5d2fSBarry Smith for (i=0; i<n; i++) { 921f1af5d2fSBarry Smith x[r[i]] = t[i]; 922f1af5d2fSBarry Smith } 923f1af5d2fSBarry Smith 924f1af5d2fSBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 925f1af5d2fSBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 926b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 9271ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 928dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*(a->nz) - A->cmap->n);CHKERRQ(ierr); 929f1af5d2fSBarry Smith PetscFunctionReturn(0); 930f1af5d2fSBarry Smith } 931f1af5d2fSBarry Smith 9324a2ae208SSatish Balay #undef __FUNCT__ 93306e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_2_inplace" 93406e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_2_inplace(Mat A,Vec bb,Vec xx) 935f1af5d2fSBarry Smith { 936f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 937f1af5d2fSBarry Smith IS iscol=a->col,isrow=a->row; 9386849ba73SBarry Smith PetscErrorCode ierr; 9395d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout; 940b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 941b3260449SShri Abhyankar PetscInt i,nz,idx,idt,ii,ic,ir,oidx; 942b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 943b3260449SShri Abhyankar PetscScalar s1,s2,x1,x2,*x,*t; 944b3260449SShri Abhyankar const PetscScalar *b; 945f1af5d2fSBarry Smith 946f1af5d2fSBarry Smith PetscFunctionBegin; 947b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 9481ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 949f1af5d2fSBarry Smith t = a->solve_work; 950f1af5d2fSBarry Smith 951f1af5d2fSBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 952f1af5d2fSBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 953f1af5d2fSBarry Smith 954f1af5d2fSBarry Smith /* copy the b into temp work space according to permutation */ 955f1af5d2fSBarry Smith ii = 0; 956f1af5d2fSBarry Smith for (i=0; i<n; i++) { 957f1af5d2fSBarry Smith ic = 2*c[i]; 958f1af5d2fSBarry Smith t[ii] = b[ic]; 959f1af5d2fSBarry Smith t[ii+1] = b[ic+1]; 960f1af5d2fSBarry Smith ii += 2; 961f1af5d2fSBarry Smith } 962f1af5d2fSBarry Smith 963f1af5d2fSBarry Smith /* forward solve the U^T */ 964f1af5d2fSBarry Smith idx = 0; 965f1af5d2fSBarry Smith for (i=0; i<n; i++) { 966f1af5d2fSBarry Smith 967f1af5d2fSBarry Smith v = aa + 4*diag[i]; 968f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 969f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; 970f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2; 971f1af5d2fSBarry Smith s2 = v[2]*x1 + v[3]*x2; 972f1af5d2fSBarry Smith v += 4; 973f1af5d2fSBarry Smith 974f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 975f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 976f1af5d2fSBarry Smith while (nz--) { 977f1af5d2fSBarry Smith oidx = 2*(*vi++); 978f1af5d2fSBarry Smith t[oidx] -= v[0]*s1 + v[1]*s2; 979f1af5d2fSBarry Smith t[oidx+1] -= v[2]*s1 + v[3]*s2; 980f1af5d2fSBarry Smith v += 4; 981f1af5d2fSBarry Smith } 982f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; 983f1af5d2fSBarry Smith idx += 2; 984f1af5d2fSBarry Smith } 985f1af5d2fSBarry Smith /* backward solve the L^T */ 986f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 987f1af5d2fSBarry Smith v = aa + 4*diag[i] - 4; 988f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 989f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 990f1af5d2fSBarry Smith idt = 2*i; 991f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; 992f1af5d2fSBarry Smith while (nz--) { 993f1af5d2fSBarry Smith idx = 2*(*vi--); 994f1af5d2fSBarry Smith t[idx] -= v[0]*s1 + v[1]*s2; 995f1af5d2fSBarry Smith t[idx+1] -= v[2]*s1 + v[3]*s2; 996f1af5d2fSBarry Smith v -= 4; 997f1af5d2fSBarry Smith } 998f1af5d2fSBarry Smith } 999f1af5d2fSBarry Smith 1000f1af5d2fSBarry Smith /* copy t into x according to permutation */ 1001f1af5d2fSBarry Smith ii = 0; 1002f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1003f1af5d2fSBarry Smith ir = 2*r[i]; 1004f1af5d2fSBarry Smith x[ir] = t[ii]; 1005f1af5d2fSBarry Smith x[ir+1] = t[ii+1]; 1006f1af5d2fSBarry Smith ii += 2; 1007f1af5d2fSBarry Smith } 1008f1af5d2fSBarry Smith 1009f1af5d2fSBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 1010f1af5d2fSBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1011b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 10121ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 1013dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr); 1014f1af5d2fSBarry Smith PetscFunctionReturn(0); 1015f1af5d2fSBarry Smith } 1016f1af5d2fSBarry Smith 10174a2ae208SSatish Balay #undef __FUNCT__ 10184dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_2" 10194dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_2(Mat A,Vec bb,Vec xx) 102032121132SShri Abhyankar { 102132121132SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 102232121132SShri Abhyankar PetscErrorCode ierr; 102332121132SShri Abhyankar IS iscol=a->col,isrow=a->row; 1024b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 102532121132SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 102632121132SShri Abhyankar PetscInt nz,idx,idt,j,i,oidx,ii,ic,ir; 1027b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 1028b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1029b3260449SShri Abhyankar PetscScalar s1,s2,x1,x2,*x,*t; 1030b3260449SShri Abhyankar const PetscScalar *b; 103132121132SShri Abhyankar 103232121132SShri Abhyankar PetscFunctionBegin; 1033b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 103432121132SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 103532121132SShri Abhyankar t = a->solve_work; 103632121132SShri Abhyankar 103732121132SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 103832121132SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 103932121132SShri Abhyankar 104032121132SShri Abhyankar /* copy b into temp work space according to permutation */ 104132121132SShri Abhyankar for(i=0;i<n;i++){ 104232121132SShri Abhyankar ii = bs*i; ic = bs*c[i]; 104332121132SShri Abhyankar t[ii] = b[ic]; t[ii+1] = b[ic+1]; 104432121132SShri Abhyankar } 104532121132SShri Abhyankar 104632121132SShri Abhyankar /* forward solve the U^T */ 104732121132SShri Abhyankar idx = 0; 104832121132SShri Abhyankar for (i=0; i<n; i++) { 104932121132SShri Abhyankar v = aa + bs2*diag[i]; 105032121132SShri Abhyankar /* multiply by the inverse of the block diagonal */ 105132121132SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; 105232121132SShri Abhyankar s1 = v[0]*x1 + v[1]*x2; 105332121132SShri Abhyankar s2 = v[2]*x1 + v[3]*x2; 105432121132SShri Abhyankar v -= bs2; 105532121132SShri Abhyankar 105632121132SShri Abhyankar vi = aj + diag[i] - 1; 105732121132SShri Abhyankar nz = diag[i] - diag[i+1] - 1; 105832121132SShri Abhyankar for(j=0;j>-nz;j--){ 105932121132SShri Abhyankar oidx = bs*vi[j]; 106032121132SShri Abhyankar t[oidx] -= v[0]*s1 + v[1]*s2; 106132121132SShri Abhyankar t[oidx+1] -= v[2]*s1 + v[3]*s2; 106232121132SShri Abhyankar v -= bs2; 106332121132SShri Abhyankar } 106432121132SShri Abhyankar t[idx] = s1;t[1+idx] = s2; 106532121132SShri Abhyankar idx += bs; 106632121132SShri Abhyankar } 106732121132SShri Abhyankar /* backward solve the L^T */ 106832121132SShri Abhyankar for (i=n-1; i>=0; i--){ 106932121132SShri Abhyankar v = aa + bs2*ai[i]; 107032121132SShri Abhyankar vi = aj + ai[i]; 107132121132SShri Abhyankar nz = ai[i+1] - ai[i]; 107232121132SShri Abhyankar idt = bs*i; 107332121132SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; 107432121132SShri Abhyankar for(j=0;j<nz;j++){ 107532121132SShri Abhyankar idx = bs*vi[j]; 107632121132SShri Abhyankar t[idx] -= v[0]*s1 + v[1]*s2; 107732121132SShri Abhyankar t[idx+1] -= v[2]*s1 + v[3]*s2; 107832121132SShri Abhyankar v += bs2; 107932121132SShri Abhyankar } 108032121132SShri Abhyankar } 108132121132SShri Abhyankar 108232121132SShri Abhyankar /* copy t into x according to permutation */ 108332121132SShri Abhyankar for(i=0;i<n;i++){ 108432121132SShri Abhyankar ii = bs*i; ir = bs*r[i]; 108532121132SShri Abhyankar x[ir] = t[ii]; x[ir+1] = t[ii+1]; 108632121132SShri Abhyankar } 108732121132SShri Abhyankar 108832121132SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 108932121132SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1090b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 109132121132SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 109232121132SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 109332121132SShri Abhyankar PetscFunctionReturn(0); 109432121132SShri Abhyankar } 109532121132SShri Abhyankar 109632121132SShri Abhyankar #undef __FUNCT__ 109706e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_3_inplace" 109806e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_3_inplace(Mat A,Vec bb,Vec xx) 1099f1af5d2fSBarry Smith { 1100f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 1101f1af5d2fSBarry Smith IS iscol=a->col,isrow=a->row; 11026849ba73SBarry Smith PetscErrorCode ierr; 11035d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout; 1104b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 1105b3260449SShri Abhyankar PetscInt i,nz,idx,idt,ii,ic,ir,oidx; 1106b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1107b3260449SShri Abhyankar PetscScalar s1,s2,s3,x1,x2,x3,*x,*t; 1108b3260449SShri Abhyankar const PetscScalar *b; 1109f1af5d2fSBarry Smith 1110f1af5d2fSBarry Smith PetscFunctionBegin; 1111b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 11121ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 1113f1af5d2fSBarry Smith t = a->solve_work; 1114f1af5d2fSBarry Smith 1115f1af5d2fSBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 1116f1af5d2fSBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 1117f1af5d2fSBarry Smith 1118f1af5d2fSBarry Smith /* copy the b into temp work space according to permutation */ 1119f1af5d2fSBarry Smith ii = 0; 1120f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1121f1af5d2fSBarry Smith ic = 3*c[i]; 1122f1af5d2fSBarry Smith t[ii] = b[ic]; 1123f1af5d2fSBarry Smith t[ii+1] = b[ic+1]; 1124f1af5d2fSBarry Smith t[ii+2] = b[ic+2]; 1125f1af5d2fSBarry Smith ii += 3; 1126f1af5d2fSBarry Smith } 1127f1af5d2fSBarry Smith 1128f1af5d2fSBarry Smith /* forward solve the U^T */ 1129f1af5d2fSBarry Smith idx = 0; 1130f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1131f1af5d2fSBarry Smith 1132f1af5d2fSBarry Smith v = aa + 9*diag[i]; 1133f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 1134f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; 1135f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3; 1136f1af5d2fSBarry Smith s2 = v[3]*x1 + v[4]*x2 + v[5]*x3; 1137f1af5d2fSBarry Smith s3 = v[6]*x1 + v[7]*x2 + v[8]*x3; 1138f1af5d2fSBarry Smith v += 9; 1139f1af5d2fSBarry Smith 1140f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 1141f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 1142f1af5d2fSBarry Smith while (nz--) { 1143f1af5d2fSBarry Smith oidx = 3*(*vi++); 1144f1af5d2fSBarry Smith t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3; 1145f1af5d2fSBarry Smith t[oidx+1] -= v[3]*s1 + v[4]*s2 + v[5]*s3; 1146f1af5d2fSBarry Smith t[oidx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3; 1147f1af5d2fSBarry Smith v += 9; 1148f1af5d2fSBarry Smith } 1149f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3; 1150f1af5d2fSBarry Smith idx += 3; 1151f1af5d2fSBarry Smith } 1152f1af5d2fSBarry Smith /* backward solve the L^T */ 1153f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 1154f1af5d2fSBarry Smith v = aa + 9*diag[i] - 9; 1155f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 1156f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 1157f1af5d2fSBarry Smith idt = 3*i; 1158f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; 1159f1af5d2fSBarry Smith while (nz--) { 1160f1af5d2fSBarry Smith idx = 3*(*vi--); 1161f1af5d2fSBarry Smith t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3; 1162f1af5d2fSBarry Smith t[idx+1] -= v[3]*s1 + v[4]*s2 + v[5]*s3; 1163f1af5d2fSBarry Smith t[idx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3; 1164f1af5d2fSBarry Smith v -= 9; 1165f1af5d2fSBarry Smith } 1166f1af5d2fSBarry Smith } 1167f1af5d2fSBarry Smith 1168f1af5d2fSBarry Smith /* copy t into x according to permutation */ 1169f1af5d2fSBarry Smith ii = 0; 1170f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1171f1af5d2fSBarry Smith ir = 3*r[i]; 1172f1af5d2fSBarry Smith x[ir] = t[ii]; 1173f1af5d2fSBarry Smith x[ir+1] = t[ii+1]; 1174f1af5d2fSBarry Smith x[ir+2] = t[ii+2]; 1175f1af5d2fSBarry Smith ii += 3; 1176f1af5d2fSBarry Smith } 1177f1af5d2fSBarry Smith 1178f1af5d2fSBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 1179f1af5d2fSBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1180b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 11811ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 1182dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr); 1183f1af5d2fSBarry Smith PetscFunctionReturn(0); 1184f1af5d2fSBarry Smith } 1185f1af5d2fSBarry Smith 11864a2ae208SSatish Balay #undef __FUNCT__ 11874dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_3" 11884dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_3(Mat A,Vec bb,Vec xx) 118932121132SShri Abhyankar { 119032121132SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 119132121132SShri Abhyankar PetscErrorCode ierr; 119232121132SShri Abhyankar IS iscol=a->col,isrow=a->row; 1193b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 119432121132SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 119532121132SShri Abhyankar PetscInt nz,idx,idt,j,i,oidx,ii,ic,ir; 1196b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 1197b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1198b3260449SShri Abhyankar PetscScalar s1,s2,s3,x1,x2,x3,*x,*t; 1199b3260449SShri Abhyankar const PetscScalar *b; 120032121132SShri Abhyankar 120132121132SShri Abhyankar PetscFunctionBegin; 1202b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 120332121132SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 120432121132SShri Abhyankar t = a->solve_work; 120532121132SShri Abhyankar 120632121132SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 120732121132SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 120832121132SShri Abhyankar 120932121132SShri Abhyankar /* copy b into temp work space according to permutation */ 121032121132SShri Abhyankar for(i=0;i<n;i++){ 121132121132SShri Abhyankar ii = bs*i; ic = bs*c[i]; 121232121132SShri Abhyankar t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; 121332121132SShri Abhyankar } 121432121132SShri Abhyankar 121532121132SShri Abhyankar /* forward solve the U^T */ 121632121132SShri Abhyankar idx = 0; 121732121132SShri Abhyankar for (i=0; i<n; i++) { 121832121132SShri Abhyankar v = aa + bs2*diag[i]; 121932121132SShri Abhyankar /* multiply by the inverse of the block diagonal */ 122032121132SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; 122132121132SShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3; 122232121132SShri Abhyankar s2 = v[3]*x1 + v[4]*x2 + v[5]*x3; 122332121132SShri Abhyankar s3 = v[6]*x1 + v[7]*x2 + v[8]*x3; 122432121132SShri Abhyankar v -= bs2; 122532121132SShri Abhyankar 122632121132SShri Abhyankar vi = aj + diag[i] - 1; 122732121132SShri Abhyankar nz = diag[i] - diag[i+1] - 1; 122832121132SShri Abhyankar for(j=0;j>-nz;j--){ 122932121132SShri Abhyankar oidx = bs*vi[j]; 123032121132SShri Abhyankar t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3; 123132121132SShri Abhyankar t[oidx+1] -= v[3]*s1 + v[4]*s2 + v[5]*s3; 123232121132SShri Abhyankar t[oidx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3; 123332121132SShri Abhyankar v -= bs2; 123432121132SShri Abhyankar } 123532121132SShri Abhyankar t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3; 123632121132SShri Abhyankar idx += bs; 123732121132SShri Abhyankar } 123832121132SShri Abhyankar /* backward solve the L^T */ 123932121132SShri Abhyankar for (i=n-1; i>=0; i--){ 124032121132SShri Abhyankar v = aa + bs2*ai[i]; 124132121132SShri Abhyankar vi = aj + ai[i]; 124232121132SShri Abhyankar nz = ai[i+1] - ai[i]; 124332121132SShri Abhyankar idt = bs*i; 124432121132SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; 124532121132SShri Abhyankar for(j=0;j<nz;j++){ 124632121132SShri Abhyankar idx = bs*vi[j]; 124732121132SShri Abhyankar t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3; 124832121132SShri Abhyankar t[idx+1] -= v[3]*s1 + v[4]*s2 + v[5]*s3; 124932121132SShri Abhyankar t[idx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3; 125032121132SShri Abhyankar v += bs2; 125132121132SShri Abhyankar } 125232121132SShri Abhyankar } 125332121132SShri Abhyankar 125432121132SShri Abhyankar /* copy t into x according to permutation */ 125532121132SShri Abhyankar for(i=0;i<n;i++){ 125632121132SShri Abhyankar ii = bs*i; ir = bs*r[i]; 125732121132SShri Abhyankar x[ir] = t[ii]; x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2]; 125832121132SShri Abhyankar } 125932121132SShri Abhyankar 126032121132SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 126132121132SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1262b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 126332121132SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 126432121132SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 126532121132SShri Abhyankar PetscFunctionReturn(0); 126632121132SShri Abhyankar } 126732121132SShri Abhyankar 126832121132SShri Abhyankar #undef __FUNCT__ 126906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_4_inplace" 127006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_4_inplace(Mat A,Vec bb,Vec xx) 1271f1af5d2fSBarry Smith { 1272f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 1273f1af5d2fSBarry Smith IS iscol=a->col,isrow=a->row; 12746849ba73SBarry Smith PetscErrorCode ierr; 12755d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout; 1276b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 1277b3260449SShri Abhyankar PetscInt i,nz,idx,idt,ii,ic,ir,oidx; 1278b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1279b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,x1,x2,x3,x4,*x,*t; 1280b3260449SShri Abhyankar const PetscScalar *b; 1281f1af5d2fSBarry Smith 1282f1af5d2fSBarry Smith PetscFunctionBegin; 1283b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 12841ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 1285f1af5d2fSBarry Smith t = a->solve_work; 1286f1af5d2fSBarry Smith 1287f1af5d2fSBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 1288f1af5d2fSBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 1289f1af5d2fSBarry Smith 1290f1af5d2fSBarry Smith /* copy the b into temp work space according to permutation */ 1291f1af5d2fSBarry Smith ii = 0; 1292f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1293f1af5d2fSBarry Smith ic = 4*c[i]; 1294f1af5d2fSBarry Smith t[ii] = b[ic]; 1295f1af5d2fSBarry Smith t[ii+1] = b[ic+1]; 1296f1af5d2fSBarry Smith t[ii+2] = b[ic+2]; 1297f1af5d2fSBarry Smith t[ii+3] = b[ic+3]; 1298f1af5d2fSBarry Smith ii += 4; 1299f1af5d2fSBarry Smith } 1300f1af5d2fSBarry Smith 1301f1af5d2fSBarry Smith /* forward solve the U^T */ 1302f1af5d2fSBarry Smith idx = 0; 1303f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1304f1af5d2fSBarry Smith 1305f1af5d2fSBarry Smith v = aa + 16*diag[i]; 1306f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 1307f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; 1308f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4; 1309f1af5d2fSBarry Smith s2 = v[4]*x1 + v[5]*x2 + v[6]*x3 + v[7]*x4; 1310f1af5d2fSBarry Smith s3 = v[8]*x1 + v[9]*x2 + v[10]*x3 + v[11]*x4; 1311f1af5d2fSBarry Smith s4 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4; 1312f1af5d2fSBarry Smith v += 16; 1313f1af5d2fSBarry Smith 1314f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 1315f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 1316f1af5d2fSBarry Smith while (nz--) { 1317f1af5d2fSBarry Smith oidx = 4*(*vi++); 1318f1af5d2fSBarry Smith t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4; 1319f1af5d2fSBarry Smith t[oidx+1] -= v[4]*s1 + v[5]*s2 + v[6]*s3 + v[7]*s4; 1320f1af5d2fSBarry Smith t[oidx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4; 1321f1af5d2fSBarry Smith t[oidx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4; 1322f1af5d2fSBarry Smith v += 16; 1323f1af5d2fSBarry Smith } 1324f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3;t[3+idx] = s4; 1325f1af5d2fSBarry Smith idx += 4; 1326f1af5d2fSBarry Smith } 1327f1af5d2fSBarry Smith /* backward solve the L^T */ 1328f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 1329f1af5d2fSBarry Smith v = aa + 16*diag[i] - 16; 1330f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 1331f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 1332f1af5d2fSBarry Smith idt = 4*i; 1333f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt];s4 = t[3+idt]; 1334f1af5d2fSBarry Smith while (nz--) { 1335f1af5d2fSBarry Smith idx = 4*(*vi--); 1336f1af5d2fSBarry Smith t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4; 1337f1af5d2fSBarry Smith t[idx+1] -= v[4]*s1 + v[5]*s2 + v[6]*s3 + v[7]*s4; 1338f1af5d2fSBarry Smith t[idx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4; 1339f1af5d2fSBarry Smith t[idx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4; 1340f1af5d2fSBarry Smith v -= 16; 1341f1af5d2fSBarry Smith } 1342f1af5d2fSBarry Smith } 1343f1af5d2fSBarry Smith 1344f1af5d2fSBarry Smith /* copy t into x according to permutation */ 1345f1af5d2fSBarry Smith ii = 0; 1346f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1347f1af5d2fSBarry Smith ir = 4*r[i]; 1348f1af5d2fSBarry Smith x[ir] = t[ii]; 1349f1af5d2fSBarry Smith x[ir+1] = t[ii+1]; 1350f1af5d2fSBarry Smith x[ir+2] = t[ii+2]; 1351f1af5d2fSBarry Smith x[ir+3] = t[ii+3]; 1352f1af5d2fSBarry Smith ii += 4; 1353f1af5d2fSBarry Smith } 1354f1af5d2fSBarry Smith 1355f1af5d2fSBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 1356f1af5d2fSBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1357b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 13581ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 1359dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 1360f1af5d2fSBarry Smith PetscFunctionReturn(0); 1361f1af5d2fSBarry Smith } 1362f1af5d2fSBarry Smith 13634a2ae208SSatish Balay #undef __FUNCT__ 13644dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_4" 13654dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_4(Mat A,Vec bb,Vec xx) 136632121132SShri Abhyankar { 136732121132SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 136832121132SShri Abhyankar PetscErrorCode ierr; 136932121132SShri Abhyankar IS iscol=a->col,isrow=a->row; 1370b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 137132121132SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 137232121132SShri Abhyankar PetscInt nz,idx,idt,j,i,oidx,ii,ic,ir; 1373b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 1374b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1375b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,x1,x2,x3,x4,*x,*t; 1376b3260449SShri Abhyankar const PetscScalar *b; 137732121132SShri Abhyankar 137832121132SShri Abhyankar PetscFunctionBegin; 1379b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 138032121132SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 138132121132SShri Abhyankar t = a->solve_work; 138232121132SShri Abhyankar 138332121132SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 138432121132SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 138532121132SShri Abhyankar 138632121132SShri Abhyankar /* copy b into temp work space according to permutation */ 138732121132SShri Abhyankar for(i=0;i<n;i++){ 138832121132SShri Abhyankar ii = bs*i; ic = bs*c[i]; 138932121132SShri Abhyankar t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; t[ii+3] = b[ic+3]; 139032121132SShri Abhyankar } 139132121132SShri Abhyankar 139232121132SShri Abhyankar /* forward solve the U^T */ 139332121132SShri Abhyankar idx = 0; 139432121132SShri Abhyankar for (i=0; i<n; i++) { 139532121132SShri Abhyankar v = aa + bs2*diag[i]; 139632121132SShri Abhyankar /* multiply by the inverse of the block diagonal */ 139732121132SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; 139832121132SShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4; 139932121132SShri Abhyankar s2 = v[4]*x1 + v[5]*x2 + v[6]*x3 + v[7]*x4; 140032121132SShri Abhyankar s3 = v[8]*x1 + v[9]*x2 + v[10]*x3 + v[11]*x4; 140132121132SShri Abhyankar s4 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4; 140232121132SShri Abhyankar v -= bs2; 140332121132SShri Abhyankar 140432121132SShri Abhyankar vi = aj + diag[i] - 1; 140532121132SShri Abhyankar nz = diag[i] - diag[i+1] - 1; 140632121132SShri Abhyankar for(j=0;j>-nz;j--){ 140732121132SShri Abhyankar oidx = bs*vi[j]; 140832121132SShri Abhyankar t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4; 140932121132SShri Abhyankar t[oidx+1] -= v[4]*s1 + v[5]*s2 + v[6]*s3 + v[7]*s4; 141032121132SShri Abhyankar t[oidx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4; 141132121132SShri Abhyankar t[oidx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4; 141232121132SShri Abhyankar v -= bs2; 141332121132SShri Abhyankar } 141432121132SShri Abhyankar t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3; t[3+idx] = s4; 141532121132SShri Abhyankar idx += bs; 141632121132SShri Abhyankar } 141732121132SShri Abhyankar /* backward solve the L^T */ 141832121132SShri Abhyankar for (i=n-1; i>=0; i--){ 141932121132SShri Abhyankar v = aa + bs2*ai[i]; 142032121132SShri Abhyankar vi = aj + ai[i]; 142132121132SShri Abhyankar nz = ai[i+1] - ai[i]; 142232121132SShri Abhyankar idt = bs*i; 142332121132SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; s4 = t[3+idt]; 142432121132SShri Abhyankar for(j=0;j<nz;j++){ 142532121132SShri Abhyankar idx = bs*vi[j]; 142632121132SShri Abhyankar t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4; 142732121132SShri Abhyankar t[idx+1] -= v[4]*s1 + v[5]*s2 + v[6]*s3 + v[7]*s4; 142832121132SShri Abhyankar t[idx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4; 142932121132SShri Abhyankar t[idx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4; 143032121132SShri Abhyankar v += bs2; 143132121132SShri Abhyankar } 143232121132SShri Abhyankar } 143332121132SShri Abhyankar 143432121132SShri Abhyankar /* copy t into x according to permutation */ 143532121132SShri Abhyankar for(i=0;i<n;i++){ 143632121132SShri Abhyankar ii = bs*i; ir = bs*r[i]; 143732121132SShri Abhyankar x[ir] = t[ii]; x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2]; x[ir+3] = t[ii+3]; 143832121132SShri Abhyankar } 143932121132SShri Abhyankar 144032121132SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 144132121132SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1442b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 144332121132SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 144432121132SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 144532121132SShri Abhyankar PetscFunctionReturn(0); 144632121132SShri Abhyankar } 144732121132SShri Abhyankar 144832121132SShri Abhyankar #undef __FUNCT__ 144906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_5_inplace" 145006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_5_inplace(Mat A,Vec bb,Vec xx) 1451f1af5d2fSBarry Smith { 1452f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 1453f1af5d2fSBarry Smith IS iscol=a->col,isrow=a->row; 14546849ba73SBarry Smith PetscErrorCode ierr; 14555d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout; 1456b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 1457b3260449SShri Abhyankar PetscInt i,nz,idx,idt,ii,ic,ir,oidx; 1458b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1459b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x,*t; 1460b3260449SShri Abhyankar const PetscScalar *b; 1461f1af5d2fSBarry Smith 1462f1af5d2fSBarry Smith PetscFunctionBegin; 1463b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 14641ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 1465f1af5d2fSBarry Smith t = a->solve_work; 1466f1af5d2fSBarry Smith 1467f1af5d2fSBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 1468f1af5d2fSBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 1469f1af5d2fSBarry Smith 1470f1af5d2fSBarry Smith /* copy the b into temp work space according to permutation */ 1471f1af5d2fSBarry Smith ii = 0; 1472f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1473f1af5d2fSBarry Smith ic = 5*c[i]; 1474f1af5d2fSBarry Smith t[ii] = b[ic]; 1475f1af5d2fSBarry Smith t[ii+1] = b[ic+1]; 1476f1af5d2fSBarry Smith t[ii+2] = b[ic+2]; 1477f1af5d2fSBarry Smith t[ii+3] = b[ic+3]; 1478f1af5d2fSBarry Smith t[ii+4] = b[ic+4]; 1479f1af5d2fSBarry Smith ii += 5; 1480f1af5d2fSBarry Smith } 1481f1af5d2fSBarry Smith 1482f1af5d2fSBarry Smith /* forward solve the U^T */ 1483f1af5d2fSBarry Smith idx = 0; 1484f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1485f1af5d2fSBarry Smith 1486f1af5d2fSBarry Smith v = aa + 25*diag[i]; 1487f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 1488f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 1489f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5; 1490f1af5d2fSBarry Smith s2 = v[5]*x1 + v[6]*x2 + v[7]*x3 + v[8]*x4 + v[9]*x5; 1491f1af5d2fSBarry Smith s3 = v[10]*x1 + v[11]*x2 + v[12]*x3 + v[13]*x4 + v[14]*x5; 1492f1af5d2fSBarry Smith s4 = v[15]*x1 + v[16]*x2 + v[17]*x3 + v[18]*x4 + v[19]*x5; 1493f1af5d2fSBarry Smith s5 = v[20]*x1 + v[21]*x2 + v[22]*x3 + v[23]*x4 + v[24]*x5; 1494f1af5d2fSBarry Smith v += 25; 1495f1af5d2fSBarry Smith 1496f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 1497f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 1498f1af5d2fSBarry Smith while (nz--) { 1499f1af5d2fSBarry Smith oidx = 5*(*vi++); 1500f1af5d2fSBarry Smith t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5; 1501f1af5d2fSBarry Smith t[oidx+1] -= v[5]*s1 + v[6]*s2 + v[7]*s3 + v[8]*s4 + v[9]*s5; 1502f1af5d2fSBarry Smith t[oidx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5; 1503f1af5d2fSBarry Smith t[oidx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5; 1504f1af5d2fSBarry Smith t[oidx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5; 1505f1af5d2fSBarry Smith v += 25; 1506f1af5d2fSBarry Smith } 1507f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5; 1508f1af5d2fSBarry Smith idx += 5; 1509f1af5d2fSBarry Smith } 1510f1af5d2fSBarry Smith /* backward solve the L^T */ 1511f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 1512f1af5d2fSBarry Smith v = aa + 25*diag[i] - 25; 1513f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 1514f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 1515f1af5d2fSBarry Smith idt = 5*i; 1516f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt]; 1517f1af5d2fSBarry Smith while (nz--) { 1518f1af5d2fSBarry Smith idx = 5*(*vi--); 1519f1af5d2fSBarry Smith t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5; 1520f1af5d2fSBarry Smith t[idx+1] -= v[5]*s1 + v[6]*s2 + v[7]*s3 + v[8]*s4 + v[9]*s5; 1521f1af5d2fSBarry Smith t[idx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5; 1522f1af5d2fSBarry Smith t[idx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5; 1523f1af5d2fSBarry Smith t[idx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5; 1524f1af5d2fSBarry Smith v -= 25; 1525f1af5d2fSBarry Smith } 1526f1af5d2fSBarry Smith } 1527f1af5d2fSBarry Smith 1528f1af5d2fSBarry Smith /* copy t into x according to permutation */ 1529f1af5d2fSBarry Smith ii = 0; 1530f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1531f1af5d2fSBarry Smith ir = 5*r[i]; 1532f1af5d2fSBarry Smith x[ir] = t[ii]; 1533f1af5d2fSBarry Smith x[ir+1] = t[ii+1]; 1534f1af5d2fSBarry Smith x[ir+2] = t[ii+2]; 1535f1af5d2fSBarry Smith x[ir+3] = t[ii+3]; 1536f1af5d2fSBarry Smith x[ir+4] = t[ii+4]; 1537f1af5d2fSBarry Smith ii += 5; 1538f1af5d2fSBarry Smith } 1539f1af5d2fSBarry Smith 1540f1af5d2fSBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 1541f1af5d2fSBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1542b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 15431ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 1544dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr); 1545f1af5d2fSBarry Smith PetscFunctionReturn(0); 1546f1af5d2fSBarry Smith } 1547f1af5d2fSBarry Smith 15484a2ae208SSatish Balay #undef __FUNCT__ 15494dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_5" 15504dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_5(Mat A,Vec bb,Vec xx) 155132121132SShri Abhyankar { 155232121132SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 155332121132SShri Abhyankar PetscErrorCode ierr; 155432121132SShri Abhyankar IS iscol=a->col,isrow=a->row; 1555b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 155632121132SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 155732121132SShri Abhyankar PetscInt nz,idx,idt,j,i,oidx,ii,ic,ir; 1558b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 1559b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1560b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x,*t; 1561b3260449SShri Abhyankar const PetscScalar *b; 156232121132SShri Abhyankar 156332121132SShri Abhyankar PetscFunctionBegin; 1564b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 156532121132SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 156632121132SShri Abhyankar t = a->solve_work; 156732121132SShri Abhyankar 156832121132SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 156932121132SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 157032121132SShri Abhyankar 157132121132SShri Abhyankar /* copy b into temp work space according to permutation */ 157232121132SShri Abhyankar for(i=0;i<n;i++){ 157332121132SShri Abhyankar ii = bs*i; ic = bs*c[i]; 157432121132SShri Abhyankar t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; t[ii+3] = b[ic+3]; 157532121132SShri Abhyankar t[ii+4] = b[ic+4]; 157632121132SShri Abhyankar } 157732121132SShri Abhyankar 157832121132SShri Abhyankar /* forward solve the U^T */ 157932121132SShri Abhyankar idx = 0; 158032121132SShri Abhyankar for (i=0; i<n; i++) { 158132121132SShri Abhyankar v = aa + bs2*diag[i]; 158232121132SShri Abhyankar /* multiply by the inverse of the block diagonal */ 158332121132SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 158432121132SShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5; 158532121132SShri Abhyankar s2 = v[5]*x1 + v[6]*x2 + v[7]*x3 + v[8]*x4 + v[9]*x5; 158632121132SShri Abhyankar s3 = v[10]*x1 + v[11]*x2 + v[12]*x3 + v[13]*x4 + v[14]*x5; 158732121132SShri Abhyankar s4 = v[15]*x1 + v[16]*x2 + v[17]*x3 + v[18]*x4 + v[19]*x5; 158832121132SShri Abhyankar s5 = v[20]*x1 + v[21]*x2 + v[22]*x3 + v[23]*x4 + v[24]*x5; 158932121132SShri Abhyankar v -= bs2; 159032121132SShri Abhyankar 159132121132SShri Abhyankar vi = aj + diag[i] - 1; 159232121132SShri Abhyankar nz = diag[i] - diag[i+1] - 1; 159332121132SShri Abhyankar for(j=0;j>-nz;j--){ 159432121132SShri Abhyankar oidx = bs*vi[j]; 159532121132SShri Abhyankar t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5; 159632121132SShri Abhyankar t[oidx+1] -= v[5]*s1 + v[6]*s2 + v[7]*s3 + v[8]*s4 + v[9]*s5; 159732121132SShri Abhyankar t[oidx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5; 159832121132SShri Abhyankar t[oidx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5; 159932121132SShri Abhyankar t[oidx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5; 160032121132SShri Abhyankar v -= bs2; 160132121132SShri Abhyankar } 160232121132SShri Abhyankar t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3; t[3+idx] = s4; t[4+idx] =s5; 160332121132SShri Abhyankar idx += bs; 160432121132SShri Abhyankar } 160532121132SShri Abhyankar /* backward solve the L^T */ 160632121132SShri Abhyankar for (i=n-1; i>=0; i--){ 160732121132SShri Abhyankar v = aa + bs2*ai[i]; 160832121132SShri Abhyankar vi = aj + ai[i]; 160932121132SShri Abhyankar nz = ai[i+1] - ai[i]; 161032121132SShri Abhyankar idt = bs*i; 161132121132SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; s4 = t[3+idt]; s5 = t[4+idt]; 161232121132SShri Abhyankar for(j=0;j<nz;j++){ 161332121132SShri Abhyankar idx = bs*vi[j]; 161432121132SShri Abhyankar t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5; 161532121132SShri Abhyankar t[idx+1] -= v[5]*s1 + v[6]*s2 + v[7]*s3 + v[8]*s4 + v[9]*s5; 161632121132SShri Abhyankar t[idx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5; 161732121132SShri Abhyankar t[idx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5; 161832121132SShri Abhyankar t[idx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5; 161932121132SShri Abhyankar v += bs2; 162032121132SShri Abhyankar } 162132121132SShri Abhyankar } 162232121132SShri Abhyankar 162332121132SShri Abhyankar /* copy t into x according to permutation */ 162432121132SShri Abhyankar for(i=0;i<n;i++){ 162532121132SShri Abhyankar ii = bs*i; ir = bs*r[i]; 162632121132SShri Abhyankar x[ir] = t[ii]; x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2]; x[ir+3] = t[ii+3]; 162732121132SShri Abhyankar x[ir+4] = t[ii+4]; 162832121132SShri Abhyankar } 162932121132SShri Abhyankar 163032121132SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 163132121132SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1632b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 163332121132SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 163432121132SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 163532121132SShri Abhyankar PetscFunctionReturn(0); 163632121132SShri Abhyankar } 163732121132SShri Abhyankar 163832121132SShri Abhyankar #undef __FUNCT__ 163906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_6_inplace" 164006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_6_inplace(Mat A,Vec bb,Vec xx) 1641f1af5d2fSBarry Smith { 1642f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 1643f1af5d2fSBarry Smith IS iscol=a->col,isrow=a->row; 16446849ba73SBarry Smith PetscErrorCode ierr; 16455d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout; 1646b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 1647b3260449SShri Abhyankar PetscInt i,nz,idx,idt,ii,ic,ir,oidx; 1648b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1649b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x,*t; 1650b3260449SShri Abhyankar const PetscScalar *b; 1651f1af5d2fSBarry Smith 1652f1af5d2fSBarry Smith PetscFunctionBegin; 1653b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 16541ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 1655f1af5d2fSBarry Smith t = a->solve_work; 1656f1af5d2fSBarry Smith 1657f1af5d2fSBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 1658f1af5d2fSBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 1659f1af5d2fSBarry Smith 1660f1af5d2fSBarry Smith /* copy the b into temp work space according to permutation */ 1661f1af5d2fSBarry Smith ii = 0; 1662f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1663f1af5d2fSBarry Smith ic = 6*c[i]; 1664f1af5d2fSBarry Smith t[ii] = b[ic]; 1665f1af5d2fSBarry Smith t[ii+1] = b[ic+1]; 1666f1af5d2fSBarry Smith t[ii+2] = b[ic+2]; 1667f1af5d2fSBarry Smith t[ii+3] = b[ic+3]; 1668f1af5d2fSBarry Smith t[ii+4] = b[ic+4]; 1669f1af5d2fSBarry Smith t[ii+5] = b[ic+5]; 1670f1af5d2fSBarry Smith ii += 6; 1671f1af5d2fSBarry Smith } 1672f1af5d2fSBarry Smith 1673f1af5d2fSBarry Smith /* forward solve the U^T */ 1674f1af5d2fSBarry Smith idx = 0; 1675f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1676f1af5d2fSBarry Smith 1677f1af5d2fSBarry Smith v = aa + 36*diag[i]; 1678f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 1679f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 1680f1af5d2fSBarry Smith x6 = t[5+idx]; 1681f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6; 1682f1af5d2fSBarry Smith s2 = v[6]*x1 + v[7]*x2 + v[8]*x3 + v[9]*x4 + v[10]*x5 + v[11]*x6; 1683f1af5d2fSBarry Smith s3 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4 + v[16]*x5 + v[17]*x6; 1684f1af5d2fSBarry Smith s4 = v[18]*x1 + v[19]*x2 + v[20]*x3 + v[21]*x4 + v[22]*x5 + v[23]*x6; 1685f1af5d2fSBarry Smith s5 = v[24]*x1 + v[25]*x2 + v[26]*x3 + v[27]*x4 + v[28]*x5 + v[29]*x6; 1686f1af5d2fSBarry Smith s6 = v[30]*x1 + v[31]*x2 + v[32]*x3 + v[33]*x4 + v[34]*x5 + v[35]*x6; 1687f1af5d2fSBarry Smith v += 36; 1688f1af5d2fSBarry Smith 1689f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 1690f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 1691f1af5d2fSBarry Smith while (nz--) { 1692f1af5d2fSBarry Smith oidx = 6*(*vi++); 1693f1af5d2fSBarry Smith t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6; 1694f1af5d2fSBarry Smith t[oidx+1] -= v[6]*s1 + v[7]*s2 + v[8]*s3 + v[9]*s4 + v[10]*s5 + v[11]*s6; 1695f1af5d2fSBarry Smith t[oidx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6; 1696f1af5d2fSBarry Smith t[oidx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6; 1697f1af5d2fSBarry Smith t[oidx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6; 1698f1af5d2fSBarry Smith t[oidx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6; 1699f1af5d2fSBarry Smith v += 36; 1700f1af5d2fSBarry Smith } 1701f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5; 1702f1af5d2fSBarry Smith t[5+idx] = s6; 1703f1af5d2fSBarry Smith idx += 6; 1704f1af5d2fSBarry Smith } 1705f1af5d2fSBarry Smith /* backward solve the L^T */ 1706f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 1707f1af5d2fSBarry Smith v = aa + 36*diag[i] - 36; 1708f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 1709f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 1710f1af5d2fSBarry Smith idt = 6*i; 1711f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt]; 1712f1af5d2fSBarry Smith s6 = t[5+idt]; 1713f1af5d2fSBarry Smith while (nz--) { 1714f1af5d2fSBarry Smith idx = 6*(*vi--); 1715f1af5d2fSBarry Smith t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6; 1716f1af5d2fSBarry Smith t[idx+1] -= v[6]*s1 + v[7]*s2 + v[8]*s3 + v[9]*s4 + v[10]*s5 + v[11]*s6; 1717f1af5d2fSBarry Smith t[idx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6; 1718f1af5d2fSBarry Smith t[idx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6; 1719f1af5d2fSBarry Smith t[idx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6; 1720f1af5d2fSBarry Smith t[idx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6; 1721f1af5d2fSBarry Smith v -= 36; 1722f1af5d2fSBarry Smith } 1723f1af5d2fSBarry Smith } 1724f1af5d2fSBarry Smith 1725f1af5d2fSBarry Smith /* copy t into x according to permutation */ 1726f1af5d2fSBarry Smith ii = 0; 1727f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1728f1af5d2fSBarry Smith ir = 6*r[i]; 1729f1af5d2fSBarry Smith x[ir] = t[ii]; 1730f1af5d2fSBarry Smith x[ir+1] = t[ii+1]; 1731f1af5d2fSBarry Smith x[ir+2] = t[ii+2]; 1732f1af5d2fSBarry Smith x[ir+3] = t[ii+3]; 1733f1af5d2fSBarry Smith x[ir+4] = t[ii+4]; 1734f1af5d2fSBarry Smith x[ir+5] = t[ii+5]; 1735f1af5d2fSBarry Smith ii += 6; 1736f1af5d2fSBarry Smith } 1737f1af5d2fSBarry Smith 1738f1af5d2fSBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 1739f1af5d2fSBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1740b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 17411ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 1742dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr); 1743f1af5d2fSBarry Smith PetscFunctionReturn(0); 1744f1af5d2fSBarry Smith } 1745f1af5d2fSBarry Smith 17464a2ae208SSatish Balay #undef __FUNCT__ 17474dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_6" 17484dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_6(Mat A,Vec bb,Vec xx) 174932121132SShri Abhyankar { 175032121132SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 175132121132SShri Abhyankar PetscErrorCode ierr; 175232121132SShri Abhyankar IS iscol=a->col,isrow=a->row; 1753b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 175432121132SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 175532121132SShri Abhyankar PetscInt nz,idx,idt,j,i,oidx,ii,ic,ir; 1756b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 1757b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1758b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x,*t; 1759b3260449SShri Abhyankar const PetscScalar *b; 176032121132SShri Abhyankar 176132121132SShri Abhyankar PetscFunctionBegin; 1762b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 176332121132SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 176432121132SShri Abhyankar t = a->solve_work; 176532121132SShri Abhyankar 176632121132SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 176732121132SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 176832121132SShri Abhyankar 176932121132SShri Abhyankar /* copy b into temp work space according to permutation */ 177032121132SShri Abhyankar for(i=0;i<n;i++){ 177132121132SShri Abhyankar ii = bs*i; ic = bs*c[i]; 177232121132SShri Abhyankar t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; t[ii+3] = b[ic+3]; 177332121132SShri Abhyankar t[ii+4] = b[ic+4]; t[ii+5] = b[ic+5]; 177432121132SShri Abhyankar } 177532121132SShri Abhyankar 177632121132SShri Abhyankar /* forward solve the U^T */ 177732121132SShri Abhyankar idx = 0; 177832121132SShri Abhyankar for (i=0; i<n; i++) { 177932121132SShri Abhyankar v = aa + bs2*diag[i]; 178032121132SShri Abhyankar /* multiply by the inverse of the block diagonal */ 178132121132SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 178232121132SShri Abhyankar x6 = t[5+idx]; 178332121132SShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6; 178432121132SShri Abhyankar s2 = v[6]*x1 + v[7]*x2 + v[8]*x3 + v[9]*x4 + v[10]*x5 + v[11]*x6; 178532121132SShri Abhyankar s3 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4 + v[16]*x5 + v[17]*x6; 178632121132SShri Abhyankar s4 = v[18]*x1 + v[19]*x2 + v[20]*x3 + v[21]*x4 + v[22]*x5 + v[23]*x6; 178732121132SShri Abhyankar s5 = v[24]*x1 + v[25]*x2 + v[26]*x3 + v[27]*x4 + v[28]*x5 + v[29]*x6; 178832121132SShri Abhyankar s6 = v[30]*x1 + v[31]*x2 + v[32]*x3 + v[33]*x4 + v[34]*x5 + v[35]*x6; 178932121132SShri Abhyankar v -= bs2; 179032121132SShri Abhyankar 179132121132SShri Abhyankar vi = aj + diag[i] - 1; 179232121132SShri Abhyankar nz = diag[i] - diag[i+1] - 1; 179332121132SShri Abhyankar for(j=0;j>-nz;j--){ 179432121132SShri Abhyankar oidx = bs*vi[j]; 179532121132SShri Abhyankar t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6; 179632121132SShri Abhyankar t[oidx+1] -= v[6]*s1 + v[7]*s2 + v[8]*s3 + v[9]*s4 + v[10]*s5 + v[11]*s6; 179732121132SShri Abhyankar t[oidx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6; 179832121132SShri Abhyankar t[oidx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6; 179932121132SShri Abhyankar t[oidx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6; 180032121132SShri Abhyankar t[oidx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6; 180132121132SShri Abhyankar v -= bs2; 180232121132SShri Abhyankar } 180332121132SShri Abhyankar t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3; t[3+idx] = s4; t[4+idx] =s5; 180432121132SShri Abhyankar t[5+idx] = s6; 180532121132SShri Abhyankar idx += bs; 180632121132SShri Abhyankar } 180732121132SShri Abhyankar /* backward solve the L^T */ 180832121132SShri Abhyankar for (i=n-1; i>=0; i--){ 180932121132SShri Abhyankar v = aa + bs2*ai[i]; 181032121132SShri Abhyankar vi = aj + ai[i]; 181132121132SShri Abhyankar nz = ai[i+1] - ai[i]; 181232121132SShri Abhyankar idt = bs*i; 181332121132SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; s4 = t[3+idt]; s5 = t[4+idt]; 181432121132SShri Abhyankar s6 = t[5+idt]; 181532121132SShri Abhyankar for(j=0;j<nz;j++){ 181632121132SShri Abhyankar idx = bs*vi[j]; 181732121132SShri Abhyankar t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6; 181832121132SShri Abhyankar t[idx+1] -= v[6]*s1 + v[7]*s2 + v[8]*s3 + v[9]*s4 + v[10]*s5 + v[11]*s6; 181932121132SShri Abhyankar t[idx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6; 182032121132SShri Abhyankar t[idx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6; 182132121132SShri Abhyankar t[idx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6; 182232121132SShri Abhyankar t[idx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6; 182332121132SShri Abhyankar v += bs2; 182432121132SShri Abhyankar } 182532121132SShri Abhyankar } 182632121132SShri Abhyankar 182732121132SShri Abhyankar /* copy t into x according to permutation */ 182832121132SShri Abhyankar for(i=0;i<n;i++){ 182932121132SShri Abhyankar ii = bs*i; ir = bs*r[i]; 183032121132SShri Abhyankar x[ir] = t[ii]; x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2]; x[ir+3] = t[ii+3]; 183132121132SShri Abhyankar x[ir+4] = t[ii+4]; x[ir+5] = t[ii+5]; 183232121132SShri Abhyankar } 183332121132SShri Abhyankar 183432121132SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 183532121132SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1836b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 183732121132SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 183832121132SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 183932121132SShri Abhyankar PetscFunctionReturn(0); 184032121132SShri Abhyankar } 184132121132SShri Abhyankar 184232121132SShri Abhyankar #undef __FUNCT__ 184306e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_7_inplace" 184406e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_7_inplace(Mat A,Vec bb,Vec xx) 1845f1af5d2fSBarry Smith { 1846f1af5d2fSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 1847f1af5d2fSBarry Smith IS iscol=a->col,isrow=a->row; 18486849ba73SBarry Smith PetscErrorCode ierr; 18495d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout; 1850b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 1851b3260449SShri Abhyankar PetscInt i,nz,idx,idt,ii,ic,ir,oidx; 1852b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1853b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t; 1854b3260449SShri Abhyankar const PetscScalar *b; 1855f1af5d2fSBarry Smith 1856f1af5d2fSBarry Smith PetscFunctionBegin; 1857b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 18581ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 1859f1af5d2fSBarry Smith t = a->solve_work; 1860f1af5d2fSBarry Smith 1861f1af5d2fSBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 1862f1af5d2fSBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 1863f1af5d2fSBarry Smith 1864f1af5d2fSBarry Smith /* copy the b into temp work space according to permutation */ 1865f1af5d2fSBarry Smith ii = 0; 1866f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1867f1af5d2fSBarry Smith ic = 7*c[i]; 1868f1af5d2fSBarry Smith t[ii] = b[ic]; 1869f1af5d2fSBarry Smith t[ii+1] = b[ic+1]; 1870f1af5d2fSBarry Smith t[ii+2] = b[ic+2]; 1871f1af5d2fSBarry Smith t[ii+3] = b[ic+3]; 1872f1af5d2fSBarry Smith t[ii+4] = b[ic+4]; 1873f1af5d2fSBarry Smith t[ii+5] = b[ic+5]; 1874f1af5d2fSBarry Smith t[ii+6] = b[ic+6]; 1875f1af5d2fSBarry Smith ii += 7; 1876f1af5d2fSBarry Smith } 1877f1af5d2fSBarry Smith 1878f1af5d2fSBarry Smith /* forward solve the U^T */ 1879f1af5d2fSBarry Smith idx = 0; 1880f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1881f1af5d2fSBarry Smith 1882f1af5d2fSBarry Smith v = aa + 49*diag[i]; 1883f1af5d2fSBarry Smith /* multiply by the inverse of the block diagonal */ 1884f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 1885f1af5d2fSBarry Smith x6 = t[5+idx]; x7 = t[6+idx]; 1886f1af5d2fSBarry Smith s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6 + v[6]*x7; 1887f1af5d2fSBarry Smith s2 = v[7]*x1 + v[8]*x2 + v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7; 1888f1af5d2fSBarry Smith s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7; 1889f1af5d2fSBarry Smith s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7; 1890f1af5d2fSBarry Smith s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7; 1891f1af5d2fSBarry Smith s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7; 1892f1af5d2fSBarry Smith s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7; 1893f1af5d2fSBarry Smith v += 49; 1894f1af5d2fSBarry Smith 1895f1af5d2fSBarry Smith vi = aj + diag[i] + 1; 1896f1af5d2fSBarry Smith nz = ai[i+1] - diag[i] - 1; 1897f1af5d2fSBarry Smith while (nz--) { 1898f1af5d2fSBarry Smith oidx = 7*(*vi++); 1899f1af5d2fSBarry Smith t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 1900f1af5d2fSBarry Smith t[oidx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 1901f1af5d2fSBarry Smith t[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 1902f1af5d2fSBarry Smith t[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 1903f1af5d2fSBarry Smith t[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 1904f1af5d2fSBarry Smith t[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 1905f1af5d2fSBarry Smith t[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 1906f1af5d2fSBarry Smith v += 49; 1907f1af5d2fSBarry Smith } 1908f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5; 1909f1af5d2fSBarry Smith t[5+idx] = s6;t[6+idx] = s7; 1910f1af5d2fSBarry Smith idx += 7; 1911f1af5d2fSBarry Smith } 1912f1af5d2fSBarry Smith /* backward solve the L^T */ 1913f1af5d2fSBarry Smith for (i=n-1; i>=0; i--){ 1914f1af5d2fSBarry Smith v = aa + 49*diag[i] - 49; 1915f1af5d2fSBarry Smith vi = aj + diag[i] - 1; 1916f1af5d2fSBarry Smith nz = diag[i] - ai[i]; 1917f1af5d2fSBarry Smith idt = 7*i; 1918f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt]; 1919f1af5d2fSBarry Smith s6 = t[5+idt];s7 = t[6+idt]; 1920f1af5d2fSBarry Smith while (nz--) { 1921f1af5d2fSBarry Smith idx = 7*(*vi--); 1922f1af5d2fSBarry Smith t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 1923f1af5d2fSBarry Smith t[idx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 1924f1af5d2fSBarry Smith t[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 1925f1af5d2fSBarry Smith t[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 1926f1af5d2fSBarry Smith t[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 1927f1af5d2fSBarry Smith t[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 1928f1af5d2fSBarry Smith t[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 1929f1af5d2fSBarry Smith v -= 49; 1930f1af5d2fSBarry Smith } 1931f1af5d2fSBarry Smith } 1932f1af5d2fSBarry Smith 1933f1af5d2fSBarry Smith /* copy t into x according to permutation */ 1934f1af5d2fSBarry Smith ii = 0; 1935f1af5d2fSBarry Smith for (i=0; i<n; i++) { 1936f1af5d2fSBarry Smith ir = 7*r[i]; 1937f1af5d2fSBarry Smith x[ir] = t[ii]; 1938f1af5d2fSBarry Smith x[ir+1] = t[ii+1]; 1939f1af5d2fSBarry Smith x[ir+2] = t[ii+2]; 1940f1af5d2fSBarry Smith x[ir+3] = t[ii+3]; 1941f1af5d2fSBarry Smith x[ir+4] = t[ii+4]; 1942f1af5d2fSBarry Smith x[ir+5] = t[ii+5]; 1943f1af5d2fSBarry Smith x[ir+6] = t[ii+6]; 1944f1af5d2fSBarry Smith ii += 7; 1945f1af5d2fSBarry Smith } 1946f1af5d2fSBarry Smith 1947f1af5d2fSBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 1948f1af5d2fSBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 1949b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 19501ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 1951dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr); 1952f1af5d2fSBarry Smith PetscFunctionReturn(0); 1953f1af5d2fSBarry Smith } 195432121132SShri Abhyankar #undef __FUNCT__ 19554dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_7" 19564dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_7(Mat A,Vec bb,Vec xx) 195732121132SShri Abhyankar { 195832121132SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 195932121132SShri Abhyankar PetscErrorCode ierr; 196032121132SShri Abhyankar IS iscol=a->col,isrow=a->row; 1961b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 196232121132SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 196332121132SShri Abhyankar PetscInt nz,idx,idt,j,i,oidx,ii,ic,ir; 1964b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 1965b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 1966b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t; 1967b3260449SShri Abhyankar const PetscScalar *b; 196832121132SShri Abhyankar 196932121132SShri Abhyankar PetscFunctionBegin; 1970b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 197132121132SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 197232121132SShri Abhyankar t = a->solve_work; 197332121132SShri Abhyankar 197432121132SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 197532121132SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 197632121132SShri Abhyankar 197732121132SShri Abhyankar /* copy b into temp work space according to permutation */ 197832121132SShri Abhyankar for(i=0;i<n;i++){ 197932121132SShri Abhyankar ii = bs*i; ic = bs*c[i]; 198032121132SShri Abhyankar t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; t[ii+3] = b[ic+3]; 198132121132SShri Abhyankar t[ii+4] = b[ic+4]; t[ii+5] = b[ic+5]; t[ii+6] = b[ic+6]; 198232121132SShri Abhyankar } 198332121132SShri Abhyankar 198432121132SShri Abhyankar /* forward solve the U^T */ 198532121132SShri Abhyankar idx = 0; 198632121132SShri Abhyankar for (i=0; i<n; i++) { 198732121132SShri Abhyankar v = aa + bs2*diag[i]; 198832121132SShri Abhyankar /* multiply by the inverse of the block diagonal */ 198932121132SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 199032121132SShri Abhyankar x6 = t[5+idx]; x7 = t[6+idx]; 199132121132SShri Abhyankar s1 = v[0]*x1 + v[1]*x2 + v[2]*x3 + v[3]*x4 + v[4]*x5 + v[5]*x6 + v[6]*x7; 199232121132SShri Abhyankar s2 = v[7]*x1 + v[8]*x2 + v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7; 199332121132SShri Abhyankar s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7; 199432121132SShri Abhyankar s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7; 199532121132SShri Abhyankar s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7; 199632121132SShri Abhyankar s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7; 199732121132SShri Abhyankar s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7; 199832121132SShri Abhyankar v -= bs2; 199932121132SShri Abhyankar 200032121132SShri Abhyankar vi = aj + diag[i] - 1; 200132121132SShri Abhyankar nz = diag[i] - diag[i+1] - 1; 200232121132SShri Abhyankar for(j=0;j>-nz;j--){ 200332121132SShri Abhyankar oidx = bs*vi[j]; 200432121132SShri Abhyankar t[oidx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 200532121132SShri Abhyankar t[oidx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 200632121132SShri Abhyankar t[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 200732121132SShri Abhyankar t[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 200832121132SShri Abhyankar t[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 200932121132SShri Abhyankar t[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 201032121132SShri Abhyankar t[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 201132121132SShri Abhyankar v -= bs2; 201232121132SShri Abhyankar } 201332121132SShri Abhyankar t[idx] = s1;t[1+idx] = s2; t[2+idx] = s3; t[3+idx] = s4; t[4+idx] =s5; 201432121132SShri Abhyankar t[5+idx] = s6; t[6+idx] = s7; 201532121132SShri Abhyankar idx += bs; 201632121132SShri Abhyankar } 201732121132SShri Abhyankar /* backward solve the L^T */ 201832121132SShri Abhyankar for (i=n-1; i>=0; i--){ 201932121132SShri Abhyankar v = aa + bs2*ai[i]; 202032121132SShri Abhyankar vi = aj + ai[i]; 202132121132SShri Abhyankar nz = ai[i+1] - ai[i]; 202232121132SShri Abhyankar idt = bs*i; 202332121132SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; s4 = t[3+idt]; s5 = t[4+idt]; 202432121132SShri Abhyankar s6 = t[5+idt]; s7 = t[6+idt]; 202532121132SShri Abhyankar for(j=0;j<nz;j++){ 202632121132SShri Abhyankar idx = bs*vi[j]; 202732121132SShri Abhyankar t[idx] -= v[0]*s1 + v[1]*s2 + v[2]*s3 + v[3]*s4 + v[4]*s5 + v[5]*s6 + v[6]*s7; 202832121132SShri Abhyankar t[idx+1] -= v[7]*s1 + v[8]*s2 + v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7; 202932121132SShri Abhyankar t[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7; 203032121132SShri Abhyankar t[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7; 203132121132SShri Abhyankar t[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7; 203232121132SShri Abhyankar t[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7; 203332121132SShri Abhyankar t[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7; 203432121132SShri Abhyankar v += bs2; 203532121132SShri Abhyankar } 203632121132SShri Abhyankar } 203732121132SShri Abhyankar 203832121132SShri Abhyankar /* copy t into x according to permutation */ 203932121132SShri Abhyankar for(i=0;i<n;i++){ 204032121132SShri Abhyankar ii = bs*i; ir = bs*r[i]; 204132121132SShri Abhyankar x[ir] = t[ii]; x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2]; x[ir+3] = t[ii+3]; 204232121132SShri Abhyankar x[ir+4] = t[ii+4]; x[ir+5] = t[ii+5]; x[ir+6] = t[ii+6]; 204332121132SShri Abhyankar } 204432121132SShri Abhyankar 204532121132SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 204632121132SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 2047b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 204832121132SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 204932121132SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 205032121132SShri Abhyankar PetscFunctionReturn(0); 205132121132SShri Abhyankar } 2052f1af5d2fSBarry Smith 20534e2b4712SSatish Balay /* ----------------------------------------------------------- */ 20544a2ae208SSatish Balay #undef __FUNCT__ 205506e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_N_inplace" 205606e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_N_inplace(Mat A,Vec bb,Vec xx) 20574e2b4712SSatish Balay { 20584e2b4712SSatish Balay Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 20594e2b4712SSatish Balay IS iscol=a->col,isrow=a->row; 20606849ba73SBarry Smith PetscErrorCode ierr; 2061b3260449SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 2062b3260449SShri Abhyankar const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*vi; 2063b3260449SShri Abhyankar PetscInt i,nz; 2064b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 2065b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 2066b3260449SShri Abhyankar PetscScalar *x,*s,*t,*ls; 2067b3260449SShri Abhyankar const PetscScalar *b; 20684e2b4712SSatish Balay 20694e2b4712SSatish Balay PetscFunctionBegin; 2070b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 20711ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 2072f1af5d2fSBarry Smith t = a->solve_work; 20734e2b4712SSatish Balay 20744e2b4712SSatish Balay ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 20754e2b4712SSatish Balay ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 20764e2b4712SSatish Balay 20774e2b4712SSatish Balay /* forward solve the lower triangular */ 207887828ca2SBarry Smith ierr = PetscMemcpy(t,b+bs*(*r++),bs*sizeof(PetscScalar));CHKERRQ(ierr); 20794e2b4712SSatish Balay for (i=1; i<n; i++) { 20804e2b4712SSatish Balay v = aa + bs2*ai[i]; 20814e2b4712SSatish Balay vi = aj + ai[i]; 20824e2b4712SSatish Balay nz = a->diag[i] - ai[i]; 2083f1af5d2fSBarry Smith s = t + bs*i; 208487828ca2SBarry Smith ierr = PetscMemcpy(s,b+bs*(*r++),bs*sizeof(PetscScalar));CHKERRQ(ierr); 20854e2b4712SSatish Balay while (nz--) { 2086f1af5d2fSBarry Smith Kernel_v_gets_v_minus_A_times_w(bs,s,v,t+bs*(*vi++)); 20874e2b4712SSatish Balay v += bs2; 20884e2b4712SSatish Balay } 20894e2b4712SSatish Balay } 20904e2b4712SSatish Balay /* backward solve the upper triangular */ 2091d0f46423SBarry Smith ls = a->solve_work + A->cmap->n; 20924e2b4712SSatish Balay for (i=n-1; i>=0; i--){ 20934e2b4712SSatish Balay v = aa + bs2*(a->diag[i] + 1); 20944e2b4712SSatish Balay vi = aj + a->diag[i] + 1; 20954e2b4712SSatish Balay nz = ai[i+1] - a->diag[i] - 1; 209687828ca2SBarry Smith ierr = PetscMemcpy(ls,t+i*bs,bs*sizeof(PetscScalar));CHKERRQ(ierr); 20974e2b4712SSatish Balay while (nz--) { 2098f1af5d2fSBarry Smith Kernel_v_gets_v_minus_A_times_w(bs,ls,v,t+bs*(*vi++)); 20994e2b4712SSatish Balay v += bs2; 21004e2b4712SSatish Balay } 2101f1af5d2fSBarry Smith Kernel_w_gets_A_times_v(bs,ls,aa+bs2*a->diag[i],t+i*bs); 210287828ca2SBarry Smith ierr = PetscMemcpy(x + bs*(*c--),t+i*bs,bs*sizeof(PetscScalar));CHKERRQ(ierr); 21034e2b4712SSatish Balay } 21044e2b4712SSatish Balay 21054e2b4712SSatish Balay ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 21064e2b4712SSatish Balay ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 2107b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 21081ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 2109dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*(a->bs2)*(a->nz) - A->rmap->bs*A->cmap->n);CHKERRQ(ierr); 21104e2b4712SSatish Balay PetscFunctionReturn(0); 21114e2b4712SSatish Balay } 21124e2b4712SSatish Balay 21135c42ef9dSBarry Smith /* ----------------------------------------------------------- */ 21145c42ef9dSBarry Smith #undef __FUNCT__ 211506e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_N_inplace" 211606e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_N_inplace(Mat A,Vec bb,Vec xx) 21175c42ef9dSBarry Smith { 21185c42ef9dSBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 21195c42ef9dSBarry Smith IS iscol=a->col,isrow=a->row; 21205c42ef9dSBarry Smith PetscErrorCode ierr; 21215c42ef9dSBarry Smith const PetscInt *r,*c,*rout,*cout,*ai=a->i,*aj=a->j,*vi; 2122b3260449SShri Abhyankar PetscInt i,nz,j; 2123b3260449SShri Abhyankar const PetscInt n=a->mbs,bs=A->rmap->bs,bs2=a->bs2; 21245c42ef9dSBarry Smith const MatScalar *aa=a->a,*v; 21255c42ef9dSBarry Smith PetscScalar *x,*t,*ls; 21265c42ef9dSBarry Smith const PetscScalar *b; 21275c42ef9dSBarry Smith PetscFunctionBegin; 21285c42ef9dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 21295c42ef9dSBarry Smith ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 21305c42ef9dSBarry Smith t = a->solve_work; 21315c42ef9dSBarry Smith 21325c42ef9dSBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 21335c42ef9dSBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 21345c42ef9dSBarry Smith 21355c42ef9dSBarry Smith /* copy the b into temp work space according to permutation */ 21365c42ef9dSBarry Smith for (i=0; i<n; i++) { 21375c42ef9dSBarry Smith for (j=0; j<bs; j++) { 21385c42ef9dSBarry Smith t[i*bs+j] = b[c[i]*bs+j]; 21395c42ef9dSBarry Smith } 21405c42ef9dSBarry Smith } 21415c42ef9dSBarry Smith 21425c42ef9dSBarry Smith 21435c42ef9dSBarry Smith /* forward solve the upper triangular transpose */ 21445c42ef9dSBarry Smith ls = a->solve_work + A->cmap->n; 21455c42ef9dSBarry Smith for (i=0; i<n; i++){ 21465c42ef9dSBarry Smith ierr = PetscMemcpy(ls,t+i*bs,bs*sizeof(PetscScalar));CHKERRQ(ierr); 21475c42ef9dSBarry Smith Kernel_w_gets_transA_times_v(bs,ls,aa+bs2*a->diag[i],t+i*bs); 21485c42ef9dSBarry Smith v = aa + bs2*(a->diag[i] + 1); 21495c42ef9dSBarry Smith vi = aj + a->diag[i] + 1; 21505c42ef9dSBarry Smith nz = ai[i+1] - a->diag[i] - 1; 21515c42ef9dSBarry Smith while (nz--) { 21525c42ef9dSBarry Smith Kernel_v_gets_v_minus_transA_times_w(bs,t+bs*(*vi++),v,t+i*bs); 21535c42ef9dSBarry Smith v += bs2; 21545c42ef9dSBarry Smith } 21555c42ef9dSBarry Smith } 21565c42ef9dSBarry Smith 21575c42ef9dSBarry Smith /* backward solve the lower triangular transpose */ 21585c42ef9dSBarry Smith for (i=n-1; i>=0; i--) { 21595c42ef9dSBarry Smith v = aa + bs2*ai[i]; 21605c42ef9dSBarry Smith vi = aj + ai[i]; 21615c42ef9dSBarry Smith nz = a->diag[i] - ai[i]; 21625c42ef9dSBarry Smith while (nz--) { 21635c42ef9dSBarry Smith Kernel_v_gets_v_minus_transA_times_w(bs,t+bs*(*vi++),v,t+i*bs); 21645c42ef9dSBarry Smith v += bs2; 21655c42ef9dSBarry Smith } 21665c42ef9dSBarry Smith } 21675c42ef9dSBarry Smith 21685c42ef9dSBarry Smith /* copy t into x according to permutation */ 21695c42ef9dSBarry Smith for (i=0; i<n; i++) { 21705c42ef9dSBarry Smith for (j=0; j<bs; j++) { 21715c42ef9dSBarry Smith x[bs*r[i]+j] = t[bs*i+j]; 21725c42ef9dSBarry Smith } 21735c42ef9dSBarry Smith } 21745c42ef9dSBarry Smith 21755c42ef9dSBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 21765c42ef9dSBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 21775c42ef9dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 21785c42ef9dSBarry Smith ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 21795c42ef9dSBarry Smith ierr = PetscLogFlops(2.0*(a->bs2)*(a->nz) - A->rmap->bs*A->cmap->n);CHKERRQ(ierr); 21805c42ef9dSBarry Smith PetscFunctionReturn(0); 21815c42ef9dSBarry Smith } 21825c42ef9dSBarry Smith 21834a2ae208SSatish Balay #undef __FUNCT__ 21844dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_N" 21854dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_N(Mat A,Vec bb,Vec xx) 21868499736aSShri Abhyankar { 21878499736aSShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 21888499736aSShri Abhyankar IS iscol=a->col,isrow=a->row; 21898499736aSShri Abhyankar PetscErrorCode ierr; 2190b3260449SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 2191b3260449SShri Abhyankar const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*vi,*diag=a->diag; 2192b3260449SShri Abhyankar PetscInt i,j,nz; 2193b3260449SShri Abhyankar const PetscInt bs=A->rmap->bs,bs2=a->bs2; 21948499736aSShri Abhyankar const MatScalar *aa=a->a,*v; 21958499736aSShri Abhyankar PetscScalar *x,*t,*ls; 21968499736aSShri Abhyankar const PetscScalar *b; 2197b3260449SShri Abhyankar 21988499736aSShri Abhyankar PetscFunctionBegin; 21998499736aSShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 22008499736aSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 22018499736aSShri Abhyankar t = a->solve_work; 22028499736aSShri Abhyankar 22038499736aSShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 22048499736aSShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 22058499736aSShri Abhyankar 22068499736aSShri Abhyankar /* copy the b into temp work space according to permutation */ 22078499736aSShri Abhyankar for (i=0; i<n; i++) { 22088499736aSShri Abhyankar for (j=0; j<bs; j++) { 22098499736aSShri Abhyankar t[i*bs+j] = b[c[i]*bs+j]; 22108499736aSShri Abhyankar } 22118499736aSShri Abhyankar } 22128499736aSShri Abhyankar 22138499736aSShri Abhyankar 22148499736aSShri Abhyankar /* forward solve the upper triangular transpose */ 22158499736aSShri Abhyankar ls = a->solve_work + A->cmap->n; 22168499736aSShri Abhyankar for (i=0; i<n; i++){ 22178499736aSShri Abhyankar ierr = PetscMemcpy(ls,t+i*bs,bs*sizeof(PetscScalar));CHKERRQ(ierr); 22188499736aSShri Abhyankar Kernel_w_gets_transA_times_v(bs,ls,aa+bs2*diag[i],t+i*bs); 22198499736aSShri Abhyankar v = aa + bs2*(diag[i] - 1); 22208499736aSShri Abhyankar vi = aj + diag[i] - 1; 22218499736aSShri Abhyankar nz = diag[i] - diag[i+1] - 1; 22228499736aSShri Abhyankar for(j=0;j>-nz;j--){ 22238499736aSShri Abhyankar Kernel_v_gets_v_minus_transA_times_w(bs,t+bs*(vi[j]),v,t+i*bs); 22248499736aSShri Abhyankar v -= bs2; 22258499736aSShri Abhyankar } 22268499736aSShri Abhyankar } 22278499736aSShri Abhyankar 22288499736aSShri Abhyankar /* backward solve the lower triangular transpose */ 22298499736aSShri Abhyankar for (i=n-1; i>=0; i--) { 22308499736aSShri Abhyankar v = aa + bs2*ai[i]; 22318499736aSShri Abhyankar vi = aj + ai[i]; 22328499736aSShri Abhyankar nz = ai[i+1] - ai[i]; 22338499736aSShri Abhyankar for(j=0;j<nz;j++){ 22348499736aSShri Abhyankar Kernel_v_gets_v_minus_transA_times_w(bs,t+bs*(vi[j]),v,t+i*bs); 22358499736aSShri Abhyankar v += bs2; 22368499736aSShri Abhyankar } 22378499736aSShri Abhyankar } 22388499736aSShri Abhyankar 22398499736aSShri Abhyankar /* copy t into x according to permutation */ 22408499736aSShri Abhyankar for (i=0; i<n; i++) { 22418499736aSShri Abhyankar for (j=0; j<bs; j++) { 22428499736aSShri Abhyankar x[bs*r[i]+j] = t[bs*i+j]; 22438499736aSShri Abhyankar } 22448499736aSShri Abhyankar } 22458499736aSShri Abhyankar 22468499736aSShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 22478499736aSShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 22488499736aSShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 22498499736aSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 22508499736aSShri Abhyankar ierr = PetscLogFlops(2.0*(a->bs2)*(a->nz) - A->rmap->bs*A->cmap->n);CHKERRQ(ierr); 22518499736aSShri Abhyankar PetscFunctionReturn(0); 22528499736aSShri Abhyankar } 22538499736aSShri Abhyankar 22542b0b2ea7SShri Abhyankar /* bs = 15 for PFLOTRAN */ 225529a97285SShri Abhyankar 22562b0b2ea7SShri Abhyankar #undef __FUNCT__ 225729a97285SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_15_NaturalOrdering" 225829a97285SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_15_NaturalOrdering(Mat A,Vec bb,Vec xx) 22592b0b2ea7SShri Abhyankar { 22602b0b2ea7SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 22612b0b2ea7SShri Abhyankar PetscErrorCode ierr; 2262b3260449SShri Abhyankar const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*adiag=a->diag,*vi,bs=A->rmap->bs,bs2=a->bs2; 2263b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc,m; 22640b68f018SBarry Smith const MatScalar *aa=a->a,*v; 22652b0b2ea7SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15; 22662b0b2ea7SShri Abhyankar PetscScalar x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15; 22670b68f018SBarry Smith PetscScalar *x,*t; 22680b68f018SBarry Smith const PetscScalar *b; 22692b0b2ea7SShri Abhyankar 22702b0b2ea7SShri Abhyankar PetscFunctionBegin; 22710b68f018SBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 22722b0b2ea7SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 22732b0b2ea7SShri Abhyankar t = a->solve_work; 22742b0b2ea7SShri Abhyankar 22752b0b2ea7SShri Abhyankar /* forward solve the lower triangular */ 227629a97285SShri Abhyankar idx = 0; 22772b0b2ea7SShri Abhyankar t[0] = b[idx]; t[1] = b[1+idx]; t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx]; 22782b0b2ea7SShri Abhyankar t[5] = b[5+idx]; t[6] = b[6+idx]; t[7] = b[7+idx]; t[8] = b[8+idx]; t[9] = b[9+idx]; 22792b0b2ea7SShri Abhyankar t[10] = b[10+idx]; t[11] = b[11+idx]; t[12] = b[12+idx]; t[13] = b[13+idx]; t[14] = b[14+idx]; 22802b0b2ea7SShri Abhyankar 22812b0b2ea7SShri Abhyankar for (i=1; i<n; i++) { 22822b0b2ea7SShri Abhyankar v = aa + bs2*ai[i]; 22832b0b2ea7SShri Abhyankar vi = aj + ai[i]; 22842b0b2ea7SShri Abhyankar nz = ai[i+1] - ai[i]; 228529a97285SShri Abhyankar idx = bs*i; 22862b0b2ea7SShri Abhyankar s1 = b[idx]; s2 = b[1+idx]; s3 = b[2+idx]; s4 = b[3+idx]; s5 = b[4+idx]; 22872b0b2ea7SShri Abhyankar s6 = b[5+idx]; s7 = b[6+idx]; s8 = b[7+idx]; s9 = b[8+idx]; s10 = b[9+idx]; 22882b0b2ea7SShri Abhyankar s11 = b[10+idx]; s12 = b[11+idx]; s13 = b[12+idx]; s14 = b[13+idx]; s15 = b[14+idx]; 22892b0b2ea7SShri Abhyankar for(m=0;m<nz;m++){ 22902b0b2ea7SShri Abhyankar idx = bs*vi[m]; 22912b0b2ea7SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 22922b0b2ea7SShri Abhyankar x6 = t[5+idx]; x7 = t[6+idx]; x8 = t[7+idx]; x9 = t[8+idx]; x10 = t[9+idx]; 22932b0b2ea7SShri Abhyankar x11 = t[10+idx]; x12 = t[11+idx]; x13 = t[12+idx]; x14 = t[13+idx]; x15 = t[14+idx]; 22942b0b2ea7SShri Abhyankar 2295*0b8f6341SShri Abhyankar 22962b0b2ea7SShri Abhyankar 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; 22972b0b2ea7SShri Abhyankar 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; 22982b0b2ea7SShri Abhyankar 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; 22992b0b2ea7SShri Abhyankar 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; 23002b0b2ea7SShri Abhyankar 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; 23012b0b2ea7SShri Abhyankar 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; 23022b0b2ea7SShri Abhyankar 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; 23032b0b2ea7SShri Abhyankar 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; 23042b0b2ea7SShri Abhyankar 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; 23052b0b2ea7SShri Abhyankar 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; 23062b0b2ea7SShri Abhyankar 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; 23072b0b2ea7SShri Abhyankar 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; 23082b0b2ea7SShri Abhyankar 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; 23092b0b2ea7SShri Abhyankar 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; 23102b0b2ea7SShri Abhyankar 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; 23112b0b2ea7SShri Abhyankar 23122b0b2ea7SShri Abhyankar v += bs2; 23132b0b2ea7SShri Abhyankar } 23142b0b2ea7SShri Abhyankar idx = bs*i; 23152b0b2ea7SShri Abhyankar t[idx] = s1; t[1+idx] = s2; t[2+idx] = s3; t[3+idx] = s4; t[4+idx] = s5; 23162b0b2ea7SShri Abhyankar t[5+idx] = s6; t[6+idx] = s7; t[7+idx] = s8; t[8+idx] = s9; t[9+idx] = s10; 23172b0b2ea7SShri Abhyankar t[10+idx] = s11; t[11+idx] = s12; t[12+idx] = s13; t[13+idx] = s14; t[14+idx] = s15; 23182b0b2ea7SShri Abhyankar 23192b0b2ea7SShri Abhyankar } 23202b0b2ea7SShri Abhyankar /* backward solve the upper triangular */ 23212b0b2ea7SShri Abhyankar for (i=n-1; i>=0; i--){ 23222b0b2ea7SShri Abhyankar v = aa + bs2*(adiag[i+1]+1); 23232b0b2ea7SShri Abhyankar vi = aj + adiag[i+1]+1; 23242b0b2ea7SShri Abhyankar nz = adiag[i] - adiag[i+1] - 1; 23252b0b2ea7SShri Abhyankar idt = bs*i; 23262b0b2ea7SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; s4 = t[3+idt]; s5 = t[4+idt]; 23272b0b2ea7SShri Abhyankar s6 = t[5+idt]; s7 = t[6+idt]; s8 = t[7+idt]; s9 = t[8+idt]; s10 = t[9+idt]; 23282b0b2ea7SShri Abhyankar s11 = t[10+idt]; s12 = t[11+idt]; s13 = t[12+idt]; s14 = t[13+idt]; s15 = t[14+idt]; 23292b0b2ea7SShri Abhyankar 23302b0b2ea7SShri Abhyankar for(m=0;m<nz;m++){ 23312b0b2ea7SShri Abhyankar idx = bs*vi[m]; 23322b0b2ea7SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 23332b0b2ea7SShri Abhyankar x6 = t[5+idx]; x7 = t[6+idx]; x8 = t[7+idx]; x9 = t[8+idx]; x10 = t[9+idx]; 23342b0b2ea7SShri Abhyankar x11 = t[10+idx]; x12 = t[11+idx]; x13 = t[12+idx]; x14 = t[13+idx]; x15 = t[14+idx]; 23352b0b2ea7SShri Abhyankar 23362b0b2ea7SShri Abhyankar 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; 23372b0b2ea7SShri Abhyankar 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; 23382b0b2ea7SShri Abhyankar 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; 23392b0b2ea7SShri Abhyankar 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; 23402b0b2ea7SShri Abhyankar 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; 23412b0b2ea7SShri Abhyankar 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; 23422b0b2ea7SShri Abhyankar 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; 23432b0b2ea7SShri Abhyankar 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; 23442b0b2ea7SShri Abhyankar 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; 23452b0b2ea7SShri Abhyankar 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; 23462b0b2ea7SShri Abhyankar 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; 23472b0b2ea7SShri Abhyankar 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; 23482b0b2ea7SShri Abhyankar 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; 23492b0b2ea7SShri Abhyankar 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; 23502b0b2ea7SShri Abhyankar 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; 23512b0b2ea7SShri Abhyankar 23522b0b2ea7SShri Abhyankar v += bs2; 23532b0b2ea7SShri Abhyankar } 235429a97285SShri Abhyankar idc = bs*i; 23552b0b2ea7SShri Abhyankar 23562b0b2ea7SShri Abhyankar x[idc] = t[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; 23572b0b2ea7SShri Abhyankar x[1+idc] = t[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; 23582b0b2ea7SShri Abhyankar x[2+idc] = t[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; 23592b0b2ea7SShri Abhyankar x[3+idc] = t[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; 23602b0b2ea7SShri Abhyankar x[4+idc] = t[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; 23612b0b2ea7SShri Abhyankar x[5+idc] = t[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; 23622b0b2ea7SShri Abhyankar x[6+idc] = t[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; 23632b0b2ea7SShri Abhyankar x[7+idc] = t[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; 23642b0b2ea7SShri Abhyankar x[8+idc] = t[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; 23652b0b2ea7SShri Abhyankar x[9+idc] = t[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; 23662b0b2ea7SShri Abhyankar x[10+idc] = t[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; 23672b0b2ea7SShri Abhyankar x[11+idc] = t[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; 23682b0b2ea7SShri Abhyankar x[12+idc] = t[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; 23692b0b2ea7SShri Abhyankar x[13+idc] = t[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; 23702b0b2ea7SShri Abhyankar x[14+idc] = t[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; 23712b0b2ea7SShri Abhyankar 23722b0b2ea7SShri Abhyankar } 23732b0b2ea7SShri Abhyankar 23740b68f018SBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 23752b0b2ea7SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 23762b0b2ea7SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 23772b0b2ea7SShri Abhyankar PetscFunctionReturn(0); 23782b0b2ea7SShri Abhyankar } 23792b0b2ea7SShri Abhyankar 23808499736aSShri Abhyankar #undef __FUNCT__ 2381*0b8f6341SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_15_NaturalOrdering_ver2" 2382*0b8f6341SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_15_NaturalOrdering_ver2(Mat A,Vec bb,Vec xx) 2383*0b8f6341SShri Abhyankar { 2384*0b8f6341SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 2385*0b8f6341SShri Abhyankar PetscErrorCode ierr; 2386*0b8f6341SShri Abhyankar const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*adiag=a->diag,*vi,bs=A->rmap->bs,bs2=a->bs2; 2387*0b8f6341SShri Abhyankar PetscInt i,k,nz,idx,idt,idc,m; 2388*0b8f6341SShri Abhyankar const MatScalar *aa=a->a,*v; 2389*0b8f6341SShri Abhyankar PetscScalar s[15]; 2390*0b8f6341SShri Abhyankar PetscScalar *x,*t; 2391*0b8f6341SShri Abhyankar const PetscScalar *b; 2392*0b8f6341SShri Abhyankar 2393*0b8f6341SShri Abhyankar PetscFunctionBegin; 2394*0b8f6341SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 2395*0b8f6341SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 2396*0b8f6341SShri Abhyankar t = a->solve_work; 2397*0b8f6341SShri Abhyankar 2398*0b8f6341SShri Abhyankar /* forward solve the lower triangular */ 2399*0b8f6341SShri Abhyankar idx = 0; 2400*0b8f6341SShri Abhyankar t[0] = b[idx]; t[1] = b[1+idx]; t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx]; 2401*0b8f6341SShri Abhyankar t[5] = b[5+idx]; t[6] = b[6+idx]; t[7] = b[7+idx]; t[8] = b[8+idx]; t[9] = b[9+idx]; 2402*0b8f6341SShri Abhyankar t[10] = b[10+idx]; t[11] = b[11+idx]; t[12] = b[12+idx]; t[13] = b[13+idx]; t[14] = b[14+idx]; 2403*0b8f6341SShri Abhyankar 2404*0b8f6341SShri Abhyankar for (i=1; i<n; i++) { 2405*0b8f6341SShri Abhyankar v = aa + bs2*ai[i]; 2406*0b8f6341SShri Abhyankar vi = aj + ai[i]; 2407*0b8f6341SShri Abhyankar nz = ai[i+1] - ai[i]; 2408*0b8f6341SShri Abhyankar idx = bs*i; 2409*0b8f6341SShri Abhyankar s[0] = b[idx]; s[1] = b[1+idx]; s[2] = b[2+idx]; s[3] = b[3+idx]; s[4] = b[4+idx]; 2410*0b8f6341SShri Abhyankar s[5] = b[5+idx]; s[6] = b[6+idx]; s[7] = b[7+idx]; s[8] = b[8+idx]; s[9] = b[9+idx]; 2411*0b8f6341SShri Abhyankar s[10] = b[10+idx]; s[11] = b[11+idx]; s[12] = b[12+idx]; s[13] = b[13+idx]; s[14] = b[14+idx]; 2412*0b8f6341SShri Abhyankar for(m=0;m<nz;m++){ 2413*0b8f6341SShri Abhyankar idx = bs*vi[m]; 2414*0b8f6341SShri Abhyankar 2415*0b8f6341SShri Abhyankar for(k=0;k<15;k++){ 2416*0b8f6341SShri Abhyankar s[0] -= v[0]*t[k+idx]; 2417*0b8f6341SShri Abhyankar s[1] -= v[1]*t[k+idx]; 2418*0b8f6341SShri Abhyankar s[2] -= v[2]*t[k+idx]; 2419*0b8f6341SShri Abhyankar s[3] -= v[3]*t[k+idx]; 2420*0b8f6341SShri Abhyankar s[4] -= v[4]*t[k+idx]; 2421*0b8f6341SShri Abhyankar s[5] -= v[5]*t[k+idx]; 2422*0b8f6341SShri Abhyankar s[6] -= v[6]*t[k+idx]; 2423*0b8f6341SShri Abhyankar s[7] -= v[7]*t[k+idx]; 2424*0b8f6341SShri Abhyankar s[8] -= v[8]*t[k+idx]; 2425*0b8f6341SShri Abhyankar s[9] -= v[9]*t[k+idx]; 2426*0b8f6341SShri Abhyankar s[10] -= v[10]*t[k+idx]; 2427*0b8f6341SShri Abhyankar s[11] -= v[11]*t[k+idx]; 2428*0b8f6341SShri Abhyankar s[12] -= v[12]*t[k+idx]; 2429*0b8f6341SShri Abhyankar s[13] -= v[13]*t[k+idx]; 2430*0b8f6341SShri Abhyankar s[14] -= v[14]*t[k+idx]; 2431*0b8f6341SShri Abhyankar v += 15; 2432*0b8f6341SShri Abhyankar } 2433*0b8f6341SShri Abhyankar } 2434*0b8f6341SShri Abhyankar idx = bs*i; 2435*0b8f6341SShri Abhyankar t[idx] = s[0]; t[1+idx] = s[1]; t[2+idx] = s[2]; t[3+idx] = s[3]; t[4+idx] = s[4]; 2436*0b8f6341SShri Abhyankar t[5+idx] = s[5]; t[6+idx] = s[6]; t[7+idx] = s[7]; t[8+idx] = s[8]; t[9+idx] = s[9]; 2437*0b8f6341SShri Abhyankar t[10+idx] = s[10]; t[11+idx] = s[11]; t[12+idx] = s[12]; t[13+idx] = s[13]; t[14+idx] = s[14]; 2438*0b8f6341SShri Abhyankar 2439*0b8f6341SShri Abhyankar } 2440*0b8f6341SShri Abhyankar /* backward solve the upper triangular */ 2441*0b8f6341SShri Abhyankar for (i=n-1; i>=0; i--){ 2442*0b8f6341SShri Abhyankar v = aa + bs2*(adiag[i+1]+1); 2443*0b8f6341SShri Abhyankar vi = aj + adiag[i+1]+1; 2444*0b8f6341SShri Abhyankar nz = adiag[i] - adiag[i+1] - 1; 2445*0b8f6341SShri Abhyankar idt = bs*i; 2446*0b8f6341SShri Abhyankar s[0] = t[idt]; s[1] = t[1+idt]; s[2] = t[2+idt]; s[3] = t[3+idt]; s[4] = t[4+idt]; 2447*0b8f6341SShri Abhyankar s[5] = t[5+idt]; s[6] = t[6+idt]; s[7] = t[7+idt]; s[8] = t[8+idt]; s[9] = t[9+idt]; 2448*0b8f6341SShri Abhyankar s[10] = t[10+idt]; s[11] = t[11+idt]; s[12] = t[12+idt]; s[13] = t[13+idt]; s[14] = t[14+idt]; 2449*0b8f6341SShri Abhyankar 2450*0b8f6341SShri Abhyankar for(m=0;m<nz;m++){ 2451*0b8f6341SShri Abhyankar idx = bs*vi[m]; 2452*0b8f6341SShri Abhyankar for(k=0;k<15;k++){ 2453*0b8f6341SShri Abhyankar s[0] -= v[0]*t[k+idx]; 2454*0b8f6341SShri Abhyankar s[1] -= v[1]*t[k+idx]; 2455*0b8f6341SShri Abhyankar s[2] -= v[2]*t[k+idx]; 2456*0b8f6341SShri Abhyankar s[3] -= v[3]*t[k+idx]; 2457*0b8f6341SShri Abhyankar s[4] -= v[4]*t[k+idx]; 2458*0b8f6341SShri Abhyankar s[5] -= v[5]*t[k+idx]; 2459*0b8f6341SShri Abhyankar s[6] -= v[6]*t[k+idx]; 2460*0b8f6341SShri Abhyankar s[7] -= v[7]*t[k+idx]; 2461*0b8f6341SShri Abhyankar s[8] -= v[8]*t[k+idx]; 2462*0b8f6341SShri Abhyankar s[9] -= v[9]*t[k+idx]; 2463*0b8f6341SShri Abhyankar s[10] -= v[10]*t[k+idx]; 2464*0b8f6341SShri Abhyankar s[11] -= v[11]*t[k+idx]; 2465*0b8f6341SShri Abhyankar s[12] -= v[12]*t[k+idx]; 2466*0b8f6341SShri Abhyankar s[13] -= v[13]*t[k+idx]; 2467*0b8f6341SShri Abhyankar s[14] -= v[14]*t[k+idx]; 2468*0b8f6341SShri Abhyankar v += 15; 2469*0b8f6341SShri Abhyankar } 2470*0b8f6341SShri Abhyankar } 2471*0b8f6341SShri Abhyankar idc = bs*i; 2472*0b8f6341SShri Abhyankar 2473*0b8f6341SShri Abhyankar for(k=0;k<15;k++){ 2474*0b8f6341SShri Abhyankar t[idt] += v[0]*s[k]; 2475*0b8f6341SShri Abhyankar t[1+idt] += v[1]*s[k]; 2476*0b8f6341SShri Abhyankar t[2+idt] += v[2]*s[k]; 2477*0b8f6341SShri Abhyankar t[3+idt] += v[3]*s[k]; 2478*0b8f6341SShri Abhyankar t[4+idt] += v[4]*s[k]; 2479*0b8f6341SShri Abhyankar t[5+idt] += v[5]*s[k]; 2480*0b8f6341SShri Abhyankar t[6+idt] += v[6]*s[k]; 2481*0b8f6341SShri Abhyankar t[7+idt] += v[7]*s[k]; 2482*0b8f6341SShri Abhyankar t[8+idt] += v[8]*s[k]; 2483*0b8f6341SShri Abhyankar t[9+idt] += v[9]*s[k]; 2484*0b8f6341SShri Abhyankar t[10+idt] += v[10]*s[k]; 2485*0b8f6341SShri Abhyankar t[11+idt] += v[11]*s[k]; 2486*0b8f6341SShri Abhyankar t[12+idt] += v[12]*s[k]; 2487*0b8f6341SShri Abhyankar t[13+idt] += v[13]*s[k]; 2488*0b8f6341SShri Abhyankar t[14+idt] += v[14]*s[k]; 2489*0b8f6341SShri Abhyankar v += 15; 2490*0b8f6341SShri Abhyankar } 2491*0b8f6341SShri Abhyankar x[idc] = t[idt]; x[1+idc] = t[1+idt]; x[2+idc] = t[2+idt]; x[3+idc] = t[3+idt]; x[4+idc] = t[4+idt]; 2492*0b8f6341SShri Abhyankar x[5+idc] = t[5+idt]; x[6+idc] = t[6+idt]; x[7+idc] = t[7+idt]; x[8+idc] = t[8+idt]; x[9+idc] = t[9+idt]; 2493*0b8f6341SShri Abhyankar x[10+idc] = t[10+idt]; x[11+idc] = t[11+idt]; x[12+idc] = t[12+idt]; x[13+idc] = t[13+idt]; x[14+idc] = t[14+idt]; 2494*0b8f6341SShri Abhyankar } 2495*0b8f6341SShri Abhyankar 2496*0b8f6341SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 2497*0b8f6341SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 2498*0b8f6341SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 2499*0b8f6341SShri Abhyankar PetscFunctionReturn(0); 2500*0b8f6341SShri Abhyankar } 2501*0b8f6341SShri Abhyankar 2502*0b8f6341SShri Abhyankar 2503*0b8f6341SShri Abhyankar #undef __FUNCT__ 250406e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_7_inplace" 250506e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_7_inplace(Mat A,Vec bb,Vec xx) 25064e2b4712SSatish Balay { 25074e2b4712SSatish Balay Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 25084e2b4712SSatish Balay IS iscol=a->col,isrow=a->row; 25096849ba73SBarry Smith PetscErrorCode ierr; 2510b3260449SShri Abhyankar const PetscInt *r,*c,*ai=a->i,*aj=a->j; 2511b3260449SShri Abhyankar const PetscInt *rout,*cout,*diag = a->diag,*vi,n=a->mbs; 2512b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc; 2513b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 2514b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t; 2515b3260449SShri Abhyankar const PetscScalar *b; 25164e2b4712SSatish Balay 25174e2b4712SSatish Balay PetscFunctionBegin; 2518b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 25191ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 2520f1af5d2fSBarry Smith t = a->solve_work; 25214e2b4712SSatish Balay 25224e2b4712SSatish Balay ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 25234e2b4712SSatish Balay ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 25244e2b4712SSatish Balay 25254e2b4712SSatish Balay /* forward solve the lower triangular */ 25264e2b4712SSatish Balay idx = 7*(*r++); 2527f1af5d2fSBarry Smith t[0] = b[idx]; t[1] = b[1+idx]; 2528f1af5d2fSBarry Smith t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx]; 2529f1af5d2fSBarry Smith t[5] = b[5+idx]; t[6] = b[6+idx]; 25304e2b4712SSatish Balay 25314e2b4712SSatish Balay for (i=1; i<n; i++) { 25324e2b4712SSatish Balay v = aa + 49*ai[i]; 25334e2b4712SSatish Balay vi = aj + ai[i]; 25344e2b4712SSatish Balay nz = diag[i] - ai[i]; 25354e2b4712SSatish Balay idx = 7*(*r++); 2536f1af5d2fSBarry Smith s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 2537f1af5d2fSBarry Smith s5 = b[4+idx];s6 = b[5+idx];s7 = b[6+idx]; 25384e2b4712SSatish Balay while (nz--) { 25394e2b4712SSatish Balay idx = 7*(*vi++); 2540f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx];x3 = t[2+idx]; 2541f1af5d2fSBarry Smith x4 = t[3+idx];x5 = t[4+idx]; 2542f1af5d2fSBarry Smith x6 = t[5+idx];x7 = t[6+idx]; 2543f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7; 2544f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7; 2545f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7; 2546f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7; 2547f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7; 2548f1af5d2fSBarry Smith s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7; 2549f1af5d2fSBarry Smith s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7; 25504e2b4712SSatish Balay v += 49; 25514e2b4712SSatish Balay } 25524e2b4712SSatish Balay idx = 7*i; 2553f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; 2554f1af5d2fSBarry Smith t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5; 2555f1af5d2fSBarry Smith t[5+idx] = s6;t[6+idx] = s7; 25564e2b4712SSatish Balay } 25574e2b4712SSatish Balay /* backward solve the upper triangular */ 25584e2b4712SSatish Balay for (i=n-1; i>=0; i--){ 25594e2b4712SSatish Balay v = aa + 49*diag[i] + 49; 25604e2b4712SSatish Balay vi = aj + diag[i] + 1; 25614e2b4712SSatish Balay nz = ai[i+1] - diag[i] - 1; 25624e2b4712SSatish Balay idt = 7*i; 2563f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; 2564f1af5d2fSBarry Smith s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt]; 2565f1af5d2fSBarry Smith s6 = t[5+idt];s7 = t[6+idt]; 25664e2b4712SSatish Balay while (nz--) { 25674e2b4712SSatish Balay idx = 7*(*vi++); 2568f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; 2569f1af5d2fSBarry Smith x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 2570f1af5d2fSBarry Smith x6 = t[5+idx]; x7 = t[6+idx]; 2571f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7; 2572f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7; 2573f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7; 2574f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7; 2575f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7; 2576f1af5d2fSBarry Smith s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7; 2577f1af5d2fSBarry Smith s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7; 25784e2b4712SSatish Balay v += 49; 25794e2b4712SSatish Balay } 25804e2b4712SSatish Balay idc = 7*(*c--); 25814e2b4712SSatish Balay v = aa + 49*diag[i]; 2582f1af5d2fSBarry Smith x[idc] = t[idt] = v[0]*s1+v[7]*s2+v[14]*s3+ 2583f1af5d2fSBarry Smith v[21]*s4+v[28]*s5+v[35]*s6+v[42]*s7; 2584f1af5d2fSBarry Smith x[1+idc] = t[1+idt] = v[1]*s1+v[8]*s2+v[15]*s3+ 2585f1af5d2fSBarry Smith v[22]*s4+v[29]*s5+v[36]*s6+v[43]*s7; 2586f1af5d2fSBarry Smith x[2+idc] = t[2+idt] = v[2]*s1+v[9]*s2+v[16]*s3+ 2587f1af5d2fSBarry Smith v[23]*s4+v[30]*s5+v[37]*s6+v[44]*s7; 2588f1af5d2fSBarry Smith x[3+idc] = t[3+idt] = v[3]*s1+v[10]*s2+v[17]*s3+ 2589f1af5d2fSBarry Smith v[24]*s4+v[31]*s5+v[38]*s6+v[45]*s7; 2590f1af5d2fSBarry Smith x[4+idc] = t[4+idt] = v[4]*s1+v[11]*s2+v[18]*s3+ 2591f1af5d2fSBarry Smith v[25]*s4+v[32]*s5+v[39]*s6+v[46]*s7; 2592f1af5d2fSBarry Smith x[5+idc] = t[5+idt] = v[5]*s1+v[12]*s2+v[19]*s3+ 2593f1af5d2fSBarry Smith v[26]*s4+v[33]*s5+v[40]*s6+v[47]*s7; 2594f1af5d2fSBarry Smith x[6+idc] = t[6+idt] = v[6]*s1+v[13]*s2+v[20]*s3+ 2595f1af5d2fSBarry Smith v[27]*s4+v[34]*s5+v[41]*s6+v[48]*s7; 25964e2b4712SSatish Balay } 25974e2b4712SSatish Balay 25984e2b4712SSatish Balay ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 25994e2b4712SSatish Balay ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 2600b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 26011ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 2602dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr); 26034e2b4712SSatish Balay PetscFunctionReturn(0); 26044e2b4712SSatish Balay } 26054e2b4712SSatish Balay 26068f690400SShri Abhyankar #undef __FUNCT__ 26074dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_7" 26084dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_7(Mat A,Vec bb,Vec xx) 260935aa4fcfSShri Abhyankar { 261035aa4fcfSShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 261135aa4fcfSShri Abhyankar IS iscol=a->col,isrow=a->row; 261235aa4fcfSShri Abhyankar PetscErrorCode ierr; 2613b3260449SShri Abhyankar const PetscInt *r,*c,*ai=a->i,*aj=a->j,*adiag=a->diag; 2614b3260449SShri Abhyankar const PetscInt n=a->mbs,*rout,*cout,*vi; 2615b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc,m; 2616b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 2617b3260449SShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t; 2618b3260449SShri Abhyankar const PetscScalar *b; 261935aa4fcfSShri Abhyankar 262035aa4fcfSShri Abhyankar PetscFunctionBegin; 2621b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 262235aa4fcfSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 262335aa4fcfSShri Abhyankar t = a->solve_work; 262435aa4fcfSShri Abhyankar 262535aa4fcfSShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 262635aa4fcfSShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 262735aa4fcfSShri Abhyankar 262835aa4fcfSShri Abhyankar /* forward solve the lower triangular */ 262935aa4fcfSShri Abhyankar idx = 7*r[0]; 263035aa4fcfSShri Abhyankar t[0] = b[idx]; t[1] = b[1+idx]; 263135aa4fcfSShri Abhyankar t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx]; 263235aa4fcfSShri Abhyankar t[5] = b[5+idx]; t[6] = b[6+idx]; 263335aa4fcfSShri Abhyankar 263435aa4fcfSShri Abhyankar for (i=1; i<n; i++) { 263535aa4fcfSShri Abhyankar v = aa + 49*ai[i]; 263635aa4fcfSShri Abhyankar vi = aj + ai[i]; 263735aa4fcfSShri Abhyankar nz = ai[i+1] - ai[i]; 263835aa4fcfSShri Abhyankar idx = 7*r[i]; 263935aa4fcfSShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 264035aa4fcfSShri Abhyankar s5 = b[4+idx];s6 = b[5+idx];s7 = b[6+idx]; 264135aa4fcfSShri Abhyankar for(m=0;m<nz;m++){ 264235aa4fcfSShri Abhyankar idx = 7*vi[m]; 264335aa4fcfSShri Abhyankar x1 = t[idx]; x2 = t[1+idx];x3 = t[2+idx]; 264435aa4fcfSShri Abhyankar x4 = t[3+idx];x5 = t[4+idx]; 264535aa4fcfSShri Abhyankar x6 = t[5+idx];x7 = t[6+idx]; 264635aa4fcfSShri Abhyankar s1 -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7; 264735aa4fcfSShri Abhyankar s2 -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7; 264835aa4fcfSShri Abhyankar s3 -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7; 264935aa4fcfSShri Abhyankar s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7; 265035aa4fcfSShri Abhyankar s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7; 265135aa4fcfSShri Abhyankar s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7; 265235aa4fcfSShri Abhyankar s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7; 265335aa4fcfSShri Abhyankar v += 49; 265435aa4fcfSShri Abhyankar } 265535aa4fcfSShri Abhyankar idx = 7*i; 265635aa4fcfSShri Abhyankar t[idx] = s1;t[1+idx] = s2; 265735aa4fcfSShri Abhyankar t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5; 265835aa4fcfSShri Abhyankar t[5+idx] = s6;t[6+idx] = s7; 265935aa4fcfSShri Abhyankar } 266035aa4fcfSShri Abhyankar /* backward solve the upper triangular */ 266135aa4fcfSShri Abhyankar for (i=n-1; i>=0; i--){ 266235aa4fcfSShri Abhyankar v = aa + 49*(adiag[i+1]+1); 266335aa4fcfSShri Abhyankar vi = aj + adiag[i+1]+1; 266435aa4fcfSShri Abhyankar nz = adiag[i] - adiag[i+1] - 1; 266535aa4fcfSShri Abhyankar idt = 7*i; 266635aa4fcfSShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; 266735aa4fcfSShri Abhyankar s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt]; 266835aa4fcfSShri Abhyankar s6 = t[5+idt];s7 = t[6+idt]; 266935aa4fcfSShri Abhyankar for(m=0;m<nz;m++){ 267035aa4fcfSShri Abhyankar idx = 7*vi[m]; 267135aa4fcfSShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; 267235aa4fcfSShri Abhyankar x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 267335aa4fcfSShri Abhyankar x6 = t[5+idx]; x7 = t[6+idx]; 267435aa4fcfSShri Abhyankar s1 -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7; 267535aa4fcfSShri Abhyankar s2 -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7; 267635aa4fcfSShri Abhyankar s3 -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7; 267735aa4fcfSShri Abhyankar s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7; 267835aa4fcfSShri Abhyankar s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7; 267935aa4fcfSShri Abhyankar s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7; 268035aa4fcfSShri Abhyankar s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7; 268135aa4fcfSShri Abhyankar v += 49; 268235aa4fcfSShri Abhyankar } 268335aa4fcfSShri Abhyankar idc = 7*c[i]; 268435aa4fcfSShri Abhyankar x[idc] = t[idt] = v[0]*s1+v[7]*s2+v[14]*s3+ 268535aa4fcfSShri Abhyankar v[21]*s4+v[28]*s5+v[35]*s6+v[42]*s7; 268635aa4fcfSShri Abhyankar x[1+idc] = t[1+idt] = v[1]*s1+v[8]*s2+v[15]*s3+ 268735aa4fcfSShri Abhyankar v[22]*s4+v[29]*s5+v[36]*s6+v[43]*s7; 268835aa4fcfSShri Abhyankar x[2+idc] = t[2+idt] = v[2]*s1+v[9]*s2+v[16]*s3+ 268935aa4fcfSShri Abhyankar v[23]*s4+v[30]*s5+v[37]*s6+v[44]*s7; 269035aa4fcfSShri Abhyankar x[3+idc] = t[3+idt] = v[3]*s1+v[10]*s2+v[17]*s3+ 269135aa4fcfSShri Abhyankar v[24]*s4+v[31]*s5+v[38]*s6+v[45]*s7; 269235aa4fcfSShri Abhyankar x[4+idc] = t[4+idt] = v[4]*s1+v[11]*s2+v[18]*s3+ 269335aa4fcfSShri Abhyankar v[25]*s4+v[32]*s5+v[39]*s6+v[46]*s7; 269435aa4fcfSShri Abhyankar x[5+idc] = t[5+idt] = v[5]*s1+v[12]*s2+v[19]*s3+ 269535aa4fcfSShri Abhyankar v[26]*s4+v[33]*s5+v[40]*s6+v[47]*s7; 269635aa4fcfSShri Abhyankar x[6+idc] = t[6+idt] = v[6]*s1+v[13]*s2+v[20]*s3+ 269735aa4fcfSShri Abhyankar v[27]*s4+v[34]*s5+v[41]*s6+v[48]*s7; 269835aa4fcfSShri Abhyankar } 269935aa4fcfSShri Abhyankar 270035aa4fcfSShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 270135aa4fcfSShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 2702b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 270335aa4fcfSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 270435aa4fcfSShri Abhyankar ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr); 270535aa4fcfSShri Abhyankar PetscFunctionReturn(0); 270635aa4fcfSShri Abhyankar } 270735aa4fcfSShri Abhyankar 270835aa4fcfSShri Abhyankar #undef __FUNCT__ 270906e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_7_NaturalOrdering_inplace" 271006e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_7_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 271115091d37SBarry Smith { 271215091d37SBarry Smith Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 2713b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 2714dfbe8321SBarry Smith PetscErrorCode ierr; 2715b3260449SShri Abhyankar PetscInt i,nz,idx,idt,jdx; 2716d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 2717d9fead3dSBarry Smith PetscScalar *x,s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7; 2718d9fead3dSBarry Smith const PetscScalar *b; 271915091d37SBarry Smith 272015091d37SBarry Smith PetscFunctionBegin; 2721d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 27221ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 272315091d37SBarry Smith /* forward solve the lower triangular */ 272415091d37SBarry Smith idx = 0; 272515091d37SBarry Smith x[0] = b[idx]; x[1] = b[1+idx]; x[2] = b[2+idx]; 272615091d37SBarry Smith x[3] = b[3+idx]; x[4] = b[4+idx]; x[5] = b[5+idx]; 272715091d37SBarry Smith x[6] = b[6+idx]; 272815091d37SBarry Smith for (i=1; i<n; i++) { 272915091d37SBarry Smith v = aa + 49*ai[i]; 273015091d37SBarry Smith vi = aj + ai[i]; 273115091d37SBarry Smith nz = diag[i] - ai[i]; 273215091d37SBarry Smith idx = 7*i; 2733f1af5d2fSBarry Smith s1 = b[idx]; s2 = b[1+idx]; s3 = b[2+idx]; 2734f1af5d2fSBarry Smith s4 = b[3+idx]; s5 = b[4+idx]; s6 = b[5+idx]; 2735f1af5d2fSBarry Smith s7 = b[6+idx]; 273615091d37SBarry Smith while (nz--) { 273715091d37SBarry Smith jdx = 7*(*vi++); 273815091d37SBarry Smith x1 = x[jdx]; x2 = x[1+jdx]; x3 = x[2+jdx]; 273915091d37SBarry Smith x4 = x[3+jdx]; x5 = x[4+jdx]; x6 = x[5+jdx]; 274015091d37SBarry Smith x7 = x[6+jdx]; 2741f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7; 2742f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7; 2743f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7; 2744f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7; 2745f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7; 2746f1af5d2fSBarry Smith s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7; 2747f1af5d2fSBarry Smith s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7; 274815091d37SBarry Smith v += 49; 274915091d37SBarry Smith } 2750f1af5d2fSBarry Smith x[idx] = s1; 2751f1af5d2fSBarry Smith x[1+idx] = s2; 2752f1af5d2fSBarry Smith x[2+idx] = s3; 2753f1af5d2fSBarry Smith x[3+idx] = s4; 2754f1af5d2fSBarry Smith x[4+idx] = s5; 2755f1af5d2fSBarry Smith x[5+idx] = s6; 2756f1af5d2fSBarry Smith x[6+idx] = s7; 275715091d37SBarry Smith } 275815091d37SBarry Smith /* backward solve the upper triangular */ 275915091d37SBarry Smith for (i=n-1; i>=0; i--){ 276015091d37SBarry Smith v = aa + 49*diag[i] + 49; 276115091d37SBarry Smith vi = aj + diag[i] + 1; 276215091d37SBarry Smith nz = ai[i+1] - diag[i] - 1; 276315091d37SBarry Smith idt = 7*i; 2764f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; 2765f1af5d2fSBarry Smith s3 = x[2+idt]; s4 = x[3+idt]; 2766f1af5d2fSBarry Smith s5 = x[4+idt]; s6 = x[5+idt]; 2767f1af5d2fSBarry Smith s7 = x[6+idt]; 276815091d37SBarry Smith while (nz--) { 276915091d37SBarry Smith idx = 7*(*vi++); 277015091d37SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; 277115091d37SBarry Smith x4 = x[3+idx]; x5 = x[4+idx]; x6 = x[5+idx]; 277215091d37SBarry Smith x7 = x[6+idx]; 2773f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7; 2774f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7; 2775f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7; 2776f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7; 2777f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7; 2778f1af5d2fSBarry Smith s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7; 2779f1af5d2fSBarry Smith s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7; 278015091d37SBarry Smith v += 49; 278115091d37SBarry Smith } 278215091d37SBarry Smith v = aa + 49*diag[i]; 2783f1af5d2fSBarry Smith x[idt] = v[0]*s1 + v[7]*s2 + v[14]*s3 + v[21]*s4 2784f1af5d2fSBarry Smith + v[28]*s5 + v[35]*s6 + v[42]*s7; 2785f1af5d2fSBarry Smith x[1+idt] = v[1]*s1 + v[8]*s2 + v[15]*s3 + v[22]*s4 2786f1af5d2fSBarry Smith + v[29]*s5 + v[36]*s6 + v[43]*s7; 2787f1af5d2fSBarry Smith x[2+idt] = v[2]*s1 + v[9]*s2 + v[16]*s3 + v[23]*s4 2788f1af5d2fSBarry Smith + v[30]*s5 + v[37]*s6 + v[44]*s7; 2789f1af5d2fSBarry Smith x[3+idt] = v[3]*s1 + v[10]*s2 + v[17]*s3 + v[24]*s4 2790f1af5d2fSBarry Smith + v[31]*s5 + v[38]*s6 + v[45]*s7; 2791f1af5d2fSBarry Smith x[4+idt] = v[4]*s1 + v[11]*s2 + v[18]*s3 + v[25]*s4 2792f1af5d2fSBarry Smith + v[32]*s5 + v[39]*s6 + v[46]*s7; 2793f1af5d2fSBarry Smith x[5+idt] = v[5]*s1 + v[12]*s2 + v[19]*s3 + v[26]*s4 2794f1af5d2fSBarry Smith + v[33]*s5 + v[40]*s6 + v[47]*s7; 2795f1af5d2fSBarry Smith x[6+idt] = v[6]*s1 + v[13]*s2 + v[20]*s3 + v[27]*s4 2796f1af5d2fSBarry Smith + v[34]*s5 + v[41]*s6 + v[48]*s7; 279715091d37SBarry Smith } 279815091d37SBarry Smith 2799d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 28001ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 2801dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr); 280215091d37SBarry Smith PetscFunctionReturn(0); 280315091d37SBarry Smith } 280415091d37SBarry Smith 2805cee9d6f2SShri Abhyankar #undef __FUNCT__ 28064dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_7_NaturalOrdering" 28074dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_7_NaturalOrdering(Mat A,Vec bb,Vec xx) 280853cca76cSShri Abhyankar { 280953cca76cSShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 2810b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 281153cca76cSShri Abhyankar PetscErrorCode ierr; 2812b3260449SShri Abhyankar PetscInt i,k,nz,idx,jdx,idt; 2813b3260449SShri Abhyankar const PetscInt bs = A->rmap->bs,bs2 = a->bs2; 281453cca76cSShri Abhyankar const MatScalar *aa=a->a,*v; 281553cca76cSShri Abhyankar PetscScalar *x; 281653cca76cSShri Abhyankar const PetscScalar *b; 281753cca76cSShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7; 281853cca76cSShri Abhyankar 281953cca76cSShri Abhyankar PetscFunctionBegin; 282053cca76cSShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 282153cca76cSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 282253cca76cSShri Abhyankar /* forward solve the lower triangular */ 282353cca76cSShri Abhyankar idx = 0; 282453cca76cSShri Abhyankar x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx]; 282553cca76cSShri Abhyankar x[4] = b[4+idx];x[5] = b[5+idx];x[6] = b[6+idx]; 282653cca76cSShri Abhyankar for (i=1; i<n; i++) { 282753cca76cSShri Abhyankar v = aa + bs2*ai[i]; 282853cca76cSShri Abhyankar vi = aj + ai[i]; 282953cca76cSShri Abhyankar nz = ai[i+1] - ai[i]; 283053cca76cSShri Abhyankar idx = bs*i; 283153cca76cSShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 283253cca76cSShri Abhyankar s5 = b[4+idx];s6 = b[5+idx];s7 = b[6+idx]; 283353cca76cSShri Abhyankar for(k=0;k<nz;k++) { 283453cca76cSShri Abhyankar jdx = bs*vi[k]; 283553cca76cSShri Abhyankar x1 = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx]; 283653cca76cSShri Abhyankar x5 = x[4+jdx]; x6 = x[5+jdx];x7 = x[6+jdx]; 283753cca76cSShri Abhyankar s1 -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7; 283853cca76cSShri Abhyankar s2 -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7; 283953cca76cSShri Abhyankar s3 -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7; 284053cca76cSShri Abhyankar s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7; 284153cca76cSShri Abhyankar s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7; 284253cca76cSShri Abhyankar s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7; 284353cca76cSShri Abhyankar s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7; 284453cca76cSShri Abhyankar v += bs2; 284553cca76cSShri Abhyankar } 284653cca76cSShri Abhyankar 284753cca76cSShri Abhyankar x[idx] = s1; 284853cca76cSShri Abhyankar x[1+idx] = s2; 284953cca76cSShri Abhyankar x[2+idx] = s3; 285053cca76cSShri Abhyankar x[3+idx] = s4; 285153cca76cSShri Abhyankar x[4+idx] = s5; 285253cca76cSShri Abhyankar x[5+idx] = s6; 285353cca76cSShri Abhyankar x[6+idx] = s7; 285453cca76cSShri Abhyankar } 285553cca76cSShri Abhyankar 285653cca76cSShri Abhyankar /* backward solve the upper triangular */ 285753cca76cSShri Abhyankar for (i=n-1; i>=0; i--){ 285853cca76cSShri Abhyankar v = aa + bs2*(adiag[i+1]+1); 285953cca76cSShri Abhyankar vi = aj + adiag[i+1]+1; 286053cca76cSShri Abhyankar nz = adiag[i] - adiag[i+1]-1; 286153cca76cSShri Abhyankar idt = bs*i; 286253cca76cSShri Abhyankar s1 = x[idt]; s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt]; 286353cca76cSShri Abhyankar s5 = x[4+idt];s6 = x[5+idt];s7 = x[6+idt]; 286453cca76cSShri Abhyankar for(k=0;k<nz;k++) { 286553cca76cSShri Abhyankar idx = bs*vi[k]; 286653cca76cSShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx]; 286753cca76cSShri Abhyankar x5 = x[4+idx];x6 = x[5+idx];x7 = x[6+idx]; 286853cca76cSShri Abhyankar s1 -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7; 286953cca76cSShri Abhyankar s2 -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7; 287053cca76cSShri Abhyankar s3 -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7; 287153cca76cSShri Abhyankar s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7; 287253cca76cSShri Abhyankar s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7; 287353cca76cSShri Abhyankar s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7; 287453cca76cSShri Abhyankar s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7; 287553cca76cSShri Abhyankar v += bs2; 287653cca76cSShri Abhyankar } 287753cca76cSShri Abhyankar /* x = inv_diagonal*x */ 287853cca76cSShri Abhyankar x[idt] = v[0]*s1 + v[7]*s2 + v[14]*s3 + v[21]*s4 + v[28]*s5 + v[35]*s6 + v[42]*s7; 287953cca76cSShri Abhyankar x[1+idt] = v[1]*s1 + v[8]*s2 + v[15]*s3 + v[22]*s4 + v[29]*s5 + v[36]*s6 + v[43]*s7; 288053cca76cSShri Abhyankar x[2+idt] = v[2]*s1 + v[9]*s2 + v[16]*s3 + v[23]*s4 + v[30]*s5 + v[37]*s6 + v[44]*s7; 288153cca76cSShri Abhyankar x[3+idt] = v[3]*s1 + v[10]*s2 + v[17]*s3 + v[24]*s4 + v[31]*s5 + v[38]*s6 + v[45]*s7; 288253cca76cSShri Abhyankar x[4+idt] = v[4]*s1 + v[11]*s2 + v[18]*s3 + v[25]*s4 + v[32]*s5 + v[39]*s6 + v[46]*s7; 288353cca76cSShri Abhyankar x[5+idt] = v[5]*s1 + v[12]*s2 + v[19]*s3 + v[26]*s4 + v[33]*s5 + v[40]*s6 + v[47]*s7; 288453cca76cSShri Abhyankar x[6+idt] = v[6]*s1 + v[13]*s2 + v[20]*s3 + v[27]*s4 + v[34]*s5 + v[41]*s6 + v[48]*s7; 288553cca76cSShri Abhyankar } 288653cca76cSShri Abhyankar 288753cca76cSShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 288853cca76cSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 288953cca76cSShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 289053cca76cSShri Abhyankar PetscFunctionReturn(0); 289153cca76cSShri Abhyankar } 289253cca76cSShri Abhyankar 289353cca76cSShri Abhyankar #undef __FUNCT__ 289406e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_6_inplace" 289506e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_6_inplace(Mat A,Vec bb,Vec xx) 289615091d37SBarry Smith { 289715091d37SBarry Smith Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 289815091d37SBarry Smith IS iscol=a->col,isrow=a->row; 28996849ba73SBarry Smith PetscErrorCode ierr; 29005d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout; 2901b3260449SShri Abhyankar const PetscInt *diag = a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 2902b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc; 2903d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 2904d9fead3dSBarry Smith PetscScalar *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*t; 2905d9fead3dSBarry Smith const PetscScalar *b; 2906b3260449SShri Abhyankar 290715091d37SBarry Smith PetscFunctionBegin; 2908d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 29091ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 2910f1af5d2fSBarry Smith t = a->solve_work; 291115091d37SBarry Smith 291215091d37SBarry Smith ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 291315091d37SBarry Smith ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 291415091d37SBarry Smith 291515091d37SBarry Smith /* forward solve the lower triangular */ 291615091d37SBarry Smith idx = 6*(*r++); 2917f1af5d2fSBarry Smith t[0] = b[idx]; t[1] = b[1+idx]; 2918f1af5d2fSBarry Smith t[2] = b[2+idx]; t[3] = b[3+idx]; 2919f1af5d2fSBarry Smith t[4] = b[4+idx]; t[5] = b[5+idx]; 292015091d37SBarry Smith for (i=1; i<n; i++) { 292115091d37SBarry Smith v = aa + 36*ai[i]; 292215091d37SBarry Smith vi = aj + ai[i]; 292315091d37SBarry Smith nz = diag[i] - ai[i]; 292415091d37SBarry Smith idx = 6*(*r++); 2925f1af5d2fSBarry Smith s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 2926f1af5d2fSBarry Smith s5 = b[4+idx]; s6 = b[5+idx]; 292715091d37SBarry Smith while (nz--) { 292815091d37SBarry Smith idx = 6*(*vi++); 2929f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; 2930f1af5d2fSBarry Smith x4 = t[3+idx]; x5 = t[4+idx]; x6 = t[5+idx]; 2931f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6; 2932f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6; 2933f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6; 2934f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6; 2935f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6; 2936f1af5d2fSBarry Smith s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6; 293715091d37SBarry Smith v += 36; 293815091d37SBarry Smith } 293915091d37SBarry Smith idx = 6*i; 2940f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; 2941f1af5d2fSBarry Smith t[2+idx] = s3;t[3+idx] = s4; 2942f1af5d2fSBarry Smith t[4+idx] = s5;t[5+idx] = s6; 294315091d37SBarry Smith } 294415091d37SBarry Smith /* backward solve the upper triangular */ 294515091d37SBarry Smith for (i=n-1; i>=0; i--){ 294615091d37SBarry Smith v = aa + 36*diag[i] + 36; 294715091d37SBarry Smith vi = aj + diag[i] + 1; 294815091d37SBarry Smith nz = ai[i+1] - diag[i] - 1; 294915091d37SBarry Smith idt = 6*i; 2950f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; 2951f1af5d2fSBarry Smith s3 = t[2+idt];s4 = t[3+idt]; 2952f1af5d2fSBarry Smith s5 = t[4+idt];s6 = t[5+idt]; 295315091d37SBarry Smith while (nz--) { 295415091d37SBarry Smith idx = 6*(*vi++); 2955f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; 2956f1af5d2fSBarry Smith x3 = t[2+idx]; x4 = t[3+idx]; 2957f1af5d2fSBarry Smith x5 = t[4+idx]; x6 = t[5+idx]; 2958f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6; 2959f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6; 2960f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6; 2961f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6; 2962f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6; 2963f1af5d2fSBarry Smith s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6; 296415091d37SBarry Smith v += 36; 296515091d37SBarry Smith } 296615091d37SBarry Smith idc = 6*(*c--); 296715091d37SBarry Smith v = aa + 36*diag[i]; 2968f1af5d2fSBarry Smith x[idc] = t[idt] = v[0]*s1+v[6]*s2+v[12]*s3+ 2969f1af5d2fSBarry Smith v[18]*s4+v[24]*s5+v[30]*s6; 2970f1af5d2fSBarry Smith x[1+idc] = t[1+idt] = v[1]*s1+v[7]*s2+v[13]*s3+ 2971f1af5d2fSBarry Smith v[19]*s4+v[25]*s5+v[31]*s6; 2972f1af5d2fSBarry Smith x[2+idc] = t[2+idt] = v[2]*s1+v[8]*s2+v[14]*s3+ 2973f1af5d2fSBarry Smith v[20]*s4+v[26]*s5+v[32]*s6; 2974f1af5d2fSBarry Smith x[3+idc] = t[3+idt] = v[3]*s1+v[9]*s2+v[15]*s3+ 2975f1af5d2fSBarry Smith v[21]*s4+v[27]*s5+v[33]*s6; 2976f1af5d2fSBarry Smith x[4+idc] = t[4+idt] = v[4]*s1+v[10]*s2+v[16]*s3+ 2977f1af5d2fSBarry Smith v[22]*s4+v[28]*s5+v[34]*s6; 2978f1af5d2fSBarry Smith x[5+idc] = t[5+idt] = v[5]*s1+v[11]*s2+v[17]*s3+ 2979f1af5d2fSBarry Smith v[23]*s4+v[29]*s5+v[35]*s6; 298015091d37SBarry Smith } 298115091d37SBarry Smith 298215091d37SBarry Smith ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 298315091d37SBarry Smith ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 2984d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 29851ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 2986dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr); 298715091d37SBarry Smith PetscFunctionReturn(0); 298815091d37SBarry Smith } 298915091d37SBarry Smith 29906506fda5SShri Abhyankar #undef __FUNCT__ 29914dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_6" 29924dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_6(Mat A,Vec bb,Vec xx) 29936506fda5SShri Abhyankar { 29946506fda5SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 29956506fda5SShri Abhyankar IS iscol=a->col,isrow=a->row; 29966506fda5SShri Abhyankar PetscErrorCode ierr; 29976506fda5SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 2998b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 2999b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc,m; 30006506fda5SShri Abhyankar const MatScalar *aa=a->a,*v; 30016506fda5SShri Abhyankar PetscScalar *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*t; 30026506fda5SShri Abhyankar const PetscScalar *b; 3003b3260449SShri Abhyankar 30046506fda5SShri Abhyankar PetscFunctionBegin; 30056506fda5SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 30066506fda5SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 30076506fda5SShri Abhyankar t = a->solve_work; 30086506fda5SShri Abhyankar 30096506fda5SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 30106506fda5SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 30116506fda5SShri Abhyankar 30126506fda5SShri Abhyankar /* forward solve the lower triangular */ 30136506fda5SShri Abhyankar idx = 6*r[0]; 30146506fda5SShri Abhyankar t[0] = b[idx]; t[1] = b[1+idx]; 30156506fda5SShri Abhyankar t[2] = b[2+idx]; t[3] = b[3+idx]; 30166506fda5SShri Abhyankar t[4] = b[4+idx]; t[5] = b[5+idx]; 30176506fda5SShri Abhyankar for (i=1; i<n; i++) { 30186506fda5SShri Abhyankar v = aa + 36*ai[i]; 30196506fda5SShri Abhyankar vi = aj + ai[i]; 30206506fda5SShri Abhyankar nz = ai[i+1] - ai[i]; 30216506fda5SShri Abhyankar idx = 6*r[i]; 30226506fda5SShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 30236506fda5SShri Abhyankar s5 = b[4+idx]; s6 = b[5+idx]; 30246506fda5SShri Abhyankar for(m=0;m<nz;m++){ 30256506fda5SShri Abhyankar idx = 6*vi[m]; 30266506fda5SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; 30276506fda5SShri Abhyankar x4 = t[3+idx]; x5 = t[4+idx]; x6 = t[5+idx]; 30286506fda5SShri Abhyankar s1 -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6; 30296506fda5SShri Abhyankar s2 -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6; 30306506fda5SShri Abhyankar s3 -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6; 30316506fda5SShri Abhyankar s4 -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6; 30326506fda5SShri Abhyankar s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6; 30336506fda5SShri Abhyankar s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6; 30346506fda5SShri Abhyankar v += 36; 30356506fda5SShri Abhyankar } 30366506fda5SShri Abhyankar idx = 6*i; 30376506fda5SShri Abhyankar t[idx] = s1;t[1+idx] = s2; 30386506fda5SShri Abhyankar t[2+idx] = s3;t[3+idx] = s4; 30396506fda5SShri Abhyankar t[4+idx] = s5;t[5+idx] = s6; 30406506fda5SShri Abhyankar } 30416506fda5SShri Abhyankar /* backward solve the upper triangular */ 30426506fda5SShri Abhyankar for (i=n-1; i>=0; i--){ 30436506fda5SShri Abhyankar v = aa + 36*(adiag[i+1]+1); 30446506fda5SShri Abhyankar vi = aj + adiag[i+1]+1; 30456506fda5SShri Abhyankar nz = adiag[i] - adiag[i+1] - 1; 30466506fda5SShri Abhyankar idt = 6*i; 30476506fda5SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; 30486506fda5SShri Abhyankar s3 = t[2+idt];s4 = t[3+idt]; 30496506fda5SShri Abhyankar s5 = t[4+idt];s6 = t[5+idt]; 30506506fda5SShri Abhyankar for(m=0;m<nz;m++){ 30516506fda5SShri Abhyankar idx = 6*vi[m]; 30526506fda5SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; 30536506fda5SShri Abhyankar x3 = t[2+idx]; x4 = t[3+idx]; 30546506fda5SShri Abhyankar x5 = t[4+idx]; x6 = t[5+idx]; 30556506fda5SShri Abhyankar s1 -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6; 30566506fda5SShri Abhyankar s2 -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6; 30576506fda5SShri Abhyankar s3 -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6; 30586506fda5SShri Abhyankar s4 -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6; 30596506fda5SShri Abhyankar s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6; 30606506fda5SShri Abhyankar s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6; 30616506fda5SShri Abhyankar v += 36; 30626506fda5SShri Abhyankar } 30636506fda5SShri Abhyankar idc = 6*c[i]; 30646506fda5SShri Abhyankar x[idc] = t[idt] = v[0]*s1+v[6]*s2+v[12]*s3+ 30656506fda5SShri Abhyankar v[18]*s4+v[24]*s5+v[30]*s6; 30666506fda5SShri Abhyankar x[1+idc] = t[1+idt] = v[1]*s1+v[7]*s2+v[13]*s3+ 30676506fda5SShri Abhyankar v[19]*s4+v[25]*s5+v[31]*s6; 30686506fda5SShri Abhyankar x[2+idc] = t[2+idt] = v[2]*s1+v[8]*s2+v[14]*s3+ 30696506fda5SShri Abhyankar v[20]*s4+v[26]*s5+v[32]*s6; 30706506fda5SShri Abhyankar x[3+idc] = t[3+idt] = v[3]*s1+v[9]*s2+v[15]*s3+ 30716506fda5SShri Abhyankar v[21]*s4+v[27]*s5+v[33]*s6; 30726506fda5SShri Abhyankar x[4+idc] = t[4+idt] = v[4]*s1+v[10]*s2+v[16]*s3+ 30736506fda5SShri Abhyankar v[22]*s4+v[28]*s5+v[34]*s6; 30746506fda5SShri Abhyankar x[5+idc] = t[5+idt] = v[5]*s1+v[11]*s2+v[17]*s3+ 30756506fda5SShri Abhyankar v[23]*s4+v[29]*s5+v[35]*s6; 30766506fda5SShri Abhyankar } 30776506fda5SShri Abhyankar 30786506fda5SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 30796506fda5SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 30806506fda5SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 30816506fda5SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 30826506fda5SShri Abhyankar ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr); 30836506fda5SShri Abhyankar PetscFunctionReturn(0); 30846506fda5SShri Abhyankar } 30858f690400SShri Abhyankar 30868f690400SShri Abhyankar #undef __FUNCT__ 308706e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_6_NaturalOrdering_inplace" 308806e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_6_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 308915091d37SBarry Smith { 309015091d37SBarry Smith Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 3091b3260449SShri Abhyankar PetscInt i,nz,idx,idt,jdx; 3092dfbe8321SBarry Smith PetscErrorCode ierr; 3093b3260449SShri Abhyankar const PetscInt *diag = a->diag,*vi,n=a->mbs,*ai=a->i,*aj=a->j; 3094d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 3095d9fead3dSBarry Smith PetscScalar *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6; 3096d9fead3dSBarry Smith const PetscScalar *b; 309715091d37SBarry Smith 309815091d37SBarry Smith PetscFunctionBegin; 3099d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 31001ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 310115091d37SBarry Smith /* forward solve the lower triangular */ 310215091d37SBarry Smith idx = 0; 310315091d37SBarry Smith x[0] = b[idx]; x[1] = b[1+idx]; x[2] = b[2+idx]; 310415091d37SBarry Smith x[3] = b[3+idx]; x[4] = b[4+idx]; x[5] = b[5+idx]; 310515091d37SBarry Smith for (i=1; i<n; i++) { 310615091d37SBarry Smith v = aa + 36*ai[i]; 310715091d37SBarry Smith vi = aj + ai[i]; 310815091d37SBarry Smith nz = diag[i] - ai[i]; 310915091d37SBarry Smith idx = 6*i; 3110f1af5d2fSBarry Smith s1 = b[idx]; s2 = b[1+idx]; s3 = b[2+idx]; 3111f1af5d2fSBarry Smith s4 = b[3+idx]; s5 = b[4+idx]; s6 = b[5+idx]; 311215091d37SBarry Smith while (nz--) { 311315091d37SBarry Smith jdx = 6*(*vi++); 311415091d37SBarry Smith x1 = x[jdx]; x2 = x[1+jdx]; x3 = x[2+jdx]; 311515091d37SBarry Smith x4 = x[3+jdx]; x5 = x[4+jdx]; x6 = x[5+jdx]; 3116f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6; 3117f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6; 3118f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6; 3119f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6; 3120f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6; 3121f1af5d2fSBarry Smith s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6; 312215091d37SBarry Smith v += 36; 312315091d37SBarry Smith } 3124f1af5d2fSBarry Smith x[idx] = s1; 3125f1af5d2fSBarry Smith x[1+idx] = s2; 3126f1af5d2fSBarry Smith x[2+idx] = s3; 3127f1af5d2fSBarry Smith x[3+idx] = s4; 3128f1af5d2fSBarry Smith x[4+idx] = s5; 3129f1af5d2fSBarry Smith x[5+idx] = s6; 313015091d37SBarry Smith } 313115091d37SBarry Smith /* backward solve the upper triangular */ 313215091d37SBarry Smith for (i=n-1; i>=0; i--){ 313315091d37SBarry Smith v = aa + 36*diag[i] + 36; 313415091d37SBarry Smith vi = aj + diag[i] + 1; 313515091d37SBarry Smith nz = ai[i+1] - diag[i] - 1; 313615091d37SBarry Smith idt = 6*i; 3137f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; 3138f1af5d2fSBarry Smith s3 = x[2+idt]; s4 = x[3+idt]; 3139f1af5d2fSBarry Smith s5 = x[4+idt]; s6 = x[5+idt]; 314015091d37SBarry Smith while (nz--) { 314115091d37SBarry Smith idx = 6*(*vi++); 314215091d37SBarry Smith x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; 314315091d37SBarry Smith x4 = x[3+idx]; x5 = x[4+idx]; x6 = x[5+idx]; 3144f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6; 3145f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6; 3146f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6; 3147f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6; 3148f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6; 3149f1af5d2fSBarry Smith s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6; 315015091d37SBarry Smith v += 36; 315115091d37SBarry Smith } 315215091d37SBarry Smith v = aa + 36*diag[i]; 3153f1af5d2fSBarry Smith x[idt] = v[0]*s1 + v[6]*s2 + v[12]*s3 + v[18]*s4 + v[24]*s5 + v[30]*s6; 3154f1af5d2fSBarry Smith x[1+idt] = v[1]*s1 + v[7]*s2 + v[13]*s3 + v[19]*s4 + v[25]*s5 + v[31]*s6; 3155f1af5d2fSBarry Smith x[2+idt] = v[2]*s1 + v[8]*s2 + v[14]*s3 + v[20]*s4 + v[26]*s5 + v[32]*s6; 3156f1af5d2fSBarry Smith x[3+idt] = v[3]*s1 + v[9]*s2 + v[15]*s3 + v[21]*s4 + v[27]*s5 + v[33]*s6; 3157f1af5d2fSBarry Smith x[4+idt] = v[4]*s1 + v[10]*s2 + v[16]*s3 + v[22]*s4 + v[28]*s5 + v[34]*s6; 3158f1af5d2fSBarry Smith x[5+idt] = v[5]*s1 + v[11]*s2 + v[17]*s3 + v[23]*s4 + v[29]*s5 + v[35]*s6; 315915091d37SBarry Smith } 316015091d37SBarry Smith 3161d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 31621ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 3163dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr); 316415091d37SBarry Smith PetscFunctionReturn(0); 316515091d37SBarry Smith } 316615091d37SBarry Smith 3167cee9d6f2SShri Abhyankar #undef __FUNCT__ 31684dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_6_NaturalOrdering" 31694dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_6_NaturalOrdering(Mat A,Vec bb,Vec xx) 317053cca76cSShri Abhyankar { 317153cca76cSShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 3172b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 317353cca76cSShri Abhyankar PetscErrorCode ierr; 3174b3260449SShri Abhyankar PetscInt i,k,nz,idx,jdx,idt; 3175b3260449SShri Abhyankar const PetscInt bs = A->rmap->bs,bs2 = a->bs2; 317653cca76cSShri Abhyankar const MatScalar *aa=a->a,*v; 317753cca76cSShri Abhyankar PetscScalar *x; 317853cca76cSShri Abhyankar const PetscScalar *b; 317953cca76cSShri Abhyankar PetscScalar s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6; 318053cca76cSShri Abhyankar 318153cca76cSShri Abhyankar PetscFunctionBegin; 318253cca76cSShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 318353cca76cSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 318453cca76cSShri Abhyankar /* forward solve the lower triangular */ 318553cca76cSShri Abhyankar idx = 0; 318653cca76cSShri Abhyankar x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx]; 318753cca76cSShri Abhyankar x[4] = b[4+idx];x[5] = b[5+idx]; 318853cca76cSShri Abhyankar for (i=1; i<n; i++) { 318953cca76cSShri Abhyankar v = aa + bs2*ai[i]; 319053cca76cSShri Abhyankar vi = aj + ai[i]; 319153cca76cSShri Abhyankar nz = ai[i+1] - ai[i]; 319253cca76cSShri Abhyankar idx = bs*i; 319353cca76cSShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 319453cca76cSShri Abhyankar s5 = b[4+idx];s6 = b[5+idx]; 319553cca76cSShri Abhyankar for(k=0;k<nz;k++){ 319653cca76cSShri Abhyankar jdx = bs*vi[k]; 319753cca76cSShri Abhyankar x1 = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx]; 319853cca76cSShri Abhyankar x5 = x[4+jdx]; x6 = x[5+jdx]; 319953cca76cSShri Abhyankar s1 -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6; 320053cca76cSShri Abhyankar s2 -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;; 320153cca76cSShri Abhyankar s3 -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6; 320253cca76cSShri Abhyankar s4 -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6; 320353cca76cSShri Abhyankar s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6; 320453cca76cSShri Abhyankar s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6; 320553cca76cSShri Abhyankar v += bs2; 320653cca76cSShri Abhyankar } 320753cca76cSShri Abhyankar 320853cca76cSShri Abhyankar x[idx] = s1; 320953cca76cSShri Abhyankar x[1+idx] = s2; 321053cca76cSShri Abhyankar x[2+idx] = s3; 321153cca76cSShri Abhyankar x[3+idx] = s4; 321253cca76cSShri Abhyankar x[4+idx] = s5; 321353cca76cSShri Abhyankar x[5+idx] = s6; 321453cca76cSShri Abhyankar } 321553cca76cSShri Abhyankar 321653cca76cSShri Abhyankar /* backward solve the upper triangular */ 321753cca76cSShri Abhyankar for (i=n-1; i>=0; i--){ 321853cca76cSShri Abhyankar v = aa + bs2*(adiag[i+1]+1); 321953cca76cSShri Abhyankar vi = aj + adiag[i+1]+1; 322053cca76cSShri Abhyankar nz = adiag[i] - adiag[i+1]-1; 322153cca76cSShri Abhyankar idt = bs*i; 322253cca76cSShri Abhyankar s1 = x[idt]; s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt]; 322353cca76cSShri Abhyankar s5 = x[4+idt];s6 = x[5+idt]; 322453cca76cSShri Abhyankar for(k=0;k<nz;k++){ 322553cca76cSShri Abhyankar idx = bs*vi[k]; 322653cca76cSShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx]; 322753cca76cSShri Abhyankar x5 = x[4+idx];x6 = x[5+idx]; 322853cca76cSShri Abhyankar s1 -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6; 322953cca76cSShri Abhyankar s2 -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;; 323053cca76cSShri Abhyankar s3 -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6; 323153cca76cSShri Abhyankar s4 -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6; 323253cca76cSShri Abhyankar s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6; 323353cca76cSShri Abhyankar s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6; 323453cca76cSShri Abhyankar v += bs2; 323553cca76cSShri Abhyankar } 323653cca76cSShri Abhyankar /* x = inv_diagonal*x */ 323753cca76cSShri Abhyankar x[idt] = v[0]*s1 + v[6]*s2 + v[12]*s3 + v[18]*s4 + v[24]*s5 + v[30]*s6; 323853cca76cSShri Abhyankar x[1+idt] = v[1]*s1 + v[7]*s2 + v[13]*s3 + v[19]*s4 + v[25]*s5 + v[31]*s6; 323953cca76cSShri Abhyankar x[2+idt] = v[2]*s1 + v[8]*s2 + v[14]*s3 + v[20]*s4 + v[26]*s5 + v[32]*s6; 324053cca76cSShri Abhyankar x[3+idt] = v[3]*s1 + v[9]*s2 + v[15]*s3 + v[21]*s4 + v[27]*s5 + v[33]*s6; 324153cca76cSShri Abhyankar x[4+idt] = v[4]*s1 + v[10]*s2 + v[16]*s3 + v[22]*s4 + v[28]*s5 + v[34]*s6; 324253cca76cSShri Abhyankar x[5+idt] = v[5]*s1 + v[11]*s2 + v[17]*s3 + v[23]*s4 + v[29]*s5 + v[35]*s6; 324353cca76cSShri Abhyankar } 324453cca76cSShri Abhyankar 324553cca76cSShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 324653cca76cSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 324753cca76cSShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 324853cca76cSShri Abhyankar PetscFunctionReturn(0); 324953cca76cSShri Abhyankar } 325053cca76cSShri Abhyankar 325153cca76cSShri Abhyankar #undef __FUNCT__ 325206e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_5_inplace" 325306e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_5_inplace(Mat A,Vec bb,Vec xx) 32544e2b4712SSatish Balay { 32554e2b4712SSatish Balay Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 32564e2b4712SSatish Balay IS iscol=a->col,isrow=a->row; 32576849ba73SBarry Smith PetscErrorCode ierr; 32585d0c19d7SBarry Smith const PetscInt *r,*c,*rout,*cout,*diag = a->diag; 3259b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j; 3260b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc; 3261d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 3262d9fead3dSBarry Smith PetscScalar *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*t; 3263d9fead3dSBarry Smith const PetscScalar *b; 32644e2b4712SSatish Balay 32654e2b4712SSatish Balay PetscFunctionBegin; 3266d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 32671ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 3268f1af5d2fSBarry Smith t = a->solve_work; 32694e2b4712SSatish Balay 32704e2b4712SSatish Balay ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 32714e2b4712SSatish Balay ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 32724e2b4712SSatish Balay 32734e2b4712SSatish Balay /* forward solve the lower triangular */ 32744e2b4712SSatish Balay idx = 5*(*r++); 3275f1af5d2fSBarry Smith t[0] = b[idx]; t[1] = b[1+idx]; 3276f1af5d2fSBarry Smith t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx]; 32774e2b4712SSatish Balay for (i=1; i<n; i++) { 32784e2b4712SSatish Balay v = aa + 25*ai[i]; 32794e2b4712SSatish Balay vi = aj + ai[i]; 32804e2b4712SSatish Balay nz = diag[i] - ai[i]; 32814e2b4712SSatish Balay idx = 5*(*r++); 3282f1af5d2fSBarry Smith s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 3283f1af5d2fSBarry Smith s5 = b[4+idx]; 32844e2b4712SSatish Balay while (nz--) { 32854e2b4712SSatish Balay idx = 5*(*vi++); 3286f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx];x3 = t[2+idx]; 3287f1af5d2fSBarry Smith x4 = t[3+idx];x5 = t[4+idx]; 3288f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5; 3289f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5; 3290f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5; 3291f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5; 3292f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5; 32934e2b4712SSatish Balay v += 25; 32944e2b4712SSatish Balay } 32954e2b4712SSatish Balay idx = 5*i; 3296f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; 3297f1af5d2fSBarry Smith t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5; 32984e2b4712SSatish Balay } 32994e2b4712SSatish Balay /* backward solve the upper triangular */ 33004e2b4712SSatish Balay for (i=n-1; i>=0; i--){ 33014e2b4712SSatish Balay v = aa + 25*diag[i] + 25; 33024e2b4712SSatish Balay vi = aj + diag[i] + 1; 33034e2b4712SSatish Balay nz = ai[i+1] - diag[i] - 1; 33044e2b4712SSatish Balay idt = 5*i; 3305f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; 3306f1af5d2fSBarry Smith s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt]; 33074e2b4712SSatish Balay while (nz--) { 33084e2b4712SSatish Balay idx = 5*(*vi++); 3309f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; 3310f1af5d2fSBarry Smith x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 3311f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5; 3312f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5; 3313f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5; 3314f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5; 3315f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5; 33164e2b4712SSatish Balay v += 25; 33174e2b4712SSatish Balay } 33184e2b4712SSatish Balay idc = 5*(*c--); 33194e2b4712SSatish Balay v = aa + 25*diag[i]; 3320f1af5d2fSBarry Smith x[idc] = t[idt] = v[0]*s1+v[5]*s2+v[10]*s3+ 3321f1af5d2fSBarry Smith v[15]*s4+v[20]*s5; 3322f1af5d2fSBarry Smith x[1+idc] = t[1+idt] = v[1]*s1+v[6]*s2+v[11]*s3+ 3323f1af5d2fSBarry Smith v[16]*s4+v[21]*s5; 3324f1af5d2fSBarry Smith x[2+idc] = t[2+idt] = v[2]*s1+v[7]*s2+v[12]*s3+ 3325f1af5d2fSBarry Smith v[17]*s4+v[22]*s5; 3326f1af5d2fSBarry Smith x[3+idc] = t[3+idt] = v[3]*s1+v[8]*s2+v[13]*s3+ 3327f1af5d2fSBarry Smith v[18]*s4+v[23]*s5; 3328f1af5d2fSBarry Smith x[4+idc] = t[4+idt] = v[4]*s1+v[9]*s2+v[14]*s3+ 3329f1af5d2fSBarry Smith v[19]*s4+v[24]*s5; 33304e2b4712SSatish Balay } 33314e2b4712SSatish Balay 33324e2b4712SSatish Balay ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 33334e2b4712SSatish Balay ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 3334d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 33351ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 3336dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr); 33374e2b4712SSatish Balay PetscFunctionReturn(0); 33384e2b4712SSatish Balay } 33394e2b4712SSatish Balay 334078bb4007SShri Abhyankar #undef __FUNCT__ 33414dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_5" 33424dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_5(Mat A,Vec bb,Vec xx) 334378bb4007SShri Abhyankar { 334478bb4007SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 334578bb4007SShri Abhyankar IS iscol=a->col,isrow=a->row; 334678bb4007SShri Abhyankar PetscErrorCode ierr; 334778bb4007SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 3348b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 3349b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc,m; 335078bb4007SShri Abhyankar const MatScalar *aa=a->a,*v; 335178bb4007SShri Abhyankar PetscScalar *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*t; 335278bb4007SShri Abhyankar const PetscScalar *b; 335378bb4007SShri Abhyankar 335478bb4007SShri Abhyankar PetscFunctionBegin; 335578bb4007SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 335678bb4007SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 335778bb4007SShri Abhyankar t = a->solve_work; 335878bb4007SShri Abhyankar 335978bb4007SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 336078bb4007SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 336178bb4007SShri Abhyankar 336278bb4007SShri Abhyankar /* forward solve the lower triangular */ 336378bb4007SShri Abhyankar idx = 5*r[0]; 336478bb4007SShri Abhyankar t[0] = b[idx]; t[1] = b[1+idx]; 336578bb4007SShri Abhyankar t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx]; 336678bb4007SShri Abhyankar for (i=1; i<n; i++) { 336778bb4007SShri Abhyankar v = aa + 25*ai[i]; 336878bb4007SShri Abhyankar vi = aj + ai[i]; 336978bb4007SShri Abhyankar nz = ai[i+1] - ai[i]; 337078bb4007SShri Abhyankar idx = 5*r[i]; 337178bb4007SShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 337278bb4007SShri Abhyankar s5 = b[4+idx]; 337378bb4007SShri Abhyankar for(m=0;m<nz;m++){ 337478bb4007SShri Abhyankar idx = 5*vi[m]; 337578bb4007SShri Abhyankar x1 = t[idx]; x2 = t[1+idx];x3 = t[2+idx]; 337678bb4007SShri Abhyankar x4 = t[3+idx];x5 = t[4+idx]; 337778bb4007SShri Abhyankar s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5; 337878bb4007SShri Abhyankar s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5; 337978bb4007SShri Abhyankar s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5; 338078bb4007SShri Abhyankar s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5; 338178bb4007SShri Abhyankar s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5; 338278bb4007SShri Abhyankar v += 25; 338378bb4007SShri Abhyankar } 338478bb4007SShri Abhyankar idx = 5*i; 338578bb4007SShri Abhyankar t[idx] = s1;t[1+idx] = s2; 338678bb4007SShri Abhyankar t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5; 338778bb4007SShri Abhyankar } 338878bb4007SShri Abhyankar /* backward solve the upper triangular */ 338978bb4007SShri Abhyankar for (i=n-1; i>=0; i--){ 339078bb4007SShri Abhyankar v = aa + 25*(adiag[i+1]+1); 339178bb4007SShri Abhyankar vi = aj + adiag[i+1]+1; 339278bb4007SShri Abhyankar nz = adiag[i] - adiag[i+1] - 1; 339378bb4007SShri Abhyankar idt = 5*i; 339478bb4007SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; 339578bb4007SShri Abhyankar s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt]; 339678bb4007SShri Abhyankar for(m=0;m<nz;m++){ 339778bb4007SShri Abhyankar idx = 5*vi[m]; 339878bb4007SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; 339978bb4007SShri Abhyankar x3 = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx]; 340078bb4007SShri Abhyankar s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5; 340178bb4007SShri Abhyankar s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5; 340278bb4007SShri Abhyankar s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5; 340378bb4007SShri Abhyankar s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5; 340478bb4007SShri Abhyankar s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5; 340578bb4007SShri Abhyankar v += 25; 340678bb4007SShri Abhyankar } 340778bb4007SShri Abhyankar idc = 5*c[i]; 340878bb4007SShri Abhyankar x[idc] = t[idt] = v[0]*s1+v[5]*s2+v[10]*s3+ 340978bb4007SShri Abhyankar v[15]*s4+v[20]*s5; 341078bb4007SShri Abhyankar x[1+idc] = t[1+idt] = v[1]*s1+v[6]*s2+v[11]*s3+ 341178bb4007SShri Abhyankar v[16]*s4+v[21]*s5; 341278bb4007SShri Abhyankar x[2+idc] = t[2+idt] = v[2]*s1+v[7]*s2+v[12]*s3+ 341378bb4007SShri Abhyankar v[17]*s4+v[22]*s5; 341478bb4007SShri Abhyankar x[3+idc] = t[3+idt] = v[3]*s1+v[8]*s2+v[13]*s3+ 341578bb4007SShri Abhyankar v[18]*s4+v[23]*s5; 341678bb4007SShri Abhyankar x[4+idc] = t[4+idt] = v[4]*s1+v[9]*s2+v[14]*s3+ 341778bb4007SShri Abhyankar v[19]*s4+v[24]*s5; 341878bb4007SShri Abhyankar } 341978bb4007SShri Abhyankar 342078bb4007SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 342178bb4007SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 342278bb4007SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 342378bb4007SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 342478bb4007SShri Abhyankar ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr); 342578bb4007SShri Abhyankar PetscFunctionReturn(0); 342678bb4007SShri Abhyankar } 342778bb4007SShri Abhyankar 34288f690400SShri Abhyankar #undef __FUNCT__ 342906e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_5_NaturalOrdering_inplace" 343006e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_5_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 343115091d37SBarry Smith { 343215091d37SBarry Smith Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 3433b3260449SShri Abhyankar const PetscInt *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j; 3434b3260449SShri Abhyankar PetscInt i,nz,idx,idt,jdx; 3435dfbe8321SBarry Smith PetscErrorCode ierr; 3436d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 3437d9fead3dSBarry Smith PetscScalar *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5; 3438d9fead3dSBarry Smith const PetscScalar *b; 343915091d37SBarry Smith 344015091d37SBarry Smith PetscFunctionBegin; 3441d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 34421ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 344315091d37SBarry Smith /* forward solve the lower triangular */ 344415091d37SBarry Smith idx = 0; 344515091d37SBarry 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]; 344615091d37SBarry Smith for (i=1; i<n; i++) { 344715091d37SBarry Smith v = aa + 25*ai[i]; 344815091d37SBarry Smith vi = aj + ai[i]; 344915091d37SBarry Smith nz = diag[i] - ai[i]; 345015091d37SBarry Smith idx = 5*i; 3451f1af5d2fSBarry Smith s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];s5 = b[4+idx]; 345215091d37SBarry Smith while (nz--) { 345315091d37SBarry Smith jdx = 5*(*vi++); 345415091d37SBarry Smith x1 = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx];x5 = x[4+jdx]; 3455f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5; 3456f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5; 3457f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5; 3458f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5; 3459f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5; 346015091d37SBarry Smith v += 25; 346115091d37SBarry Smith } 3462f1af5d2fSBarry Smith x[idx] = s1; 3463f1af5d2fSBarry Smith x[1+idx] = s2; 3464f1af5d2fSBarry Smith x[2+idx] = s3; 3465f1af5d2fSBarry Smith x[3+idx] = s4; 3466f1af5d2fSBarry Smith x[4+idx] = s5; 346715091d37SBarry Smith } 346815091d37SBarry Smith /* backward solve the upper triangular */ 346915091d37SBarry Smith for (i=n-1; i>=0; i--){ 347015091d37SBarry Smith v = aa + 25*diag[i] + 25; 347115091d37SBarry Smith vi = aj + diag[i] + 1; 347215091d37SBarry Smith nz = ai[i+1] - diag[i] - 1; 347315091d37SBarry Smith idt = 5*i; 3474f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; 3475f1af5d2fSBarry Smith s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt]; 347615091d37SBarry Smith while (nz--) { 347715091d37SBarry Smith idx = 5*(*vi++); 347815091d37SBarry Smith x1 = x[idx]; x2 = x[1+idx];x3 = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx]; 3479f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5; 3480f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5; 3481f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5; 3482f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5; 3483f1af5d2fSBarry Smith s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5; 348415091d37SBarry Smith v += 25; 348515091d37SBarry Smith } 348615091d37SBarry Smith v = aa + 25*diag[i]; 3487f1af5d2fSBarry Smith x[idt] = v[0]*s1 + v[5]*s2 + v[10]*s3 + v[15]*s4 + v[20]*s5; 3488f1af5d2fSBarry Smith x[1+idt] = v[1]*s1 + v[6]*s2 + v[11]*s3 + v[16]*s4 + v[21]*s5; 3489f1af5d2fSBarry Smith x[2+idt] = v[2]*s1 + v[7]*s2 + v[12]*s3 + v[17]*s4 + v[22]*s5; 3490f1af5d2fSBarry Smith x[3+idt] = v[3]*s1 + v[8]*s2 + v[13]*s3 + v[18]*s4 + v[23]*s5; 3491f1af5d2fSBarry Smith x[4+idt] = v[4]*s1 + v[9]*s2 + v[14]*s3 + v[19]*s4 + v[24]*s5; 349215091d37SBarry Smith } 349315091d37SBarry Smith 3494d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 34951ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 3496dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr); 349715091d37SBarry Smith PetscFunctionReturn(0); 349815091d37SBarry Smith } 349915091d37SBarry Smith 3500cee9d6f2SShri Abhyankar #undef __FUNCT__ 35014dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_5_NaturalOrdering" 35024dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_5_NaturalOrdering(Mat A,Vec bb,Vec xx) 350353cca76cSShri Abhyankar { 350453cca76cSShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 3505b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 3506b3260449SShri Abhyankar PetscInt i,k,nz,idx,idt,jdx; 350753cca76cSShri Abhyankar PetscErrorCode ierr; 350853cca76cSShri Abhyankar const MatScalar *aa=a->a,*v; 350953cca76cSShri Abhyankar PetscScalar *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5; 351053cca76cSShri Abhyankar const PetscScalar *b; 351153cca76cSShri Abhyankar 351253cca76cSShri Abhyankar PetscFunctionBegin; 351353cca76cSShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 351453cca76cSShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 351553cca76cSShri Abhyankar /* forward solve the lower triangular */ 351653cca76cSShri Abhyankar idx = 0; 351753cca76cSShri Abhyankar x[0] = b[idx]; x[1] = b[1+idx]; x[2] = b[2+idx]; x[3] = b[3+idx];x[4] = b[4+idx]; 351853cca76cSShri Abhyankar for (i=1; i<n; i++) { 351953cca76cSShri Abhyankar v = aa + 25*ai[i]; 352053cca76cSShri Abhyankar vi = aj + ai[i]; 352153cca76cSShri Abhyankar nz = ai[i+1] - ai[i]; 352253cca76cSShri Abhyankar idx = 5*i; 352353cca76cSShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];s5 = b[4+idx]; 352453cca76cSShri Abhyankar for(k=0;k<nz;k++) { 352553cca76cSShri Abhyankar jdx = 5*vi[k]; 352653cca76cSShri Abhyankar x1 = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx];x5 = x[4+jdx]; 352753cca76cSShri Abhyankar s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5; 352853cca76cSShri Abhyankar s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5; 352953cca76cSShri Abhyankar s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5; 353053cca76cSShri Abhyankar s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5; 353153cca76cSShri Abhyankar s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5; 353253cca76cSShri Abhyankar v += 25; 353353cca76cSShri Abhyankar } 353453cca76cSShri Abhyankar x[idx] = s1; 353553cca76cSShri Abhyankar x[1+idx] = s2; 353653cca76cSShri Abhyankar x[2+idx] = s3; 353753cca76cSShri Abhyankar x[3+idx] = s4; 353853cca76cSShri Abhyankar x[4+idx] = s5; 353953cca76cSShri Abhyankar } 354053cca76cSShri Abhyankar 354153cca76cSShri Abhyankar /* backward solve the upper triangular */ 354253cca76cSShri Abhyankar for (i=n-1; i>=0; i--){ 354353cca76cSShri Abhyankar v = aa + 25*(adiag[i+1]+1); 354453cca76cSShri Abhyankar vi = aj + adiag[i+1]+1; 354553cca76cSShri Abhyankar nz = adiag[i] - adiag[i+1]-1; 354653cca76cSShri Abhyankar idt = 5*i; 354753cca76cSShri Abhyankar s1 = x[idt]; s2 = x[1+idt]; 354853cca76cSShri Abhyankar s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt]; 354953cca76cSShri Abhyankar for(k=0;k<nz;k++){ 355053cca76cSShri Abhyankar idx = 5*vi[k]; 355153cca76cSShri Abhyankar x1 = x[idx]; x2 = x[1+idx];x3 = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx]; 355253cca76cSShri Abhyankar s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5; 355353cca76cSShri Abhyankar s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5; 355453cca76cSShri Abhyankar s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5; 355553cca76cSShri Abhyankar s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5; 355653cca76cSShri Abhyankar s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5; 355753cca76cSShri Abhyankar v += 25; 355853cca76cSShri Abhyankar } 355953cca76cSShri Abhyankar /* x = inv_diagonal*x */ 356053cca76cSShri Abhyankar x[idt] = v[0]*s1 + v[5]*s2 + v[10]*s3 + v[15]*s4 + v[20]*s5; 356153cca76cSShri Abhyankar x[1+idt] = v[1]*s1 + v[6]*s2 + v[11]*s3 + v[16]*s4 + v[21]*s5; 356253cca76cSShri Abhyankar x[2+idt] = v[2]*s1 + v[7]*s2 + v[12]*s3 + v[17]*s4 + v[22]*s5; 356353cca76cSShri Abhyankar x[3+idt] = v[3]*s1 + v[8]*s2 + v[13]*s3 + v[18]*s4 + v[23]*s5; 356453cca76cSShri Abhyankar x[4+idt] = v[4]*s1 + v[9]*s2 + v[14]*s3 + v[19]*s4 + v[24]*s5; 356553cca76cSShri Abhyankar } 356653cca76cSShri Abhyankar 356753cca76cSShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 356853cca76cSShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 356953cca76cSShri Abhyankar ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr); 357053cca76cSShri Abhyankar PetscFunctionReturn(0); 357153cca76cSShri Abhyankar } 357253cca76cSShri Abhyankar 357353cca76cSShri Abhyankar #undef __FUNCT__ 357406e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_4_inplace" 357506e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_4_inplace(Mat A,Vec bb,Vec xx) 35764e2b4712SSatish Balay { 35774e2b4712SSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 35784e2b4712SSatish Balay IS iscol=a->col,isrow=a->row; 35796849ba73SBarry Smith PetscErrorCode ierr; 3580b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j; 3581b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc; 35825d0c19d7SBarry Smith const PetscInt *r,*c,*diag = a->diag,*rout,*cout; 3583d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 3584d9fead3dSBarry Smith PetscScalar *x,s1,s2,s3,s4,x1,x2,x3,x4,*t; 3585d9fead3dSBarry Smith const PetscScalar *b; 35864e2b4712SSatish Balay 35874e2b4712SSatish Balay PetscFunctionBegin; 3588d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 35891ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 3590f1af5d2fSBarry Smith t = a->solve_work; 35914e2b4712SSatish Balay 35924e2b4712SSatish Balay ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 35934e2b4712SSatish Balay ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 35944e2b4712SSatish Balay 35954e2b4712SSatish Balay /* forward solve the lower triangular */ 35964e2b4712SSatish Balay idx = 4*(*r++); 3597f1af5d2fSBarry Smith t[0] = b[idx]; t[1] = b[1+idx]; 3598f1af5d2fSBarry Smith t[2] = b[2+idx]; t[3] = b[3+idx]; 35994e2b4712SSatish Balay for (i=1; i<n; i++) { 36004e2b4712SSatish Balay v = aa + 16*ai[i]; 36014e2b4712SSatish Balay vi = aj + ai[i]; 36024e2b4712SSatish Balay nz = diag[i] - ai[i]; 36034e2b4712SSatish Balay idx = 4*(*r++); 3604f1af5d2fSBarry Smith s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 36054e2b4712SSatish Balay while (nz--) { 36064e2b4712SSatish Balay idx = 4*(*vi++); 3607f1af5d2fSBarry Smith x1 = t[idx];x2 = t[1+idx];x3 = t[2+idx];x4 = t[3+idx]; 3608f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 3609f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 3610f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 3611f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 36124e2b4712SSatish Balay v += 16; 36134e2b4712SSatish Balay } 36144e2b4712SSatish Balay idx = 4*i; 3615f1af5d2fSBarry Smith t[idx] = s1;t[1+idx] = s2; 3616f1af5d2fSBarry Smith t[2+idx] = s3;t[3+idx] = s4; 36174e2b4712SSatish Balay } 36184e2b4712SSatish Balay /* backward solve the upper triangular */ 36194e2b4712SSatish Balay for (i=n-1; i>=0; i--){ 36204e2b4712SSatish Balay v = aa + 16*diag[i] + 16; 36214e2b4712SSatish Balay vi = aj + diag[i] + 1; 36224e2b4712SSatish Balay nz = ai[i+1] - diag[i] - 1; 36234e2b4712SSatish Balay idt = 4*i; 3624f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; 3625f1af5d2fSBarry Smith s3 = t[2+idt];s4 = t[3+idt]; 36264e2b4712SSatish Balay while (nz--) { 36274e2b4712SSatish Balay idx = 4*(*vi++); 3628f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; 3629f1af5d2fSBarry Smith x3 = t[2+idx]; x4 = t[3+idx]; 3630f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 3631f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 3632f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 3633f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 36344e2b4712SSatish Balay v += 16; 36354e2b4712SSatish Balay } 36364e2b4712SSatish Balay idc = 4*(*c--); 36374e2b4712SSatish Balay v = aa + 16*diag[i]; 3638f1af5d2fSBarry Smith x[idc] = t[idt] = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4; 3639f1af5d2fSBarry Smith x[1+idc] = t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4; 3640f1af5d2fSBarry Smith x[2+idc] = t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4; 3641f1af5d2fSBarry Smith x[3+idc] = t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4; 36424e2b4712SSatish Balay } 36434e2b4712SSatish Balay 36444e2b4712SSatish Balay ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 36454e2b4712SSatish Balay ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 3646d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 36471ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 3648dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 36494e2b4712SSatish Balay PetscFunctionReturn(0); 36504e2b4712SSatish Balay } 3651f26ec98cSKris Buschelman 36528f690400SShri Abhyankar #undef __FUNCT__ 36534dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_4" 36544dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_4(Mat A,Vec bb,Vec xx) 365578bb4007SShri Abhyankar { 365678bb4007SShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 365778bb4007SShri Abhyankar IS iscol=a->col,isrow=a->row; 365878bb4007SShri Abhyankar PetscErrorCode ierr; 3659b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 3660b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc,m; 366178bb4007SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 366278bb4007SShri Abhyankar const MatScalar *aa=a->a,*v; 366378bb4007SShri Abhyankar PetscScalar *x,s1,s2,s3,s4,x1,x2,x3,x4,*t; 366478bb4007SShri Abhyankar const PetscScalar *b; 366578bb4007SShri Abhyankar 366678bb4007SShri Abhyankar PetscFunctionBegin; 366778bb4007SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 366878bb4007SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 366978bb4007SShri Abhyankar t = a->solve_work; 367078bb4007SShri Abhyankar 367178bb4007SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 367278bb4007SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 367378bb4007SShri Abhyankar 367478bb4007SShri Abhyankar /* forward solve the lower triangular */ 367578bb4007SShri Abhyankar idx = 4*r[0]; 367678bb4007SShri Abhyankar t[0] = b[idx]; t[1] = b[1+idx]; 367778bb4007SShri Abhyankar t[2] = b[2+idx]; t[3] = b[3+idx]; 367878bb4007SShri Abhyankar for (i=1; i<n; i++) { 367978bb4007SShri Abhyankar v = aa + 16*ai[i]; 368078bb4007SShri Abhyankar vi = aj + ai[i]; 368178bb4007SShri Abhyankar nz = ai[i+1] - ai[i]; 368278bb4007SShri Abhyankar idx = 4*r[i]; 368378bb4007SShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 368478bb4007SShri Abhyankar for(m=0;m<nz;m++){ 368578bb4007SShri Abhyankar idx = 4*vi[m]; 368678bb4007SShri Abhyankar x1 = t[idx];x2 = t[1+idx];x3 = t[2+idx];x4 = t[3+idx]; 368778bb4007SShri Abhyankar s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 368878bb4007SShri Abhyankar s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 368978bb4007SShri Abhyankar s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 369078bb4007SShri Abhyankar s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 369178bb4007SShri Abhyankar v += 16; 369278bb4007SShri Abhyankar } 369378bb4007SShri Abhyankar idx = 4*i; 369478bb4007SShri Abhyankar t[idx] = s1;t[1+idx] = s2; 369578bb4007SShri Abhyankar t[2+idx] = s3;t[3+idx] = s4; 369678bb4007SShri Abhyankar } 369778bb4007SShri Abhyankar /* backward solve the upper triangular */ 369878bb4007SShri Abhyankar for (i=n-1; i>=0; i--){ 369978bb4007SShri Abhyankar v = aa + 16*(adiag[i+1]+1); 370078bb4007SShri Abhyankar vi = aj + adiag[i+1]+1; 370178bb4007SShri Abhyankar nz = adiag[i] - adiag[i+1] - 1; 370278bb4007SShri Abhyankar idt = 4*i; 370378bb4007SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; 370478bb4007SShri Abhyankar s3 = t[2+idt];s4 = t[3+idt]; 370578bb4007SShri Abhyankar for(m=0;m<nz;m++){ 370678bb4007SShri Abhyankar idx = 4*vi[m]; 370778bb4007SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; 370878bb4007SShri Abhyankar x3 = t[2+idx]; x4 = t[3+idx]; 370978bb4007SShri Abhyankar s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 371078bb4007SShri Abhyankar s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 371178bb4007SShri Abhyankar s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 371278bb4007SShri Abhyankar s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 371378bb4007SShri Abhyankar v += 16; 371478bb4007SShri Abhyankar } 371578bb4007SShri Abhyankar idc = 4*c[i]; 371678bb4007SShri Abhyankar x[idc] = t[idt] = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4; 371778bb4007SShri Abhyankar x[1+idc] = t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4; 371878bb4007SShri Abhyankar x[2+idc] = t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4; 371978bb4007SShri Abhyankar x[3+idc] = t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4; 372078bb4007SShri Abhyankar } 372178bb4007SShri Abhyankar 372278bb4007SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 372378bb4007SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 372478bb4007SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 372578bb4007SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 372678bb4007SShri Abhyankar ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 372778bb4007SShri Abhyankar PetscFunctionReturn(0); 372878bb4007SShri Abhyankar } 372978bb4007SShri Abhyankar 373078bb4007SShri Abhyankar #undef __FUNCT__ 3731f26ec98cSKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_Demotion" 3732dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_Demotion(Mat A,Vec bb,Vec xx) 3733f26ec98cSKris Buschelman { 3734f26ec98cSKris Buschelman Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 3735f26ec98cSKris Buschelman IS iscol=a->col,isrow=a->row; 37366849ba73SBarry Smith PetscErrorCode ierr; 3737b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j; 3738b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc; 37395d0c19d7SBarry Smith const PetscInt *r,*c,*diag = a->diag,*rout,*cout; 3740d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 3741d9fead3dSBarry Smith MatScalar s1,s2,s3,s4,x1,x2,x3,x4,*t; 3742d9fead3dSBarry Smith PetscScalar *x; 3743d9fead3dSBarry Smith const PetscScalar *b; 3744f26ec98cSKris Buschelman 3745f26ec98cSKris Buschelman PetscFunctionBegin; 3746d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 37471ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 3748f26ec98cSKris Buschelman t = (MatScalar *)a->solve_work; 3749f26ec98cSKris Buschelman 3750f26ec98cSKris Buschelman ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 3751f26ec98cSKris Buschelman ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 3752f26ec98cSKris Buschelman 3753f26ec98cSKris Buschelman /* forward solve the lower triangular */ 3754f26ec98cSKris Buschelman idx = 4*(*r++); 3755f26ec98cSKris Buschelman t[0] = (MatScalar)b[idx]; 3756f26ec98cSKris Buschelman t[1] = (MatScalar)b[1+idx]; 3757f26ec98cSKris Buschelman t[2] = (MatScalar)b[2+idx]; 3758f26ec98cSKris Buschelman t[3] = (MatScalar)b[3+idx]; 3759f26ec98cSKris Buschelman for (i=1; i<n; i++) { 3760f26ec98cSKris Buschelman v = aa + 16*ai[i]; 3761f26ec98cSKris Buschelman vi = aj + ai[i]; 3762f26ec98cSKris Buschelman nz = diag[i] - ai[i]; 3763f26ec98cSKris Buschelman idx = 4*(*r++); 3764f26ec98cSKris Buschelman s1 = (MatScalar)b[idx]; 3765f26ec98cSKris Buschelman s2 = (MatScalar)b[1+idx]; 3766f26ec98cSKris Buschelman s3 = (MatScalar)b[2+idx]; 3767f26ec98cSKris Buschelman s4 = (MatScalar)b[3+idx]; 3768f26ec98cSKris Buschelman while (nz--) { 3769f26ec98cSKris Buschelman idx = 4*(*vi++); 3770f26ec98cSKris Buschelman x1 = t[idx]; 3771f26ec98cSKris Buschelman x2 = t[1+idx]; 3772f26ec98cSKris Buschelman x3 = t[2+idx]; 3773f26ec98cSKris Buschelman x4 = t[3+idx]; 3774f26ec98cSKris Buschelman s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 3775f26ec98cSKris Buschelman s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 3776f26ec98cSKris Buschelman s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 3777f26ec98cSKris Buschelman s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 3778f26ec98cSKris Buschelman v += 16; 3779f26ec98cSKris Buschelman } 3780f26ec98cSKris Buschelman idx = 4*i; 3781f26ec98cSKris Buschelman t[idx] = s1; 3782f26ec98cSKris Buschelman t[1+idx] = s2; 3783f26ec98cSKris Buschelman t[2+idx] = s3; 3784f26ec98cSKris Buschelman t[3+idx] = s4; 3785f26ec98cSKris Buschelman } 3786f26ec98cSKris Buschelman /* backward solve the upper triangular */ 3787f26ec98cSKris Buschelman for (i=n-1; i>=0; i--){ 3788f26ec98cSKris Buschelman v = aa + 16*diag[i] + 16; 3789f26ec98cSKris Buschelman vi = aj + diag[i] + 1; 3790f26ec98cSKris Buschelman nz = ai[i+1] - diag[i] - 1; 3791f26ec98cSKris Buschelman idt = 4*i; 3792f26ec98cSKris Buschelman s1 = t[idt]; 3793f26ec98cSKris Buschelman s2 = t[1+idt]; 3794f26ec98cSKris Buschelman s3 = t[2+idt]; 3795f26ec98cSKris Buschelman s4 = t[3+idt]; 3796f26ec98cSKris Buschelman while (nz--) { 3797f26ec98cSKris Buschelman idx = 4*(*vi++); 3798f26ec98cSKris Buschelman x1 = t[idx]; 3799f26ec98cSKris Buschelman x2 = t[1+idx]; 3800f26ec98cSKris Buschelman x3 = t[2+idx]; 3801f26ec98cSKris Buschelman x4 = t[3+idx]; 3802f26ec98cSKris Buschelman s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 3803f26ec98cSKris Buschelman s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 3804f26ec98cSKris Buschelman s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 3805f26ec98cSKris Buschelman s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 3806f26ec98cSKris Buschelman v += 16; 3807f26ec98cSKris Buschelman } 3808f26ec98cSKris Buschelman idc = 4*(*c--); 3809f26ec98cSKris Buschelman v = aa + 16*diag[i]; 3810f26ec98cSKris Buschelman t[idt] = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4; 3811f26ec98cSKris Buschelman t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4; 3812f26ec98cSKris Buschelman t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4; 3813f26ec98cSKris Buschelman t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4; 3814f26ec98cSKris Buschelman x[idc] = (PetscScalar)t[idt]; 3815f26ec98cSKris Buschelman x[1+idc] = (PetscScalar)t[1+idt]; 3816f26ec98cSKris Buschelman x[2+idc] = (PetscScalar)t[2+idt]; 3817f26ec98cSKris Buschelman x[3+idc] = (PetscScalar)t[3+idt]; 3818f26ec98cSKris Buschelman } 3819f26ec98cSKris Buschelman 3820f26ec98cSKris Buschelman ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 3821f26ec98cSKris Buschelman ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 3822d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 38231ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 3824dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 3825f26ec98cSKris Buschelman PetscFunctionReturn(0); 3826f26ec98cSKris Buschelman } 3827f26ec98cSKris Buschelman 382824c233c2SKris Buschelman #if defined (PETSC_HAVE_SSE) 382924c233c2SKris Buschelman 383024c233c2SKris Buschelman #include PETSC_HAVE_SSE 383124c233c2SKris Buschelman 383224c233c2SKris Buschelman #undef __FUNCT__ 383324c233c2SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_SSE_Demotion" 3834dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_SSE_Demotion(Mat A,Vec bb,Vec xx) 383524c233c2SKris Buschelman { 383624c233c2SKris Buschelman /* 383724c233c2SKris Buschelman Note: This code uses demotion of double 383824c233c2SKris Buschelman to float when performing the mixed-mode computation. 383924c233c2SKris Buschelman This may not be numerically reasonable for all applications. 384024c233c2SKris Buschelman */ 384124c233c2SKris Buschelman Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 384224c233c2SKris Buschelman IS iscol=a->col,isrow=a->row; 38436849ba73SBarry Smith PetscErrorCode ierr; 38445d0c19d7SBarry Smith PetscInt i,n=a->mbs,*vi,*ai=a->i,*aj=a->j,nz,idx,idt,idc,ai16; 38455d0c19d7SBarry Smith const PetscInt *r,*c,*diag = a->diag,*rout,*cout; 384624c233c2SKris Buschelman MatScalar *aa=a->a,*v; 384787828ca2SBarry Smith PetscScalar *x,*b,*t; 384824c233c2SKris Buschelman 384924c233c2SKris Buschelman /* Make space in temp stack for 16 Byte Aligned arrays */ 385024c233c2SKris Buschelman float ssealignedspace[11],*tmps,*tmpx; 385124c233c2SKris Buschelman unsigned long offset; 385224c233c2SKris Buschelman 385324c233c2SKris Buschelman PetscFunctionBegin; 385424c233c2SKris Buschelman SSE_SCOPE_BEGIN; 385524c233c2SKris Buschelman 385624c233c2SKris Buschelman offset = (unsigned long)ssealignedspace % 16; 385724c233c2SKris Buschelman if (offset) offset = (16 - offset)/4; 385824c233c2SKris Buschelman tmps = &ssealignedspace[offset]; 385924c233c2SKris Buschelman tmpx = &ssealignedspace[offset+4]; 386024c233c2SKris Buschelman PREFETCH_NTA(aa+16*ai[1]); 386124c233c2SKris Buschelman 38621ebc52fbSHong Zhang ierr = VecGetArray(bb,&b);CHKERRQ(ierr); 38631ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 386424c233c2SKris Buschelman t = a->solve_work; 386524c233c2SKris Buschelman 386624c233c2SKris Buschelman ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 386724c233c2SKris Buschelman ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 386824c233c2SKris Buschelman 386924c233c2SKris Buschelman /* forward solve the lower triangular */ 387024c233c2SKris Buschelman idx = 4*(*r++); 387124c233c2SKris Buschelman t[0] = b[idx]; t[1] = b[1+idx]; 387224c233c2SKris Buschelman t[2] = b[2+idx]; t[3] = b[3+idx]; 387324c233c2SKris Buschelman v = aa + 16*ai[1]; 387424c233c2SKris Buschelman 387524c233c2SKris Buschelman for (i=1; i<n;) { 387624c233c2SKris Buschelman PREFETCH_NTA(&v[8]); 387724c233c2SKris Buschelman vi = aj + ai[i]; 387824c233c2SKris Buschelman nz = diag[i] - ai[i]; 387924c233c2SKris Buschelman idx = 4*(*r++); 388024c233c2SKris Buschelman 388124c233c2SKris Buschelman /* Demote sum from double to float */ 388224c233c2SKris Buschelman CONVERT_DOUBLE4_FLOAT4(tmps,&b[idx]); 388324c233c2SKris Buschelman LOAD_PS(tmps,XMM7); 388424c233c2SKris Buschelman 388524c233c2SKris Buschelman while (nz--) { 388624c233c2SKris Buschelman PREFETCH_NTA(&v[16]); 388724c233c2SKris Buschelman idx = 4*(*vi++); 388824c233c2SKris Buschelman 388924c233c2SKris Buschelman /* Demote solution (so far) from double to float */ 389024c233c2SKris Buschelman CONVERT_DOUBLE4_FLOAT4(tmpx,&x[idx]); 389124c233c2SKris Buschelman 389224c233c2SKris Buschelman /* 4x4 Matrix-Vector product with negative accumulation: */ 389324c233c2SKris Buschelman SSE_INLINE_BEGIN_2(tmpx,v) 389424c233c2SKris Buschelman SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6) 389524c233c2SKris Buschelman 389624c233c2SKris Buschelman /* First Column */ 389724c233c2SKris Buschelman SSE_COPY_PS(XMM0,XMM6) 389824c233c2SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 389924c233c2SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0) 390024c233c2SKris Buschelman SSE_SUB_PS(XMM7,XMM0) 390124c233c2SKris Buschelman 390224c233c2SKris Buschelman /* Second Column */ 390324c233c2SKris Buschelman SSE_COPY_PS(XMM1,XMM6) 390424c233c2SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 390524c233c2SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4) 390624c233c2SKris Buschelman SSE_SUB_PS(XMM7,XMM1) 390724c233c2SKris Buschelman 390824c233c2SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24) 390924c233c2SKris Buschelman 391024c233c2SKris Buschelman /* Third Column */ 391124c233c2SKris Buschelman SSE_COPY_PS(XMM2,XMM6) 391224c233c2SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 391324c233c2SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8) 391424c233c2SKris Buschelman SSE_SUB_PS(XMM7,XMM2) 391524c233c2SKris Buschelman 391624c233c2SKris Buschelman /* Fourth Column */ 391724c233c2SKris Buschelman SSE_COPY_PS(XMM3,XMM6) 391824c233c2SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 391924c233c2SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12) 392024c233c2SKris Buschelman SSE_SUB_PS(XMM7,XMM3) 392124c233c2SKris Buschelman SSE_INLINE_END_2 392224c233c2SKris Buschelman 392324c233c2SKris Buschelman v += 16; 392424c233c2SKris Buschelman } 392524c233c2SKris Buschelman idx = 4*i; 392624c233c2SKris Buschelman v = aa + 16*ai[++i]; 392724c233c2SKris Buschelman PREFETCH_NTA(v); 392824c233c2SKris Buschelman STORE_PS(tmps,XMM7); 392924c233c2SKris Buschelman 393024c233c2SKris Buschelman /* Promote result from float to double */ 393124c233c2SKris Buschelman CONVERT_FLOAT4_DOUBLE4(&t[idx],tmps); 393224c233c2SKris Buschelman } 393324c233c2SKris Buschelman /* backward solve the upper triangular */ 393424c233c2SKris Buschelman idt = 4*(n-1); 393524c233c2SKris Buschelman ai16 = 16*diag[n-1]; 393624c233c2SKris Buschelman v = aa + ai16 + 16; 393724c233c2SKris Buschelman for (i=n-1; i>=0;){ 393824c233c2SKris Buschelman PREFETCH_NTA(&v[8]); 393924c233c2SKris Buschelman vi = aj + diag[i] + 1; 394024c233c2SKris Buschelman nz = ai[i+1] - diag[i] - 1; 394124c233c2SKris Buschelman 394224c233c2SKris Buschelman /* Demote accumulator from double to float */ 394324c233c2SKris Buschelman CONVERT_DOUBLE4_FLOAT4(tmps,&t[idt]); 394424c233c2SKris Buschelman LOAD_PS(tmps,XMM7); 394524c233c2SKris Buschelman 394624c233c2SKris Buschelman while (nz--) { 394724c233c2SKris Buschelman PREFETCH_NTA(&v[16]); 394824c233c2SKris Buschelman idx = 4*(*vi++); 394924c233c2SKris Buschelman 395024c233c2SKris Buschelman /* Demote solution (so far) from double to float */ 395124c233c2SKris Buschelman CONVERT_DOUBLE4_FLOAT4(tmpx,&t[idx]); 395224c233c2SKris Buschelman 395324c233c2SKris Buschelman /* 4x4 Matrix-Vector Product with negative accumulation: */ 395424c233c2SKris Buschelman SSE_INLINE_BEGIN_2(tmpx,v) 395524c233c2SKris Buschelman SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6) 395624c233c2SKris Buschelman 395724c233c2SKris Buschelman /* First Column */ 395824c233c2SKris Buschelman SSE_COPY_PS(XMM0,XMM6) 395924c233c2SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 396024c233c2SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0) 396124c233c2SKris Buschelman SSE_SUB_PS(XMM7,XMM0) 396224c233c2SKris Buschelman 396324c233c2SKris Buschelman /* Second Column */ 396424c233c2SKris Buschelman SSE_COPY_PS(XMM1,XMM6) 396524c233c2SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 396624c233c2SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4) 396724c233c2SKris Buschelman SSE_SUB_PS(XMM7,XMM1) 396824c233c2SKris Buschelman 396924c233c2SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24) 397024c233c2SKris Buschelman 397124c233c2SKris Buschelman /* Third Column */ 397224c233c2SKris Buschelman SSE_COPY_PS(XMM2,XMM6) 397324c233c2SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 397424c233c2SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8) 397524c233c2SKris Buschelman SSE_SUB_PS(XMM7,XMM2) 397624c233c2SKris Buschelman 397724c233c2SKris Buschelman /* Fourth Column */ 397824c233c2SKris Buschelman SSE_COPY_PS(XMM3,XMM6) 397924c233c2SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 398024c233c2SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12) 398124c233c2SKris Buschelman SSE_SUB_PS(XMM7,XMM3) 398224c233c2SKris Buschelman SSE_INLINE_END_2 398324c233c2SKris Buschelman v += 16; 398424c233c2SKris Buschelman } 398524c233c2SKris Buschelman v = aa + ai16; 398624c233c2SKris Buschelman ai16 = 16*diag[--i]; 398724c233c2SKris Buschelman PREFETCH_NTA(aa+ai16+16); 398824c233c2SKris Buschelman /* 398924c233c2SKris Buschelman Scale the result by the diagonal 4x4 block, 399024c233c2SKris Buschelman which was inverted as part of the factorization 399124c233c2SKris Buschelman */ 399224c233c2SKris Buschelman SSE_INLINE_BEGIN_3(v,tmps,aa+ai16) 399324c233c2SKris Buschelman /* First Column */ 399424c233c2SKris Buschelman SSE_COPY_PS(XMM0,XMM7) 399524c233c2SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 399624c233c2SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0) 399724c233c2SKris Buschelman 399824c233c2SKris Buschelman /* Second Column */ 399924c233c2SKris Buschelman SSE_COPY_PS(XMM1,XMM7) 400024c233c2SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 400124c233c2SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4) 400224c233c2SKris Buschelman SSE_ADD_PS(XMM0,XMM1) 400324c233c2SKris Buschelman 400424c233c2SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24) 400524c233c2SKris Buschelman 400624c233c2SKris Buschelman /* Third Column */ 400724c233c2SKris Buschelman SSE_COPY_PS(XMM2,XMM7) 400824c233c2SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 400924c233c2SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8) 401024c233c2SKris Buschelman SSE_ADD_PS(XMM0,XMM2) 401124c233c2SKris Buschelman 401224c233c2SKris Buschelman /* Fourth Column */ 401324c233c2SKris Buschelman SSE_COPY_PS(XMM3,XMM7) 401424c233c2SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 401524c233c2SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12) 401624c233c2SKris Buschelman SSE_ADD_PS(XMM0,XMM3) 401724c233c2SKris Buschelman 401824c233c2SKris Buschelman SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0) 401924c233c2SKris Buschelman SSE_INLINE_END_3 402024c233c2SKris Buschelman 402124c233c2SKris Buschelman /* Promote solution from float to double */ 402224c233c2SKris Buschelman CONVERT_FLOAT4_DOUBLE4(&t[idt],tmps); 402324c233c2SKris Buschelman 402424c233c2SKris Buschelman /* Apply reordering to t and stream into x. */ 402524c233c2SKris Buschelman /* This way, x doesn't pollute the cache. */ 402624c233c2SKris Buschelman /* Be careful with size: 2 doubles = 4 floats! */ 402724c233c2SKris Buschelman idc = 4*(*c--); 402824c233c2SKris Buschelman SSE_INLINE_BEGIN_2((float *)&t[idt],(float *)&x[idc]) 402924c233c2SKris Buschelman /* x[idc] = t[idt]; x[1+idc] = t[1+idc]; */ 403024c233c2SKris Buschelman SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM0) 403124c233c2SKris Buschelman SSE_STREAM_PS(SSE_ARG_2,FLOAT_0,XMM0) 403224c233c2SKris Buschelman /* x[idc+2] = t[idt+2]; x[3+idc] = t[3+idc]; */ 403324c233c2SKris Buschelman SSE_LOAD_PS(SSE_ARG_1,FLOAT_4,XMM1) 403424c233c2SKris Buschelman SSE_STREAM_PS(SSE_ARG_2,FLOAT_4,XMM1) 403524c233c2SKris Buschelman SSE_INLINE_END_2 403624c233c2SKris Buschelman v = aa + ai16 + 16; 403724c233c2SKris Buschelman idt -= 4; 403824c233c2SKris Buschelman } 403924c233c2SKris Buschelman 404024c233c2SKris Buschelman ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 404124c233c2SKris Buschelman ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 40421ebc52fbSHong Zhang ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr); 40431ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4044dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 404524c233c2SKris Buschelman SSE_SCOPE_END; 404624c233c2SKris Buschelman PetscFunctionReturn(0); 404724c233c2SKris Buschelman } 404824c233c2SKris Buschelman 404924c233c2SKris Buschelman #endif 40500ef38995SBarry Smith 40510ef38995SBarry Smith 40524e2b4712SSatish Balay /* 40534e2b4712SSatish Balay Special case where the matrix was ILU(0) factored in the natural 40544e2b4712SSatish Balay ordering. This eliminates the need for the column and row permutation. 40554e2b4712SSatish Balay */ 40564a2ae208SSatish Balay #undef __FUNCT__ 405706e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_inplace" 405806e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 40594e2b4712SSatish Balay { 40604e2b4712SSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 4061356650c2SBarry Smith PetscInt n=a->mbs; 4062356650c2SBarry Smith const PetscInt *ai=a->i,*aj=a->j; 4063dfbe8321SBarry Smith PetscErrorCode ierr; 4064356650c2SBarry Smith const PetscInt *diag = a->diag; 4065d9fead3dSBarry Smith const MatScalar *aa=a->a; 4066d9fead3dSBarry Smith PetscScalar *x; 4067d9fead3dSBarry Smith const PetscScalar *b; 40684e2b4712SSatish Balay 40694e2b4712SSatish Balay PetscFunctionBegin; 4070d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 40711ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 40724e2b4712SSatish Balay 4073aa482453SBarry Smith #if defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJBLAS) 40742853dc0eSBarry Smith { 407587828ca2SBarry Smith static PetscScalar w[2000]; /* very BAD need to fix */ 40762853dc0eSBarry Smith fortransolvebaij4blas_(&n,x,ai,aj,diag,aa,b,w); 40772853dc0eSBarry Smith } 4078aa482453SBarry Smith #elif defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 40792853dc0eSBarry Smith { 408087828ca2SBarry Smith static PetscScalar w[2000]; /* very BAD need to fix */ 40812853dc0eSBarry Smith fortransolvebaij4_(&n,x,ai,aj,diag,aa,b,w); 40822853dc0eSBarry Smith } 4083aa482453SBarry Smith #elif defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJUNROLL) 40842853dc0eSBarry Smith fortransolvebaij4unroll_(&n,x,ai,aj,diag,aa,b); 4085e1293385SBarry Smith #else 408630d4dcafSBarry Smith { 408787828ca2SBarry Smith PetscScalar s1,s2,s3,s4,x1,x2,x3,x4; 4088d9fead3dSBarry Smith const MatScalar *v; 4089356650c2SBarry Smith PetscInt jdx,idt,idx,nz,i,ai16; 4090356650c2SBarry Smith const PetscInt *vi; 4091e1293385SBarry Smith 40924e2b4712SSatish Balay /* forward solve the lower triangular */ 40934e2b4712SSatish Balay idx = 0; 4094e1293385SBarry Smith x[0] = b[0]; x[1] = b[1]; x[2] = b[2]; x[3] = b[3]; 40954e2b4712SSatish Balay for (i=1; i<n; i++) { 40964e2b4712SSatish Balay v = aa + 16*ai[i]; 40974e2b4712SSatish Balay vi = aj + ai[i]; 40984e2b4712SSatish Balay nz = diag[i] - ai[i]; 4099e1293385SBarry Smith idx += 4; 4100f1af5d2fSBarry Smith s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 41014e2b4712SSatish Balay while (nz--) { 41024e2b4712SSatish Balay jdx = 4*(*vi++); 41034e2b4712SSatish Balay x1 = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx]; 4104f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 4105f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 4106f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 4107f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 41084e2b4712SSatish Balay v += 16; 41094e2b4712SSatish Balay } 4110f1af5d2fSBarry Smith x[idx] = s1; 4111f1af5d2fSBarry Smith x[1+idx] = s2; 4112f1af5d2fSBarry Smith x[2+idx] = s3; 4113f1af5d2fSBarry Smith x[3+idx] = s4; 41144e2b4712SSatish Balay } 41154e2b4712SSatish Balay /* backward solve the upper triangular */ 41164e555682SBarry Smith idt = 4*(n-1); 41174e2b4712SSatish Balay for (i=n-1; i>=0; i--){ 41184e555682SBarry Smith ai16 = 16*diag[i]; 41194e555682SBarry Smith v = aa + ai16 + 16; 41204e2b4712SSatish Balay vi = aj + diag[i] + 1; 41214e2b4712SSatish Balay nz = ai[i+1] - diag[i] - 1; 4122f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; 4123f1af5d2fSBarry Smith s3 = x[2+idt];s4 = x[3+idt]; 41244e2b4712SSatish Balay while (nz--) { 41254e2b4712SSatish Balay idx = 4*(*vi++); 41264e2b4712SSatish Balay x1 = x[idx]; x2 = x[1+idx];x3 = x[2+idx]; x4 = x[3+idx]; 4127f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 4128f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 4129f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 4130f1af5d2fSBarry Smith s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 41314e2b4712SSatish Balay v += 16; 41324e2b4712SSatish Balay } 41334e555682SBarry Smith v = aa + ai16; 4134f1af5d2fSBarry Smith x[idt] = v[0]*s1 + v[4]*s2 + v[8]*s3 + v[12]*s4; 4135f1af5d2fSBarry Smith x[1+idt] = v[1]*s1 + v[5]*s2 + v[9]*s3 + v[13]*s4; 4136f1af5d2fSBarry Smith x[2+idt] = v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4; 4137f1af5d2fSBarry Smith x[3+idt] = v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4; 4138329f5518SBarry Smith idt -= 4; 41394e2b4712SSatish Balay } 414030d4dcafSBarry Smith } 4141e1293385SBarry Smith #endif 41424e2b4712SSatish Balay 4143d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 41441ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4145dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 41464e2b4712SSatish Balay PetscFunctionReturn(0); 41474e2b4712SSatish Balay } 41484e2b4712SSatish Balay 4149b2b2dd24SShri Abhyankar #undef __FUNCT__ 41504dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering" 41514dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering(Mat A,Vec bb,Vec xx) 4152b2b2dd24SShri Abhyankar { 4153b2b2dd24SShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 4154b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 4155b3260449SShri Abhyankar PetscInt i,k,nz,idx,jdx,idt; 4156b2b2dd24SShri Abhyankar PetscErrorCode ierr; 4157b3260449SShri Abhyankar const PetscInt bs = A->rmap->bs,bs2 = a->bs2; 4158b2b2dd24SShri Abhyankar const MatScalar *aa=a->a,*v; 4159b2b2dd24SShri Abhyankar PetscScalar *x; 4160b2b2dd24SShri Abhyankar const PetscScalar *b; 4161b2b2dd24SShri Abhyankar PetscScalar s1,s2,s3,s4,x1,x2,x3,x4; 4162cee9d6f2SShri Abhyankar 4163b2b2dd24SShri Abhyankar PetscFunctionBegin; 4164b2b2dd24SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 4165b2b2dd24SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 4166b2b2dd24SShri Abhyankar /* forward solve the lower triangular */ 4167b2b2dd24SShri Abhyankar idx = 0; 4168b2b2dd24SShri Abhyankar x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx]; 4169b2b2dd24SShri Abhyankar for (i=1; i<n; i++) { 4170b2b2dd24SShri Abhyankar v = aa + bs2*ai[i]; 4171b2b2dd24SShri Abhyankar vi = aj + ai[i]; 4172b2b2dd24SShri Abhyankar nz = ai[i+1] - ai[i]; 4173b2b2dd24SShri Abhyankar idx = bs*i; 4174b2b2dd24SShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx]; 4175b2b2dd24SShri Abhyankar for(k=0;k<nz;k++) { 4176b2b2dd24SShri Abhyankar jdx = bs*vi[k]; 4177b2b2dd24SShri Abhyankar x1 = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx]; 4178b2b2dd24SShri Abhyankar s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 4179b2b2dd24SShri Abhyankar s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 4180b2b2dd24SShri Abhyankar s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 4181b2b2dd24SShri Abhyankar s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 4182b2b2dd24SShri Abhyankar 4183b2b2dd24SShri Abhyankar v += bs2; 4184b2b2dd24SShri Abhyankar } 4185b2b2dd24SShri Abhyankar 4186b2b2dd24SShri Abhyankar x[idx] = s1; 4187b2b2dd24SShri Abhyankar x[1+idx] = s2; 4188b2b2dd24SShri Abhyankar x[2+idx] = s3; 4189b2b2dd24SShri Abhyankar x[3+idx] = s4; 4190b2b2dd24SShri Abhyankar } 4191b2b2dd24SShri Abhyankar 4192b2b2dd24SShri Abhyankar /* backward solve the upper triangular */ 4193b2b2dd24SShri Abhyankar for (i=n-1; i>=0; i--){ 4194b2b2dd24SShri Abhyankar v = aa + bs2*(adiag[i+1]+1); 4195b2b2dd24SShri Abhyankar vi = aj + adiag[i+1]+1; 4196b2b2dd24SShri Abhyankar nz = adiag[i] - adiag[i+1]-1; 4197b2b2dd24SShri Abhyankar idt = bs*i; 4198b2b2dd24SShri Abhyankar s1 = x[idt]; s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt]; 4199b2b2dd24SShri Abhyankar 4200b2b2dd24SShri Abhyankar for(k=0;k<nz;k++){ 4201b2b2dd24SShri Abhyankar idx = bs*vi[k]; 4202b2b2dd24SShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx]; 4203b2b2dd24SShri Abhyankar s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 4204b2b2dd24SShri Abhyankar s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 4205b2b2dd24SShri Abhyankar s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 4206b2b2dd24SShri Abhyankar s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 4207b2b2dd24SShri Abhyankar 4208b2b2dd24SShri Abhyankar v += bs2; 4209b2b2dd24SShri Abhyankar } 4210b2b2dd24SShri Abhyankar /* x = inv_diagonal*x */ 4211b2b2dd24SShri Abhyankar x[idt] = v[0]*s1 + v[4]*s2 + v[8]*s3 + v[12]*s4; 4212b2b2dd24SShri Abhyankar x[1+idt] = v[1]*s1 + v[5]*s2 + v[9]*s3 + v[13]*s4;; 4213b2b2dd24SShri Abhyankar x[2+idt] = v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4; 4214b2b2dd24SShri Abhyankar x[3+idt] = v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4; 4215b2b2dd24SShri Abhyankar 4216b2b2dd24SShri Abhyankar } 4217b2b2dd24SShri Abhyankar 4218b2b2dd24SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 4219b2b2dd24SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4220b2b2dd24SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 4221b2b2dd24SShri Abhyankar PetscFunctionReturn(0); 4222b2b2dd24SShri Abhyankar } 4223cee9d6f2SShri Abhyankar 4224cee9d6f2SShri Abhyankar #undef __FUNCT__ 4225f26ec98cSKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_Demotion" 4226dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_Demotion(Mat A,Vec bb,Vec xx) 4227f26ec98cSKris Buschelman { 4228f26ec98cSKris Buschelman Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 4229b3260449SShri Abhyankar const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*diag=a->diag; 4230dfbe8321SBarry Smith PetscErrorCode ierr; 4231b3260449SShri Abhyankar const MatScalar *aa=a->a; 4232b3260449SShri Abhyankar const PetscScalar *b; 4233b3260449SShri Abhyankar PetscScalar *x; 4234f26ec98cSKris Buschelman 4235f26ec98cSKris Buschelman PetscFunctionBegin; 4236b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 42371ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 4238f26ec98cSKris Buschelman 4239f26ec98cSKris Buschelman { 4240f26ec98cSKris Buschelman MatScalar s1,s2,s3,s4,x1,x2,x3,x4; 4241b3260449SShri Abhyankar const MatScalar *v; 4242b3260449SShri Abhyankar MatScalar *t=(MatScalar *)x; 4243b3260449SShri Abhyankar PetscInt jdx,idt,idx,nz,i,ai16; 4244b3260449SShri Abhyankar const PetscInt *vi; 4245f26ec98cSKris Buschelman 4246f26ec98cSKris Buschelman /* forward solve the lower triangular */ 4247f26ec98cSKris Buschelman idx = 0; 4248f26ec98cSKris Buschelman t[0] = (MatScalar)b[0]; 4249f26ec98cSKris Buschelman t[1] = (MatScalar)b[1]; 4250f26ec98cSKris Buschelman t[2] = (MatScalar)b[2]; 4251f26ec98cSKris Buschelman t[3] = (MatScalar)b[3]; 4252f26ec98cSKris Buschelman for (i=1; i<n; i++) { 4253f26ec98cSKris Buschelman v = aa + 16*ai[i]; 4254f26ec98cSKris Buschelman vi = aj + ai[i]; 4255f26ec98cSKris Buschelman nz = diag[i] - ai[i]; 4256f26ec98cSKris Buschelman idx += 4; 4257f26ec98cSKris Buschelman s1 = (MatScalar)b[idx]; 4258f26ec98cSKris Buschelman s2 = (MatScalar)b[1+idx]; 4259f26ec98cSKris Buschelman s3 = (MatScalar)b[2+idx]; 4260f26ec98cSKris Buschelman s4 = (MatScalar)b[3+idx]; 4261f26ec98cSKris Buschelman while (nz--) { 4262f26ec98cSKris Buschelman jdx = 4*(*vi++); 4263f26ec98cSKris Buschelman x1 = t[jdx]; 4264f26ec98cSKris Buschelman x2 = t[1+jdx]; 4265f26ec98cSKris Buschelman x3 = t[2+jdx]; 4266f26ec98cSKris Buschelman x4 = t[3+jdx]; 4267f26ec98cSKris Buschelman s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 4268f26ec98cSKris Buschelman s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 4269f26ec98cSKris Buschelman s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 4270f26ec98cSKris Buschelman s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 4271f26ec98cSKris Buschelman v += 16; 4272f26ec98cSKris Buschelman } 4273f26ec98cSKris Buschelman t[idx] = s1; 4274f26ec98cSKris Buschelman t[1+idx] = s2; 4275f26ec98cSKris Buschelman t[2+idx] = s3; 4276f26ec98cSKris Buschelman t[3+idx] = s4; 4277f26ec98cSKris Buschelman } 4278f26ec98cSKris Buschelman /* backward solve the upper triangular */ 4279f26ec98cSKris Buschelman idt = 4*(n-1); 4280f26ec98cSKris Buschelman for (i=n-1; i>=0; i--){ 4281f26ec98cSKris Buschelman ai16 = 16*diag[i]; 4282f26ec98cSKris Buschelman v = aa + ai16 + 16; 4283f26ec98cSKris Buschelman vi = aj + diag[i] + 1; 4284f26ec98cSKris Buschelman nz = ai[i+1] - diag[i] - 1; 4285f26ec98cSKris Buschelman s1 = t[idt]; 4286f26ec98cSKris Buschelman s2 = t[1+idt]; 4287f26ec98cSKris Buschelman s3 = t[2+idt]; 4288f26ec98cSKris Buschelman s4 = t[3+idt]; 4289f26ec98cSKris Buschelman while (nz--) { 4290f26ec98cSKris Buschelman idx = 4*(*vi++); 4291f26ec98cSKris Buschelman x1 = (MatScalar)x[idx]; 4292f26ec98cSKris Buschelman x2 = (MatScalar)x[1+idx]; 4293f26ec98cSKris Buschelman x3 = (MatScalar)x[2+idx]; 4294f26ec98cSKris Buschelman x4 = (MatScalar)x[3+idx]; 4295f26ec98cSKris Buschelman s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4; 4296f26ec98cSKris Buschelman s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4; 4297f26ec98cSKris Buschelman s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4; 4298f26ec98cSKris Buschelman s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4; 4299f26ec98cSKris Buschelman v += 16; 4300f26ec98cSKris Buschelman } 4301f26ec98cSKris Buschelman v = aa + ai16; 4302f26ec98cSKris Buschelman x[idt] = (PetscScalar)(v[0]*s1 + v[4]*s2 + v[8]*s3 + v[12]*s4); 4303f26ec98cSKris Buschelman x[1+idt] = (PetscScalar)(v[1]*s1 + v[5]*s2 + v[9]*s3 + v[13]*s4); 4304f26ec98cSKris Buschelman x[2+idt] = (PetscScalar)(v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4); 4305f26ec98cSKris Buschelman x[3+idt] = (PetscScalar)(v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4); 4306f26ec98cSKris Buschelman idt -= 4; 4307f26ec98cSKris Buschelman } 4308f26ec98cSKris Buschelman } 4309f26ec98cSKris Buschelman 4310b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 43111ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4312dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 4313f26ec98cSKris Buschelman PetscFunctionReturn(0); 4314f26ec98cSKris Buschelman } 4315f26ec98cSKris Buschelman 43163660e330SKris Buschelman #if defined (PETSC_HAVE_SSE) 43173660e330SKris Buschelman 43183660e330SKris Buschelman #include PETSC_HAVE_SSE 43193660e330SKris Buschelman #undef __FUNCT__ 43207cf1b8d3SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion_usj" 4321dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion_usj(Mat A,Vec bb,Vec xx) 43223660e330SKris Buschelman { 43233660e330SKris Buschelman Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 43242aa5897fSKris Buschelman unsigned short *aj=(unsigned short *)a->j; 4325dfbe8321SBarry Smith PetscErrorCode ierr; 4326dfbe8321SBarry Smith int *ai=a->i,n=a->mbs,*diag = a->diag; 43273660e330SKris Buschelman MatScalar *aa=a->a; 432887828ca2SBarry Smith PetscScalar *x,*b; 43293660e330SKris Buschelman 43303660e330SKris Buschelman PetscFunctionBegin; 43313660e330SKris Buschelman SSE_SCOPE_BEGIN; 43323660e330SKris Buschelman /* 43333660e330SKris Buschelman Note: This code currently uses demotion of double 43343660e330SKris Buschelman to float when performing the mixed-mode computation. 43353660e330SKris Buschelman This may not be numerically reasonable for all applications. 43363660e330SKris Buschelman */ 43373660e330SKris Buschelman PREFETCH_NTA(aa+16*ai[1]); 43383660e330SKris Buschelman 43391ebc52fbSHong Zhang ierr = VecGetArray(bb,&b);CHKERRQ(ierr); 43401ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 43413660e330SKris Buschelman { 4342eb05f457SKris Buschelman /* x will first be computed in single precision then promoted inplace to double */ 4343eb05f457SKris Buschelman MatScalar *v,*t=(MatScalar *)x; 43442aa5897fSKris Buschelman int nz,i,idt,ai16; 43452aa5897fSKris Buschelman unsigned int jdx,idx; 43462aa5897fSKris Buschelman unsigned short *vi; 4347eb05f457SKris Buschelman /* Forward solve the lower triangular factor. */ 43483660e330SKris Buschelman 4349eb05f457SKris Buschelman /* First block is the identity. */ 43503660e330SKris Buschelman idx = 0; 4351eb05f457SKris Buschelman CONVERT_DOUBLE4_FLOAT4(t,b); 43522aa5897fSKris Buschelman v = aa + 16*((unsigned int)ai[1]); 43533660e330SKris Buschelman 43543660e330SKris Buschelman for (i=1; i<n;) { 43553660e330SKris Buschelman PREFETCH_NTA(&v[8]); 43563660e330SKris Buschelman vi = aj + ai[i]; 43573660e330SKris Buschelman nz = diag[i] - ai[i]; 43583660e330SKris Buschelman idx += 4; 43593660e330SKris Buschelman 4360eb05f457SKris Buschelman /* Demote RHS from double to float. */ 4361eb05f457SKris Buschelman CONVERT_DOUBLE4_FLOAT4(&t[idx],&b[idx]); 4362eb05f457SKris Buschelman LOAD_PS(&t[idx],XMM7); 43633660e330SKris Buschelman 43643660e330SKris Buschelman while (nz--) { 43653660e330SKris Buschelman PREFETCH_NTA(&v[16]); 43662aa5897fSKris Buschelman jdx = 4*((unsigned int)(*vi++)); 43673660e330SKris Buschelman 43683660e330SKris Buschelman /* 4x4 Matrix-Vector product with negative accumulation: */ 4369eb05f457SKris Buschelman SSE_INLINE_BEGIN_2(&t[jdx],v) 43703660e330SKris Buschelman SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6) 43713660e330SKris Buschelman 43723660e330SKris Buschelman /* First Column */ 43733660e330SKris Buschelman SSE_COPY_PS(XMM0,XMM6) 43743660e330SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 43753660e330SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0) 43763660e330SKris Buschelman SSE_SUB_PS(XMM7,XMM0) 43773660e330SKris Buschelman 43783660e330SKris Buschelman /* Second Column */ 43793660e330SKris Buschelman SSE_COPY_PS(XMM1,XMM6) 43803660e330SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 43813660e330SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4) 43823660e330SKris Buschelman SSE_SUB_PS(XMM7,XMM1) 43833660e330SKris Buschelman 43843660e330SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24) 43853660e330SKris Buschelman 43863660e330SKris Buschelman /* Third Column */ 43873660e330SKris Buschelman SSE_COPY_PS(XMM2,XMM6) 43883660e330SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 43893660e330SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8) 43903660e330SKris Buschelman SSE_SUB_PS(XMM7,XMM2) 43913660e330SKris Buschelman 43923660e330SKris Buschelman /* Fourth Column */ 43933660e330SKris Buschelman SSE_COPY_PS(XMM3,XMM6) 43943660e330SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 43953660e330SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12) 43963660e330SKris Buschelman SSE_SUB_PS(XMM7,XMM3) 43973660e330SKris Buschelman SSE_INLINE_END_2 43983660e330SKris Buschelman 43993660e330SKris Buschelman v += 16; 44003660e330SKris Buschelman } 44013660e330SKris Buschelman v = aa + 16*ai[++i]; 44023660e330SKris Buschelman PREFETCH_NTA(v); 4403eb05f457SKris Buschelman STORE_PS(&t[idx],XMM7); 44043660e330SKris Buschelman } 4405eb05f457SKris Buschelman 4406eb05f457SKris Buschelman /* Backward solve the upper triangular factor.*/ 4407eb05f457SKris Buschelman 44083660e330SKris Buschelman idt = 4*(n-1); 44093660e330SKris Buschelman ai16 = 16*diag[n-1]; 44103660e330SKris Buschelman v = aa + ai16 + 16; 44113660e330SKris Buschelman for (i=n-1; i>=0;){ 44123660e330SKris Buschelman PREFETCH_NTA(&v[8]); 44133660e330SKris Buschelman vi = aj + diag[i] + 1; 44143660e330SKris Buschelman nz = ai[i+1] - diag[i] - 1; 44153660e330SKris Buschelman 4416eb05f457SKris Buschelman LOAD_PS(&t[idt],XMM7); 44173660e330SKris Buschelman 44183660e330SKris Buschelman while (nz--) { 44193660e330SKris Buschelman PREFETCH_NTA(&v[16]); 44202aa5897fSKris Buschelman idx = 4*((unsigned int)(*vi++)); 44213660e330SKris Buschelman 44223660e330SKris Buschelman /* 4x4 Matrix-Vector Product with negative accumulation: */ 4423eb05f457SKris Buschelman SSE_INLINE_BEGIN_2(&t[idx],v) 44243660e330SKris Buschelman SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6) 44253660e330SKris Buschelman 44263660e330SKris Buschelman /* First Column */ 44273660e330SKris Buschelman SSE_COPY_PS(XMM0,XMM6) 44283660e330SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 44293660e330SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0) 44303660e330SKris Buschelman SSE_SUB_PS(XMM7,XMM0) 44313660e330SKris Buschelman 44323660e330SKris Buschelman /* Second Column */ 44333660e330SKris Buschelman SSE_COPY_PS(XMM1,XMM6) 44343660e330SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 44353660e330SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4) 44363660e330SKris Buschelman SSE_SUB_PS(XMM7,XMM1) 44373660e330SKris Buschelman 44383660e330SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24) 44393660e330SKris Buschelman 44403660e330SKris Buschelman /* Third Column */ 44413660e330SKris Buschelman SSE_COPY_PS(XMM2,XMM6) 44423660e330SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 44433660e330SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8) 44443660e330SKris Buschelman SSE_SUB_PS(XMM7,XMM2) 44453660e330SKris Buschelman 44463660e330SKris Buschelman /* Fourth Column */ 44473660e330SKris Buschelman SSE_COPY_PS(XMM3,XMM6) 44483660e330SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 44493660e330SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12) 44503660e330SKris Buschelman SSE_SUB_PS(XMM7,XMM3) 44513660e330SKris Buschelman SSE_INLINE_END_2 44523660e330SKris Buschelman v += 16; 44533660e330SKris Buschelman } 44543660e330SKris Buschelman v = aa + ai16; 44553660e330SKris Buschelman ai16 = 16*diag[--i]; 44563660e330SKris Buschelman PREFETCH_NTA(aa+ai16+16); 44573660e330SKris Buschelman /* 44583660e330SKris Buschelman Scale the result by the diagonal 4x4 block, 44593660e330SKris Buschelman which was inverted as part of the factorization 44603660e330SKris Buschelman */ 4461eb05f457SKris Buschelman SSE_INLINE_BEGIN_3(v,&t[idt],aa+ai16) 44623660e330SKris Buschelman /* First Column */ 44633660e330SKris Buschelman SSE_COPY_PS(XMM0,XMM7) 44643660e330SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 44653660e330SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0) 44663660e330SKris Buschelman 44673660e330SKris Buschelman /* Second Column */ 44683660e330SKris Buschelman SSE_COPY_PS(XMM1,XMM7) 44693660e330SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 44703660e330SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4) 44713660e330SKris Buschelman SSE_ADD_PS(XMM0,XMM1) 44723660e330SKris Buschelman 44733660e330SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24) 44743660e330SKris Buschelman 44753660e330SKris Buschelman /* Third Column */ 44763660e330SKris Buschelman SSE_COPY_PS(XMM2,XMM7) 44773660e330SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 44783660e330SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8) 44793660e330SKris Buschelman SSE_ADD_PS(XMM0,XMM2) 44803660e330SKris Buschelman 44813660e330SKris Buschelman /* Fourth Column */ 44823660e330SKris Buschelman SSE_COPY_PS(XMM3,XMM7) 44833660e330SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 44843660e330SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12) 44853660e330SKris Buschelman SSE_ADD_PS(XMM0,XMM3) 44863660e330SKris Buschelman 44873660e330SKris Buschelman SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0) 44883660e330SKris Buschelman SSE_INLINE_END_3 44893660e330SKris Buschelman 44903660e330SKris Buschelman v = aa + ai16 + 16; 44913660e330SKris Buschelman idt -= 4; 44923660e330SKris Buschelman } 4493eb05f457SKris Buschelman 4494eb05f457SKris Buschelman /* Convert t from single precision back to double precision (inplace)*/ 4495eb05f457SKris Buschelman idt = 4*(n-1); 4496eb05f457SKris Buschelman for (i=n-1;i>=0;i--) { 4497eb05f457SKris Buschelman /* CONVERT_FLOAT4_DOUBLE4(&x[idt],&t[idt]); */ 4498eb05f457SKris Buschelman /* Unfortunately, CONVERT_ will count from 0 to 3 which doesn't work here. */ 4499eb05f457SKris Buschelman PetscScalar *xtemp=&x[idt]; 4500eb05f457SKris Buschelman MatScalar *ttemp=&t[idt]; 4501eb05f457SKris Buschelman xtemp[3] = (PetscScalar)ttemp[3]; 4502eb05f457SKris Buschelman xtemp[2] = (PetscScalar)ttemp[2]; 4503eb05f457SKris Buschelman xtemp[1] = (PetscScalar)ttemp[1]; 4504eb05f457SKris Buschelman xtemp[0] = (PetscScalar)ttemp[0]; 450554693613SKris Buschelman idt -= 4; 45063660e330SKris Buschelman } 4507eb05f457SKris Buschelman 4508eb05f457SKris Buschelman } /* End of artificial scope. */ 45091ebc52fbSHong Zhang ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr); 45101ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4511dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 45123660e330SKris Buschelman SSE_SCOPE_END; 45133660e330SKris Buschelman PetscFunctionReturn(0); 45143660e330SKris Buschelman } 45153660e330SKris Buschelman 45167cf1b8d3SKris Buschelman #undef __FUNCT__ 45177cf1b8d3SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion" 4518dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion(Mat A,Vec bb,Vec xx) 45197cf1b8d3SKris Buschelman { 45207cf1b8d3SKris Buschelman Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 45217cf1b8d3SKris Buschelman int *aj=a->j; 4522dfbe8321SBarry Smith PetscErrorCode ierr; 4523dfbe8321SBarry Smith int *ai=a->i,n=a->mbs,*diag = a->diag; 45247cf1b8d3SKris Buschelman MatScalar *aa=a->a; 45257cf1b8d3SKris Buschelman PetscScalar *x,*b; 45267cf1b8d3SKris Buschelman 45277cf1b8d3SKris Buschelman PetscFunctionBegin; 45287cf1b8d3SKris Buschelman SSE_SCOPE_BEGIN; 45297cf1b8d3SKris Buschelman /* 45307cf1b8d3SKris Buschelman Note: This code currently uses demotion of double 45317cf1b8d3SKris Buschelman to float when performing the mixed-mode computation. 45327cf1b8d3SKris Buschelman This may not be numerically reasonable for all applications. 45337cf1b8d3SKris Buschelman */ 45347cf1b8d3SKris Buschelman PREFETCH_NTA(aa+16*ai[1]); 45357cf1b8d3SKris Buschelman 45361ebc52fbSHong Zhang ierr = VecGetArray(bb,&b);CHKERRQ(ierr); 45371ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 45387cf1b8d3SKris Buschelman { 45397cf1b8d3SKris Buschelman /* x will first be computed in single precision then promoted inplace to double */ 45407cf1b8d3SKris Buschelman MatScalar *v,*t=(MatScalar *)x; 45417cf1b8d3SKris Buschelman int nz,i,idt,ai16; 45427cf1b8d3SKris Buschelman int jdx,idx; 45437cf1b8d3SKris Buschelman int *vi; 45447cf1b8d3SKris Buschelman /* Forward solve the lower triangular factor. */ 45457cf1b8d3SKris Buschelman 45467cf1b8d3SKris Buschelman /* First block is the identity. */ 45477cf1b8d3SKris Buschelman idx = 0; 45487cf1b8d3SKris Buschelman CONVERT_DOUBLE4_FLOAT4(t,b); 45497cf1b8d3SKris Buschelman v = aa + 16*ai[1]; 45507cf1b8d3SKris Buschelman 45517cf1b8d3SKris Buschelman for (i=1; i<n;) { 45527cf1b8d3SKris Buschelman PREFETCH_NTA(&v[8]); 45537cf1b8d3SKris Buschelman vi = aj + ai[i]; 45547cf1b8d3SKris Buschelman nz = diag[i] - ai[i]; 45557cf1b8d3SKris Buschelman idx += 4; 45567cf1b8d3SKris Buschelman 45577cf1b8d3SKris Buschelman /* Demote RHS from double to float. */ 45587cf1b8d3SKris Buschelman CONVERT_DOUBLE4_FLOAT4(&t[idx],&b[idx]); 45597cf1b8d3SKris Buschelman LOAD_PS(&t[idx],XMM7); 45607cf1b8d3SKris Buschelman 45617cf1b8d3SKris Buschelman while (nz--) { 45627cf1b8d3SKris Buschelman PREFETCH_NTA(&v[16]); 45637cf1b8d3SKris Buschelman jdx = 4*(*vi++); 45647cf1b8d3SKris Buschelman /* jdx = *vi++; */ 45657cf1b8d3SKris Buschelman 45667cf1b8d3SKris Buschelman /* 4x4 Matrix-Vector product with negative accumulation: */ 45677cf1b8d3SKris Buschelman SSE_INLINE_BEGIN_2(&t[jdx],v) 45687cf1b8d3SKris Buschelman SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6) 45697cf1b8d3SKris Buschelman 45707cf1b8d3SKris Buschelman /* First Column */ 45717cf1b8d3SKris Buschelman SSE_COPY_PS(XMM0,XMM6) 45727cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 45737cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0) 45747cf1b8d3SKris Buschelman SSE_SUB_PS(XMM7,XMM0) 45757cf1b8d3SKris Buschelman 45767cf1b8d3SKris Buschelman /* Second Column */ 45777cf1b8d3SKris Buschelman SSE_COPY_PS(XMM1,XMM6) 45787cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 45797cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4) 45807cf1b8d3SKris Buschelman SSE_SUB_PS(XMM7,XMM1) 45817cf1b8d3SKris Buschelman 45827cf1b8d3SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24) 45837cf1b8d3SKris Buschelman 45847cf1b8d3SKris Buschelman /* Third Column */ 45857cf1b8d3SKris Buschelman SSE_COPY_PS(XMM2,XMM6) 45867cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 45877cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8) 45887cf1b8d3SKris Buschelman SSE_SUB_PS(XMM7,XMM2) 45897cf1b8d3SKris Buschelman 45907cf1b8d3SKris Buschelman /* Fourth Column */ 45917cf1b8d3SKris Buschelman SSE_COPY_PS(XMM3,XMM6) 45927cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 45937cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12) 45947cf1b8d3SKris Buschelman SSE_SUB_PS(XMM7,XMM3) 45957cf1b8d3SKris Buschelman SSE_INLINE_END_2 45967cf1b8d3SKris Buschelman 45977cf1b8d3SKris Buschelman v += 16; 45987cf1b8d3SKris Buschelman } 45997cf1b8d3SKris Buschelman v = aa + 16*ai[++i]; 46007cf1b8d3SKris Buschelman PREFETCH_NTA(v); 46017cf1b8d3SKris Buschelman STORE_PS(&t[idx],XMM7); 46027cf1b8d3SKris Buschelman } 46037cf1b8d3SKris Buschelman 46047cf1b8d3SKris Buschelman /* Backward solve the upper triangular factor.*/ 46057cf1b8d3SKris Buschelman 46067cf1b8d3SKris Buschelman idt = 4*(n-1); 46077cf1b8d3SKris Buschelman ai16 = 16*diag[n-1]; 46087cf1b8d3SKris Buschelman v = aa + ai16 + 16; 46097cf1b8d3SKris Buschelman for (i=n-1; i>=0;){ 46107cf1b8d3SKris Buschelman PREFETCH_NTA(&v[8]); 46117cf1b8d3SKris Buschelman vi = aj + diag[i] + 1; 46127cf1b8d3SKris Buschelman nz = ai[i+1] - diag[i] - 1; 46137cf1b8d3SKris Buschelman 46147cf1b8d3SKris Buschelman LOAD_PS(&t[idt],XMM7); 46157cf1b8d3SKris Buschelman 46167cf1b8d3SKris Buschelman while (nz--) { 46177cf1b8d3SKris Buschelman PREFETCH_NTA(&v[16]); 46187cf1b8d3SKris Buschelman idx = 4*(*vi++); 46197cf1b8d3SKris Buschelman /* idx = *vi++; */ 46207cf1b8d3SKris Buschelman 46217cf1b8d3SKris Buschelman /* 4x4 Matrix-Vector Product with negative accumulation: */ 46227cf1b8d3SKris Buschelman SSE_INLINE_BEGIN_2(&t[idx],v) 46237cf1b8d3SKris Buschelman SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6) 46247cf1b8d3SKris Buschelman 46257cf1b8d3SKris Buschelman /* First Column */ 46267cf1b8d3SKris Buschelman SSE_COPY_PS(XMM0,XMM6) 46277cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 46287cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0) 46297cf1b8d3SKris Buschelman SSE_SUB_PS(XMM7,XMM0) 46307cf1b8d3SKris Buschelman 46317cf1b8d3SKris Buschelman /* Second Column */ 46327cf1b8d3SKris Buschelman SSE_COPY_PS(XMM1,XMM6) 46337cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 46347cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4) 46357cf1b8d3SKris Buschelman SSE_SUB_PS(XMM7,XMM1) 46367cf1b8d3SKris Buschelman 46377cf1b8d3SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24) 46387cf1b8d3SKris Buschelman 46397cf1b8d3SKris Buschelman /* Third Column */ 46407cf1b8d3SKris Buschelman SSE_COPY_PS(XMM2,XMM6) 46417cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 46427cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8) 46437cf1b8d3SKris Buschelman SSE_SUB_PS(XMM7,XMM2) 46447cf1b8d3SKris Buschelman 46457cf1b8d3SKris Buschelman /* Fourth Column */ 46467cf1b8d3SKris Buschelman SSE_COPY_PS(XMM3,XMM6) 46477cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 46487cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12) 46497cf1b8d3SKris Buschelman SSE_SUB_PS(XMM7,XMM3) 46507cf1b8d3SKris Buschelman SSE_INLINE_END_2 46517cf1b8d3SKris Buschelman v += 16; 46527cf1b8d3SKris Buschelman } 46537cf1b8d3SKris Buschelman v = aa + ai16; 46547cf1b8d3SKris Buschelman ai16 = 16*diag[--i]; 46557cf1b8d3SKris Buschelman PREFETCH_NTA(aa+ai16+16); 46567cf1b8d3SKris Buschelman /* 46577cf1b8d3SKris Buschelman Scale the result by the diagonal 4x4 block, 46587cf1b8d3SKris Buschelman which was inverted as part of the factorization 46597cf1b8d3SKris Buschelman */ 46607cf1b8d3SKris Buschelman SSE_INLINE_BEGIN_3(v,&t[idt],aa+ai16) 46617cf1b8d3SKris Buschelman /* First Column */ 46627cf1b8d3SKris Buschelman SSE_COPY_PS(XMM0,XMM7) 46637cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM0,XMM0,0x00) 46647cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0) 46657cf1b8d3SKris Buschelman 46667cf1b8d3SKris Buschelman /* Second Column */ 46677cf1b8d3SKris Buschelman SSE_COPY_PS(XMM1,XMM7) 46687cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM1,XMM1,0x55) 46697cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4) 46707cf1b8d3SKris Buschelman SSE_ADD_PS(XMM0,XMM1) 46717cf1b8d3SKris Buschelman 46727cf1b8d3SKris Buschelman SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24) 46737cf1b8d3SKris Buschelman 46747cf1b8d3SKris Buschelman /* Third Column */ 46757cf1b8d3SKris Buschelman SSE_COPY_PS(XMM2,XMM7) 46767cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM2,XMM2,0xAA) 46777cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8) 46787cf1b8d3SKris Buschelman SSE_ADD_PS(XMM0,XMM2) 46797cf1b8d3SKris Buschelman 46807cf1b8d3SKris Buschelman /* Fourth Column */ 46817cf1b8d3SKris Buschelman SSE_COPY_PS(XMM3,XMM7) 46827cf1b8d3SKris Buschelman SSE_SHUFFLE(XMM3,XMM3,0xFF) 46837cf1b8d3SKris Buschelman SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12) 46847cf1b8d3SKris Buschelman SSE_ADD_PS(XMM0,XMM3) 46857cf1b8d3SKris Buschelman 46867cf1b8d3SKris Buschelman SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0) 46877cf1b8d3SKris Buschelman SSE_INLINE_END_3 46887cf1b8d3SKris Buschelman 46897cf1b8d3SKris Buschelman v = aa + ai16 + 16; 46907cf1b8d3SKris Buschelman idt -= 4; 46917cf1b8d3SKris Buschelman } 46927cf1b8d3SKris Buschelman 46937cf1b8d3SKris Buschelman /* Convert t from single precision back to double precision (inplace)*/ 46947cf1b8d3SKris Buschelman idt = 4*(n-1); 46957cf1b8d3SKris Buschelman for (i=n-1;i>=0;i--) { 46967cf1b8d3SKris Buschelman /* CONVERT_FLOAT4_DOUBLE4(&x[idt],&t[idt]); */ 46977cf1b8d3SKris Buschelman /* Unfortunately, CONVERT_ will count from 0 to 3 which doesn't work here. */ 46987cf1b8d3SKris Buschelman PetscScalar *xtemp=&x[idt]; 46997cf1b8d3SKris Buschelman MatScalar *ttemp=&t[idt]; 47007cf1b8d3SKris Buschelman xtemp[3] = (PetscScalar)ttemp[3]; 47017cf1b8d3SKris Buschelman xtemp[2] = (PetscScalar)ttemp[2]; 47027cf1b8d3SKris Buschelman xtemp[1] = (PetscScalar)ttemp[1]; 47037cf1b8d3SKris Buschelman xtemp[0] = (PetscScalar)ttemp[0]; 47047cf1b8d3SKris Buschelman idt -= 4; 47057cf1b8d3SKris Buschelman } 47067cf1b8d3SKris Buschelman 47077cf1b8d3SKris Buschelman } /* End of artificial scope. */ 47081ebc52fbSHong Zhang ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr); 47091ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4710dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr); 47117cf1b8d3SKris Buschelman SSE_SCOPE_END; 47127cf1b8d3SKris Buschelman PetscFunctionReturn(0); 47137cf1b8d3SKris Buschelman } 47147cf1b8d3SKris Buschelman 47153660e330SKris Buschelman #endif 47168f690400SShri Abhyankar 47174a2ae208SSatish Balay #undef __FUNCT__ 471806e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_3_inplace" 471906e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_3_inplace(Mat A,Vec bb,Vec xx) 47204e2b4712SSatish Balay { 47214e2b4712SSatish Balay Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 47224e2b4712SSatish Balay IS iscol=a->col,isrow=a->row; 47236849ba73SBarry Smith PetscErrorCode ierr; 4724b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j; 4725b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc; 47265d0c19d7SBarry Smith const PetscInt *r,*c,*diag = a->diag,*rout,*cout; 4727d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 4728d9fead3dSBarry Smith PetscScalar *x,s1,s2,s3,x1,x2,x3,*t; 4729d9fead3dSBarry Smith const PetscScalar *b; 47304e2b4712SSatish Balay 47314e2b4712SSatish Balay PetscFunctionBegin; 4732d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 47331ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 4734f1af5d2fSBarry Smith t = a->solve_work; 47354e2b4712SSatish Balay 47364e2b4712SSatish Balay ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 47374e2b4712SSatish Balay ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 47384e2b4712SSatish Balay 47394e2b4712SSatish Balay /* forward solve the lower triangular */ 47404e2b4712SSatish Balay idx = 3*(*r++); 4741f1af5d2fSBarry Smith t[0] = b[idx]; t[1] = b[1+idx]; t[2] = b[2+idx]; 47424e2b4712SSatish Balay for (i=1; i<n; i++) { 47434e2b4712SSatish Balay v = aa + 9*ai[i]; 47444e2b4712SSatish Balay vi = aj + ai[i]; 47454e2b4712SSatish Balay nz = diag[i] - ai[i]; 47464e2b4712SSatish Balay idx = 3*(*r++); 4747f1af5d2fSBarry Smith s1 = b[idx]; s2 = b[1+idx]; s3 = b[2+idx]; 47484e2b4712SSatish Balay while (nz--) { 47494e2b4712SSatish Balay idx = 3*(*vi++); 4750f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; 4751f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3; 4752f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3; 4753f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3; 47544e2b4712SSatish Balay v += 9; 47554e2b4712SSatish Balay } 47564e2b4712SSatish Balay idx = 3*i; 4757f1af5d2fSBarry Smith t[idx] = s1; t[1+idx] = s2; t[2+idx] = s3; 47584e2b4712SSatish Balay } 47594e2b4712SSatish Balay /* backward solve the upper triangular */ 47604e2b4712SSatish Balay for (i=n-1; i>=0; i--){ 47614e2b4712SSatish Balay v = aa + 9*diag[i] + 9; 47624e2b4712SSatish Balay vi = aj + diag[i] + 1; 47634e2b4712SSatish Balay nz = ai[i+1] - diag[i] - 1; 47644e2b4712SSatish Balay idt = 3*i; 4765f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; 47664e2b4712SSatish Balay while (nz--) { 47674e2b4712SSatish Balay idx = 3*(*vi++); 4768f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; 4769f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3; 4770f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3; 4771f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3; 47724e2b4712SSatish Balay v += 9; 47734e2b4712SSatish Balay } 47744e2b4712SSatish Balay idc = 3*(*c--); 47754e2b4712SSatish Balay v = aa + 9*diag[i]; 4776f1af5d2fSBarry Smith x[idc] = t[idt] = v[0]*s1 + v[3]*s2 + v[6]*s3; 4777f1af5d2fSBarry Smith x[1+idc] = t[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3; 4778f1af5d2fSBarry Smith x[2+idc] = t[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3; 47794e2b4712SSatish Balay } 47804e2b4712SSatish Balay ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 47814e2b4712SSatish Balay ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 4782d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 47831ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4784dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr); 47854e2b4712SSatish Balay PetscFunctionReturn(0); 47864e2b4712SSatish Balay } 47874e2b4712SSatish Balay 47880c4413a7SShri Abhyankar #undef __FUNCT__ 47894dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_3" 47904dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_3(Mat A,Vec bb,Vec xx) 47910c4413a7SShri Abhyankar { 47920c4413a7SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 47930c4413a7SShri Abhyankar IS iscol=a->col,isrow=a->row; 47940c4413a7SShri Abhyankar PetscErrorCode ierr; 4795b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 4796b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc,m; 47970c4413a7SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 47980c4413a7SShri Abhyankar const MatScalar *aa=a->a,*v; 47990c4413a7SShri Abhyankar PetscScalar *x,s1,s2,s3,x1,x2,x3,*t; 48000c4413a7SShri Abhyankar const PetscScalar *b; 48010c4413a7SShri Abhyankar 48020c4413a7SShri Abhyankar PetscFunctionBegin; 48030c4413a7SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 48040c4413a7SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 48050c4413a7SShri Abhyankar t = a->solve_work; 48060c4413a7SShri Abhyankar 48070c4413a7SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 48080c4413a7SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 48090c4413a7SShri Abhyankar 48100c4413a7SShri Abhyankar /* forward solve the lower triangular */ 48110c4413a7SShri Abhyankar idx = 3*r[0]; 48120c4413a7SShri Abhyankar t[0] = b[idx]; t[1] = b[1+idx]; t[2] = b[2+idx]; 48130c4413a7SShri Abhyankar for (i=1; i<n; i++) { 48140c4413a7SShri Abhyankar v = aa + 9*ai[i]; 48150c4413a7SShri Abhyankar vi = aj + ai[i]; 48160c4413a7SShri Abhyankar nz = ai[i+1] - ai[i]; 48170c4413a7SShri Abhyankar idx = 3*r[i]; 48180c4413a7SShri Abhyankar s1 = b[idx]; s2 = b[1+idx]; s3 = b[2+idx]; 48190c4413a7SShri Abhyankar for(m=0;m<nz;m++){ 48200c4413a7SShri Abhyankar idx = 3*vi[m]; 48210c4413a7SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; 48220c4413a7SShri Abhyankar s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3; 48230c4413a7SShri Abhyankar s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3; 48240c4413a7SShri Abhyankar s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3; 48250c4413a7SShri Abhyankar v += 9; 48260c4413a7SShri Abhyankar } 48270c4413a7SShri Abhyankar idx = 3*i; 48280c4413a7SShri Abhyankar t[idx] = s1; t[1+idx] = s2; t[2+idx] = s3; 48290c4413a7SShri Abhyankar } 48300c4413a7SShri Abhyankar /* backward solve the upper triangular */ 48310c4413a7SShri Abhyankar for (i=n-1; i>=0; i--){ 48320c4413a7SShri Abhyankar v = aa + 9*(adiag[i+1]+1); 48330c4413a7SShri Abhyankar vi = aj + adiag[i+1]+1; 48340c4413a7SShri Abhyankar nz = adiag[i] - adiag[i+1] - 1; 48350c4413a7SShri Abhyankar idt = 3*i; 48360c4413a7SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt]; 48370c4413a7SShri Abhyankar for(m=0;m<nz;m++){ 48380c4413a7SShri Abhyankar idx = 3*vi[m]; 48390c4413a7SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; x3 = t[2+idx]; 48400c4413a7SShri Abhyankar s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3; 48410c4413a7SShri Abhyankar s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3; 48420c4413a7SShri Abhyankar s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3; 48430c4413a7SShri Abhyankar v += 9; 48440c4413a7SShri Abhyankar } 48450c4413a7SShri Abhyankar idc = 3*c[i]; 48460c4413a7SShri Abhyankar x[idc] = t[idt] = v[0]*s1 + v[3]*s2 + v[6]*s3; 48470c4413a7SShri Abhyankar x[1+idc] = t[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3; 48480c4413a7SShri Abhyankar x[2+idc] = t[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3; 48490c4413a7SShri Abhyankar } 48500c4413a7SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 48510c4413a7SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 48520c4413a7SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 48530c4413a7SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 48540c4413a7SShri Abhyankar ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr); 48550c4413a7SShri Abhyankar PetscFunctionReturn(0); 48560c4413a7SShri Abhyankar } 48570c4413a7SShri Abhyankar 485815091d37SBarry Smith /* 485915091d37SBarry Smith Special case where the matrix was ILU(0) factored in the natural 486015091d37SBarry Smith ordering. This eliminates the need for the column and row permutation. 486115091d37SBarry Smith */ 48624a2ae208SSatish Balay #undef __FUNCT__ 486306e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_3_NaturalOrdering_inplace" 486406e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_3_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 486515091d37SBarry Smith { 486615091d37SBarry Smith Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 48670b68f018SBarry Smith const PetscInt n=a->mbs,*ai=a->i,*aj=a->j; 4868dfbe8321SBarry Smith PetscErrorCode ierr; 48690b68f018SBarry Smith const PetscInt *diag = a->diag,*vi; 4870d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 4871d9fead3dSBarry Smith PetscScalar *x,s1,s2,s3,x1,x2,x3; 4872d9fead3dSBarry Smith const PetscScalar *b; 48730b68f018SBarry Smith PetscInt jdx,idt,idx,nz,i; 487415091d37SBarry Smith 487515091d37SBarry Smith PetscFunctionBegin; 4876d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 48771ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 487815091d37SBarry Smith 487915091d37SBarry Smith /* forward solve the lower triangular */ 488015091d37SBarry Smith idx = 0; 488115091d37SBarry Smith x[0] = b[0]; x[1] = b[1]; x[2] = b[2]; 488215091d37SBarry Smith for (i=1; i<n; i++) { 488315091d37SBarry Smith v = aa + 9*ai[i]; 488415091d37SBarry Smith vi = aj + ai[i]; 488515091d37SBarry Smith nz = diag[i] - ai[i]; 488615091d37SBarry Smith idx += 3; 4887f1af5d2fSBarry Smith s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx]; 488815091d37SBarry Smith while (nz--) { 488915091d37SBarry Smith jdx = 3*(*vi++); 489015091d37SBarry Smith x1 = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx]; 4891f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3; 4892f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3; 4893f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3; 489415091d37SBarry Smith v += 9; 489515091d37SBarry Smith } 4896f1af5d2fSBarry Smith x[idx] = s1; 4897f1af5d2fSBarry Smith x[1+idx] = s2; 4898f1af5d2fSBarry Smith x[2+idx] = s3; 489915091d37SBarry Smith } 490015091d37SBarry Smith /* backward solve the upper triangular */ 490115091d37SBarry Smith for (i=n-1; i>=0; i--){ 490215091d37SBarry Smith v = aa + 9*diag[i] + 9; 490315091d37SBarry Smith vi = aj + diag[i] + 1; 490415091d37SBarry Smith nz = ai[i+1] - diag[i] - 1; 490515091d37SBarry Smith idt = 3*i; 4906f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; 4907f1af5d2fSBarry Smith s3 = x[2+idt]; 490815091d37SBarry Smith while (nz--) { 490915091d37SBarry Smith idx = 3*(*vi++); 491015091d37SBarry Smith x1 = x[idx]; x2 = x[1+idx];x3 = x[2+idx]; 4911f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3; 4912f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3; 4913f1af5d2fSBarry Smith s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3; 491415091d37SBarry Smith v += 9; 491515091d37SBarry Smith } 491615091d37SBarry Smith v = aa + 9*diag[i]; 4917f1af5d2fSBarry Smith x[idt] = v[0]*s1 + v[3]*s2 + v[6]*s3; 4918f1af5d2fSBarry Smith x[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3; 4919f1af5d2fSBarry Smith x[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3; 492015091d37SBarry Smith } 492115091d37SBarry Smith 4922d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 49231ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4924dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr); 492515091d37SBarry Smith PetscFunctionReturn(0); 492615091d37SBarry Smith } 492715091d37SBarry Smith 4928cee9d6f2SShri Abhyankar #undef __FUNCT__ 49294dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_3_NaturalOrdering" 49304dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_3_NaturalOrdering(Mat A,Vec bb,Vec xx) 4931b2b2dd24SShri Abhyankar { 4932b2b2dd24SShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 4933b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 4934b2b2dd24SShri Abhyankar PetscErrorCode ierr; 4935b3260449SShri Abhyankar PetscInt i,k,nz,idx,jdx,idt; 4936b3260449SShri Abhyankar const PetscInt bs = A->rmap->bs,bs2 = a->bs2; 4937b2b2dd24SShri Abhyankar const MatScalar *aa=a->a,*v; 4938b2b2dd24SShri Abhyankar PetscScalar *x; 4939b2b2dd24SShri Abhyankar const PetscScalar *b; 4940b2b2dd24SShri Abhyankar PetscScalar s1,s2,s3,x1,x2,x3; 4941b2b2dd24SShri Abhyankar 4942b2b2dd24SShri Abhyankar PetscFunctionBegin; 4943b2b2dd24SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 4944b2b2dd24SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 4945b2b2dd24SShri Abhyankar /* forward solve the lower triangular */ 4946b2b2dd24SShri Abhyankar idx = 0; 4947b2b2dd24SShri Abhyankar x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx]; 4948b2b2dd24SShri Abhyankar for (i=1; i<n; i++) { 4949b2b2dd24SShri Abhyankar v = aa + bs2*ai[i]; 4950b2b2dd24SShri Abhyankar vi = aj + ai[i]; 4951b2b2dd24SShri Abhyankar nz = ai[i+1] - ai[i]; 4952b2b2dd24SShri Abhyankar idx = bs*i; 4953b2b2dd24SShri Abhyankar s1 = b[idx];s2 = b[1+idx];s3 = b[2+idx]; 4954b2b2dd24SShri Abhyankar for(k=0;k<nz;k++){ 4955b2b2dd24SShri Abhyankar jdx = bs*vi[k]; 4956b2b2dd24SShri Abhyankar x1 = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx]; 4957b2b2dd24SShri Abhyankar s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3; 4958b2b2dd24SShri Abhyankar s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3; 4959b2b2dd24SShri Abhyankar s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3; 4960b2b2dd24SShri Abhyankar 4961b2b2dd24SShri Abhyankar v += bs2; 4962b2b2dd24SShri Abhyankar } 4963b2b2dd24SShri Abhyankar 4964b2b2dd24SShri Abhyankar x[idx] = s1; 4965b2b2dd24SShri Abhyankar x[1+idx] = s2; 4966b2b2dd24SShri Abhyankar x[2+idx] = s3; 4967b2b2dd24SShri Abhyankar } 4968b2b2dd24SShri Abhyankar 4969b2b2dd24SShri Abhyankar /* backward solve the upper triangular */ 4970b2b2dd24SShri Abhyankar for (i=n-1; i>=0; i--){ 4971b2b2dd24SShri Abhyankar v = aa + bs2*(adiag[i+1]+1); 4972b2b2dd24SShri Abhyankar vi = aj + adiag[i+1]+1; 4973b2b2dd24SShri Abhyankar nz = adiag[i] - adiag[i+1]-1; 4974b2b2dd24SShri Abhyankar idt = bs*i; 4975b2b2dd24SShri Abhyankar s1 = x[idt]; s2 = x[1+idt];s3 = x[2+idt]; 4976b2b2dd24SShri Abhyankar 4977b2b2dd24SShri Abhyankar for(k=0;k<nz;k++){ 4978b2b2dd24SShri Abhyankar idx = bs*vi[k]; 4979b2b2dd24SShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; x3 = x[2+idx]; 4980b2b2dd24SShri Abhyankar s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3; 4981b2b2dd24SShri Abhyankar s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3; 4982b2b2dd24SShri Abhyankar s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3; 4983b2b2dd24SShri Abhyankar 4984b2b2dd24SShri Abhyankar v += bs2; 4985b2b2dd24SShri Abhyankar } 4986b2b2dd24SShri Abhyankar /* x = inv_diagonal*x */ 4987b2b2dd24SShri Abhyankar x[idt] = v[0]*s1 + v[3]*s2 + v[6]*s3; 4988b2b2dd24SShri Abhyankar x[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3; 4989b2b2dd24SShri Abhyankar x[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3; 4990b2b2dd24SShri Abhyankar 4991b2b2dd24SShri Abhyankar } 4992b2b2dd24SShri Abhyankar 4993b2b2dd24SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 4994b2b2dd24SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 4995b2b2dd24SShri Abhyankar ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr); 4996b2b2dd24SShri Abhyankar PetscFunctionReturn(0); 4997b2b2dd24SShri Abhyankar } 4998b2b2dd24SShri Abhyankar 4999b2b2dd24SShri Abhyankar #undef __FUNCT__ 500006e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_2_inplace" 500106e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_2_inplace(Mat A,Vec bb,Vec xx) 50024e2b4712SSatish Balay { 50034e2b4712SSatish Balay Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 50044e2b4712SSatish Balay IS iscol=a->col,isrow=a->row; 50056849ba73SBarry Smith PetscErrorCode ierr; 5006b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j; 5007b3260449SShri Abhyankar PetscInt i,nz,idx,idt,idc; 50085d0c19d7SBarry Smith const PetscInt *r,*c,*diag = a->diag,*rout,*cout; 5009d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 5010d9fead3dSBarry Smith PetscScalar *x,s1,s2,x1,x2,*t; 5011d9fead3dSBarry Smith const PetscScalar *b; 50124e2b4712SSatish Balay 50134e2b4712SSatish Balay PetscFunctionBegin; 5014d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 50151ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 5016f1af5d2fSBarry Smith t = a->solve_work; 50174e2b4712SSatish Balay 50184e2b4712SSatish Balay ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 50194e2b4712SSatish Balay ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 50204e2b4712SSatish Balay 50214e2b4712SSatish Balay /* forward solve the lower triangular */ 50224e2b4712SSatish Balay idx = 2*(*r++); 5023f1af5d2fSBarry Smith t[0] = b[idx]; t[1] = b[1+idx]; 50244e2b4712SSatish Balay for (i=1; i<n; i++) { 50254e2b4712SSatish Balay v = aa + 4*ai[i]; 50264e2b4712SSatish Balay vi = aj + ai[i]; 50274e2b4712SSatish Balay nz = diag[i] - ai[i]; 50284e2b4712SSatish Balay idx = 2*(*r++); 5029f1af5d2fSBarry Smith s1 = b[idx]; s2 = b[1+idx]; 50304e2b4712SSatish Balay while (nz--) { 50314e2b4712SSatish Balay idx = 2*(*vi++); 5032f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; 5033f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[2]*x2; 5034f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[3]*x2; 50354e2b4712SSatish Balay v += 4; 50364e2b4712SSatish Balay } 50374e2b4712SSatish Balay idx = 2*i; 5038f1af5d2fSBarry Smith t[idx] = s1; t[1+idx] = s2; 50394e2b4712SSatish Balay } 50404e2b4712SSatish Balay /* backward solve the upper triangular */ 50414e2b4712SSatish Balay for (i=n-1; i>=0; i--){ 50424e2b4712SSatish Balay v = aa + 4*diag[i] + 4; 50434e2b4712SSatish Balay vi = aj + diag[i] + 1; 50444e2b4712SSatish Balay nz = ai[i+1] - diag[i] - 1; 50454e2b4712SSatish Balay idt = 2*i; 5046f1af5d2fSBarry Smith s1 = t[idt]; s2 = t[1+idt]; 50474e2b4712SSatish Balay while (nz--) { 50484e2b4712SSatish Balay idx = 2*(*vi++); 5049f1af5d2fSBarry Smith x1 = t[idx]; x2 = t[1+idx]; 5050f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[2]*x2; 5051f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[3]*x2; 50524e2b4712SSatish Balay v += 4; 50534e2b4712SSatish Balay } 50544e2b4712SSatish Balay idc = 2*(*c--); 50554e2b4712SSatish Balay v = aa + 4*diag[i]; 5056f1af5d2fSBarry Smith x[idc] = t[idt] = v[0]*s1 + v[2]*s2; 5057f1af5d2fSBarry Smith x[1+idc] = t[1+idt] = v[1]*s1 + v[3]*s2; 50584e2b4712SSatish Balay } 50594e2b4712SSatish Balay ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 50604e2b4712SSatish Balay ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 5061d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 50621ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 5063dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr); 50644e2b4712SSatish Balay PetscFunctionReturn(0); 50654e2b4712SSatish Balay } 50664e2b4712SSatish Balay 50670c4413a7SShri Abhyankar #undef __FUNCT__ 50684dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_2" 50694dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_2(Mat A,Vec bb,Vec xx) 50700c4413a7SShri Abhyankar { 50710c4413a7SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 50720c4413a7SShri Abhyankar IS iscol=a->col,isrow=a->row; 50730c4413a7SShri Abhyankar PetscErrorCode ierr; 5074b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 5075b3260449SShri Abhyankar PetscInt i,nz,idx,jdx,idt,idc,m; 50760c4413a7SShri Abhyankar const PetscInt *r,*c,*rout,*cout; 50770c4413a7SShri Abhyankar const MatScalar *aa=a->a,*v; 50780c4413a7SShri Abhyankar PetscScalar *x,s1,s2,x1,x2,*t; 50790c4413a7SShri Abhyankar const PetscScalar *b; 50800c4413a7SShri Abhyankar 50810c4413a7SShri Abhyankar PetscFunctionBegin; 50820c4413a7SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 50830c4413a7SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 50840c4413a7SShri Abhyankar t = a->solve_work; 50850c4413a7SShri Abhyankar 50860c4413a7SShri Abhyankar ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 50870c4413a7SShri Abhyankar ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout; 50880c4413a7SShri Abhyankar 50890c4413a7SShri Abhyankar /* forward solve the lower triangular */ 50900c4413a7SShri Abhyankar idx = 2*r[0]; 50910c4413a7SShri Abhyankar t[0] = b[idx]; t[1] = b[1+idx]; 50920c4413a7SShri Abhyankar for (i=1; i<n; i++) { 50930c4413a7SShri Abhyankar v = aa + 4*ai[i]; 50940c4413a7SShri Abhyankar vi = aj + ai[i]; 50950c4413a7SShri Abhyankar nz = ai[i+1] - ai[i]; 50960c4413a7SShri Abhyankar idx = 2*r[i]; 50970c4413a7SShri Abhyankar s1 = b[idx]; s2 = b[1+idx]; 50980c4413a7SShri Abhyankar for(m=0;m<nz;m++){ 50990c4413a7SShri Abhyankar jdx = 2*vi[m]; 51000c4413a7SShri Abhyankar x1 = t[jdx]; x2 = t[1+jdx]; 51010c4413a7SShri Abhyankar s1 -= v[0]*x1 + v[2]*x2; 51020c4413a7SShri Abhyankar s2 -= v[1]*x1 + v[3]*x2; 51030c4413a7SShri Abhyankar v += 4; 51040c4413a7SShri Abhyankar } 51050c4413a7SShri Abhyankar idx = 2*i; 51060c4413a7SShri Abhyankar t[idx] = s1; t[1+idx] = s2; 51070c4413a7SShri Abhyankar } 51080c4413a7SShri Abhyankar /* backward solve the upper triangular */ 51090c4413a7SShri Abhyankar for (i=n-1; i>=0; i--){ 51100c4413a7SShri Abhyankar v = aa + 4*(adiag[i+1]+1); 51110c4413a7SShri Abhyankar vi = aj + adiag[i+1]+1; 51120c4413a7SShri Abhyankar nz = adiag[i] - adiag[i+1] - 1; 51130c4413a7SShri Abhyankar idt = 2*i; 51140c4413a7SShri Abhyankar s1 = t[idt]; s2 = t[1+idt]; 51150c4413a7SShri Abhyankar for(m=0;m<nz;m++){ 51160c4413a7SShri Abhyankar idx = 2*vi[m]; 51170c4413a7SShri Abhyankar x1 = t[idx]; x2 = t[1+idx]; 51180c4413a7SShri Abhyankar s1 -= v[0]*x1 + v[2]*x2; 51190c4413a7SShri Abhyankar s2 -= v[1]*x1 + v[3]*x2; 51200c4413a7SShri Abhyankar v += 4; 51210c4413a7SShri Abhyankar } 51220c4413a7SShri Abhyankar idc = 2*c[i]; 51230c4413a7SShri Abhyankar x[idc] = t[idt] = v[0]*s1 + v[2]*s2; 51240c4413a7SShri Abhyankar x[1+idc] = t[1+idt] = v[1]*s1 + v[3]*s2; 51250c4413a7SShri Abhyankar } 51260c4413a7SShri Abhyankar ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 51270c4413a7SShri Abhyankar ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 51280c4413a7SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 51290c4413a7SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 51300c4413a7SShri Abhyankar ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr); 51310c4413a7SShri Abhyankar PetscFunctionReturn(0); 51320c4413a7SShri Abhyankar } 51338f690400SShri Abhyankar 513415091d37SBarry Smith /* 513515091d37SBarry Smith Special case where the matrix was ILU(0) factored in the natural 513615091d37SBarry Smith ordering. This eliminates the need for the column and row permutation. 513715091d37SBarry Smith */ 51384a2ae208SSatish Balay #undef __FUNCT__ 513906e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_2_NaturalOrdering_inplace" 514006e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_2_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 514115091d37SBarry Smith { 514215091d37SBarry Smith Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 5143b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 5144dfbe8321SBarry Smith PetscErrorCode ierr; 5145d9fead3dSBarry Smith const MatScalar *aa=a->a,*v; 5146d9fead3dSBarry Smith PetscScalar *x,s1,s2,x1,x2; 5147d9fead3dSBarry Smith const PetscScalar *b; 5148b3260449SShri Abhyankar PetscInt jdx,idt,idx,nz,i; 514915091d37SBarry Smith 515015091d37SBarry Smith PetscFunctionBegin; 5151d9fead3dSBarry Smith ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 51521ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 515315091d37SBarry Smith 515415091d37SBarry Smith /* forward solve the lower triangular */ 515515091d37SBarry Smith idx = 0; 515615091d37SBarry Smith x[0] = b[0]; x[1] = b[1]; 515715091d37SBarry Smith for (i=1; i<n; i++) { 515815091d37SBarry Smith v = aa + 4*ai[i]; 515915091d37SBarry Smith vi = aj + ai[i]; 516015091d37SBarry Smith nz = diag[i] - ai[i]; 516115091d37SBarry Smith idx += 2; 5162f1af5d2fSBarry Smith s1 = b[idx];s2 = b[1+idx]; 516315091d37SBarry Smith while (nz--) { 516415091d37SBarry Smith jdx = 2*(*vi++); 516515091d37SBarry Smith x1 = x[jdx];x2 = x[1+jdx]; 5166f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[2]*x2; 5167f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[3]*x2; 516815091d37SBarry Smith v += 4; 516915091d37SBarry Smith } 5170f1af5d2fSBarry Smith x[idx] = s1; 5171f1af5d2fSBarry Smith x[1+idx] = s2; 517215091d37SBarry Smith } 517315091d37SBarry Smith /* backward solve the upper triangular */ 517415091d37SBarry Smith for (i=n-1; i>=0; i--){ 517515091d37SBarry Smith v = aa + 4*diag[i] + 4; 517615091d37SBarry Smith vi = aj + diag[i] + 1; 517715091d37SBarry Smith nz = ai[i+1] - diag[i] - 1; 517815091d37SBarry Smith idt = 2*i; 5179f1af5d2fSBarry Smith s1 = x[idt]; s2 = x[1+idt]; 518015091d37SBarry Smith while (nz--) { 518115091d37SBarry Smith idx = 2*(*vi++); 518215091d37SBarry Smith x1 = x[idx]; x2 = x[1+idx]; 5183f1af5d2fSBarry Smith s1 -= v[0]*x1 + v[2]*x2; 5184f1af5d2fSBarry Smith s2 -= v[1]*x1 + v[3]*x2; 518515091d37SBarry Smith v += 4; 518615091d37SBarry Smith } 518715091d37SBarry Smith v = aa + 4*diag[i]; 5188f1af5d2fSBarry Smith x[idt] = v[0]*s1 + v[2]*s2; 5189f1af5d2fSBarry Smith x[1+idt] = v[1]*s1 + v[3]*s2; 519015091d37SBarry Smith } 519115091d37SBarry Smith 5192d9fead3dSBarry Smith ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 51931ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 5194dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr); 519515091d37SBarry Smith PetscFunctionReturn(0); 519615091d37SBarry Smith } 519715091d37SBarry Smith 5198cee9d6f2SShri Abhyankar #undef __FUNCT__ 51994dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_2_NaturalOrdering" 52004dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_2_NaturalOrdering(Mat A,Vec bb,Vec xx) 5201b2b2dd24SShri Abhyankar { 5202b2b2dd24SShri Abhyankar Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 5203b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag; 5204b3260449SShri Abhyankar PetscInt i,k,nz,idx,idt,jdx; 5205b2b2dd24SShri Abhyankar PetscErrorCode ierr; 5206b2b2dd24SShri Abhyankar const MatScalar *aa=a->a,*v; 5207b2b2dd24SShri Abhyankar PetscScalar *x,s1,s2,x1,x2; 5208b2b2dd24SShri Abhyankar const PetscScalar *b; 5209b2b2dd24SShri Abhyankar 5210b2b2dd24SShri Abhyankar PetscFunctionBegin; 5211b2b2dd24SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 5212b2b2dd24SShri Abhyankar ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 5213b2b2dd24SShri Abhyankar /* forward solve the lower triangular */ 5214b2b2dd24SShri Abhyankar idx = 0; 5215b2b2dd24SShri Abhyankar x[0] = b[idx]; x[1] = b[1+idx]; 5216b2b2dd24SShri Abhyankar for (i=1; i<n; i++) { 5217b2b2dd24SShri Abhyankar v = aa + 4*ai[i]; 5218b2b2dd24SShri Abhyankar vi = aj + ai[i]; 5219b2b2dd24SShri Abhyankar nz = ai[i+1] - ai[i]; 5220b2b2dd24SShri Abhyankar idx = 2*i; 5221b2b2dd24SShri Abhyankar s1 = b[idx];s2 = b[1+idx]; 5222b2b2dd24SShri Abhyankar for(k=0;k<nz;k++){ 5223b2b2dd24SShri Abhyankar jdx = 2*vi[k]; 5224b2b2dd24SShri Abhyankar x1 = x[jdx];x2 = x[1+jdx]; 5225b2b2dd24SShri Abhyankar s1 -= v[0]*x1 + v[2]*x2; 5226b2b2dd24SShri Abhyankar s2 -= v[1]*x1 + v[3]*x2; 5227b2b2dd24SShri Abhyankar v += 4; 5228b2b2dd24SShri Abhyankar } 5229b2b2dd24SShri Abhyankar x[idx] = s1; 5230b2b2dd24SShri Abhyankar x[1+idx] = s2; 5231b2b2dd24SShri Abhyankar } 5232b2b2dd24SShri Abhyankar 5233b2b2dd24SShri Abhyankar /* backward solve the upper triangular */ 5234b2b2dd24SShri Abhyankar for (i=n-1; i>=0; i--){ 5235b2b2dd24SShri Abhyankar v = aa + 4*(adiag[i+1]+1); 5236b2b2dd24SShri Abhyankar vi = aj + adiag[i+1]+1; 5237b2b2dd24SShri Abhyankar nz = adiag[i] - adiag[i+1]-1; 5238b2b2dd24SShri Abhyankar idt = 2*i; 5239b2b2dd24SShri Abhyankar s1 = x[idt]; s2 = x[1+idt]; 5240b2b2dd24SShri Abhyankar for(k=0;k<nz;k++){ 5241b2b2dd24SShri Abhyankar idx = 2*vi[k]; 5242b2b2dd24SShri Abhyankar x1 = x[idx]; x2 = x[1+idx]; 5243b2b2dd24SShri Abhyankar s1 -= v[0]*x1 + v[2]*x2; 5244b2b2dd24SShri Abhyankar s2 -= v[1]*x1 + v[3]*x2; 5245b2b2dd24SShri Abhyankar v += 4; 5246b2b2dd24SShri Abhyankar } 5247b2b2dd24SShri Abhyankar /* x = inv_diagonal*x */ 5248b2b2dd24SShri Abhyankar x[idt] = v[0]*s1 + v[2]*s2; 5249b2b2dd24SShri Abhyankar x[1+idt] = v[1]*s1 + v[3]*s2; 5250b2b2dd24SShri Abhyankar } 5251b2b2dd24SShri Abhyankar 5252b2b2dd24SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 5253b2b2dd24SShri Abhyankar ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 5254b2b2dd24SShri Abhyankar ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr); 5255b2b2dd24SShri Abhyankar PetscFunctionReturn(0); 5256b2b2dd24SShri Abhyankar } 5257b2b2dd24SShri Abhyankar 5258b2b2dd24SShri Abhyankar #undef __FUNCT__ 525906e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_1_inplace" 526006e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_1_inplace(Mat A,Vec bb,Vec xx) 52614e2b4712SSatish Balay { 52624e2b4712SSatish Balay Mat_SeqBAIJ *a=(Mat_SeqBAIJ *)A->data; 52634e2b4712SSatish Balay IS iscol=a->col,isrow=a->row; 52646849ba73SBarry Smith PetscErrorCode ierr; 5265b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j; 5266b3260449SShri Abhyankar PetscInt i,nz; 52675d0c19d7SBarry Smith const PetscInt *r,*c,*diag = a->diag,*rout,*cout; 5268b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 5269b3260449SShri Abhyankar PetscScalar *x,s1,*t; 5270b3260449SShri Abhyankar const PetscScalar *b; 52714e2b4712SSatish Balay 52724e2b4712SSatish Balay PetscFunctionBegin; 52734e2b4712SSatish Balay if (!n) PetscFunctionReturn(0); 52744e2b4712SSatish Balay 5275b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 52761ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 5277f1af5d2fSBarry Smith t = a->solve_work; 52784e2b4712SSatish Balay 52794e2b4712SSatish Balay ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout; 52804e2b4712SSatish Balay ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1); 52814e2b4712SSatish Balay 52824e2b4712SSatish Balay /* forward solve the lower triangular */ 5283f1af5d2fSBarry Smith t[0] = b[*r++]; 52844e2b4712SSatish Balay for (i=1; i<n; i++) { 52854e2b4712SSatish Balay v = aa + ai[i]; 52864e2b4712SSatish Balay vi = aj + ai[i]; 52874e2b4712SSatish Balay nz = diag[i] - ai[i]; 5288f1af5d2fSBarry Smith s1 = b[*r++]; 52894e2b4712SSatish Balay while (nz--) { 5290f1af5d2fSBarry Smith s1 -= (*v++)*t[*vi++]; 52914e2b4712SSatish Balay } 5292f1af5d2fSBarry Smith t[i] = s1; 52934e2b4712SSatish Balay } 52944e2b4712SSatish Balay /* backward solve the upper triangular */ 52954e2b4712SSatish Balay for (i=n-1; i>=0; i--){ 52964e2b4712SSatish Balay v = aa + diag[i] + 1; 52974e2b4712SSatish Balay vi = aj + diag[i] + 1; 52984e2b4712SSatish Balay nz = ai[i+1] - diag[i] - 1; 5299f1af5d2fSBarry Smith s1 = t[i]; 53004e2b4712SSatish Balay while (nz--) { 5301f1af5d2fSBarry Smith s1 -= (*v++)*t[*vi++]; 53024e2b4712SSatish Balay } 5303f1af5d2fSBarry Smith x[*c--] = t[i] = aa[diag[i]]*s1; 53044e2b4712SSatish Balay } 53054e2b4712SSatish Balay 53064e2b4712SSatish Balay ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr); 53074e2b4712SSatish Balay ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr); 5308b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 53091ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 5310dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*1*(a->nz) - A->cmap->n);CHKERRQ(ierr); 53114e2b4712SSatish Balay PetscFunctionReturn(0); 53124e2b4712SSatish Balay } 531315091d37SBarry Smith /* 531415091d37SBarry Smith Special case where the matrix was ILU(0) factored in the natural 531515091d37SBarry Smith ordering. This eliminates the need for the column and row permutation. 531615091d37SBarry Smith */ 53174a2ae208SSatish Balay #undef __FUNCT__ 531806e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_1_NaturalOrdering_inplace" 531906e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_1_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx) 532015091d37SBarry Smith { 532115091d37SBarry Smith Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 5322b3260449SShri Abhyankar const PetscInt n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag; 5323dfbe8321SBarry Smith PetscErrorCode ierr; 5324b3260449SShri Abhyankar const MatScalar *aa=a->a,*v; 5325b3260449SShri Abhyankar PetscScalar *x; 5326b3260449SShri Abhyankar const PetscScalar *b; 532787828ca2SBarry Smith PetscScalar s1,x1; 5328b3260449SShri Abhyankar PetscInt jdx,idt,idx,nz,i; 532915091d37SBarry Smith 533015091d37SBarry Smith PetscFunctionBegin; 5331b3260449SShri Abhyankar ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 53321ebc52fbSHong Zhang ierr = VecGetArray(xx,&x);CHKERRQ(ierr); 533315091d37SBarry Smith 533415091d37SBarry Smith /* forward solve the lower triangular */ 533515091d37SBarry Smith idx = 0; 533615091d37SBarry Smith x[0] = b[0]; 533715091d37SBarry Smith for (i=1; i<n; i++) { 533815091d37SBarry Smith v = aa + ai[i]; 533915091d37SBarry Smith vi = aj + ai[i]; 534015091d37SBarry Smith nz = diag[i] - ai[i]; 534115091d37SBarry Smith idx += 1; 5342f1af5d2fSBarry Smith s1 = b[idx]; 534315091d37SBarry Smith while (nz--) { 534415091d37SBarry Smith jdx = *vi++; 534515091d37SBarry Smith x1 = x[jdx]; 5346f1af5d2fSBarry Smith s1 -= v[0]*x1; 534715091d37SBarry Smith v += 1; 534815091d37SBarry Smith } 5349f1af5d2fSBarry Smith x[idx] = s1; 535015091d37SBarry Smith } 535115091d37SBarry Smith /* backward solve the upper triangular */ 535215091d37SBarry Smith for (i=n-1; i>=0; i--){ 535315091d37SBarry Smith v = aa + diag[i] + 1; 535415091d37SBarry Smith vi = aj + diag[i] + 1; 535515091d37SBarry Smith nz = ai[i+1] - diag[i] - 1; 535615091d37SBarry Smith idt = i; 5357f1af5d2fSBarry Smith s1 = x[idt]; 535815091d37SBarry Smith while (nz--) { 535915091d37SBarry Smith idx = *vi++; 536015091d37SBarry Smith x1 = x[idx]; 5361f1af5d2fSBarry Smith s1 -= v[0]*x1; 536215091d37SBarry Smith v += 1; 536315091d37SBarry Smith } 536415091d37SBarry Smith v = aa + diag[i]; 5365f1af5d2fSBarry Smith x[idt] = v[0]*s1; 536615091d37SBarry Smith } 5367b3260449SShri Abhyankar ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr); 53681ebc52fbSHong Zhang ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr); 5369dc0b31edSSatish Balay ierr = PetscLogFlops(2.0*(a->nz) - A->cmap->n);CHKERRQ(ierr); 537015091d37SBarry Smith PetscFunctionReturn(0); 537115091d37SBarry Smith } 53724e2b4712SSatish Balay 53734e2b4712SSatish Balay /* ----------------------------------------------------------------*/ 537416a2bf60SHong Zhang EXTERN PetscErrorCode MatDuplicateNoCreate_SeqBAIJ(Mat,Mat,MatDuplicateOption,PetscTruth); 53756bce7ff8SHong Zhang 53762b0b2ea7SShri Abhyankar #undef __FUNCT__ 537729a97285SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_15_NaturalOrdering" 5378766f9fbaSBarry Smith /* 5379766f9fbaSBarry Smith This is not much faster than MatLUFactorNumeric_SeqBAIJ_N() but the solve is faster at least sometimes 5380766f9fbaSBarry Smith */ 538129a97285SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_15_NaturalOrdering(Mat B,Mat A,const MatFactorInfo *info) 53822b0b2ea7SShri Abhyankar { 53832b0b2ea7SShri Abhyankar Mat C=B; 53842b0b2ea7SShri Abhyankar Mat_SeqBAIJ *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data; 53852b0b2ea7SShri Abhyankar PetscErrorCode ierr; 5386766f9fbaSBarry Smith PetscInt i,j,k,ipvt[15]; 5387766f9fbaSBarry Smith const PetscInt n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j,*ajtmp,*bjtmp,*bdiag=b->diag,*pj; 5388766f9fbaSBarry Smith PetscInt nz,nzL,row; 5389766f9fbaSBarry Smith MatScalar *rtmp,*pc,*mwork,*pv,*vv,work[225]; 5390766f9fbaSBarry Smith const MatScalar *v,*aa=a->a; 53912b0b2ea7SShri Abhyankar PetscInt bs2 = a->bs2,bs=A->rmap->bs,flg; 53922b0b2ea7SShri Abhyankar 53932b0b2ea7SShri Abhyankar PetscFunctionBegin; 53942b0b2ea7SShri Abhyankar 53952b0b2ea7SShri Abhyankar /* generate work space needed by the factorization */ 53962b0b2ea7SShri Abhyankar ierr = PetscMalloc2(bs2*n,MatScalar,&rtmp,bs2,MatScalar,&mwork);CHKERRQ(ierr); 53972b0b2ea7SShri Abhyankar ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr); 53982b0b2ea7SShri Abhyankar 53992b0b2ea7SShri Abhyankar for (i=0; i<n; i++){ 54002b0b2ea7SShri Abhyankar /* zero rtmp */ 54012b0b2ea7SShri Abhyankar /* L part */ 54022b0b2ea7SShri Abhyankar nz = bi[i+1] - bi[i]; 54032b0b2ea7SShri Abhyankar bjtmp = bj + bi[i]; 54042b0b2ea7SShri Abhyankar for (j=0; j<nz; j++){ 54052b0b2ea7SShri Abhyankar ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 54062b0b2ea7SShri Abhyankar } 54072b0b2ea7SShri Abhyankar 54082b0b2ea7SShri Abhyankar /* U part */ 54092b0b2ea7SShri Abhyankar nz = bdiag[i] - bdiag[i+1]; 54102b0b2ea7SShri Abhyankar bjtmp = bj + bdiag[i+1]+1; 54112b0b2ea7SShri Abhyankar for (j=0; j<nz; j++){ 54122b0b2ea7SShri Abhyankar ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 54132b0b2ea7SShri Abhyankar } 54142b0b2ea7SShri Abhyankar 54152b0b2ea7SShri Abhyankar /* load in initial (unfactored row) */ 541629a97285SShri Abhyankar nz = ai[i+1] - ai[i]; 541729a97285SShri Abhyankar ajtmp = aj + ai[i]; 541829a97285SShri Abhyankar v = aa + bs2*ai[i]; 54192b0b2ea7SShri Abhyankar for (j=0; j<nz; j++) { 542029a97285SShri Abhyankar ierr = PetscMemcpy(rtmp+bs2*ajtmp[j],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr); 54212b0b2ea7SShri Abhyankar } 54222b0b2ea7SShri Abhyankar 54232b0b2ea7SShri Abhyankar /* elimination */ 54242b0b2ea7SShri Abhyankar bjtmp = bj + bi[i]; 54252b0b2ea7SShri Abhyankar nzL = bi[i+1] - bi[i]; 54262b0b2ea7SShri Abhyankar for(k=0;k < nzL;k++) { 54272b0b2ea7SShri Abhyankar row = bjtmp[k]; 54282b0b2ea7SShri Abhyankar pc = rtmp + bs2*row; 54292b0b2ea7SShri Abhyankar for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }} 54302b0b2ea7SShri Abhyankar if (flg) { 54312b0b2ea7SShri Abhyankar pv = b->a + bs2*bdiag[row]; 5432766f9fbaSBarry Smith Kernel_A_gets_A_times_B(bs,pc,pv,mwork); 5433766f9fbaSBarry Smith /*ierr = Kernel_A_gets_A_times_B_15(pc,pv,mwork);CHKERRQ(ierr);*/ 54342b0b2ea7SShri Abhyankar pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */ 54352b0b2ea7SShri Abhyankar pv = b->a + bs2*(bdiag[row+1]+1); 54362b0b2ea7SShri Abhyankar nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */ 54372b0b2ea7SShri Abhyankar for (j=0; j<nz; j++) { 5438766f9fbaSBarry Smith vv = rtmp + bs2*pj[j]; 5439766f9fbaSBarry Smith Kernel_A_gets_A_minus_B_times_C(bs,vv,pc,pv); 5440766f9fbaSBarry Smith /* ierr = Kernel_A_gets_A_minus_B_times_C_15(vv,pc,pv);CHKERRQ(ierr); */ 54412b0b2ea7SShri Abhyankar pv += bs2; 54422b0b2ea7SShri Abhyankar } 5443766f9fbaSBarry Smith ierr = PetscLogFlops(2*bs2*bs*(nz+1)-bs2);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */ 54442b0b2ea7SShri Abhyankar } 54452b0b2ea7SShri Abhyankar } 54462b0b2ea7SShri Abhyankar 54472b0b2ea7SShri Abhyankar /* finished row so stick it into b->a */ 54482b0b2ea7SShri Abhyankar /* L part */ 54492b0b2ea7SShri Abhyankar pv = b->a + bs2*bi[i] ; 54502b0b2ea7SShri Abhyankar pj = b->j + bi[i] ; 54512b0b2ea7SShri Abhyankar nz = bi[i+1] - bi[i]; 54522b0b2ea7SShri Abhyankar for (j=0; j<nz; j++) { 54532b0b2ea7SShri Abhyankar ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 54542b0b2ea7SShri Abhyankar } 54552b0b2ea7SShri Abhyankar 54562b0b2ea7SShri Abhyankar /* Mark diagonal and invert diagonal for simplier triangular solves */ 54572b0b2ea7SShri Abhyankar pv = b->a + bs2*bdiag[i]; 54582b0b2ea7SShri Abhyankar pj = b->j + bdiag[i]; 54592b0b2ea7SShri Abhyankar ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr); 5460766f9fbaSBarry Smith /* Kernel_A_gets_inverse_A(bs,pv,pivots,work); */ 5461766f9fbaSBarry Smith ierr = Kernel_A_gets_inverse_A_15(pv,ipvt,work,info->shiftinblocks);CHKERRQ(ierr); 54622b0b2ea7SShri Abhyankar 54632b0b2ea7SShri Abhyankar /* U part */ 54642b0b2ea7SShri Abhyankar pv = b->a + bs2*(bdiag[i+1]+1); 54652b0b2ea7SShri Abhyankar pj = b->j + bdiag[i+1]+1; 54662b0b2ea7SShri Abhyankar nz = bdiag[i] - bdiag[i+1] - 1; 54672b0b2ea7SShri Abhyankar for (j=0; j<nz; j++){ 54682b0b2ea7SShri Abhyankar ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 54692b0b2ea7SShri Abhyankar } 54702b0b2ea7SShri Abhyankar } 54712b0b2ea7SShri Abhyankar 54722b0b2ea7SShri Abhyankar ierr = PetscFree2(rtmp,mwork);CHKERRQ(ierr); 547329a97285SShri Abhyankar C->ops->solve = MatSolve_SeqBAIJ_15_NaturalOrdering; 5474766f9fbaSBarry Smith C->ops->solvetranspose = MatSolve_SeqBAIJ_N_NaturalOrdering; 54752b0b2ea7SShri Abhyankar C->assembled = PETSC_TRUE; 5476766f9fbaSBarry Smith ierr = PetscLogFlops(1.333333333333*bs*bs2*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */ 54772b0b2ea7SShri Abhyankar PetscFunctionReturn(0); 54782b0b2ea7SShri Abhyankar } 54792b0b2ea7SShri Abhyankar 54806bce7ff8SHong Zhang #undef __FUNCT__ 54814dd39f65SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_N" 54824dd39f65SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_N(Mat B,Mat A,const MatFactorInfo *info) 54836bce7ff8SHong Zhang { 54846bce7ff8SHong Zhang Mat C=B; 54856bce7ff8SHong Zhang Mat_SeqBAIJ *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data; 54866bce7ff8SHong Zhang IS isrow = b->row,isicol = b->icol; 54876bce7ff8SHong Zhang PetscErrorCode ierr; 54886bce7ff8SHong Zhang const PetscInt *r,*ic,*ics; 54896bce7ff8SHong Zhang PetscInt i,j,k,n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j; 54906bce7ff8SHong Zhang PetscInt *ajtmp,*bjtmp,nz,nzL,row,*bdiag=b->diag,*pj; 5491b588c5a2SHong Zhang MatScalar *rtmp,*pc,*mwork,*v,*pv,*aa=a->a; 5492914a18a2SHong Zhang PetscInt bs=A->rmap->bs,bs2 = a->bs2,*v_pivots,flg; 5493914a18a2SHong Zhang MatScalar *v_work; 5494ae3d28f0SHong Zhang PetscTruth col_identity,row_identity,both_identity; 54956bce7ff8SHong Zhang 54966bce7ff8SHong Zhang PetscFunctionBegin; 54976bce7ff8SHong Zhang ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 54986bce7ff8SHong Zhang ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 5499ae3d28f0SHong Zhang 5500fca92195SBarry Smith ierr = PetscMalloc(bs2*n*sizeof(MatScalar),&rtmp);CHKERRQ(ierr); 5501fca92195SBarry Smith ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr); 55026bce7ff8SHong Zhang ics = ic; 55036bce7ff8SHong Zhang 5504914a18a2SHong Zhang /* generate work space needed by dense LU factorization */ 5505fca92195SBarry Smith ierr = PetscMalloc3(bs,MatScalar,&v_work,bs2,MatScalar,&mwork,bs,PetscInt,&v_pivots);CHKERRQ(ierr); 5506914a18a2SHong Zhang 55076bce7ff8SHong Zhang for (i=0; i<n; i++){ 55086bce7ff8SHong Zhang /* zero rtmp */ 55096bce7ff8SHong Zhang /* L part */ 55106bce7ff8SHong Zhang nz = bi[i+1] - bi[i]; 55116bce7ff8SHong Zhang bjtmp = bj + bi[i]; 5512914a18a2SHong Zhang for (j=0; j<nz; j++){ 5513914a18a2SHong Zhang ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 5514914a18a2SHong Zhang } 55156bce7ff8SHong Zhang 55166bce7ff8SHong Zhang /* U part */ 55171a83e813SShri Abhyankar nz = bdiag[i] - bdiag[i+1]; 55181a83e813SShri Abhyankar bjtmp = bj + bdiag[i+1]+1; 55191a83e813SShri Abhyankar for (j=0; j<nz; j++){ 55201a83e813SShri Abhyankar ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 55211a83e813SShri Abhyankar } 55221a83e813SShri Abhyankar 55231a83e813SShri Abhyankar /* load in initial (unfactored row) */ 55241a83e813SShri Abhyankar nz = ai[r[i]+1] - ai[r[i]]; 55251a83e813SShri Abhyankar ajtmp = aj + ai[r[i]]; 55261a83e813SShri Abhyankar v = aa + bs2*ai[r[i]]; 55271a83e813SShri Abhyankar for (j=0; j<nz; j++) { 55281a83e813SShri Abhyankar ierr = PetscMemcpy(rtmp+bs2*ic[ajtmp[j]],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr); 55291a83e813SShri Abhyankar } 55301a83e813SShri Abhyankar 55311a83e813SShri Abhyankar /* elimination */ 55321a83e813SShri Abhyankar bjtmp = bj + bi[i]; 55331a83e813SShri Abhyankar nzL = bi[i+1] - bi[i]; 55341a83e813SShri Abhyankar for(k=0;k < nzL;k++) { 55351a83e813SShri Abhyankar row = bjtmp[k]; 55361a83e813SShri Abhyankar pc = rtmp + bs2*row; 55371a83e813SShri Abhyankar for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }} 55381a83e813SShri Abhyankar if (flg) { 55391a83e813SShri Abhyankar pv = b->a + bs2*bdiag[row]; 55401a83e813SShri Abhyankar Kernel_A_gets_A_times_B(bs,pc,pv,mwork); /* *pc = *pc * (*pv); */ 55411a83e813SShri Abhyankar pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */ 55421a83e813SShri Abhyankar pv = b->a + bs2*(bdiag[row+1]+1); 55431a83e813SShri Abhyankar nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */ 55441a83e813SShri Abhyankar for (j=0; j<nz; j++) { 55451a83e813SShri Abhyankar Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j); 55461a83e813SShri Abhyankar } 55471a83e813SShri Abhyankar ierr = PetscLogFlops(2*bs2*bs*(nz+1)-bs2);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */ 55481a83e813SShri Abhyankar } 55491a83e813SShri Abhyankar } 55501a83e813SShri Abhyankar 55511a83e813SShri Abhyankar /* finished row so stick it into b->a */ 55521a83e813SShri Abhyankar /* L part */ 55531a83e813SShri Abhyankar pv = b->a + bs2*bi[i] ; 55541a83e813SShri Abhyankar pj = b->j + bi[i] ; 55551a83e813SShri Abhyankar nz = bi[i+1] - bi[i]; 55561a83e813SShri Abhyankar for (j=0; j<nz; j++) { 55571a83e813SShri Abhyankar ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 55581a83e813SShri Abhyankar } 55591a83e813SShri Abhyankar 55601a83e813SShri Abhyankar /* Mark diagonal and invert diagonal for simplier triangular solves */ 55611a83e813SShri Abhyankar pv = b->a + bs2*bdiag[i]; 55621a83e813SShri Abhyankar pj = b->j + bdiag[i]; 55631a83e813SShri Abhyankar /* if (*pj != i)SETERRQ2(PETSC_ERR_SUP,"row %d != *pj %d",i,*pj); */ 55641a83e813SShri Abhyankar ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr); 55651a83e813SShri Abhyankar ierr = Kernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr); 55661a83e813SShri Abhyankar 55671a83e813SShri Abhyankar /* U part */ 55681a83e813SShri Abhyankar pv = b->a + bs2*(bdiag[i+1]+1); 55691a83e813SShri Abhyankar pj = b->j + bdiag[i+1]+1; 55701a83e813SShri Abhyankar nz = bdiag[i] - bdiag[i+1] - 1; 55711a83e813SShri Abhyankar for (j=0; j<nz; j++){ 55721a83e813SShri Abhyankar ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr); 55731a83e813SShri Abhyankar } 55741a83e813SShri Abhyankar } 55751a83e813SShri Abhyankar 55761a83e813SShri Abhyankar ierr = PetscFree(rtmp);CHKERRQ(ierr); 5577fca92195SBarry Smith ierr = PetscFree3(v_work,mwork,v_pivots);CHKERRQ(ierr); 55781a83e813SShri Abhyankar ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 55791a83e813SShri Abhyankar ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 55801a83e813SShri Abhyankar 5581ae3d28f0SHong Zhang ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr); 5582ae3d28f0SHong Zhang ierr = ISIdentity(isicol,&col_identity);CHKERRQ(ierr); 5583ae3d28f0SHong Zhang both_identity = (PetscTruth) (row_identity && col_identity); 5584ae3d28f0SHong Zhang if (both_identity){ 55854dd39f65SShri Abhyankar C->ops->solve = MatSolve_SeqBAIJ_N_NaturalOrdering; 5586ae3d28f0SHong Zhang } else { 55874dd39f65SShri Abhyankar C->ops->solve = MatSolve_SeqBAIJ_N; 5588ae3d28f0SHong Zhang } 55894dd39f65SShri Abhyankar C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_N; 5590ae3d28f0SHong Zhang 55911a83e813SShri Abhyankar C->assembled = PETSC_TRUE; 5592766f9fbaSBarry Smith ierr = PetscLogFlops(1.333333333333*bs*bs2*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */ 55931a83e813SShri Abhyankar PetscFunctionReturn(0); 55941a83e813SShri Abhyankar } 55951a83e813SShri Abhyankar 55966bce7ff8SHong Zhang /* 55976bce7ff8SHong Zhang ilu(0) with natural ordering under new data structure. 55984dd39f65SShri Abhyankar See MatILUFactorSymbolic_SeqAIJ_ilu0() for detailed description 55994dd39f65SShri Abhyankar because this code is almost identical to MatILUFactorSymbolic_SeqAIJ_ilu0_inplace(). 56006bce7ff8SHong Zhang */ 5601c0c7eb62SShri Abhyankar 56026bce7ff8SHong Zhang #undef __FUNCT__ 56034dd39f65SShri Abhyankar #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ_ilu0" 56044dd39f65SShri Abhyankar PetscErrorCode MatILUFactorSymbolic_SeqBAIJ_ilu0(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info) 56056bce7ff8SHong Zhang { 56066bce7ff8SHong Zhang 56076bce7ff8SHong Zhang Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b; 56086bce7ff8SHong Zhang PetscErrorCode ierr; 560916a2bf60SHong Zhang PetscInt n=a->mbs,*ai=a->i,*aj,*adiag=a->diag,bs2 = a->bs2; 561035aa4fcfSShri Abhyankar PetscInt i,j,nz,*bi,*bj,*bdiag,bi_temp; 561135aa4fcfSShri Abhyankar 561235aa4fcfSShri Abhyankar PetscFunctionBegin; 561335aa4fcfSShri Abhyankar ierr = MatDuplicateNoCreate_SeqBAIJ(fact,A,MAT_DO_NOT_COPY_VALUES,PETSC_FALSE);CHKERRQ(ierr); 561435aa4fcfSShri Abhyankar b = (Mat_SeqBAIJ*)(fact)->data; 561535aa4fcfSShri Abhyankar 561635aa4fcfSShri Abhyankar /* allocate matrix arrays for new data structure */ 561735aa4fcfSShri Abhyankar ierr = PetscMalloc3(bs2*ai[n]+1,PetscScalar,&b->a,ai[n]+1,PetscInt,&b->j,n+1,PetscInt,&b->i);CHKERRQ(ierr); 561835aa4fcfSShri Abhyankar ierr = PetscLogObjectMemory(fact,ai[n]*(bs2*sizeof(PetscScalar)+sizeof(PetscInt))+(n+1)*sizeof(PetscInt));CHKERRQ(ierr); 561935aa4fcfSShri Abhyankar b->singlemalloc = PETSC_TRUE; 562035aa4fcfSShri Abhyankar if (!b->diag){ 562135aa4fcfSShri Abhyankar ierr = PetscMalloc((n+1)*sizeof(PetscInt),&b->diag);CHKERRQ(ierr); 562235aa4fcfSShri Abhyankar ierr = PetscLogObjectMemory(fact,(n+1)*sizeof(PetscInt));CHKERRQ(ierr); 562335aa4fcfSShri Abhyankar } 562435aa4fcfSShri Abhyankar bdiag = b->diag; 562535aa4fcfSShri Abhyankar 562635aa4fcfSShri Abhyankar if (n > 0) { 562735aa4fcfSShri Abhyankar ierr = PetscMemzero(b->a,bs2*ai[n]*sizeof(MatScalar));CHKERRQ(ierr); 562835aa4fcfSShri Abhyankar } 562935aa4fcfSShri Abhyankar 563035aa4fcfSShri Abhyankar /* set bi and bj with new data structure */ 563135aa4fcfSShri Abhyankar bi = b->i; 563235aa4fcfSShri Abhyankar bj = b->j; 563335aa4fcfSShri Abhyankar 563435aa4fcfSShri Abhyankar /* L part */ 563535aa4fcfSShri Abhyankar bi[0] = 0; 563635aa4fcfSShri Abhyankar for (i=0; i<n; i++){ 563735aa4fcfSShri Abhyankar nz = adiag[i] - ai[i]; 563835aa4fcfSShri Abhyankar bi[i+1] = bi[i] + nz; 563935aa4fcfSShri Abhyankar aj = a->j + ai[i]; 564035aa4fcfSShri Abhyankar for (j=0; j<nz; j++){ 564135aa4fcfSShri Abhyankar *bj = aj[j]; bj++; 564235aa4fcfSShri Abhyankar } 564335aa4fcfSShri Abhyankar } 564435aa4fcfSShri Abhyankar 564535aa4fcfSShri Abhyankar /* U part */ 564635aa4fcfSShri Abhyankar bi_temp = bi[n]; 564735aa4fcfSShri Abhyankar bdiag[n] = bi[n]-1; 564835aa4fcfSShri Abhyankar for (i=n-1; i>=0; i--){ 564935aa4fcfSShri Abhyankar nz = ai[i+1] - adiag[i] - 1; 565035aa4fcfSShri Abhyankar bi_temp = bi_temp + nz + 1; 565135aa4fcfSShri Abhyankar aj = a->j + adiag[i] + 1; 565235aa4fcfSShri Abhyankar for (j=0; j<nz; j++){ 565335aa4fcfSShri Abhyankar *bj = aj[j]; bj++; 565435aa4fcfSShri Abhyankar } 565535aa4fcfSShri Abhyankar /* diag[i] */ 565635aa4fcfSShri Abhyankar *bj = i; bj++; 565735aa4fcfSShri Abhyankar bdiag[i] = bi_temp - 1; 565835aa4fcfSShri Abhyankar } 565935aa4fcfSShri Abhyankar PetscFunctionReturn(0); 566035aa4fcfSShri Abhyankar } 566135aa4fcfSShri Abhyankar 566235aa4fcfSShri Abhyankar #undef __FUNCT__ 56634dd39f65SShri Abhyankar #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ" 56644dd39f65SShri Abhyankar PetscErrorCode MatILUFactorSymbolic_SeqBAIJ(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info) 566516a2bf60SHong Zhang { 566616a2bf60SHong Zhang Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b; 566716a2bf60SHong Zhang IS isicol; 566816a2bf60SHong Zhang PetscErrorCode ierr; 566916a2bf60SHong Zhang const PetscInt *r,*ic; 56707fa3a6a0SHong Zhang PetscInt n=a->mbs,*ai=a->i,*aj=a->j,d; 567116a2bf60SHong Zhang PetscInt *bi,*cols,nnz,*cols_lvl; 567216a2bf60SHong Zhang PetscInt *bdiag,prow,fm,nzbd,reallocs=0,dcount=0; 567316a2bf60SHong Zhang PetscInt i,levels,diagonal_fill; 56747fa3a6a0SHong Zhang PetscTruth col_identity,row_identity,both_identity; 567516a2bf60SHong Zhang PetscReal f; 567616a2bf60SHong Zhang PetscInt nlnk,*lnk,*lnk_lvl=PETSC_NULL; 567716a2bf60SHong Zhang PetscBT lnkbt; 567816a2bf60SHong Zhang PetscInt nzi,*bj,**bj_ptr,**bjlvl_ptr; 567916a2bf60SHong Zhang PetscFreeSpaceList free_space=PETSC_NULL,current_space=PETSC_NULL; 568016a2bf60SHong Zhang PetscFreeSpaceList free_space_lvl=PETSC_NULL,current_space_lvl=PETSC_NULL; 568116a2bf60SHong Zhang PetscTruth missing; 56827fa3a6a0SHong Zhang PetscInt bs=A->rmap->bs,bs2=a->bs2; 568316a2bf60SHong Zhang 568416a2bf60SHong Zhang PetscFunctionBegin; 568516a2bf60SHong Zhang if (A->rmap->n != A->cmap->n) SETERRQ2(PETSC_ERR_ARG_WRONG,"Must be square matrix, rows %D columns %D",A->rmap->n,A->cmap->n); 568616a2bf60SHong Zhang ierr = MatMissingDiagonal(A,&missing,&d);CHKERRQ(ierr); 568716a2bf60SHong Zhang if (missing) SETERRQ1(PETSC_ERR_ARG_WRONGSTATE,"Matrix is missing diagonal entry %D",d); 568816a2bf60SHong Zhang 568916a2bf60SHong Zhang f = info->fill; 569016a2bf60SHong Zhang levels = (PetscInt)info->levels; 569116a2bf60SHong Zhang diagonal_fill = (PetscInt)info->diagonal_fill; 569216a2bf60SHong Zhang ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr); 569316a2bf60SHong Zhang 569416a2bf60SHong Zhang ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr); 569516a2bf60SHong Zhang ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr); 56967fa3a6a0SHong Zhang both_identity = (PetscTruth) (row_identity && col_identity); 569716a2bf60SHong Zhang 56987fa3a6a0SHong Zhang if (!levels && both_identity) { 569916a2bf60SHong Zhang /* special case: ilu(0) with natural ordering */ 57004dd39f65SShri Abhyankar ierr = MatILUFactorSymbolic_SeqBAIJ_ilu0(fact,A,isrow,iscol,info);CHKERRQ(ierr); 57014dd39f65SShri Abhyankar ierr = MatSeqBAIJSetNumericFactorization(fact,both_identity);CHKERRQ(ierr); 570235aa4fcfSShri Abhyankar 570335aa4fcfSShri Abhyankar fact->factor = MAT_FACTOR_ILU; 570435aa4fcfSShri Abhyankar (fact)->info.factor_mallocs = 0; 570535aa4fcfSShri Abhyankar (fact)->info.fill_ratio_given = info->fill; 570635aa4fcfSShri Abhyankar (fact)->info.fill_ratio_needed = 1.0; 570735aa4fcfSShri Abhyankar b = (Mat_SeqBAIJ*)(fact)->data; 570835aa4fcfSShri Abhyankar b->row = isrow; 570935aa4fcfSShri Abhyankar b->col = iscol; 571035aa4fcfSShri Abhyankar b->icol = isicol; 571135aa4fcfSShri Abhyankar ierr = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr); 571235aa4fcfSShri Abhyankar ierr = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr); 571335aa4fcfSShri Abhyankar b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE; 571435aa4fcfSShri Abhyankar ierr = PetscMalloc((n+1)*bs*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr); 571535aa4fcfSShri Abhyankar PetscFunctionReturn(0); 571635aa4fcfSShri Abhyankar } 571735aa4fcfSShri Abhyankar 571835aa4fcfSShri Abhyankar ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 571935aa4fcfSShri Abhyankar ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 572035aa4fcfSShri Abhyankar 572135aa4fcfSShri Abhyankar /* get new row pointers */ 572235aa4fcfSShri Abhyankar ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bi);CHKERRQ(ierr); 572335aa4fcfSShri Abhyankar bi[0] = 0; 572435aa4fcfSShri Abhyankar /* bdiag is location of diagonal in factor */ 572535aa4fcfSShri Abhyankar ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bdiag);CHKERRQ(ierr); 572635aa4fcfSShri Abhyankar bdiag[0] = 0; 572735aa4fcfSShri Abhyankar 5728fca92195SBarry Smith ierr = PetscMalloc2(n,PetscInt*,&bj_ptr,n,PetscInt*,&bjlvl_ptr);CHKERRQ(ierr); 572935aa4fcfSShri Abhyankar 573035aa4fcfSShri Abhyankar /* create a linked list for storing column indices of the active row */ 573135aa4fcfSShri Abhyankar nlnk = n + 1; 573235aa4fcfSShri Abhyankar ierr = PetscIncompleteLLCreate(n,n,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr); 573335aa4fcfSShri Abhyankar 573435aa4fcfSShri Abhyankar /* initial FreeSpace size is f*(ai[n]+1) */ 573535aa4fcfSShri Abhyankar ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space);CHKERRQ(ierr); 573635aa4fcfSShri Abhyankar current_space = free_space; 573735aa4fcfSShri Abhyankar ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space_lvl);CHKERRQ(ierr); 573835aa4fcfSShri Abhyankar current_space_lvl = free_space_lvl; 573935aa4fcfSShri Abhyankar 574035aa4fcfSShri Abhyankar for (i=0; i<n; i++) { 574135aa4fcfSShri Abhyankar nzi = 0; 574235aa4fcfSShri Abhyankar /* copy current row into linked list */ 574335aa4fcfSShri Abhyankar nnz = ai[r[i]+1] - ai[r[i]]; 574435aa4fcfSShri Abhyankar if (!nnz) SETERRQ2(PETSC_ERR_MAT_LU_ZRPVT,"Empty row in matrix: row in original ordering %D in permuted ordering %D",r[i],i); 574535aa4fcfSShri Abhyankar cols = aj + ai[r[i]]; 574635aa4fcfSShri Abhyankar lnk[i] = -1; /* marker to indicate if diagonal exists */ 574735aa4fcfSShri Abhyankar ierr = PetscIncompleteLLInit(nnz,cols,n,ic,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr); 574835aa4fcfSShri Abhyankar nzi += nlnk; 574935aa4fcfSShri Abhyankar 575035aa4fcfSShri Abhyankar /* make sure diagonal entry is included */ 575135aa4fcfSShri Abhyankar if (diagonal_fill && lnk[i] == -1) { 575235aa4fcfSShri Abhyankar fm = n; 575335aa4fcfSShri Abhyankar while (lnk[fm] < i) fm = lnk[fm]; 575435aa4fcfSShri Abhyankar lnk[i] = lnk[fm]; /* insert diagonal into linked list */ 575535aa4fcfSShri Abhyankar lnk[fm] = i; 575635aa4fcfSShri Abhyankar lnk_lvl[i] = 0; 575735aa4fcfSShri Abhyankar nzi++; dcount++; 575835aa4fcfSShri Abhyankar } 575935aa4fcfSShri Abhyankar 576035aa4fcfSShri Abhyankar /* add pivot rows into the active row */ 576135aa4fcfSShri Abhyankar nzbd = 0; 576235aa4fcfSShri Abhyankar prow = lnk[n]; 576335aa4fcfSShri Abhyankar while (prow < i) { 576435aa4fcfSShri Abhyankar nnz = bdiag[prow]; 576535aa4fcfSShri Abhyankar cols = bj_ptr[prow] + nnz + 1; 576635aa4fcfSShri Abhyankar cols_lvl = bjlvl_ptr[prow] + nnz + 1; 576735aa4fcfSShri Abhyankar nnz = bi[prow+1] - bi[prow] - nnz - 1; 576835aa4fcfSShri Abhyankar ierr = PetscILULLAddSorted(nnz,cols,levels,cols_lvl,prow,nlnk,lnk,lnk_lvl,lnkbt,prow);CHKERRQ(ierr); 576935aa4fcfSShri Abhyankar nzi += nlnk; 577035aa4fcfSShri Abhyankar prow = lnk[prow]; 577135aa4fcfSShri Abhyankar nzbd++; 577235aa4fcfSShri Abhyankar } 577335aa4fcfSShri Abhyankar bdiag[i] = nzbd; 577435aa4fcfSShri Abhyankar bi[i+1] = bi[i] + nzi; 577535aa4fcfSShri Abhyankar 577635aa4fcfSShri Abhyankar /* if free space is not available, make more free space */ 577735aa4fcfSShri Abhyankar if (current_space->local_remaining<nzi) { 577835aa4fcfSShri Abhyankar nnz = 2*nzi*(n - i); /* estimated and max additional space needed */ 577935aa4fcfSShri Abhyankar ierr = PetscFreeSpaceGet(nnz,¤t_space);CHKERRQ(ierr); 578035aa4fcfSShri Abhyankar ierr = PetscFreeSpaceGet(nnz,¤t_space_lvl);CHKERRQ(ierr); 578135aa4fcfSShri Abhyankar reallocs++; 578235aa4fcfSShri Abhyankar } 578335aa4fcfSShri Abhyankar 578435aa4fcfSShri Abhyankar /* copy data into free_space and free_space_lvl, then initialize lnk */ 578535aa4fcfSShri Abhyankar ierr = PetscIncompleteLLClean(n,n,nzi,lnk,lnk_lvl,current_space->array,current_space_lvl->array,lnkbt);CHKERRQ(ierr); 578635aa4fcfSShri Abhyankar bj_ptr[i] = current_space->array; 578735aa4fcfSShri Abhyankar bjlvl_ptr[i] = current_space_lvl->array; 578835aa4fcfSShri Abhyankar 578935aa4fcfSShri Abhyankar /* make sure the active row i has diagonal entry */ 579035aa4fcfSShri Abhyankar if (*(bj_ptr[i]+bdiag[i]) != i) { 579135aa4fcfSShri Abhyankar SETERRQ1(PETSC_ERR_MAT_LU_ZRPVT,"Row %D has missing diagonal in factored matrix\n\ 579235aa4fcfSShri Abhyankar try running with -pc_factor_nonzeros_along_diagonal or -pc_factor_diagonal_fill",i); 579335aa4fcfSShri Abhyankar } 579435aa4fcfSShri Abhyankar 579535aa4fcfSShri Abhyankar current_space->array += nzi; 579635aa4fcfSShri Abhyankar current_space->local_used += nzi; 579735aa4fcfSShri Abhyankar current_space->local_remaining -= nzi; 579835aa4fcfSShri Abhyankar current_space_lvl->array += nzi; 579935aa4fcfSShri Abhyankar current_space_lvl->local_used += nzi; 580035aa4fcfSShri Abhyankar current_space_lvl->local_remaining -= nzi; 580135aa4fcfSShri Abhyankar } 580235aa4fcfSShri Abhyankar 580335aa4fcfSShri Abhyankar ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 580435aa4fcfSShri Abhyankar ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 580535aa4fcfSShri Abhyankar 580635aa4fcfSShri Abhyankar /* destroy list of free space and other temporary arrays */ 580735aa4fcfSShri Abhyankar ierr = PetscMalloc((bi[n]+1)*sizeof(PetscInt),&bj);CHKERRQ(ierr); 580835aa4fcfSShri Abhyankar 580935aa4fcfSShri Abhyankar /* copy free_space into bj and free free_space; set bi, bj, bdiag in new datastructure; */ 58102ce24eb6SHong Zhang ierr = PetscFreeSpaceContiguous_LU(&free_space,bj,n,bi,bdiag);CHKERRQ(ierr); 581135aa4fcfSShri Abhyankar 581235aa4fcfSShri Abhyankar ierr = PetscIncompleteLLDestroy(lnk,lnkbt);CHKERRQ(ierr); 581335aa4fcfSShri Abhyankar ierr = PetscFreeSpaceDestroy(free_space_lvl);CHKERRQ(ierr); 5814fca92195SBarry Smith ierr = PetscFree2(bj_ptr,bjlvl_ptr);CHKERRQ(ierr); 581535aa4fcfSShri Abhyankar 581635aa4fcfSShri Abhyankar #if defined(PETSC_USE_INFO) 581735aa4fcfSShri Abhyankar { 581835aa4fcfSShri Abhyankar PetscReal af = ((PetscReal)bi[n])/((PetscReal)ai[n]); 581935aa4fcfSShri Abhyankar ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocs,f,af);CHKERRQ(ierr); 582035aa4fcfSShri Abhyankar ierr = PetscInfo1(A,"Run with -[sub_]pc_factor_fill %G or use \n",af);CHKERRQ(ierr); 582135aa4fcfSShri Abhyankar ierr = PetscInfo1(A,"PCFactorSetFill([sub]pc,%G);\n",af);CHKERRQ(ierr); 582235aa4fcfSShri Abhyankar ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr); 582335aa4fcfSShri Abhyankar if (diagonal_fill) { 582435aa4fcfSShri Abhyankar ierr = PetscInfo1(A,"Detected and replaced %D missing diagonals",dcount);CHKERRQ(ierr); 582535aa4fcfSShri Abhyankar } 582635aa4fcfSShri Abhyankar } 582735aa4fcfSShri Abhyankar #endif 582835aa4fcfSShri Abhyankar 582935aa4fcfSShri Abhyankar /* put together the new matrix */ 583035aa4fcfSShri Abhyankar ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(fact,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr); 583135aa4fcfSShri Abhyankar ierr = PetscLogObjectParent(fact,isicol);CHKERRQ(ierr); 583235aa4fcfSShri Abhyankar b = (Mat_SeqBAIJ*)(fact)->data; 583335aa4fcfSShri Abhyankar b->free_a = PETSC_TRUE; 583435aa4fcfSShri Abhyankar b->free_ij = PETSC_TRUE; 583535aa4fcfSShri Abhyankar b->singlemalloc = PETSC_FALSE; 583635aa4fcfSShri Abhyankar ierr = PetscMalloc( (bs2*(bdiag[0]+1) )*sizeof(MatScalar),&b->a);CHKERRQ(ierr); 583735aa4fcfSShri Abhyankar b->j = bj; 583835aa4fcfSShri Abhyankar b->i = bi; 583935aa4fcfSShri Abhyankar b->diag = bdiag; 584035aa4fcfSShri Abhyankar b->free_diag = PETSC_TRUE; 584135aa4fcfSShri Abhyankar b->ilen = 0; 584235aa4fcfSShri Abhyankar b->imax = 0; 584335aa4fcfSShri Abhyankar b->row = isrow; 584435aa4fcfSShri Abhyankar b->col = iscol; 584535aa4fcfSShri Abhyankar ierr = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr); 584635aa4fcfSShri Abhyankar ierr = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr); 584735aa4fcfSShri Abhyankar b->icol = isicol; 584835aa4fcfSShri Abhyankar ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr); 584935aa4fcfSShri Abhyankar /* In b structure: Free imax, ilen, old a, old j. 585035aa4fcfSShri Abhyankar Allocate bdiag, solve_work, new a, new j */ 585135aa4fcfSShri Abhyankar ierr = PetscLogObjectMemory(fact,(bdiag[0]+1) * (sizeof(PetscInt)+bs2*sizeof(PetscScalar)));CHKERRQ(ierr); 585235aa4fcfSShri Abhyankar b->maxnz = b->nz = bdiag[0]+1; 5853ae3d28f0SHong Zhang fact->info.factor_mallocs = reallocs; 5854ae3d28f0SHong Zhang fact->info.fill_ratio_given = f; 5855ae3d28f0SHong Zhang fact->info.fill_ratio_needed = ((PetscReal)(bdiag[0]+1))/((PetscReal)ai[n]); 58564dd39f65SShri Abhyankar ierr = MatSeqBAIJSetNumericFactorization(fact,both_identity);CHKERRQ(ierr); 585735aa4fcfSShri Abhyankar PetscFunctionReturn(0); 585835aa4fcfSShri Abhyankar } 585935aa4fcfSShri Abhyankar 586035aa4fcfSShri Abhyankar 58614e2b4712SSatish Balay /* 58624e2b4712SSatish Balay This code is virtually identical to MatILUFactorSymbolic_SeqAIJ 58634e2b4712SSatish Balay except that the data structure of Mat_SeqAIJ is slightly different. 58644e2b4712SSatish Balay Not a good example of code reuse. 58654e2b4712SSatish Balay */ 58664a2ae208SSatish Balay #undef __FUNCT__ 586706e38f1dSHong Zhang #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ_inplace" 586806e38f1dSHong Zhang PetscErrorCode MatILUFactorSymbolic_SeqBAIJ_inplace(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info) 58694e2b4712SSatish Balay { 58704e2b4712SSatish Balay Mat_SeqBAIJ *a = (Mat_SeqBAIJ*)A->data,*b; 58714e2b4712SSatish Balay IS isicol; 58726849ba73SBarry Smith PetscErrorCode ierr; 58735d0c19d7SBarry Smith const PetscInt *r,*ic,*ai = a->i,*aj = a->j,*xi; 58745d0c19d7SBarry Smith PetscInt prow,n = a->mbs,*ainew,*ajnew,jmax,*fill,nz,*im,*ajfill,*flev,*xitmp; 5875a96a251dSBarry Smith PetscInt *dloc,idx,row,m,fm,nzf,nzi,reallocate = 0,dcount = 0; 5876d0f46423SBarry Smith PetscInt incrlev,nnz,i,bs = A->rmap->bs,bs2 = a->bs2,levels,diagonal_fill,dd; 587741df41f0SMatthew Knepley PetscTruth col_identity,row_identity,both_identity,flg; 5878329f5518SBarry Smith PetscReal f; 58794e2b4712SSatish Balay 58804e2b4712SSatish Balay PetscFunctionBegin; 58816bce7ff8SHong Zhang ierr = MatMissingDiagonal_SeqBAIJ(A,&flg,&dd);CHKERRQ(ierr); 58826bce7ff8SHong Zhang if (flg) SETERRQ1(PETSC_ERR_ARG_WRONGSTATE,"Matrix A is missing diagonal entry in row %D",dd); 58836bce7ff8SHong Zhang 5884435faa5fSBarry Smith f = info->fill; 5885690b6cddSBarry Smith levels = (PetscInt)info->levels; 5886690b6cddSBarry Smith diagonal_fill = (PetscInt)info->diagonal_fill; 58874c49b128SBarry Smith ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr); 588816a2bf60SHong Zhang 5889667159a5SBarry Smith ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr); 5890667159a5SBarry Smith ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr); 58917d18ce8fSMatthew Knepley both_identity = (PetscTruth) (row_identity && col_identity); 5892309c388cSBarry Smith 589341df41f0SMatthew Knepley if (!levels && both_identity) { /* special case copy the nonzero structure */ 589416a2bf60SHong Zhang ierr = MatDuplicateNoCreate_SeqBAIJ(fact,A,MAT_DO_NOT_COPY_VALUES,PETSC_TRUE);CHKERRQ(ierr); 58958b1456e3SHong Zhang ierr = MatSeqBAIJSetNumericFactorization_inplace(fact,both_identity);CHKERRQ(ierr); 58966bce7ff8SHong Zhang 5897719d5645SBarry Smith fact->factor = MAT_FACTOR_ILU; 5898ae3d28f0SHong Zhang b = (Mat_SeqBAIJ*)fact->data; 5899bb3d539aSBarry Smith b->row = isrow; 5900bb3d539aSBarry Smith b->col = iscol; 5901bb3d539aSBarry Smith ierr = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr); 5902bb3d539aSBarry Smith ierr = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr); 5903bb3d539aSBarry Smith b->icol = isicol; 5904bcd9e38bSBarry Smith b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE; 5905b588c5a2SHong Zhang ierr = PetscMalloc((n+1)*bs*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr); 59066bce7ff8SHong Zhang PetscFunctionReturn(0); 59076bce7ff8SHong Zhang } 59086bce7ff8SHong Zhang 59096bce7ff8SHong Zhang /* general case perform the symbolic factorization */ 59104e2b4712SSatish Balay ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr); 59114e2b4712SSatish Balay ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr); 59124e2b4712SSatish Balay 59134e2b4712SSatish Balay /* get new row pointers */ 5914690b6cddSBarry Smith ierr = PetscMalloc((n+1)*sizeof(PetscInt),&ainew);CHKERRQ(ierr); 59154e2b4712SSatish Balay ainew[0] = 0; 59164e2b4712SSatish Balay /* don't know how many column pointers are needed so estimate */ 5917690b6cddSBarry Smith jmax = (PetscInt)(f*ai[n] + 1); 5918690b6cddSBarry Smith ierr = PetscMalloc((jmax)*sizeof(PetscInt),&ajnew);CHKERRQ(ierr); 59194e2b4712SSatish Balay /* ajfill is level of fill for each fill entry */ 5920690b6cddSBarry Smith ierr = PetscMalloc((jmax)*sizeof(PetscInt),&ajfill);CHKERRQ(ierr); 59214e2b4712SSatish Balay /* fill is a linked list of nonzeros in active row */ 5922690b6cddSBarry Smith ierr = PetscMalloc((n+1)*sizeof(PetscInt),&fill);CHKERRQ(ierr); 59234e2b4712SSatish Balay /* im is level for each filled value */ 5924690b6cddSBarry Smith ierr = PetscMalloc((n+1)*sizeof(PetscInt),&im);CHKERRQ(ierr); 59254e2b4712SSatish Balay /* dloc is location of diagonal in factor */ 5926690b6cddSBarry Smith ierr = PetscMalloc((n+1)*sizeof(PetscInt),&dloc);CHKERRQ(ierr); 59274e2b4712SSatish Balay dloc[0] = 0; 59284e2b4712SSatish Balay for (prow=0; prow<n; prow++) { 5929435faa5fSBarry Smith 5930435faa5fSBarry Smith /* copy prow into linked list */ 59314e2b4712SSatish Balay nzf = nz = ai[r[prow]+1] - ai[r[prow]]; 59323b4a8b6dSBarry Smith if (!nz) SETERRQ2(PETSC_ERR_MAT_LU_ZRPVT,"Empty row in matrix: row in original ordering %D in permuted ordering %D",r[prow],prow); 59334e2b4712SSatish Balay xi = aj + ai[r[prow]]; 59344e2b4712SSatish Balay fill[n] = n; 5935435faa5fSBarry Smith fill[prow] = -1; /* marker for diagonal entry */ 59364e2b4712SSatish Balay while (nz--) { 59374e2b4712SSatish Balay fm = n; 59384e2b4712SSatish Balay idx = ic[*xi++]; 59394e2b4712SSatish Balay do { 59404e2b4712SSatish Balay m = fm; 59414e2b4712SSatish Balay fm = fill[m]; 59424e2b4712SSatish Balay } while (fm < idx); 59434e2b4712SSatish Balay fill[m] = idx; 59444e2b4712SSatish Balay fill[idx] = fm; 59454e2b4712SSatish Balay im[idx] = 0; 59464e2b4712SSatish Balay } 5947435faa5fSBarry Smith 5948435faa5fSBarry Smith /* make sure diagonal entry is included */ 5949435faa5fSBarry Smith if (diagonal_fill && fill[prow] == -1) { 5950435faa5fSBarry Smith fm = n; 5951435faa5fSBarry Smith while (fill[fm] < prow) fm = fill[fm]; 5952435faa5fSBarry Smith fill[prow] = fill[fm]; /* insert diagonal into linked list */ 5953435faa5fSBarry Smith fill[fm] = prow; 5954435faa5fSBarry Smith im[prow] = 0; 5955435faa5fSBarry Smith nzf++; 5956335d9088SBarry Smith dcount++; 5957435faa5fSBarry Smith } 5958435faa5fSBarry Smith 59594e2b4712SSatish Balay nzi = 0; 59604e2b4712SSatish Balay row = fill[n]; 59614e2b4712SSatish Balay while (row < prow) { 59624e2b4712SSatish Balay incrlev = im[row] + 1; 59634e2b4712SSatish Balay nz = dloc[row]; 5964435faa5fSBarry Smith xi = ajnew + ainew[row] + nz + 1; 59654e2b4712SSatish Balay flev = ajfill + ainew[row] + nz + 1; 59664e2b4712SSatish Balay nnz = ainew[row+1] - ainew[row] - nz - 1; 59674e2b4712SSatish Balay fm = row; 59684e2b4712SSatish Balay while (nnz-- > 0) { 59694e2b4712SSatish Balay idx = *xi++; 59704e2b4712SSatish Balay if (*flev + incrlev > levels) { 59714e2b4712SSatish Balay flev++; 59724e2b4712SSatish Balay continue; 59734e2b4712SSatish Balay } 59744e2b4712SSatish Balay do { 59754e2b4712SSatish Balay m = fm; 59764e2b4712SSatish Balay fm = fill[m]; 59774e2b4712SSatish Balay } while (fm < idx); 59784e2b4712SSatish Balay if (fm != idx) { 59794e2b4712SSatish Balay im[idx] = *flev + incrlev; 59804e2b4712SSatish Balay fill[m] = idx; 59814e2b4712SSatish Balay fill[idx] = fm; 59824e2b4712SSatish Balay fm = idx; 59834e2b4712SSatish Balay nzf++; 5984ecf371e4SBarry Smith } else { 59854e2b4712SSatish Balay if (im[idx] > *flev + incrlev) im[idx] = *flev+incrlev; 59864e2b4712SSatish Balay } 59874e2b4712SSatish Balay flev++; 59884e2b4712SSatish Balay } 59894e2b4712SSatish Balay row = fill[row]; 59904e2b4712SSatish Balay nzi++; 59914e2b4712SSatish Balay } 59924e2b4712SSatish Balay /* copy new filled row into permanent storage */ 59934e2b4712SSatish Balay ainew[prow+1] = ainew[prow] + nzf; 59944e2b4712SSatish Balay if (ainew[prow+1] > jmax) { 5995ecf371e4SBarry Smith 5996ecf371e4SBarry Smith /* estimate how much additional space we will need */ 5997ecf371e4SBarry Smith /* use the strategy suggested by David Hysom <hysom@perch-t.icase.edu> */ 5998ecf371e4SBarry Smith /* just double the memory each time */ 5999690b6cddSBarry Smith PetscInt maxadd = jmax; 6000ecf371e4SBarry Smith /* maxadd = (int)(((f*ai[n]+1)*(n-prow+5))/n); */ 60014e2b4712SSatish Balay if (maxadd < nzf) maxadd = (n-prow)*(nzf+1); 60024e2b4712SSatish Balay jmax += maxadd; 6003ecf371e4SBarry Smith 6004ecf371e4SBarry Smith /* allocate a longer ajnew and ajfill */ 60055d0c19d7SBarry Smith ierr = PetscMalloc(jmax*sizeof(PetscInt),&xitmp);CHKERRQ(ierr); 60065d0c19d7SBarry Smith ierr = PetscMemcpy(xitmp,ajnew,ainew[prow]*sizeof(PetscInt));CHKERRQ(ierr); 6007606d414cSSatish Balay ierr = PetscFree(ajnew);CHKERRQ(ierr); 60085d0c19d7SBarry Smith ajnew = xitmp; 60095d0c19d7SBarry Smith ierr = PetscMalloc(jmax*sizeof(PetscInt),&xitmp);CHKERRQ(ierr); 60105d0c19d7SBarry Smith ierr = PetscMemcpy(xitmp,ajfill,ainew[prow]*sizeof(PetscInt));CHKERRQ(ierr); 6011606d414cSSatish Balay ierr = PetscFree(ajfill);CHKERRQ(ierr); 60125d0c19d7SBarry Smith ajfill = xitmp; 6013eb150c5cSKris Buschelman reallocate++; /* count how many reallocations are needed */ 60144e2b4712SSatish Balay } 60155d0c19d7SBarry Smith xitmp = ajnew + ainew[prow]; 60164e2b4712SSatish Balay flev = ajfill + ainew[prow]; 60174e2b4712SSatish Balay dloc[prow] = nzi; 60184e2b4712SSatish Balay fm = fill[n]; 60194e2b4712SSatish Balay while (nzf--) { 60205d0c19d7SBarry Smith *xitmp++ = fm; 60214e2b4712SSatish Balay *flev++ = im[fm]; 60224e2b4712SSatish Balay fm = fill[fm]; 60234e2b4712SSatish Balay } 6024435faa5fSBarry Smith /* make sure row has diagonal entry */ 6025435faa5fSBarry Smith if (ajnew[ainew[prow]+dloc[prow]] != prow) { 602677431f27SBarry Smith SETERRQ1(PETSC_ERR_MAT_LU_ZRPVT,"Row %D has missing diagonal in factored matrix\n\ 60272401956bSBarry Smith try running with -pc_factor_nonzeros_along_diagonal or -pc_factor_diagonal_fill",prow); 6028435faa5fSBarry Smith } 60294e2b4712SSatish Balay } 6030606d414cSSatish Balay ierr = PetscFree(ajfill);CHKERRQ(ierr); 60314e2b4712SSatish Balay ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr); 60324e2b4712SSatish Balay ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr); 6033606d414cSSatish Balay ierr = PetscFree(fill);CHKERRQ(ierr); 6034606d414cSSatish Balay ierr = PetscFree(im);CHKERRQ(ierr); 60354e2b4712SSatish Balay 60366cf91177SBarry Smith #if defined(PETSC_USE_INFO) 60374e2b4712SSatish Balay { 6038329f5518SBarry Smith PetscReal af = ((PetscReal)ainew[n])/((PetscReal)ai[n]); 6039ae15b995SBarry Smith ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocate,f,af);CHKERRQ(ierr); 6040ae15b995SBarry Smith ierr = PetscInfo1(A,"Run with -pc_factor_fill %G or use \n",af);CHKERRQ(ierr); 6041ae15b995SBarry Smith ierr = PetscInfo1(A,"PCFactorSetFill(pc,%G);\n",af);CHKERRQ(ierr); 6042ae15b995SBarry Smith ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr); 6043335d9088SBarry Smith if (diagonal_fill) { 6044ae15b995SBarry Smith ierr = PetscInfo1(A,"Detected and replaced %D missing diagonals\n",dcount);CHKERRQ(ierr); 6045335d9088SBarry Smith } 60464e2b4712SSatish Balay } 604763ba0a88SBarry Smith #endif 60484e2b4712SSatish Balay 60494e2b4712SSatish Balay /* put together the new matrix */ 6050719d5645SBarry Smith ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(fact,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr); 6051719d5645SBarry Smith ierr = PetscLogObjectParent(fact,isicol);CHKERRQ(ierr); 6052ae3d28f0SHong Zhang b = (Mat_SeqBAIJ*)fact->data; 6053e6b907acSBarry Smith b->free_a = PETSC_TRUE; 6054e6b907acSBarry Smith b->free_ij = PETSC_TRUE; 60557c922b88SBarry Smith b->singlemalloc = PETSC_FALSE; 6056a96a251dSBarry Smith ierr = PetscMalloc(bs2*ainew[n]*sizeof(MatScalar),&b->a);CHKERRQ(ierr); 60574e2b4712SSatish Balay b->j = ajnew; 60584e2b4712SSatish Balay b->i = ainew; 60594e2b4712SSatish Balay for (i=0; i<n; i++) dloc[i] += ainew[i]; 60604e2b4712SSatish Balay b->diag = dloc; 60617f53bb6cSHong Zhang b->free_diag = PETSC_TRUE; 60624e2b4712SSatish Balay b->ilen = 0; 60634e2b4712SSatish Balay b->imax = 0; 60644e2b4712SSatish Balay b->row = isrow; 60654e2b4712SSatish Balay b->col = iscol; 6066bcd9e38bSBarry Smith b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE; 6067c38d4ed2SBarry Smith ierr = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr); 6068c38d4ed2SBarry Smith ierr = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr); 6069e51c0b9cSSatish Balay b->icol = isicol; 607087828ca2SBarry Smith ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr); 60714e2b4712SSatish Balay /* In b structure: Free imax, ilen, old a, old j. 60724e2b4712SSatish Balay Allocate dloc, solve_work, new a, new j */ 6073719d5645SBarry Smith ierr = PetscLogObjectMemory(fact,(ainew[n]-n)*(sizeof(PetscInt))+bs2*ainew[n]*sizeof(PetscScalar));CHKERRQ(ierr); 60744e2b4712SSatish Balay b->maxnz = b->nz = ainew[n]; 60754e2b4712SSatish Balay 6076ae3d28f0SHong Zhang fact->info.factor_mallocs = reallocate; 6077ae3d28f0SHong Zhang fact->info.fill_ratio_given = f; 6078ae3d28f0SHong Zhang fact->info.fill_ratio_needed = ((PetscReal)ainew[n])/((PetscReal)ai[prow]); 60796bce7ff8SHong Zhang 60808b1456e3SHong Zhang ierr = MatSeqBAIJSetNumericFactorization_inplace(fact,both_identity);CHKERRQ(ierr); 60818661488fSKris Buschelman PetscFunctionReturn(0); 60828661488fSKris Buschelman } 60838661488fSKris Buschelman 6084732ee342SKris Buschelman #undef __FUNCT__ 60857e7071cdSKris Buschelman #define __FUNCT__ "MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE" 6086dfbe8321SBarry Smith PetscErrorCode MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE(Mat A) 60877e7071cdSKris Buschelman { 608812272027SHong Zhang /* Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; */ 608912272027SHong Zhang /* int i,*AJ=a->j,nz=a->nz; */ 60905a9542e3SKris Buschelman PetscFunctionBegin; 60917cf1b8d3SKris Buschelman /* Undo Column scaling */ 60927cf1b8d3SKris Buschelman /* while (nz--) { */ 60937cf1b8d3SKris Buschelman /* AJ[i] = AJ[i]/4; */ 60947cf1b8d3SKris Buschelman /* } */ 6095c115a38dSKris Buschelman /* This should really invoke a push/pop logic, but we don't have that yet. */ 6096c115a38dSKris Buschelman A->ops->setunfactored = PETSC_NULL; 60977cf1b8d3SKris Buschelman PetscFunctionReturn(0); 60987cf1b8d3SKris Buschelman } 60997cf1b8d3SKris Buschelman 61007cf1b8d3SKris Buschelman #undef __FUNCT__ 61017cf1b8d3SKris Buschelman #define __FUNCT__ "MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE_usj" 6102dfbe8321SBarry Smith PetscErrorCode MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE_usj(Mat A) 61037cf1b8d3SKris Buschelman { 61047cf1b8d3SKris Buschelman Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; 6105b24ad042SBarry Smith PetscInt *AJ=a->j,nz=a->nz; 61062aa5897fSKris Buschelman unsigned short *aj=(unsigned short *)AJ; 61075a9542e3SKris Buschelman PetscFunctionBegin; 61080b9da03eSKris Buschelman /* Is this really necessary? */ 610920235379SKris Buschelman while (nz--) { 61100b9da03eSKris Buschelman AJ[nz] = (int)((unsigned int)aj[nz]); /* First extend, then convert to signed. */ 61117e7071cdSKris Buschelman } 6112c115a38dSKris Buschelman A->ops->setunfactored = PETSC_NULL; 61137e7071cdSKris Buschelman PetscFunctionReturn(0); 61147e7071cdSKris Buschelman } 61157e7071cdSKris Buschelman 6116732ee342SKris Buschelman 6117