xref: /petsc/src/mat/impls/baij/seq/baijfact2.c (revision b3260449f1fd1d8ee827e2db9e3af502a46aaac4)
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;
64*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
65*b3260449SShri Abhyankar   const PetscInt    *diag = a->diag,*vi,n=a->mbs,*ai=a->i,*aj=a->j;
66*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
67*b3260449SShri Abhyankar   PetscScalar       s1,s2,x1,x2,*x;
68*b3260449SShri Abhyankar   const PetscScalar *b;
69f1af5d2fSBarry Smith 
70f1af5d2fSBarry Smith   PetscFunctionBegin;
71ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
72*b3260449SShri 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   }
111*b3260449SShri 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;
123*b3260449SShri 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;
125*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
126*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
127*b3260449SShri Abhyankar   PetscScalar       s1,s2,x1,x2,*x;
128*b3260449SShri Abhyankar   const PetscScalar *b;
1296929473cSShri Abhyankar 
1306929473cSShri Abhyankar   PetscFunctionBegin;
1316929473cSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
132*b3260449SShri 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   }
170*b3260449SShri 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;
182*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
183*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
184*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
185*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,x1,x2,x3,*x;
186*b3260449SShri Abhyankar   const PetscScalar *b;
187f1af5d2fSBarry Smith 
188f1af5d2fSBarry Smith   PetscFunctionBegin;
189ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
190*b3260449SShri 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   }
232*b3260449SShri 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;
244*b3260449SShri 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;
246*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
247*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
248*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,x1,x2,x3,*x;
249*b3260449SShri Abhyankar   const PetscScalar *b;
2508499736aSShri Abhyankar 
2518499736aSShri Abhyankar   PetscFunctionBegin;
2528499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
253*b3260449SShri 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   }
294*b3260449SShri 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;
306*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
307*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
308*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
309*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4,*x;
310*b3260449SShri Abhyankar   const PetscScalar *b;
311f1af5d2fSBarry Smith 
312f1af5d2fSBarry Smith   PetscFunctionBegin;
313ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
314*b3260449SShri 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   }
359*b3260449SShri 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;
371*b3260449SShri 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;
373*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
374*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
375*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4,*x;
376*b3260449SShri Abhyankar   const PetscScalar *b;
3778499736aSShri Abhyankar 
3788499736aSShri Abhyankar   PetscFunctionBegin;
3798499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
380*b3260449SShri 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   }
424*b3260449SShri 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;
436*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
437*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
438*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
439*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x;
440*b3260449SShri Abhyankar   const PetscScalar *b;
441f1af5d2fSBarry Smith 
442f1af5d2fSBarry Smith   PetscFunctionBegin;
443ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
444*b3260449SShri 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   }
492*b3260449SShri 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;
504*b3260449SShri 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;
506*b3260449SShri Abhyankar   const PetscInt       bs=A->rmap->bs,bs2=a->bs2;
507*b3260449SShri Abhyankar   const MatScalar      *aa=a->a,*v;
508*b3260449SShri Abhyankar   PetscScalar    s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x;
509*b3260449SShri Abhyankar   const PetscScalar    *b;
5108499736aSShri Abhyankar 
5118499736aSShri Abhyankar   PetscFunctionBegin;
5128499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
513*b3260449SShri 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   }
561*b3260449SShri 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;
573*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
574*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
575*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
576*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x;
577*b3260449SShri Abhyankar   const PetscScalar *b;
578f1af5d2fSBarry Smith 
579f1af5d2fSBarry Smith   PetscFunctionBegin;
580ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
581*b3260449SShri 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   }
635*b3260449SShri 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;
647*b3260449SShri 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;
649*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
650*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
651*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x;
652*b3260449SShri Abhyankar   const PetscScalar *b;
6538499736aSShri Abhyankar 
6548499736aSShri Abhyankar   PetscFunctionBegin;
6558499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
656*b3260449SShri 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   }
709*b3260449SShri 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;
721*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
722*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
723*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
724*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x;
725*b3260449SShri Abhyankar   const PetscScalar *b;
726f1af5d2fSBarry Smith 
727f1af5d2fSBarry Smith   PetscFunctionBegin;
728ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
729*b3260449SShri 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   }
786*b3260449SShri 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;
797*b3260449SShri 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;
799*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
800*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
801*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x;
802*b3260449SShri Abhyankar   const PetscScalar *b;
8038499736aSShri Abhyankar 
8048499736aSShri Abhyankar   PetscFunctionBegin;
8058499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
806*b3260449SShri 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   }
861*b3260449SShri 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;
876*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
877*b3260449SShri Abhyankar   PetscInt          i,nz;
878*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
879*b3260449SShri Abhyankar   PetscScalar       s1,*x,*t;
880*b3260449SShri Abhyankar   const PetscScalar *b;
881f1af5d2fSBarry Smith 
882f1af5d2fSBarry Smith   PetscFunctionBegin;
883*b3260449SShri 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);
926*b3260449SShri 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;
940*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
941*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
942*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
943*b3260449SShri Abhyankar   PetscScalar       s1,s2,x1,x2,*x,*t;
944*b3260449SShri Abhyankar   const PetscScalar *b;
945f1af5d2fSBarry Smith 
946f1af5d2fSBarry Smith   PetscFunctionBegin;
947*b3260449SShri 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);
1011*b3260449SShri 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;
1024*b3260449SShri 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;
1027*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1028*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1029*b3260449SShri Abhyankar   PetscScalar       s1,s2,x1,x2,*x,*t;
1030*b3260449SShri Abhyankar   const PetscScalar *b;
103132121132SShri Abhyankar 
103232121132SShri Abhyankar   PetscFunctionBegin;
1033*b3260449SShri 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);
1090*b3260449SShri 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;
1104*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1105*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1106*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1107*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,x1,x2,x3,*x,*t;
1108*b3260449SShri Abhyankar   const PetscScalar *b;
1109f1af5d2fSBarry Smith 
1110f1af5d2fSBarry Smith   PetscFunctionBegin;
1111*b3260449SShri 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);
1180*b3260449SShri 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;
1193*b3260449SShri 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;
1196*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1197*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1198*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,x1,x2,x3,*x,*t;
1199*b3260449SShri Abhyankar   const PetscScalar *b;
120032121132SShri Abhyankar 
120132121132SShri Abhyankar   PetscFunctionBegin;
1202*b3260449SShri 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);
1262*b3260449SShri 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;
1276*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1277*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1278*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1279*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4,*x,*t;
1280*b3260449SShri Abhyankar   const PetscScalar *b;
1281f1af5d2fSBarry Smith 
1282f1af5d2fSBarry Smith   PetscFunctionBegin;
1283*b3260449SShri 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);
1357*b3260449SShri 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;
1370*b3260449SShri 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;
1373*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1374*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1375*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4,*x,*t;
1376*b3260449SShri Abhyankar   const PetscScalar *b;
137732121132SShri Abhyankar 
137832121132SShri Abhyankar   PetscFunctionBegin;
1379*b3260449SShri 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);
1442*b3260449SShri 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;
1456*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1457*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1458*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1459*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x,*t;
1460*b3260449SShri Abhyankar   const PetscScalar *b;
1461f1af5d2fSBarry Smith 
1462f1af5d2fSBarry Smith   PetscFunctionBegin;
1463*b3260449SShri 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);
1542*b3260449SShri 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;
1555*b3260449SShri 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;
1558*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1559*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1560*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x,*t;
1561*b3260449SShri Abhyankar   const PetscScalar *b;
156232121132SShri Abhyankar 
156332121132SShri Abhyankar   PetscFunctionBegin;
1564*b3260449SShri 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);
1632*b3260449SShri 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;
1646*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1647*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1648*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1649*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x,*t;
1650*b3260449SShri Abhyankar   const PetscScalar *b;
1651f1af5d2fSBarry Smith 
1652f1af5d2fSBarry Smith   PetscFunctionBegin;
1653*b3260449SShri 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);
1740*b3260449SShri 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;
1753*b3260449SShri 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;
1756*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1757*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1758*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x,*t;
1759*b3260449SShri Abhyankar   const PetscScalar *b;
176032121132SShri Abhyankar 
176132121132SShri Abhyankar   PetscFunctionBegin;
1762*b3260449SShri 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);
1836*b3260449SShri 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;
1850*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1851*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1852*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1853*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t;
1854*b3260449SShri Abhyankar   const PetscScalar *b;
1855f1af5d2fSBarry Smith 
1856f1af5d2fSBarry Smith   PetscFunctionBegin;
1857*b3260449SShri 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);
1949*b3260449SShri 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;
1961*b3260449SShri 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;
1964*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1965*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1966*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t;
1967*b3260449SShri Abhyankar   const PetscScalar *b;
196832121132SShri Abhyankar 
196932121132SShri Abhyankar   PetscFunctionBegin;
1970*b3260449SShri 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);
2047*b3260449SShri 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;
2061*b3260449SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
2062*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*vi;
2063*b3260449SShri Abhyankar   PetscInt          i,nz;
2064*b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
2065*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
2066*b3260449SShri Abhyankar   PetscScalar       *x,*s,*t,*ls;
2067*b3260449SShri Abhyankar   const PetscScalar *b;
20684e2b4712SSatish Balay 
20694e2b4712SSatish Balay   PetscFunctionBegin;
2070*b3260449SShri 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);
2107*b3260449SShri 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;
2122*b3260449SShri Abhyankar   PetscInt          i,nz,j;
2123*b3260449SShri 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;
2190*b3260449SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
2191*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*vi,*diag=a->diag;
2192*b3260449SShri Abhyankar   PetscInt          i,j,nz;
2193*b3260449SShri 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;
2197*b3260449SShri 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;
2262*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*adiag=a->diag,*vi,bs=A->rmap->bs,bs2=a->bs2;
2263*b3260449SShri 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 
22952b0b2ea7SShri 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;
22962b0b2ea7SShri 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;
22972b0b2ea7SShri 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;
22982b0b2ea7SShri 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;
22992b0b2ea7SShri 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;
23002b0b2ea7SShri 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;
23012b0b2ea7SShri 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;
23022b0b2ea7SShri 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;
23032b0b2ea7SShri 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;
23042b0b2ea7SShri 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;
23052b0b2ea7SShri 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;
23062b0b2ea7SShri 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;
23072b0b2ea7SShri 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;
23082b0b2ea7SShri 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;
23092b0b2ea7SShri 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;
23102b0b2ea7SShri Abhyankar 
23112b0b2ea7SShri Abhyankar       v += bs2;
23122b0b2ea7SShri Abhyankar     }
23132b0b2ea7SShri Abhyankar     idx = bs*i;
23142b0b2ea7SShri Abhyankar     t[idx]    = s1;  t[1+idx]  = s2;  t[2+idx]  = s3;  t[3+idx]  = s4;  t[4+idx]  = s5;
23152b0b2ea7SShri Abhyankar     t[5+idx]  = s6;  t[6+idx]  = s7;  t[7+idx]  = s8;  t[8+idx]  = s9;  t[9+idx]  = s10;
23162b0b2ea7SShri Abhyankar     t[10+idx] = s11; t[11+idx] = s12; t[12+idx] = s13; t[13+idx] = s14; t[14+idx] = s15;
23172b0b2ea7SShri Abhyankar 
23182b0b2ea7SShri Abhyankar   }
23192b0b2ea7SShri Abhyankar   /* backward solve the upper triangular */
23202b0b2ea7SShri Abhyankar   for (i=n-1; i>=0; i--){
23212b0b2ea7SShri Abhyankar     v    = aa + bs2*(adiag[i+1]+1);
23222b0b2ea7SShri Abhyankar     vi   = aj + adiag[i+1]+1;
23232b0b2ea7SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
23242b0b2ea7SShri Abhyankar     idt  = bs*i;
23252b0b2ea7SShri Abhyankar     s1   = t[idt];     s2  = t[1+idt];  s3  = t[2+idt];  s4  = t[3+idt];  s5  = t[4+idt];
23262b0b2ea7SShri Abhyankar     s6   = t[5+idt];   s7  = t[6+idt];  s8  = t[7+idt];  s9  = t[8+idt];  s10 = t[9+idt];
23272b0b2ea7SShri Abhyankar     s11  = t[10+idt]; s12  = t[11+idt]; s13 = t[12+idt]; s14 = t[13+idt]; s15 = t[14+idt];
23282b0b2ea7SShri Abhyankar 
23292b0b2ea7SShri Abhyankar     for(m=0;m<nz;m++){
23302b0b2ea7SShri Abhyankar       idx   = bs*vi[m];
23312b0b2ea7SShri Abhyankar       x1   = t[idx];     x2  = t[1+idx];  x3  = t[2+idx];  x4  = t[3+idx];  x5  = t[4+idx];
23322b0b2ea7SShri Abhyankar       x6   = t[5+idx];   x7  = t[6+idx];  x8  = t[7+idx];  x9  = t[8+idx];  x10 = t[9+idx];
23332b0b2ea7SShri Abhyankar       x11  = t[10+idx]; x12  = t[11+idx]; x13 = t[12+idx]; x14 = t[13+idx]; x15 = t[14+idx];
23342b0b2ea7SShri Abhyankar 
23352b0b2ea7SShri 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;
23362b0b2ea7SShri 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;
23372b0b2ea7SShri 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;
23382b0b2ea7SShri 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;
23392b0b2ea7SShri 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;
23402b0b2ea7SShri 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;
23412b0b2ea7SShri 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;
23422b0b2ea7SShri 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;
23432b0b2ea7SShri 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;
23442b0b2ea7SShri 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;
23452b0b2ea7SShri 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;
23462b0b2ea7SShri 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;
23472b0b2ea7SShri 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;
23482b0b2ea7SShri 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;
23492b0b2ea7SShri 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;
23502b0b2ea7SShri Abhyankar 
23512b0b2ea7SShri Abhyankar       v += bs2;
23522b0b2ea7SShri Abhyankar     }
235329a97285SShri Abhyankar     idc = bs*i;
23542b0b2ea7SShri Abhyankar 
23552b0b2ea7SShri 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;
23562b0b2ea7SShri 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;
23572b0b2ea7SShri 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;
23582b0b2ea7SShri 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;
23592b0b2ea7SShri 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;
23602b0b2ea7SShri 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;
23612b0b2ea7SShri 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;
23622b0b2ea7SShri 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;
23632b0b2ea7SShri 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;
23642b0b2ea7SShri 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;
23652b0b2ea7SShri 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;
23662b0b2ea7SShri 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;
23672b0b2ea7SShri 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;
23682b0b2ea7SShri 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;
23692b0b2ea7SShri 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;
23702b0b2ea7SShri Abhyankar 
23712b0b2ea7SShri Abhyankar   }
23722b0b2ea7SShri Abhyankar 
23730b68f018SBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
23742b0b2ea7SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
23752b0b2ea7SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
23762b0b2ea7SShri Abhyankar   PetscFunctionReturn(0);
23772b0b2ea7SShri Abhyankar }
23782b0b2ea7SShri Abhyankar 
23798499736aSShri Abhyankar #undef __FUNCT__
238006e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_7_inplace"
238106e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_7_inplace(Mat A,Vec bb,Vec xx)
23824e2b4712SSatish Balay {
23834e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
23844e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
23856849ba73SBarry Smith   PetscErrorCode    ierr;
2386*b3260449SShri Abhyankar   const PetscInt    *r,*c,*ai=a->i,*aj=a->j;
2387*b3260449SShri Abhyankar   const PetscInt    *rout,*cout,*diag = a->diag,*vi,n=a->mbs;
2388*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
2389*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
2390*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t;
2391*b3260449SShri Abhyankar   const PetscScalar *b;
23924e2b4712SSatish Balay 
23934e2b4712SSatish Balay   PetscFunctionBegin;
2394*b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
23951ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
2396f1af5d2fSBarry Smith   t  = a->solve_work;
23974e2b4712SSatish Balay 
23984e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
23994e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
24004e2b4712SSatish Balay 
24014e2b4712SSatish Balay   /* forward solve the lower triangular */
24024e2b4712SSatish Balay   idx    = 7*(*r++);
2403f1af5d2fSBarry Smith   t[0] = b[idx];   t[1] = b[1+idx];
2404f1af5d2fSBarry Smith   t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx];
2405f1af5d2fSBarry Smith   t[5] = b[5+idx]; t[6] = b[6+idx];
24064e2b4712SSatish Balay 
24074e2b4712SSatish Balay   for (i=1; i<n; i++) {
24084e2b4712SSatish Balay     v     = aa + 49*ai[i];
24094e2b4712SSatish Balay     vi    = aj + ai[i];
24104e2b4712SSatish Balay     nz    = diag[i] - ai[i];
24114e2b4712SSatish Balay     idx   = 7*(*r++);
2412f1af5d2fSBarry Smith     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
2413f1af5d2fSBarry Smith     s5  = b[4+idx];s6 = b[5+idx];s7 = b[6+idx];
24144e2b4712SSatish Balay     while (nz--) {
24154e2b4712SSatish Balay       idx   = 7*(*vi++);
2416f1af5d2fSBarry Smith       x1    = t[idx];  x2 = t[1+idx];x3 = t[2+idx];
2417f1af5d2fSBarry Smith       x4    = t[3+idx];x5 = t[4+idx];
2418f1af5d2fSBarry Smith       x6    = t[5+idx];x7 = t[6+idx];
2419f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
2420f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
2421f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
2422f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
2423f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
2424f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
2425f1af5d2fSBarry Smith       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
24264e2b4712SSatish Balay       v += 49;
24274e2b4712SSatish Balay     }
24284e2b4712SSatish Balay     idx = 7*i;
2429f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
2430f1af5d2fSBarry Smith     t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
2431f1af5d2fSBarry Smith     t[5+idx] = s6;t[6+idx] = s7;
24324e2b4712SSatish Balay   }
24334e2b4712SSatish Balay   /* backward solve the upper triangular */
24344e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
24354e2b4712SSatish Balay     v    = aa + 49*diag[i] + 49;
24364e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
24374e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
24384e2b4712SSatish Balay     idt  = 7*i;
2439f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
2440f1af5d2fSBarry Smith     s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
2441f1af5d2fSBarry Smith     s6 = t[5+idt];s7 = t[6+idt];
24424e2b4712SSatish Balay     while (nz--) {
24434e2b4712SSatish Balay       idx   = 7*(*vi++);
2444f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx];
2445f1af5d2fSBarry Smith       x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
2446f1af5d2fSBarry Smith       x6    = t[5+idx]; x7 = t[6+idx];
2447f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
2448f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
2449f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
2450f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
2451f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
2452f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
2453f1af5d2fSBarry Smith       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
24544e2b4712SSatish Balay       v += 49;
24554e2b4712SSatish Balay     }
24564e2b4712SSatish Balay     idc = 7*(*c--);
24574e2b4712SSatish Balay     v   = aa + 49*diag[i];
2458f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1+v[7]*s2+v[14]*s3+
2459f1af5d2fSBarry Smith                                  v[21]*s4+v[28]*s5+v[35]*s6+v[42]*s7;
2460f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1+v[8]*s2+v[15]*s3+
2461f1af5d2fSBarry Smith                                  v[22]*s4+v[29]*s5+v[36]*s6+v[43]*s7;
2462f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1+v[9]*s2+v[16]*s3+
2463f1af5d2fSBarry Smith                                  v[23]*s4+v[30]*s5+v[37]*s6+v[44]*s7;
2464f1af5d2fSBarry Smith     x[3+idc] = t[3+idt] = v[3]*s1+v[10]*s2+v[17]*s3+
2465f1af5d2fSBarry Smith                                  v[24]*s4+v[31]*s5+v[38]*s6+v[45]*s7;
2466f1af5d2fSBarry Smith     x[4+idc] = t[4+idt] = v[4]*s1+v[11]*s2+v[18]*s3+
2467f1af5d2fSBarry Smith                                  v[25]*s4+v[32]*s5+v[39]*s6+v[46]*s7;
2468f1af5d2fSBarry Smith     x[5+idc] = t[5+idt] = v[5]*s1+v[12]*s2+v[19]*s3+
2469f1af5d2fSBarry Smith                                  v[26]*s4+v[33]*s5+v[40]*s6+v[47]*s7;
2470f1af5d2fSBarry Smith     x[6+idc] = t[6+idt] = v[6]*s1+v[13]*s2+v[20]*s3+
2471f1af5d2fSBarry Smith                                  v[27]*s4+v[34]*s5+v[41]*s6+v[48]*s7;
24724e2b4712SSatish Balay   }
24734e2b4712SSatish Balay 
24744e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
24754e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
2476*b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
24771ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
2478dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr);
24794e2b4712SSatish Balay   PetscFunctionReturn(0);
24804e2b4712SSatish Balay }
24814e2b4712SSatish Balay 
24828f690400SShri Abhyankar #undef __FUNCT__
24834dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_7"
24844dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_7(Mat A,Vec bb,Vec xx)
248535aa4fcfSShri Abhyankar {
248635aa4fcfSShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
248735aa4fcfSShri Abhyankar   IS                iscol=a->col,isrow=a->row;
248835aa4fcfSShri Abhyankar   PetscErrorCode    ierr;
2489*b3260449SShri Abhyankar   const PetscInt    *r,*c,*ai=a->i,*aj=a->j,*adiag=a->diag;
2490*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*rout,*cout,*vi;
2491*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
2492*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
2493*b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t;
2494*b3260449SShri Abhyankar   const PetscScalar *b;
249535aa4fcfSShri Abhyankar 
249635aa4fcfSShri Abhyankar   PetscFunctionBegin;
2497*b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
249835aa4fcfSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
249935aa4fcfSShri Abhyankar   t  = a->solve_work;
250035aa4fcfSShri Abhyankar 
250135aa4fcfSShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
250235aa4fcfSShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
250335aa4fcfSShri Abhyankar 
250435aa4fcfSShri Abhyankar   /* forward solve the lower triangular */
250535aa4fcfSShri Abhyankar   idx    = 7*r[0];
250635aa4fcfSShri Abhyankar   t[0] = b[idx];   t[1] = b[1+idx];
250735aa4fcfSShri Abhyankar   t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx];
250835aa4fcfSShri Abhyankar   t[5] = b[5+idx]; t[6] = b[6+idx];
250935aa4fcfSShri Abhyankar 
251035aa4fcfSShri Abhyankar   for (i=1; i<n; i++) {
251135aa4fcfSShri Abhyankar     v     = aa + 49*ai[i];
251235aa4fcfSShri Abhyankar     vi    = aj + ai[i];
251335aa4fcfSShri Abhyankar     nz    = ai[i+1] - ai[i];
251435aa4fcfSShri Abhyankar     idx   = 7*r[i];
251535aa4fcfSShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
251635aa4fcfSShri Abhyankar     s5  = b[4+idx];s6 = b[5+idx];s7 = b[6+idx];
251735aa4fcfSShri Abhyankar     for(m=0;m<nz;m++){
251835aa4fcfSShri Abhyankar       idx   = 7*vi[m];
251935aa4fcfSShri Abhyankar       x1    = t[idx];  x2 = t[1+idx];x3 = t[2+idx];
252035aa4fcfSShri Abhyankar       x4    = t[3+idx];x5 = t[4+idx];
252135aa4fcfSShri Abhyankar       x6    = t[5+idx];x7 = t[6+idx];
252235aa4fcfSShri Abhyankar       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
252335aa4fcfSShri Abhyankar       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
252435aa4fcfSShri Abhyankar       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
252535aa4fcfSShri Abhyankar       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
252635aa4fcfSShri Abhyankar       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
252735aa4fcfSShri Abhyankar       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
252835aa4fcfSShri Abhyankar       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
252935aa4fcfSShri Abhyankar       v += 49;
253035aa4fcfSShri Abhyankar     }
253135aa4fcfSShri Abhyankar     idx = 7*i;
253235aa4fcfSShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
253335aa4fcfSShri Abhyankar     t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
253435aa4fcfSShri Abhyankar     t[5+idx] = s6;t[6+idx] = s7;
253535aa4fcfSShri Abhyankar   }
253635aa4fcfSShri Abhyankar   /* backward solve the upper triangular */
253735aa4fcfSShri Abhyankar   for (i=n-1; i>=0; i--){
253835aa4fcfSShri Abhyankar     v    = aa + 49*(adiag[i+1]+1);
253935aa4fcfSShri Abhyankar     vi   = aj + adiag[i+1]+1;
254035aa4fcfSShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
254135aa4fcfSShri Abhyankar     idt  = 7*i;
254235aa4fcfSShri Abhyankar     s1 = t[idt];  s2 = t[1+idt];
254335aa4fcfSShri Abhyankar     s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
254435aa4fcfSShri Abhyankar     s6 = t[5+idt];s7 = t[6+idt];
254535aa4fcfSShri Abhyankar     for(m=0;m<nz;m++){
254635aa4fcfSShri Abhyankar       idx   = 7*vi[m];
254735aa4fcfSShri Abhyankar       x1    = t[idx];   x2 = t[1+idx];
254835aa4fcfSShri Abhyankar       x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
254935aa4fcfSShri Abhyankar       x6    = t[5+idx]; x7 = t[6+idx];
255035aa4fcfSShri Abhyankar       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
255135aa4fcfSShri Abhyankar       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
255235aa4fcfSShri Abhyankar       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
255335aa4fcfSShri Abhyankar       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
255435aa4fcfSShri Abhyankar       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
255535aa4fcfSShri Abhyankar       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
255635aa4fcfSShri Abhyankar       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
255735aa4fcfSShri Abhyankar       v += 49;
255835aa4fcfSShri Abhyankar     }
255935aa4fcfSShri Abhyankar     idc = 7*c[i];
256035aa4fcfSShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1+v[7]*s2+v[14]*s3+
256135aa4fcfSShri Abhyankar                                  v[21]*s4+v[28]*s5+v[35]*s6+v[42]*s7;
256235aa4fcfSShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1+v[8]*s2+v[15]*s3+
256335aa4fcfSShri Abhyankar                                  v[22]*s4+v[29]*s5+v[36]*s6+v[43]*s7;
256435aa4fcfSShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1+v[9]*s2+v[16]*s3+
256535aa4fcfSShri Abhyankar                                  v[23]*s4+v[30]*s5+v[37]*s6+v[44]*s7;
256635aa4fcfSShri Abhyankar     x[3+idc] = t[3+idt] = v[3]*s1+v[10]*s2+v[17]*s3+
256735aa4fcfSShri Abhyankar                                  v[24]*s4+v[31]*s5+v[38]*s6+v[45]*s7;
256835aa4fcfSShri Abhyankar     x[4+idc] = t[4+idt] = v[4]*s1+v[11]*s2+v[18]*s3+
256935aa4fcfSShri Abhyankar                                  v[25]*s4+v[32]*s5+v[39]*s6+v[46]*s7;
257035aa4fcfSShri Abhyankar     x[5+idc] = t[5+idt] = v[5]*s1+v[12]*s2+v[19]*s3+
257135aa4fcfSShri Abhyankar                                  v[26]*s4+v[33]*s5+v[40]*s6+v[47]*s7;
257235aa4fcfSShri Abhyankar     x[6+idc] = t[6+idt] = v[6]*s1+v[13]*s2+v[20]*s3+
257335aa4fcfSShri Abhyankar                                  v[27]*s4+v[34]*s5+v[41]*s6+v[48]*s7;
257435aa4fcfSShri Abhyankar   }
257535aa4fcfSShri Abhyankar 
257635aa4fcfSShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
257735aa4fcfSShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
2578*b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
257935aa4fcfSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
258035aa4fcfSShri Abhyankar   ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr);
258135aa4fcfSShri Abhyankar   PetscFunctionReturn(0);
258235aa4fcfSShri Abhyankar }
258335aa4fcfSShri Abhyankar 
258435aa4fcfSShri Abhyankar #undef __FUNCT__
258506e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_7_NaturalOrdering_inplace"
258606e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_7_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
258715091d37SBarry Smith {
258815091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
2589*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
2590dfbe8321SBarry Smith   PetscErrorCode    ierr;
2591*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,jdx;
2592d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
2593d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7;
2594d9fead3dSBarry Smith   const PetscScalar *b;
259515091d37SBarry Smith 
259615091d37SBarry Smith   PetscFunctionBegin;
2597d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
25981ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
259915091d37SBarry Smith   /* forward solve the lower triangular */
260015091d37SBarry Smith   idx    = 0;
260115091d37SBarry Smith   x[0] = b[idx];   x[1] = b[1+idx]; x[2] = b[2+idx];
260215091d37SBarry Smith   x[3] = b[3+idx]; x[4] = b[4+idx]; x[5] = b[5+idx];
260315091d37SBarry Smith   x[6] = b[6+idx];
260415091d37SBarry Smith   for (i=1; i<n; i++) {
260515091d37SBarry Smith     v     =  aa + 49*ai[i];
260615091d37SBarry Smith     vi    =  aj + ai[i];
260715091d37SBarry Smith     nz    =  diag[i] - ai[i];
260815091d37SBarry Smith     idx   =  7*i;
2609f1af5d2fSBarry Smith     s1  =  b[idx];   s2 = b[1+idx]; s3 = b[2+idx];
2610f1af5d2fSBarry Smith     s4  =  b[3+idx]; s5 = b[4+idx]; s6 = b[5+idx];
2611f1af5d2fSBarry Smith     s7  =  b[6+idx];
261215091d37SBarry Smith     while (nz--) {
261315091d37SBarry Smith       jdx   = 7*(*vi++);
261415091d37SBarry Smith       x1    = x[jdx];   x2 = x[1+jdx]; x3 = x[2+jdx];
261515091d37SBarry Smith       x4    = x[3+jdx]; x5 = x[4+jdx]; x6 = x[5+jdx];
261615091d37SBarry Smith       x7    = x[6+jdx];
2617f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
2618f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
2619f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
2620f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
2621f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
2622f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
2623f1af5d2fSBarry Smith       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
262415091d37SBarry Smith       v += 49;
262515091d37SBarry Smith      }
2626f1af5d2fSBarry Smith     x[idx]   = s1;
2627f1af5d2fSBarry Smith     x[1+idx] = s2;
2628f1af5d2fSBarry Smith     x[2+idx] = s3;
2629f1af5d2fSBarry Smith     x[3+idx] = s4;
2630f1af5d2fSBarry Smith     x[4+idx] = s5;
2631f1af5d2fSBarry Smith     x[5+idx] = s6;
2632f1af5d2fSBarry Smith     x[6+idx] = s7;
263315091d37SBarry Smith   }
263415091d37SBarry Smith   /* backward solve the upper triangular */
263515091d37SBarry Smith   for (i=n-1; i>=0; i--){
263615091d37SBarry Smith     v    = aa + 49*diag[i] + 49;
263715091d37SBarry Smith     vi   = aj + diag[i] + 1;
263815091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
263915091d37SBarry Smith     idt  = 7*i;
2640f1af5d2fSBarry Smith     s1 = x[idt];   s2 = x[1+idt];
2641f1af5d2fSBarry Smith     s3 = x[2+idt]; s4 = x[3+idt];
2642f1af5d2fSBarry Smith     s5 = x[4+idt]; s6 = x[5+idt];
2643f1af5d2fSBarry Smith     s7 = x[6+idt];
264415091d37SBarry Smith     while (nz--) {
264515091d37SBarry Smith       idx   = 7*(*vi++);
264615091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];
264715091d37SBarry Smith       x4    = x[3+idx]; x5 = x[4+idx]; x6 = x[5+idx];
264815091d37SBarry Smith       x7    = x[6+idx];
2649f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
2650f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
2651f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
2652f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
2653f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
2654f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
2655f1af5d2fSBarry Smith       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
265615091d37SBarry Smith       v += 49;
265715091d37SBarry Smith     }
265815091d37SBarry Smith     v        = aa + 49*diag[i];
2659f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[7]*s2  + v[14]*s3 + v[21]*s4
2660f1af5d2fSBarry Smith                          + v[28]*s5 + v[35]*s6 + v[42]*s7;
2661f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[8]*s2  + v[15]*s3 + v[22]*s4
2662f1af5d2fSBarry Smith                          + v[29]*s5 + v[36]*s6 + v[43]*s7;
2663f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[9]*s2  + v[16]*s3 + v[23]*s4
2664f1af5d2fSBarry Smith                          + v[30]*s5 + v[37]*s6 + v[44]*s7;
2665f1af5d2fSBarry Smith     x[3+idt] = v[3]*s1 + v[10]*s2  + v[17]*s3 + v[24]*s4
2666f1af5d2fSBarry Smith                          + v[31]*s5 + v[38]*s6 + v[45]*s7;
2667f1af5d2fSBarry Smith     x[4+idt] = v[4]*s1 + v[11]*s2  + v[18]*s3 + v[25]*s4
2668f1af5d2fSBarry Smith                          + v[32]*s5 + v[39]*s6 + v[46]*s7;
2669f1af5d2fSBarry Smith     x[5+idt] = v[5]*s1 + v[12]*s2  + v[19]*s3 + v[26]*s4
2670f1af5d2fSBarry Smith                          + v[33]*s5 + v[40]*s6 + v[47]*s7;
2671f1af5d2fSBarry Smith     x[6+idt] = v[6]*s1 + v[13]*s2  + v[20]*s3 + v[27]*s4
2672f1af5d2fSBarry Smith                          + v[34]*s5 + v[41]*s6 + v[48]*s7;
267315091d37SBarry Smith   }
267415091d37SBarry Smith 
2675d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
26761ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
2677dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
267815091d37SBarry Smith   PetscFunctionReturn(0);
267915091d37SBarry Smith }
268015091d37SBarry Smith 
2681cee9d6f2SShri Abhyankar #undef __FUNCT__
26824dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_7_NaturalOrdering"
26834dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_7_NaturalOrdering(Mat A,Vec bb,Vec xx)
268453cca76cSShri Abhyankar {
268553cca76cSShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
2686*b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
268753cca76cSShri Abhyankar     PetscErrorCode    ierr;
2688*b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,jdx,idt;
2689*b3260449SShri Abhyankar     const PetscInt    bs = A->rmap->bs,bs2 = a->bs2;
269053cca76cSShri Abhyankar     const MatScalar   *aa=a->a,*v;
269153cca76cSShri Abhyankar     PetscScalar       *x;
269253cca76cSShri Abhyankar     const PetscScalar *b;
269353cca76cSShri Abhyankar     PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7;
269453cca76cSShri Abhyankar 
269553cca76cSShri Abhyankar     PetscFunctionBegin;
269653cca76cSShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
269753cca76cSShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
269853cca76cSShri Abhyankar     /* forward solve the lower triangular */
269953cca76cSShri Abhyankar     idx    = 0;
270053cca76cSShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx];
270153cca76cSShri Abhyankar     x[4] = b[4+idx];x[5] = b[5+idx];x[6] = b[6+idx];
270253cca76cSShri Abhyankar     for (i=1; i<n; i++) {
270353cca76cSShri Abhyankar        v    = aa + bs2*ai[i];
270453cca76cSShri Abhyankar        vi   = aj + ai[i];
270553cca76cSShri Abhyankar        nz   = ai[i+1] - ai[i];
270653cca76cSShri Abhyankar       idx   = bs*i;
270753cca76cSShri Abhyankar        s1   = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
270853cca76cSShri Abhyankar        s5   = b[4+idx];s6 = b[5+idx];s7 = b[6+idx];
270953cca76cSShri Abhyankar        for(k=0;k<nz;k++) {
271053cca76cSShri Abhyankar           jdx   = bs*vi[k];
271153cca76cSShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx];
271253cca76cSShri Abhyankar 	  x5    = x[4+jdx]; x6 = x[5+jdx];x7 = x[6+jdx];
271353cca76cSShri Abhyankar           s1   -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4  + v[28]*x5 + v[35]*x6 + v[42]*x7;
271453cca76cSShri Abhyankar           s2   -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4  + v[29]*x5 + v[36]*x6 + v[43]*x7;
271553cca76cSShri Abhyankar           s3   -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4  + v[30]*x5 + v[37]*x6 + v[44]*x7;
271653cca76cSShri Abhyankar 	  s4   -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4  + v[31]*x5 + v[38]*x6 + v[45]*x7;
271753cca76cSShri Abhyankar           s5   -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4  + v[32]*x5 + v[39]*x6 + v[46]*x7;
271853cca76cSShri Abhyankar 	  s6   -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4  + v[33]*x5 + v[40]*x6 + v[47]*x7;
271953cca76cSShri Abhyankar 	  s7   -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4  + v[34]*x5 + v[41]*x6 + v[48]*x7;
272053cca76cSShri Abhyankar           v   +=  bs2;
272153cca76cSShri Abhyankar         }
272253cca76cSShri Abhyankar 
272353cca76cSShri Abhyankar        x[idx]   = s1;
272453cca76cSShri Abhyankar        x[1+idx] = s2;
272553cca76cSShri Abhyankar        x[2+idx] = s3;
272653cca76cSShri Abhyankar        x[3+idx] = s4;
272753cca76cSShri Abhyankar        x[4+idx] = s5;
272853cca76cSShri Abhyankar        x[5+idx] = s6;
272953cca76cSShri Abhyankar        x[6+idx] = s7;
273053cca76cSShri Abhyankar     }
273153cca76cSShri Abhyankar 
273253cca76cSShri Abhyankar    /* backward solve the upper triangular */
273353cca76cSShri Abhyankar   for (i=n-1; i>=0; i--){
273453cca76cSShri Abhyankar     v   = aa + bs2*(adiag[i+1]+1);
273553cca76cSShri Abhyankar      vi  = aj + adiag[i+1]+1;
273653cca76cSShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
273753cca76cSShri Abhyankar      idt = bs*i;
273853cca76cSShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt];
273953cca76cSShri Abhyankar      s5 = x[4+idt];s6 = x[5+idt];s7 = x[6+idt];
274053cca76cSShri Abhyankar     for(k=0;k<nz;k++) {
274153cca76cSShri Abhyankar       idx   = bs*vi[k];
274253cca76cSShri Abhyankar        x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx];
274353cca76cSShri Abhyankar        x5    = x[4+idx];x6 = x[5+idx];x7 = x[6+idx];
274453cca76cSShri Abhyankar        s1   -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4  + v[28]*x5 + v[35]*x6 + v[42]*x7;
274553cca76cSShri Abhyankar        s2   -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4  + v[29]*x5 + v[36]*x6 + v[43]*x7;
274653cca76cSShri Abhyankar        s3   -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4  + v[30]*x5 + v[37]*x6 + v[44]*x7;
274753cca76cSShri Abhyankar        s4   -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4  + v[31]*x5 + v[38]*x6 + v[45]*x7;
274853cca76cSShri Abhyankar        s5   -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4  + v[32]*x5 + v[39]*x6 + v[46]*x7;
274953cca76cSShri Abhyankar        s6   -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4  + v[33]*x5 + v[40]*x6 + v[47]*x7;
275053cca76cSShri Abhyankar        s7   -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4  + v[34]*x5 + v[41]*x6 + v[48]*x7;
275153cca76cSShri Abhyankar         v   +=  bs2;
275253cca76cSShri Abhyankar     }
275353cca76cSShri Abhyankar     /* x = inv_diagonal*x */
275453cca76cSShri Abhyankar     x[idt]   = v[0]*s1 + v[7]*s2 + v[14]*s3 + v[21]*s4  + v[28]*s5 + v[35]*s6 + v[42]*s7;
275553cca76cSShri 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;
275653cca76cSShri 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;
275753cca76cSShri 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;
275853cca76cSShri 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;
275953cca76cSShri 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;
276053cca76cSShri 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;
276153cca76cSShri Abhyankar   }
276253cca76cSShri Abhyankar 
276353cca76cSShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
276453cca76cSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
276553cca76cSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
276653cca76cSShri Abhyankar   PetscFunctionReturn(0);
276753cca76cSShri Abhyankar }
276853cca76cSShri Abhyankar 
276953cca76cSShri Abhyankar #undef __FUNCT__
277006e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_6_inplace"
277106e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_6_inplace(Mat A,Vec bb,Vec xx)
277215091d37SBarry Smith {
277315091d37SBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
277415091d37SBarry Smith   IS                iscol=a->col,isrow=a->row;
27756849ba73SBarry Smith   PetscErrorCode    ierr;
27765d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
2777*b3260449SShri Abhyankar   const PetscInt    *diag = a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
2778*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
2779d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
2780d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*t;
2781d9fead3dSBarry Smith   const PetscScalar *b;
2782*b3260449SShri Abhyankar 
278315091d37SBarry Smith   PetscFunctionBegin;
2784d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
27851ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
2786f1af5d2fSBarry Smith   t  = a->solve_work;
278715091d37SBarry Smith 
278815091d37SBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
278915091d37SBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
279015091d37SBarry Smith 
279115091d37SBarry Smith   /* forward solve the lower triangular */
279215091d37SBarry Smith   idx    = 6*(*r++);
2793f1af5d2fSBarry Smith   t[0] = b[idx];   t[1] = b[1+idx];
2794f1af5d2fSBarry Smith   t[2] = b[2+idx]; t[3] = b[3+idx];
2795f1af5d2fSBarry Smith   t[4] = b[4+idx]; t[5] = b[5+idx];
279615091d37SBarry Smith   for (i=1; i<n; i++) {
279715091d37SBarry Smith     v     = aa + 36*ai[i];
279815091d37SBarry Smith     vi    = aj + ai[i];
279915091d37SBarry Smith     nz    = diag[i] - ai[i];
280015091d37SBarry Smith     idx   = 6*(*r++);
2801f1af5d2fSBarry Smith     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
2802f1af5d2fSBarry Smith     s5  = b[4+idx]; s6 = b[5+idx];
280315091d37SBarry Smith     while (nz--) {
280415091d37SBarry Smith       idx   = 6*(*vi++);
2805f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx]; x3 = t[2+idx];
2806f1af5d2fSBarry Smith       x4    = t[3+idx]; x5 = t[4+idx]; x6 = t[5+idx];
2807f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
2808f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
2809f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
2810f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
2811f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
2812f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
281315091d37SBarry Smith       v += 36;
281415091d37SBarry Smith     }
281515091d37SBarry Smith     idx = 6*i;
2816f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
2817f1af5d2fSBarry Smith     t[2+idx] = s3;t[3+idx] = s4;
2818f1af5d2fSBarry Smith     t[4+idx] = s5;t[5+idx] = s6;
281915091d37SBarry Smith   }
282015091d37SBarry Smith   /* backward solve the upper triangular */
282115091d37SBarry Smith   for (i=n-1; i>=0; i--){
282215091d37SBarry Smith     v    = aa + 36*diag[i] + 36;
282315091d37SBarry Smith     vi   = aj + diag[i] + 1;
282415091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
282515091d37SBarry Smith     idt  = 6*i;
2826f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
2827f1af5d2fSBarry Smith     s3 = t[2+idt];s4 = t[3+idt];
2828f1af5d2fSBarry Smith     s5 = t[4+idt];s6 = t[5+idt];
282915091d37SBarry Smith     while (nz--) {
283015091d37SBarry Smith       idx   = 6*(*vi++);
2831f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx];
2832f1af5d2fSBarry Smith       x3    = t[2+idx]; x4 = t[3+idx];
2833f1af5d2fSBarry Smith       x5    = t[4+idx]; x6 = t[5+idx];
2834f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
2835f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
2836f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
2837f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
2838f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
2839f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
284015091d37SBarry Smith       v += 36;
284115091d37SBarry Smith     }
284215091d37SBarry Smith     idc = 6*(*c--);
284315091d37SBarry Smith     v   = aa + 36*diag[i];
2844f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1+v[6]*s2+v[12]*s3+
2845f1af5d2fSBarry Smith                                  v[18]*s4+v[24]*s5+v[30]*s6;
2846f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1+v[7]*s2+v[13]*s3+
2847f1af5d2fSBarry Smith                                  v[19]*s4+v[25]*s5+v[31]*s6;
2848f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1+v[8]*s2+v[14]*s3+
2849f1af5d2fSBarry Smith                                  v[20]*s4+v[26]*s5+v[32]*s6;
2850f1af5d2fSBarry Smith     x[3+idc] = t[3+idt] = v[3]*s1+v[9]*s2+v[15]*s3+
2851f1af5d2fSBarry Smith                                  v[21]*s4+v[27]*s5+v[33]*s6;
2852f1af5d2fSBarry Smith     x[4+idc] = t[4+idt] = v[4]*s1+v[10]*s2+v[16]*s3+
2853f1af5d2fSBarry Smith                                  v[22]*s4+v[28]*s5+v[34]*s6;
2854f1af5d2fSBarry Smith     x[5+idc] = t[5+idt] = v[5]*s1+v[11]*s2+v[17]*s3+
2855f1af5d2fSBarry Smith                                  v[23]*s4+v[29]*s5+v[35]*s6;
285615091d37SBarry Smith   }
285715091d37SBarry Smith 
285815091d37SBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
285915091d37SBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
2860d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
28611ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
2862dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
286315091d37SBarry Smith   PetscFunctionReturn(0);
286415091d37SBarry Smith }
286515091d37SBarry Smith 
28666506fda5SShri Abhyankar #undef __FUNCT__
28674dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_6"
28684dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_6(Mat A,Vec bb,Vec xx)
28696506fda5SShri Abhyankar {
28706506fda5SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
28716506fda5SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
28726506fda5SShri Abhyankar   PetscErrorCode    ierr;
28736506fda5SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
2874*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
2875*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
28766506fda5SShri Abhyankar   const MatScalar   *aa=a->a,*v;
28776506fda5SShri Abhyankar   PetscScalar       *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*t;
28786506fda5SShri Abhyankar   const PetscScalar *b;
2879*b3260449SShri Abhyankar 
28806506fda5SShri Abhyankar   PetscFunctionBegin;
28816506fda5SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
28826506fda5SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
28836506fda5SShri Abhyankar   t  = a->solve_work;
28846506fda5SShri Abhyankar 
28856506fda5SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
28866506fda5SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
28876506fda5SShri Abhyankar 
28886506fda5SShri Abhyankar   /* forward solve the lower triangular */
28896506fda5SShri Abhyankar   idx    = 6*r[0];
28906506fda5SShri Abhyankar   t[0] = b[idx];   t[1] = b[1+idx];
28916506fda5SShri Abhyankar   t[2] = b[2+idx]; t[3] = b[3+idx];
28926506fda5SShri Abhyankar   t[4] = b[4+idx]; t[5] = b[5+idx];
28936506fda5SShri Abhyankar   for (i=1; i<n; i++) {
28946506fda5SShri Abhyankar     v     = aa + 36*ai[i];
28956506fda5SShri Abhyankar     vi    = aj + ai[i];
28966506fda5SShri Abhyankar     nz    = ai[i+1] - ai[i];
28976506fda5SShri Abhyankar     idx   = 6*r[i];
28986506fda5SShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
28996506fda5SShri Abhyankar     s5  = b[4+idx]; s6 = b[5+idx];
29006506fda5SShri Abhyankar     for(m=0;m<nz;m++){
29016506fda5SShri Abhyankar       idx   = 6*vi[m];
29026506fda5SShri Abhyankar       x1    = t[idx];   x2 = t[1+idx]; x3 = t[2+idx];
29036506fda5SShri Abhyankar       x4    = t[3+idx]; x5 = t[4+idx]; x6 = t[5+idx];
29046506fda5SShri Abhyankar       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
29056506fda5SShri Abhyankar       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
29066506fda5SShri Abhyankar       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
29076506fda5SShri Abhyankar       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
29086506fda5SShri Abhyankar       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
29096506fda5SShri Abhyankar       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
29106506fda5SShri Abhyankar       v += 36;
29116506fda5SShri Abhyankar     }
29126506fda5SShri Abhyankar     idx = 6*i;
29136506fda5SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
29146506fda5SShri Abhyankar     t[2+idx] = s3;t[3+idx] = s4;
29156506fda5SShri Abhyankar     t[4+idx] = s5;t[5+idx] = s6;
29166506fda5SShri Abhyankar   }
29176506fda5SShri Abhyankar   /* backward solve the upper triangular */
29186506fda5SShri Abhyankar   for (i=n-1; i>=0; i--){
29196506fda5SShri Abhyankar     v    = aa + 36*(adiag[i+1]+1);
29206506fda5SShri Abhyankar     vi   = aj + adiag[i+1]+1;
29216506fda5SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
29226506fda5SShri Abhyankar     idt  = 6*i;
29236506fda5SShri Abhyankar     s1 = t[idt];  s2 = t[1+idt];
29246506fda5SShri Abhyankar     s3 = t[2+idt];s4 = t[3+idt];
29256506fda5SShri Abhyankar     s5 = t[4+idt];s6 = t[5+idt];
29266506fda5SShri Abhyankar     for(m=0;m<nz;m++){
29276506fda5SShri Abhyankar       idx   = 6*vi[m];
29286506fda5SShri Abhyankar       x1    = t[idx];   x2 = t[1+idx];
29296506fda5SShri Abhyankar       x3    = t[2+idx]; x4 = t[3+idx];
29306506fda5SShri Abhyankar       x5    = t[4+idx]; x6 = t[5+idx];
29316506fda5SShri Abhyankar       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
29326506fda5SShri Abhyankar       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
29336506fda5SShri Abhyankar       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
29346506fda5SShri Abhyankar       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
29356506fda5SShri Abhyankar       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
29366506fda5SShri Abhyankar       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
29376506fda5SShri Abhyankar       v += 36;
29386506fda5SShri Abhyankar     }
29396506fda5SShri Abhyankar     idc = 6*c[i];
29406506fda5SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1+v[6]*s2+v[12]*s3+
29416506fda5SShri Abhyankar                                  v[18]*s4+v[24]*s5+v[30]*s6;
29426506fda5SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1+v[7]*s2+v[13]*s3+
29436506fda5SShri Abhyankar                                  v[19]*s4+v[25]*s5+v[31]*s6;
29446506fda5SShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1+v[8]*s2+v[14]*s3+
29456506fda5SShri Abhyankar                                  v[20]*s4+v[26]*s5+v[32]*s6;
29466506fda5SShri Abhyankar     x[3+idc] = t[3+idt] = v[3]*s1+v[9]*s2+v[15]*s3+
29476506fda5SShri Abhyankar                                  v[21]*s4+v[27]*s5+v[33]*s6;
29486506fda5SShri Abhyankar     x[4+idc] = t[4+idt] = v[4]*s1+v[10]*s2+v[16]*s3+
29496506fda5SShri Abhyankar                                  v[22]*s4+v[28]*s5+v[34]*s6;
29506506fda5SShri Abhyankar     x[5+idc] = t[5+idt] = v[5]*s1+v[11]*s2+v[17]*s3+
29516506fda5SShri Abhyankar                                  v[23]*s4+v[29]*s5+v[35]*s6;
29526506fda5SShri Abhyankar   }
29536506fda5SShri Abhyankar 
29546506fda5SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
29556506fda5SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
29566506fda5SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
29576506fda5SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
29586506fda5SShri Abhyankar   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
29596506fda5SShri Abhyankar   PetscFunctionReturn(0);
29606506fda5SShri Abhyankar }
29618f690400SShri Abhyankar 
29628f690400SShri Abhyankar #undef __FUNCT__
296306e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_6_NaturalOrdering_inplace"
296406e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_6_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
296515091d37SBarry Smith {
296615091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
2967*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,jdx;
2968dfbe8321SBarry Smith   PetscErrorCode    ierr;
2969*b3260449SShri Abhyankar   const PetscInt    *diag = a->diag,*vi,n=a->mbs,*ai=a->i,*aj=a->j;
2970d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
2971d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6;
2972d9fead3dSBarry Smith   const PetscScalar *b;
297315091d37SBarry Smith 
297415091d37SBarry Smith   PetscFunctionBegin;
2975d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
29761ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
297715091d37SBarry Smith   /* forward solve the lower triangular */
297815091d37SBarry Smith   idx    = 0;
297915091d37SBarry Smith   x[0] = b[idx];   x[1] = b[1+idx]; x[2] = b[2+idx];
298015091d37SBarry Smith   x[3] = b[3+idx]; x[4] = b[4+idx]; x[5] = b[5+idx];
298115091d37SBarry Smith   for (i=1; i<n; i++) {
298215091d37SBarry Smith     v     =  aa + 36*ai[i];
298315091d37SBarry Smith     vi    =  aj + ai[i];
298415091d37SBarry Smith     nz    =  diag[i] - ai[i];
298515091d37SBarry Smith     idx   =  6*i;
2986f1af5d2fSBarry Smith     s1  =  b[idx];   s2 = b[1+idx]; s3 = b[2+idx];
2987f1af5d2fSBarry Smith     s4  =  b[3+idx]; s5 = b[4+idx]; s6 = b[5+idx];
298815091d37SBarry Smith     while (nz--) {
298915091d37SBarry Smith       jdx   = 6*(*vi++);
299015091d37SBarry Smith       x1    = x[jdx];   x2 = x[1+jdx]; x3 = x[2+jdx];
299115091d37SBarry Smith       x4    = x[3+jdx]; x5 = x[4+jdx]; x6 = x[5+jdx];
2992f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
2993f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
2994f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
2995f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
2996f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
2997f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
299815091d37SBarry Smith       v += 36;
299915091d37SBarry Smith      }
3000f1af5d2fSBarry Smith     x[idx]   = s1;
3001f1af5d2fSBarry Smith     x[1+idx] = s2;
3002f1af5d2fSBarry Smith     x[2+idx] = s3;
3003f1af5d2fSBarry Smith     x[3+idx] = s4;
3004f1af5d2fSBarry Smith     x[4+idx] = s5;
3005f1af5d2fSBarry Smith     x[5+idx] = s6;
300615091d37SBarry Smith   }
300715091d37SBarry Smith   /* backward solve the upper triangular */
300815091d37SBarry Smith   for (i=n-1; i>=0; i--){
300915091d37SBarry Smith     v    = aa + 36*diag[i] + 36;
301015091d37SBarry Smith     vi   = aj + diag[i] + 1;
301115091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
301215091d37SBarry Smith     idt  = 6*i;
3013f1af5d2fSBarry Smith     s1 = x[idt];   s2 = x[1+idt];
3014f1af5d2fSBarry Smith     s3 = x[2+idt]; s4 = x[3+idt];
3015f1af5d2fSBarry Smith     s5 = x[4+idt]; s6 = x[5+idt];
301615091d37SBarry Smith     while (nz--) {
301715091d37SBarry Smith       idx   = 6*(*vi++);
301815091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];
301915091d37SBarry Smith       x4    = x[3+idx]; x5 = x[4+idx]; x6 = x[5+idx];
3020f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
3021f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
3022f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
3023f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
3024f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
3025f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
302615091d37SBarry Smith       v += 36;
302715091d37SBarry Smith     }
302815091d37SBarry Smith     v        = aa + 36*diag[i];
3029f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[6]*s2  + v[12]*s3 + v[18]*s4 + v[24]*s5 + v[30]*s6;
3030f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[7]*s2  + v[13]*s3 + v[19]*s4 + v[25]*s5 + v[31]*s6;
3031f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[8]*s2  + v[14]*s3 + v[20]*s4 + v[26]*s5 + v[32]*s6;
3032f1af5d2fSBarry Smith     x[3+idt] = v[3]*s1 + v[9]*s2  + v[15]*s3 + v[21]*s4 + v[27]*s5 + v[33]*s6;
3033f1af5d2fSBarry Smith     x[4+idt] = v[4]*s1 + v[10]*s2 + v[16]*s3 + v[22]*s4 + v[28]*s5 + v[34]*s6;
3034f1af5d2fSBarry Smith     x[5+idt] = v[5]*s1 + v[11]*s2 + v[17]*s3 + v[23]*s4 + v[29]*s5 + v[35]*s6;
303515091d37SBarry Smith   }
303615091d37SBarry Smith 
3037d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
30381ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3039dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
304015091d37SBarry Smith   PetscFunctionReturn(0);
304115091d37SBarry Smith }
304215091d37SBarry Smith 
3043cee9d6f2SShri Abhyankar #undef __FUNCT__
30444dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_6_NaturalOrdering"
30454dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_6_NaturalOrdering(Mat A,Vec bb,Vec xx)
304653cca76cSShri Abhyankar {
304753cca76cSShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3048*b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
304953cca76cSShri Abhyankar     PetscErrorCode    ierr;
3050*b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,jdx,idt;
3051*b3260449SShri Abhyankar     const PetscInt    bs = A->rmap->bs,bs2 = a->bs2;
305253cca76cSShri Abhyankar     const MatScalar   *aa=a->a,*v;
305353cca76cSShri Abhyankar     PetscScalar       *x;
305453cca76cSShri Abhyankar     const PetscScalar *b;
305553cca76cSShri Abhyankar     PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6;
305653cca76cSShri Abhyankar 
305753cca76cSShri Abhyankar     PetscFunctionBegin;
305853cca76cSShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
305953cca76cSShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
306053cca76cSShri Abhyankar     /* forward solve the lower triangular */
306153cca76cSShri Abhyankar     idx    = 0;
306253cca76cSShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx];
306353cca76cSShri Abhyankar     x[4] = b[4+idx];x[5] = b[5+idx];
306453cca76cSShri Abhyankar     for (i=1; i<n; i++) {
306553cca76cSShri Abhyankar        v    = aa + bs2*ai[i];
306653cca76cSShri Abhyankar        vi   = aj + ai[i];
306753cca76cSShri Abhyankar        nz   = ai[i+1] - ai[i];
306853cca76cSShri Abhyankar       idx   = bs*i;
306953cca76cSShri Abhyankar        s1   = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
307053cca76cSShri Abhyankar        s5   = b[4+idx];s6 = b[5+idx];
307153cca76cSShri Abhyankar        for(k=0;k<nz;k++){
307253cca76cSShri Abhyankar           jdx   = bs*vi[k];
307353cca76cSShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx];
307453cca76cSShri Abhyankar 	  x5    = x[4+jdx]; x6 = x[5+jdx];
307553cca76cSShri Abhyankar           s1   -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4  + v[24]*x5 + v[30]*x6;
307653cca76cSShri Abhyankar           s2   -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4  + v[25]*x5 + v[31]*x6;;
307753cca76cSShri Abhyankar           s3   -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4  + v[26]*x5 + v[32]*x6;
307853cca76cSShri Abhyankar 	  s4   -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4  + v[27]*x5 + v[33]*x6;
307953cca76cSShri Abhyankar           s5   -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4  + v[28]*x5 + v[34]*x6;
308053cca76cSShri Abhyankar 	  s6   -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4  + v[29]*x5 + v[35]*x6;
308153cca76cSShri Abhyankar           v   +=  bs2;
308253cca76cSShri Abhyankar         }
308353cca76cSShri Abhyankar 
308453cca76cSShri Abhyankar        x[idx]   = s1;
308553cca76cSShri Abhyankar        x[1+idx] = s2;
308653cca76cSShri Abhyankar        x[2+idx] = s3;
308753cca76cSShri Abhyankar        x[3+idx] = s4;
308853cca76cSShri Abhyankar        x[4+idx] = s5;
308953cca76cSShri Abhyankar        x[5+idx] = s6;
309053cca76cSShri Abhyankar     }
309153cca76cSShri Abhyankar 
309253cca76cSShri Abhyankar    /* backward solve the upper triangular */
309353cca76cSShri Abhyankar   for (i=n-1; i>=0; i--){
309453cca76cSShri Abhyankar     v   = aa + bs2*(adiag[i+1]+1);
309553cca76cSShri Abhyankar      vi  = aj + adiag[i+1]+1;
309653cca76cSShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
309753cca76cSShri Abhyankar      idt = bs*i;
309853cca76cSShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt];
309953cca76cSShri Abhyankar      s5 = x[4+idt];s6 = x[5+idt];
310053cca76cSShri Abhyankar      for(k=0;k<nz;k++){
310153cca76cSShri Abhyankar       idx   = bs*vi[k];
310253cca76cSShri Abhyankar        x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx];
310353cca76cSShri Abhyankar        x5    = x[4+idx];x6 = x[5+idx];
310453cca76cSShri Abhyankar        s1   -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4  + v[24]*x5 + v[30]*x6;
310553cca76cSShri Abhyankar        s2   -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4  + v[25]*x5 + v[31]*x6;;
310653cca76cSShri Abhyankar        s3   -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4  + v[26]*x5 + v[32]*x6;
310753cca76cSShri Abhyankar        s4   -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4  + v[27]*x5 + v[33]*x6;
310853cca76cSShri Abhyankar        s5   -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4  + v[28]*x5 + v[34]*x6;
310953cca76cSShri Abhyankar        s6   -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4  + v[29]*x5 + v[35]*x6;
311053cca76cSShri Abhyankar         v   +=  bs2;
311153cca76cSShri Abhyankar     }
311253cca76cSShri Abhyankar     /* x = inv_diagonal*x */
311353cca76cSShri Abhyankar    x[idt]   = v[0]*s1 + v[6]*s2 + v[12]*s3 + v[18]*s4 + v[24]*s5 + v[30]*s6;
311453cca76cSShri Abhyankar    x[1+idt] = v[1]*s1 + v[7]*s2 + v[13]*s3 + v[19]*s4 + v[25]*s5 + v[31]*s6;
311553cca76cSShri Abhyankar    x[2+idt] = v[2]*s1 + v[8]*s2 + v[14]*s3 + v[20]*s4 + v[26]*s5 + v[32]*s6;
311653cca76cSShri Abhyankar    x[3+idt] = v[3]*s1 + v[9]*s2 + v[15]*s3 + v[21]*s4 + v[27]*s5 + v[33]*s6;
311753cca76cSShri Abhyankar    x[4+idt] = v[4]*s1 + v[10]*s2 + v[16]*s3 + v[22]*s4 + v[28]*s5 + v[34]*s6;
311853cca76cSShri Abhyankar    x[5+idt] = v[5]*s1 + v[11]*s2 + v[17]*s3 + v[23]*s4 + v[29]*s5 + v[35]*s6;
311953cca76cSShri Abhyankar   }
312053cca76cSShri Abhyankar 
312153cca76cSShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
312253cca76cSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
312353cca76cSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
312453cca76cSShri Abhyankar   PetscFunctionReturn(0);
312553cca76cSShri Abhyankar }
312653cca76cSShri Abhyankar 
312753cca76cSShri Abhyankar #undef __FUNCT__
312806e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_5_inplace"
312906e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_5_inplace(Mat A,Vec bb,Vec xx)
31304e2b4712SSatish Balay {
31314e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
31324e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
31336849ba73SBarry Smith   PetscErrorCode    ierr;
31345d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout,*diag = a->diag;
3135*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
3136*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
3137d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3138d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*t;
3139d9fead3dSBarry Smith   const PetscScalar *b;
31404e2b4712SSatish Balay 
31414e2b4712SSatish Balay   PetscFunctionBegin;
3142d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
31431ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
3144f1af5d2fSBarry Smith   t  = a->solve_work;
31454e2b4712SSatish Balay 
31464e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
31474e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
31484e2b4712SSatish Balay 
31494e2b4712SSatish Balay   /* forward solve the lower triangular */
31504e2b4712SSatish Balay   idx    = 5*(*r++);
3151f1af5d2fSBarry Smith   t[0] = b[idx];   t[1] = b[1+idx];
3152f1af5d2fSBarry Smith   t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx];
31534e2b4712SSatish Balay   for (i=1; i<n; i++) {
31544e2b4712SSatish Balay     v     = aa + 25*ai[i];
31554e2b4712SSatish Balay     vi    = aj + ai[i];
31564e2b4712SSatish Balay     nz    = diag[i] - ai[i];
31574e2b4712SSatish Balay     idx   = 5*(*r++);
3158f1af5d2fSBarry Smith     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
3159f1af5d2fSBarry Smith     s5  = b[4+idx];
31604e2b4712SSatish Balay     while (nz--) {
31614e2b4712SSatish Balay       idx   = 5*(*vi++);
3162f1af5d2fSBarry Smith       x1    = t[idx];  x2 = t[1+idx];x3 = t[2+idx];
3163f1af5d2fSBarry Smith       x4    = t[3+idx];x5 = t[4+idx];
3164f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5;
3165f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5;
3166f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5;
3167f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5;
3168f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5;
31694e2b4712SSatish Balay       v += 25;
31704e2b4712SSatish Balay     }
31714e2b4712SSatish Balay     idx = 5*i;
3172f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
3173f1af5d2fSBarry Smith     t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
31744e2b4712SSatish Balay   }
31754e2b4712SSatish Balay   /* backward solve the upper triangular */
31764e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
31774e2b4712SSatish Balay     v    = aa + 25*diag[i] + 25;
31784e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
31794e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
31804e2b4712SSatish Balay     idt  = 5*i;
3181f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
3182f1af5d2fSBarry Smith     s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
31834e2b4712SSatish Balay     while (nz--) {
31844e2b4712SSatish Balay       idx   = 5*(*vi++);
3185f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx];
3186f1af5d2fSBarry Smith       x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
3187f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5;
3188f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5;
3189f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5;
3190f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5;
3191f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5;
31924e2b4712SSatish Balay       v += 25;
31934e2b4712SSatish Balay     }
31944e2b4712SSatish Balay     idc = 5*(*c--);
31954e2b4712SSatish Balay     v   = aa + 25*diag[i];
3196f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1+v[5]*s2+v[10]*s3+
3197f1af5d2fSBarry Smith                                  v[15]*s4+v[20]*s5;
3198f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1+v[6]*s2+v[11]*s3+
3199f1af5d2fSBarry Smith                                  v[16]*s4+v[21]*s5;
3200f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1+v[7]*s2+v[12]*s3+
3201f1af5d2fSBarry Smith                                  v[17]*s4+v[22]*s5;
3202f1af5d2fSBarry Smith     x[3+idc] = t[3+idt] = v[3]*s1+v[8]*s2+v[13]*s3+
3203f1af5d2fSBarry Smith                                  v[18]*s4+v[23]*s5;
3204f1af5d2fSBarry Smith     x[4+idc] = t[4+idt] = v[4]*s1+v[9]*s2+v[14]*s3+
3205f1af5d2fSBarry Smith                                  v[19]*s4+v[24]*s5;
32064e2b4712SSatish Balay   }
32074e2b4712SSatish Balay 
32084e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
32094e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
3210d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
32111ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3212dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
32134e2b4712SSatish Balay   PetscFunctionReturn(0);
32144e2b4712SSatish Balay }
32154e2b4712SSatish Balay 
321678bb4007SShri Abhyankar #undef __FUNCT__
32174dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_5"
32184dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_5(Mat A,Vec bb,Vec xx)
321978bb4007SShri Abhyankar {
322078bb4007SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
322178bb4007SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
322278bb4007SShri Abhyankar   PetscErrorCode    ierr;
322378bb4007SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
3224*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
3225*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
322678bb4007SShri Abhyankar   const MatScalar   *aa=a->a,*v;
322778bb4007SShri Abhyankar   PetscScalar       *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*t;
322878bb4007SShri Abhyankar   const PetscScalar *b;
322978bb4007SShri Abhyankar 
323078bb4007SShri Abhyankar   PetscFunctionBegin;
323178bb4007SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
323278bb4007SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
323378bb4007SShri Abhyankar   t  = a->solve_work;
323478bb4007SShri Abhyankar 
323578bb4007SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
323678bb4007SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
323778bb4007SShri Abhyankar 
323878bb4007SShri Abhyankar   /* forward solve the lower triangular */
323978bb4007SShri Abhyankar   idx    = 5*r[0];
324078bb4007SShri Abhyankar   t[0] = b[idx];   t[1] = b[1+idx];
324178bb4007SShri Abhyankar   t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx];
324278bb4007SShri Abhyankar   for (i=1; i<n; i++) {
324378bb4007SShri Abhyankar     v     = aa + 25*ai[i];
324478bb4007SShri Abhyankar     vi    = aj + ai[i];
324578bb4007SShri Abhyankar     nz    = ai[i+1] - ai[i];
324678bb4007SShri Abhyankar     idx   = 5*r[i];
324778bb4007SShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
324878bb4007SShri Abhyankar     s5  = b[4+idx];
324978bb4007SShri Abhyankar     for(m=0;m<nz;m++){
325078bb4007SShri Abhyankar       idx   = 5*vi[m];
325178bb4007SShri Abhyankar       x1    = t[idx];  x2 = t[1+idx];x3 = t[2+idx];
325278bb4007SShri Abhyankar       x4    = t[3+idx];x5 = t[4+idx];
325378bb4007SShri Abhyankar       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5;
325478bb4007SShri Abhyankar       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5;
325578bb4007SShri Abhyankar       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5;
325678bb4007SShri Abhyankar       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5;
325778bb4007SShri Abhyankar       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5;
325878bb4007SShri Abhyankar       v += 25;
325978bb4007SShri Abhyankar     }
326078bb4007SShri Abhyankar     idx = 5*i;
326178bb4007SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
326278bb4007SShri Abhyankar     t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
326378bb4007SShri Abhyankar   }
326478bb4007SShri Abhyankar   /* backward solve the upper triangular */
326578bb4007SShri Abhyankar   for (i=n-1; i>=0; i--){
326678bb4007SShri Abhyankar     v    = aa + 25*(adiag[i+1]+1);
326778bb4007SShri Abhyankar     vi   = aj + adiag[i+1]+1;
326878bb4007SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
326978bb4007SShri Abhyankar     idt  = 5*i;
327078bb4007SShri Abhyankar     s1 = t[idt];  s2 = t[1+idt];
327178bb4007SShri Abhyankar     s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
327278bb4007SShri Abhyankar     for(m=0;m<nz;m++){
327378bb4007SShri Abhyankar       idx   = 5*vi[m];
327478bb4007SShri Abhyankar       x1    = t[idx];   x2 = t[1+idx];
327578bb4007SShri Abhyankar       x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
327678bb4007SShri Abhyankar       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5;
327778bb4007SShri Abhyankar       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5;
327878bb4007SShri Abhyankar       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5;
327978bb4007SShri Abhyankar       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5;
328078bb4007SShri Abhyankar       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5;
328178bb4007SShri Abhyankar       v += 25;
328278bb4007SShri Abhyankar     }
328378bb4007SShri Abhyankar     idc = 5*c[i];
328478bb4007SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1+v[5]*s2+v[10]*s3+
328578bb4007SShri Abhyankar                                  v[15]*s4+v[20]*s5;
328678bb4007SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1+v[6]*s2+v[11]*s3+
328778bb4007SShri Abhyankar                                  v[16]*s4+v[21]*s5;
328878bb4007SShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1+v[7]*s2+v[12]*s3+
328978bb4007SShri Abhyankar                                  v[17]*s4+v[22]*s5;
329078bb4007SShri Abhyankar     x[3+idc] = t[3+idt] = v[3]*s1+v[8]*s2+v[13]*s3+
329178bb4007SShri Abhyankar                                  v[18]*s4+v[23]*s5;
329278bb4007SShri Abhyankar     x[4+idc] = t[4+idt] = v[4]*s1+v[9]*s2+v[14]*s3+
329378bb4007SShri Abhyankar                                  v[19]*s4+v[24]*s5;
329478bb4007SShri Abhyankar   }
329578bb4007SShri Abhyankar 
329678bb4007SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
329778bb4007SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
329878bb4007SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
329978bb4007SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
330078bb4007SShri Abhyankar   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
330178bb4007SShri Abhyankar   PetscFunctionReturn(0);
330278bb4007SShri Abhyankar }
330378bb4007SShri Abhyankar 
33048f690400SShri Abhyankar #undef __FUNCT__
330506e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_5_NaturalOrdering_inplace"
330606e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_5_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
330715091d37SBarry Smith {
330815091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3309*b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
3310*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,jdx;
3311dfbe8321SBarry Smith   PetscErrorCode    ierr;
3312d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3313d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5;
3314d9fead3dSBarry Smith   const PetscScalar *b;
331515091d37SBarry Smith 
331615091d37SBarry Smith   PetscFunctionBegin;
3317d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
33181ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
331915091d37SBarry Smith   /* forward solve the lower triangular */
332015091d37SBarry Smith   idx    = 0;
332115091d37SBarry 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];
332215091d37SBarry Smith   for (i=1; i<n; i++) {
332315091d37SBarry Smith     v     =  aa + 25*ai[i];
332415091d37SBarry Smith     vi    =  aj + ai[i];
332515091d37SBarry Smith     nz    =  diag[i] - ai[i];
332615091d37SBarry Smith     idx   =  5*i;
3327f1af5d2fSBarry Smith     s1  =  b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];s5 = b[4+idx];
332815091d37SBarry Smith     while (nz--) {
332915091d37SBarry Smith       jdx   = 5*(*vi++);
333015091d37SBarry Smith       x1    = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx];x5 = x[4+jdx];
3331f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3  + v[15]*x4 + v[20]*x5;
3332f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3  + v[16]*x4 + v[21]*x5;
3333f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3  + v[17]*x4 + v[22]*x5;
3334f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3  + v[18]*x4 + v[23]*x5;
3335f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3  + v[19]*x4 + v[24]*x5;
333615091d37SBarry Smith       v    += 25;
333715091d37SBarry Smith     }
3338f1af5d2fSBarry Smith     x[idx]   = s1;
3339f1af5d2fSBarry Smith     x[1+idx] = s2;
3340f1af5d2fSBarry Smith     x[2+idx] = s3;
3341f1af5d2fSBarry Smith     x[3+idx] = s4;
3342f1af5d2fSBarry Smith     x[4+idx] = s5;
334315091d37SBarry Smith   }
334415091d37SBarry Smith   /* backward solve the upper triangular */
334515091d37SBarry Smith   for (i=n-1; i>=0; i--){
334615091d37SBarry Smith     v    = aa + 25*diag[i] + 25;
334715091d37SBarry Smith     vi   = aj + diag[i] + 1;
334815091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
334915091d37SBarry Smith     idt  = 5*i;
3350f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt];
3351f1af5d2fSBarry Smith     s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt];
335215091d37SBarry Smith     while (nz--) {
335315091d37SBarry Smith       idx   = 5*(*vi++);
335415091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx];x3    = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx];
3355f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3  + v[15]*x4 + v[20]*x5;
3356f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3  + v[16]*x4 + v[21]*x5;
3357f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3  + v[17]*x4 + v[22]*x5;
3358f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3  + v[18]*x4 + v[23]*x5;
3359f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3  + v[19]*x4 + v[24]*x5;
336015091d37SBarry Smith       v    += 25;
336115091d37SBarry Smith     }
336215091d37SBarry Smith     v        = aa + 25*diag[i];
3363f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[5]*s2 + v[10]*s3  + v[15]*s4 + v[20]*s5;
3364f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[6]*s2 + v[11]*s3  + v[16]*s4 + v[21]*s5;
3365f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[7]*s2 + v[12]*s3  + v[17]*s4 + v[22]*s5;
3366f1af5d2fSBarry Smith     x[3+idt] = v[3]*s1 + v[8]*s2 + v[13]*s3  + v[18]*s4 + v[23]*s5;
3367f1af5d2fSBarry Smith     x[4+idt] = v[4]*s1 + v[9]*s2 + v[14]*s3  + v[19]*s4 + v[24]*s5;
336815091d37SBarry Smith   }
336915091d37SBarry Smith 
3370d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
33711ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3372dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
337315091d37SBarry Smith   PetscFunctionReturn(0);
337415091d37SBarry Smith }
337515091d37SBarry Smith 
3376cee9d6f2SShri Abhyankar #undef __FUNCT__
33774dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_5_NaturalOrdering"
33784dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_5_NaturalOrdering(Mat A,Vec bb,Vec xx)
337953cca76cSShri Abhyankar {
338053cca76cSShri Abhyankar   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3381*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
3382*b3260449SShri Abhyankar   PetscInt          i,k,nz,idx,idt,jdx;
338353cca76cSShri Abhyankar   PetscErrorCode    ierr;
338453cca76cSShri Abhyankar   const MatScalar   *aa=a->a,*v;
338553cca76cSShri Abhyankar   PetscScalar       *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5;
338653cca76cSShri Abhyankar   const PetscScalar *b;
338753cca76cSShri Abhyankar 
338853cca76cSShri Abhyankar   PetscFunctionBegin;
338953cca76cSShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
339053cca76cSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
339153cca76cSShri Abhyankar   /* forward solve the lower triangular */
339253cca76cSShri Abhyankar   idx    = 0;
339353cca76cSShri 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];
339453cca76cSShri Abhyankar   for (i=1; i<n; i++) {
339553cca76cSShri Abhyankar     v   = aa + 25*ai[i];
339653cca76cSShri Abhyankar     vi  = aj + ai[i];
339753cca76cSShri Abhyankar     nz  = ai[i+1] - ai[i];
339853cca76cSShri Abhyankar     idx = 5*i;
339953cca76cSShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];s5 = b[4+idx];
340053cca76cSShri Abhyankar     for(k=0;k<nz;k++) {
340153cca76cSShri Abhyankar       jdx   = 5*vi[k];
340253cca76cSShri Abhyankar       x1    = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx];x5 = x[4+jdx];
340353cca76cSShri Abhyankar       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3  + v[15]*x4 + v[20]*x5;
340453cca76cSShri Abhyankar       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3  + v[16]*x4 + v[21]*x5;
340553cca76cSShri Abhyankar       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3  + v[17]*x4 + v[22]*x5;
340653cca76cSShri Abhyankar       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3  + v[18]*x4 + v[23]*x5;
340753cca76cSShri Abhyankar       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3  + v[19]*x4 + v[24]*x5;
340853cca76cSShri Abhyankar       v    += 25;
340953cca76cSShri Abhyankar     }
341053cca76cSShri Abhyankar     x[idx]   = s1;
341153cca76cSShri Abhyankar     x[1+idx] = s2;
341253cca76cSShri Abhyankar     x[2+idx] = s3;
341353cca76cSShri Abhyankar     x[3+idx] = s4;
341453cca76cSShri Abhyankar     x[4+idx] = s5;
341553cca76cSShri Abhyankar   }
341653cca76cSShri Abhyankar 
341753cca76cSShri Abhyankar   /* backward solve the upper triangular */
341853cca76cSShri Abhyankar   for (i=n-1; i>=0; i--){
341953cca76cSShri Abhyankar     v   = aa + 25*(adiag[i+1]+1);
342053cca76cSShri Abhyankar     vi  = aj + adiag[i+1]+1;
342153cca76cSShri Abhyankar     nz  = adiag[i] - adiag[i+1]-1;
342253cca76cSShri Abhyankar     idt = 5*i;
342353cca76cSShri Abhyankar     s1 = x[idt];  s2 = x[1+idt];
342453cca76cSShri Abhyankar     s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt];
342553cca76cSShri Abhyankar     for(k=0;k<nz;k++){
342653cca76cSShri Abhyankar       idx   = 5*vi[k];
342753cca76cSShri Abhyankar       x1    = x[idx];   x2 = x[1+idx];x3    = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx];
342853cca76cSShri Abhyankar       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3  + v[15]*x4 + v[20]*x5;
342953cca76cSShri Abhyankar       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3  + v[16]*x4 + v[21]*x5;
343053cca76cSShri Abhyankar       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3  + v[17]*x4 + v[22]*x5;
343153cca76cSShri Abhyankar       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3  + v[18]*x4 + v[23]*x5;
343253cca76cSShri Abhyankar       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3  + v[19]*x4 + v[24]*x5;
343353cca76cSShri Abhyankar       v    += 25;
343453cca76cSShri Abhyankar     }
343553cca76cSShri Abhyankar     /* x = inv_diagonal*x */
343653cca76cSShri Abhyankar     x[idt]   = v[0]*s1 + v[5]*s2 + v[10]*s3  + v[15]*s4 + v[20]*s5;
343753cca76cSShri Abhyankar     x[1+idt] = v[1]*s1 + v[6]*s2 + v[11]*s3  + v[16]*s4 + v[21]*s5;
343853cca76cSShri Abhyankar     x[2+idt] = v[2]*s1 + v[7]*s2 + v[12]*s3  + v[17]*s4 + v[22]*s5;
343953cca76cSShri Abhyankar     x[3+idt] = v[3]*s1 + v[8]*s2 + v[13]*s3  + v[18]*s4 + v[23]*s5;
344053cca76cSShri Abhyankar     x[4+idt] = v[4]*s1 + v[9]*s2 + v[14]*s3  + v[19]*s4 + v[24]*s5;
344153cca76cSShri Abhyankar   }
344253cca76cSShri Abhyankar 
344353cca76cSShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
344453cca76cSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
344553cca76cSShri Abhyankar   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
344653cca76cSShri Abhyankar   PetscFunctionReturn(0);
344753cca76cSShri Abhyankar }
344853cca76cSShri Abhyankar 
344953cca76cSShri Abhyankar #undef __FUNCT__
345006e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_4_inplace"
345106e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_4_inplace(Mat A,Vec bb,Vec xx)
34524e2b4712SSatish Balay {
34534e2b4712SSatish Balay   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
34544e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
34556849ba73SBarry Smith   PetscErrorCode    ierr;
3456*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
3457*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
34585d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
3459d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3460d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,x1,x2,x3,x4,*t;
3461d9fead3dSBarry Smith   const PetscScalar *b;
34624e2b4712SSatish Balay 
34634e2b4712SSatish Balay   PetscFunctionBegin;
3464d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
34651ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
3466f1af5d2fSBarry Smith   t  = a->solve_work;
34674e2b4712SSatish Balay 
34684e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
34694e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
34704e2b4712SSatish Balay 
34714e2b4712SSatish Balay   /* forward solve the lower triangular */
34724e2b4712SSatish Balay   idx    = 4*(*r++);
3473f1af5d2fSBarry Smith   t[0] = b[idx];   t[1] = b[1+idx];
3474f1af5d2fSBarry Smith   t[2] = b[2+idx]; t[3] = b[3+idx];
34754e2b4712SSatish Balay   for (i=1; i<n; i++) {
34764e2b4712SSatish Balay     v     = aa + 16*ai[i];
34774e2b4712SSatish Balay     vi    = aj + ai[i];
34784e2b4712SSatish Balay     nz    = diag[i] - ai[i];
34794e2b4712SSatish Balay     idx   = 4*(*r++);
3480f1af5d2fSBarry Smith     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
34814e2b4712SSatish Balay     while (nz--) {
34824e2b4712SSatish Balay       idx   = 4*(*vi++);
3483f1af5d2fSBarry Smith       x1    = t[idx];x2 = t[1+idx];x3 = t[2+idx];x4 = t[3+idx];
3484f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
3485f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
3486f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
3487f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
34884e2b4712SSatish Balay       v    += 16;
34894e2b4712SSatish Balay     }
34904e2b4712SSatish Balay     idx        = 4*i;
3491f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
3492f1af5d2fSBarry Smith     t[2+idx] = s3;t[3+idx] = s4;
34934e2b4712SSatish Balay   }
34944e2b4712SSatish Balay   /* backward solve the upper triangular */
34954e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
34964e2b4712SSatish Balay     v    = aa + 16*diag[i] + 16;
34974e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
34984e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
34994e2b4712SSatish Balay     idt  = 4*i;
3500f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
3501f1af5d2fSBarry Smith     s3 = t[2+idt];s4 = t[3+idt];
35024e2b4712SSatish Balay     while (nz--) {
35034e2b4712SSatish Balay       idx   = 4*(*vi++);
3504f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx];
3505f1af5d2fSBarry Smith       x3    = t[2+idx]; x4 = t[3+idx];
3506f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3   + v[12]*x4;
3507f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3   + v[13]*x4;
3508f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3  + v[14]*x4;
3509f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3  + v[15]*x4;
35104e2b4712SSatish Balay       v += 16;
35114e2b4712SSatish Balay     }
35124e2b4712SSatish Balay     idc      = 4*(*c--);
35134e2b4712SSatish Balay     v        = aa + 16*diag[i];
3514f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4;
3515f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4;
3516f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4;
3517f1af5d2fSBarry Smith     x[3+idc] = t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4;
35184e2b4712SSatish Balay   }
35194e2b4712SSatish Balay 
35204e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
35214e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
3522d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
35231ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3524dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
35254e2b4712SSatish Balay   PetscFunctionReturn(0);
35264e2b4712SSatish Balay }
3527f26ec98cSKris Buschelman 
35288f690400SShri Abhyankar #undef __FUNCT__
35294dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_4"
35304dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_4(Mat A,Vec bb,Vec xx)
353178bb4007SShri Abhyankar {
353278bb4007SShri Abhyankar   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
353378bb4007SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
353478bb4007SShri Abhyankar   PetscErrorCode    ierr;
3535*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
3536*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
353778bb4007SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
353878bb4007SShri Abhyankar   const MatScalar   *aa=a->a,*v;
353978bb4007SShri Abhyankar   PetscScalar       *x,s1,s2,s3,s4,x1,x2,x3,x4,*t;
354078bb4007SShri Abhyankar   const PetscScalar *b;
354178bb4007SShri Abhyankar 
354278bb4007SShri Abhyankar   PetscFunctionBegin;
354378bb4007SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
354478bb4007SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
354578bb4007SShri Abhyankar   t  = a->solve_work;
354678bb4007SShri Abhyankar 
354778bb4007SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
354878bb4007SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
354978bb4007SShri Abhyankar 
355078bb4007SShri Abhyankar   /* forward solve the lower triangular */
355178bb4007SShri Abhyankar   idx    = 4*r[0];
355278bb4007SShri Abhyankar   t[0] = b[idx];   t[1] = b[1+idx];
355378bb4007SShri Abhyankar   t[2] = b[2+idx]; t[3] = b[3+idx];
355478bb4007SShri Abhyankar   for (i=1; i<n; i++) {
355578bb4007SShri Abhyankar     v     = aa + 16*ai[i];
355678bb4007SShri Abhyankar     vi    = aj + ai[i];
355778bb4007SShri Abhyankar     nz    = ai[i+1] - ai[i];
355878bb4007SShri Abhyankar     idx   = 4*r[i];
355978bb4007SShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
356078bb4007SShri Abhyankar     for(m=0;m<nz;m++){
356178bb4007SShri Abhyankar       idx   = 4*vi[m];
356278bb4007SShri Abhyankar       x1    = t[idx];x2 = t[1+idx];x3 = t[2+idx];x4 = t[3+idx];
356378bb4007SShri Abhyankar       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
356478bb4007SShri Abhyankar       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
356578bb4007SShri Abhyankar       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
356678bb4007SShri Abhyankar       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
356778bb4007SShri Abhyankar       v    += 16;
356878bb4007SShri Abhyankar     }
356978bb4007SShri Abhyankar     idx        = 4*i;
357078bb4007SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
357178bb4007SShri Abhyankar     t[2+idx] = s3;t[3+idx] = s4;
357278bb4007SShri Abhyankar   }
357378bb4007SShri Abhyankar   /* backward solve the upper triangular */
357478bb4007SShri Abhyankar   for (i=n-1; i>=0; i--){
357578bb4007SShri Abhyankar     v    = aa + 16*(adiag[i+1]+1);
357678bb4007SShri Abhyankar     vi   = aj + adiag[i+1]+1;
357778bb4007SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
357878bb4007SShri Abhyankar     idt  = 4*i;
357978bb4007SShri Abhyankar     s1 = t[idt];  s2 = t[1+idt];
358078bb4007SShri Abhyankar     s3 = t[2+idt];s4 = t[3+idt];
358178bb4007SShri Abhyankar     for(m=0;m<nz;m++){
358278bb4007SShri Abhyankar       idx   = 4*vi[m];
358378bb4007SShri Abhyankar       x1    = t[idx];   x2 = t[1+idx];
358478bb4007SShri Abhyankar       x3    = t[2+idx]; x4 = t[3+idx];
358578bb4007SShri Abhyankar       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3   + v[12]*x4;
358678bb4007SShri Abhyankar       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3   + v[13]*x4;
358778bb4007SShri Abhyankar       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3  + v[14]*x4;
358878bb4007SShri Abhyankar       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3  + v[15]*x4;
358978bb4007SShri Abhyankar       v += 16;
359078bb4007SShri Abhyankar     }
359178bb4007SShri Abhyankar     idc      = 4*c[i];
359278bb4007SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4;
359378bb4007SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4;
359478bb4007SShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4;
359578bb4007SShri Abhyankar     x[3+idc] = t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4;
359678bb4007SShri Abhyankar   }
359778bb4007SShri Abhyankar 
359878bb4007SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
359978bb4007SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
360078bb4007SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
360178bb4007SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
360278bb4007SShri Abhyankar   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
360378bb4007SShri Abhyankar   PetscFunctionReturn(0);
360478bb4007SShri Abhyankar }
360578bb4007SShri Abhyankar 
360678bb4007SShri Abhyankar #undef __FUNCT__
3607f26ec98cSKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_Demotion"
3608dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_Demotion(Mat A,Vec bb,Vec xx)
3609f26ec98cSKris Buschelman {
3610f26ec98cSKris Buschelman   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3611f26ec98cSKris Buschelman   IS                iscol=a->col,isrow=a->row;
36126849ba73SBarry Smith   PetscErrorCode    ierr;
3613*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
3614*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
36155d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
3616d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3617d9fead3dSBarry Smith   MatScalar         s1,s2,s3,s4,x1,x2,x3,x4,*t;
3618d9fead3dSBarry Smith   PetscScalar       *x;
3619d9fead3dSBarry Smith   const PetscScalar *b;
3620f26ec98cSKris Buschelman 
3621f26ec98cSKris Buschelman   PetscFunctionBegin;
3622d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
36231ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
3624f26ec98cSKris Buschelman   t  = (MatScalar *)a->solve_work;
3625f26ec98cSKris Buschelman 
3626f26ec98cSKris Buschelman   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
3627f26ec98cSKris Buschelman   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
3628f26ec98cSKris Buschelman 
3629f26ec98cSKris Buschelman   /* forward solve the lower triangular */
3630f26ec98cSKris Buschelman   idx    = 4*(*r++);
3631f26ec98cSKris Buschelman   t[0] = (MatScalar)b[idx];
3632f26ec98cSKris Buschelman   t[1] = (MatScalar)b[1+idx];
3633f26ec98cSKris Buschelman   t[2] = (MatScalar)b[2+idx];
3634f26ec98cSKris Buschelman   t[3] = (MatScalar)b[3+idx];
3635f26ec98cSKris Buschelman   for (i=1; i<n; i++) {
3636f26ec98cSKris Buschelman     v     = aa + 16*ai[i];
3637f26ec98cSKris Buschelman     vi    = aj + ai[i];
3638f26ec98cSKris Buschelman     nz    = diag[i] - ai[i];
3639f26ec98cSKris Buschelman     idx   = 4*(*r++);
3640f26ec98cSKris Buschelman     s1 = (MatScalar)b[idx];
3641f26ec98cSKris Buschelman     s2 = (MatScalar)b[1+idx];
3642f26ec98cSKris Buschelman     s3 = (MatScalar)b[2+idx];
3643f26ec98cSKris Buschelman     s4 = (MatScalar)b[3+idx];
3644f26ec98cSKris Buschelman     while (nz--) {
3645f26ec98cSKris Buschelman       idx   = 4*(*vi++);
3646f26ec98cSKris Buschelman       x1  = t[idx];
3647f26ec98cSKris Buschelman       x2  = t[1+idx];
3648f26ec98cSKris Buschelman       x3  = t[2+idx];
3649f26ec98cSKris Buschelman       x4  = t[3+idx];
3650f26ec98cSKris Buschelman       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
3651f26ec98cSKris Buschelman       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
3652f26ec98cSKris Buschelman       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
3653f26ec98cSKris Buschelman       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
3654f26ec98cSKris Buschelman       v    += 16;
3655f26ec98cSKris Buschelman     }
3656f26ec98cSKris Buschelman     idx        = 4*i;
3657f26ec98cSKris Buschelman     t[idx]   = s1;
3658f26ec98cSKris Buschelman     t[1+idx] = s2;
3659f26ec98cSKris Buschelman     t[2+idx] = s3;
3660f26ec98cSKris Buschelman     t[3+idx] = s4;
3661f26ec98cSKris Buschelman   }
3662f26ec98cSKris Buschelman   /* backward solve the upper triangular */
3663f26ec98cSKris Buschelman   for (i=n-1; i>=0; i--){
3664f26ec98cSKris Buschelman     v    = aa + 16*diag[i] + 16;
3665f26ec98cSKris Buschelman     vi   = aj + diag[i] + 1;
3666f26ec98cSKris Buschelman     nz   = ai[i+1] - diag[i] - 1;
3667f26ec98cSKris Buschelman     idt  = 4*i;
3668f26ec98cSKris Buschelman     s1 = t[idt];
3669f26ec98cSKris Buschelman     s2 = t[1+idt];
3670f26ec98cSKris Buschelman     s3 = t[2+idt];
3671f26ec98cSKris Buschelman     s4 = t[3+idt];
3672f26ec98cSKris Buschelman     while (nz--) {
3673f26ec98cSKris Buschelman       idx   = 4*(*vi++);
3674f26ec98cSKris Buschelman       x1  = t[idx];
3675f26ec98cSKris Buschelman       x2  = t[1+idx];
3676f26ec98cSKris Buschelman       x3  = t[2+idx];
3677f26ec98cSKris Buschelman       x4  = t[3+idx];
3678f26ec98cSKris Buschelman       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3   + v[12]*x4;
3679f26ec98cSKris Buschelman       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3   + v[13]*x4;
3680f26ec98cSKris Buschelman       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3  + v[14]*x4;
3681f26ec98cSKris Buschelman       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3  + v[15]*x4;
3682f26ec98cSKris Buschelman       v += 16;
3683f26ec98cSKris Buschelman     }
3684f26ec98cSKris Buschelman     idc      = 4*(*c--);
3685f26ec98cSKris Buschelman     v        = aa + 16*diag[i];
3686f26ec98cSKris Buschelman     t[idt]   = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4;
3687f26ec98cSKris Buschelman     t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4;
3688f26ec98cSKris Buschelman     t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4;
3689f26ec98cSKris Buschelman     t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4;
3690f26ec98cSKris Buschelman     x[idc]   = (PetscScalar)t[idt];
3691f26ec98cSKris Buschelman     x[1+idc] = (PetscScalar)t[1+idt];
3692f26ec98cSKris Buschelman     x[2+idc] = (PetscScalar)t[2+idt];
3693f26ec98cSKris Buschelman     x[3+idc] = (PetscScalar)t[3+idt];
3694f26ec98cSKris Buschelman  }
3695f26ec98cSKris Buschelman 
3696f26ec98cSKris Buschelman   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
3697f26ec98cSKris Buschelman   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
3698d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
36991ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3700dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
3701f26ec98cSKris Buschelman   PetscFunctionReturn(0);
3702f26ec98cSKris Buschelman }
3703f26ec98cSKris Buschelman 
370424c233c2SKris Buschelman #if defined (PETSC_HAVE_SSE)
370524c233c2SKris Buschelman 
370624c233c2SKris Buschelman #include PETSC_HAVE_SSE
370724c233c2SKris Buschelman 
370824c233c2SKris Buschelman #undef __FUNCT__
370924c233c2SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_SSE_Demotion"
3710dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_SSE_Demotion(Mat A,Vec bb,Vec xx)
371124c233c2SKris Buschelman {
371224c233c2SKris Buschelman   /*
371324c233c2SKris Buschelman      Note: This code uses demotion of double
371424c233c2SKris Buschelman      to float when performing the mixed-mode computation.
371524c233c2SKris Buschelman      This may not be numerically reasonable for all applications.
371624c233c2SKris Buschelman   */
371724c233c2SKris Buschelman   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ *)A->data;
371824c233c2SKris Buschelman   IS             iscol=a->col,isrow=a->row;
37196849ba73SBarry Smith   PetscErrorCode ierr;
37205d0c19d7SBarry Smith   PetscInt       i,n=a->mbs,*vi,*ai=a->i,*aj=a->j,nz,idx,idt,idc,ai16;
37215d0c19d7SBarry Smith   const PetscInt *r,*c,*diag = a->diag,*rout,*cout;
372224c233c2SKris Buschelman   MatScalar      *aa=a->a,*v;
372387828ca2SBarry Smith   PetscScalar    *x,*b,*t;
372424c233c2SKris Buschelman 
372524c233c2SKris Buschelman   /* Make space in temp stack for 16 Byte Aligned arrays */
372624c233c2SKris Buschelman   float           ssealignedspace[11],*tmps,*tmpx;
372724c233c2SKris Buschelman   unsigned long   offset;
372824c233c2SKris Buschelman 
372924c233c2SKris Buschelman   PetscFunctionBegin;
373024c233c2SKris Buschelman   SSE_SCOPE_BEGIN;
373124c233c2SKris Buschelman 
373224c233c2SKris Buschelman     offset = (unsigned long)ssealignedspace % 16;
373324c233c2SKris Buschelman     if (offset) offset = (16 - offset)/4;
373424c233c2SKris Buschelman     tmps = &ssealignedspace[offset];
373524c233c2SKris Buschelman     tmpx = &ssealignedspace[offset+4];
373624c233c2SKris Buschelman     PREFETCH_NTA(aa+16*ai[1]);
373724c233c2SKris Buschelman 
37381ebc52fbSHong Zhang     ierr = VecGetArray(bb,&b);CHKERRQ(ierr);
37391ebc52fbSHong Zhang     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
374024c233c2SKris Buschelman     t  = a->solve_work;
374124c233c2SKris Buschelman 
374224c233c2SKris Buschelman     ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
374324c233c2SKris Buschelman     ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
374424c233c2SKris Buschelman 
374524c233c2SKris Buschelman     /* forward solve the lower triangular */
374624c233c2SKris Buschelman     idx  = 4*(*r++);
374724c233c2SKris Buschelman     t[0] = b[idx];   t[1] = b[1+idx];
374824c233c2SKris Buschelman     t[2] = b[2+idx]; t[3] = b[3+idx];
374924c233c2SKris Buschelman     v    =  aa + 16*ai[1];
375024c233c2SKris Buschelman 
375124c233c2SKris Buschelman     for (i=1; i<n;) {
375224c233c2SKris Buschelman       PREFETCH_NTA(&v[8]);
375324c233c2SKris Buschelman       vi   =  aj      + ai[i];
375424c233c2SKris Buschelman       nz   =  diag[i] - ai[i];
375524c233c2SKris Buschelman       idx  =  4*(*r++);
375624c233c2SKris Buschelman 
375724c233c2SKris Buschelman       /* Demote sum from double to float */
375824c233c2SKris Buschelman       CONVERT_DOUBLE4_FLOAT4(tmps,&b[idx]);
375924c233c2SKris Buschelman       LOAD_PS(tmps,XMM7);
376024c233c2SKris Buschelman 
376124c233c2SKris Buschelman       while (nz--) {
376224c233c2SKris Buschelman         PREFETCH_NTA(&v[16]);
376324c233c2SKris Buschelman         idx = 4*(*vi++);
376424c233c2SKris Buschelman 
376524c233c2SKris Buschelman         /* Demote solution (so far) from double to float */
376624c233c2SKris Buschelman         CONVERT_DOUBLE4_FLOAT4(tmpx,&x[idx]);
376724c233c2SKris Buschelman 
376824c233c2SKris Buschelman         /* 4x4 Matrix-Vector product with negative accumulation: */
376924c233c2SKris Buschelman         SSE_INLINE_BEGIN_2(tmpx,v)
377024c233c2SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
377124c233c2SKris Buschelman 
377224c233c2SKris Buschelman           /* First Column */
377324c233c2SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
377424c233c2SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
377524c233c2SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
377624c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
377724c233c2SKris Buschelman 
377824c233c2SKris Buschelman           /* Second Column */
377924c233c2SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
378024c233c2SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
378124c233c2SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
378224c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
378324c233c2SKris Buschelman 
378424c233c2SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
378524c233c2SKris Buschelman 
378624c233c2SKris Buschelman           /* Third Column */
378724c233c2SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
378824c233c2SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
378924c233c2SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
379024c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
379124c233c2SKris Buschelman 
379224c233c2SKris Buschelman           /* Fourth Column */
379324c233c2SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
379424c233c2SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
379524c233c2SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
379624c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
379724c233c2SKris Buschelman         SSE_INLINE_END_2
379824c233c2SKris Buschelman 
379924c233c2SKris Buschelman         v  += 16;
380024c233c2SKris Buschelman       }
380124c233c2SKris Buschelman       idx = 4*i;
380224c233c2SKris Buschelman       v   = aa + 16*ai[++i];
380324c233c2SKris Buschelman       PREFETCH_NTA(v);
380424c233c2SKris Buschelman       STORE_PS(tmps,XMM7);
380524c233c2SKris Buschelman 
380624c233c2SKris Buschelman       /* Promote result from float to double */
380724c233c2SKris Buschelman       CONVERT_FLOAT4_DOUBLE4(&t[idx],tmps);
380824c233c2SKris Buschelman     }
380924c233c2SKris Buschelman     /* backward solve the upper triangular */
381024c233c2SKris Buschelman     idt  = 4*(n-1);
381124c233c2SKris Buschelman     ai16 = 16*diag[n-1];
381224c233c2SKris Buschelman     v    = aa + ai16 + 16;
381324c233c2SKris Buschelman     for (i=n-1; i>=0;){
381424c233c2SKris Buschelman       PREFETCH_NTA(&v[8]);
381524c233c2SKris Buschelman       vi = aj + diag[i] + 1;
381624c233c2SKris Buschelman       nz = ai[i+1] - diag[i] - 1;
381724c233c2SKris Buschelman 
381824c233c2SKris Buschelman       /* Demote accumulator from double to float */
381924c233c2SKris Buschelman       CONVERT_DOUBLE4_FLOAT4(tmps,&t[idt]);
382024c233c2SKris Buschelman       LOAD_PS(tmps,XMM7);
382124c233c2SKris Buschelman 
382224c233c2SKris Buschelman       while (nz--) {
382324c233c2SKris Buschelman         PREFETCH_NTA(&v[16]);
382424c233c2SKris Buschelman         idx = 4*(*vi++);
382524c233c2SKris Buschelman 
382624c233c2SKris Buschelman         /* Demote solution (so far) from double to float */
382724c233c2SKris Buschelman         CONVERT_DOUBLE4_FLOAT4(tmpx,&t[idx]);
382824c233c2SKris Buschelman 
382924c233c2SKris Buschelman         /* 4x4 Matrix-Vector Product with negative accumulation: */
383024c233c2SKris Buschelman         SSE_INLINE_BEGIN_2(tmpx,v)
383124c233c2SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
383224c233c2SKris Buschelman 
383324c233c2SKris Buschelman           /* First Column */
383424c233c2SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
383524c233c2SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
383624c233c2SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
383724c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
383824c233c2SKris Buschelman 
383924c233c2SKris Buschelman           /* Second Column */
384024c233c2SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
384124c233c2SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
384224c233c2SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
384324c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
384424c233c2SKris Buschelman 
384524c233c2SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
384624c233c2SKris Buschelman 
384724c233c2SKris Buschelman           /* Third Column */
384824c233c2SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
384924c233c2SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
385024c233c2SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
385124c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
385224c233c2SKris Buschelman 
385324c233c2SKris Buschelman           /* Fourth Column */
385424c233c2SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
385524c233c2SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
385624c233c2SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
385724c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
385824c233c2SKris Buschelman         SSE_INLINE_END_2
385924c233c2SKris Buschelman         v  += 16;
386024c233c2SKris Buschelman       }
386124c233c2SKris Buschelman       v    = aa + ai16;
386224c233c2SKris Buschelman       ai16 = 16*diag[--i];
386324c233c2SKris Buschelman       PREFETCH_NTA(aa+ai16+16);
386424c233c2SKris Buschelman       /*
386524c233c2SKris Buschelman          Scale the result by the diagonal 4x4 block,
386624c233c2SKris Buschelman          which was inverted as part of the factorization
386724c233c2SKris Buschelman       */
386824c233c2SKris Buschelman       SSE_INLINE_BEGIN_3(v,tmps,aa+ai16)
386924c233c2SKris Buschelman         /* First Column */
387024c233c2SKris Buschelman         SSE_COPY_PS(XMM0,XMM7)
387124c233c2SKris Buschelman         SSE_SHUFFLE(XMM0,XMM0,0x00)
387224c233c2SKris Buschelman         SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0)
387324c233c2SKris Buschelman 
387424c233c2SKris Buschelman         /* Second Column */
387524c233c2SKris Buschelman         SSE_COPY_PS(XMM1,XMM7)
387624c233c2SKris Buschelman         SSE_SHUFFLE(XMM1,XMM1,0x55)
387724c233c2SKris Buschelman         SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4)
387824c233c2SKris Buschelman         SSE_ADD_PS(XMM0,XMM1)
387924c233c2SKris Buschelman 
388024c233c2SKris Buschelman         SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24)
388124c233c2SKris Buschelman 
388224c233c2SKris Buschelman         /* Third Column */
388324c233c2SKris Buschelman         SSE_COPY_PS(XMM2,XMM7)
388424c233c2SKris Buschelman         SSE_SHUFFLE(XMM2,XMM2,0xAA)
388524c233c2SKris Buschelman         SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8)
388624c233c2SKris Buschelman         SSE_ADD_PS(XMM0,XMM2)
388724c233c2SKris Buschelman 
388824c233c2SKris Buschelman         /* Fourth Column */
388924c233c2SKris Buschelman         SSE_COPY_PS(XMM3,XMM7)
389024c233c2SKris Buschelman         SSE_SHUFFLE(XMM3,XMM3,0xFF)
389124c233c2SKris Buschelman         SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12)
389224c233c2SKris Buschelman         SSE_ADD_PS(XMM0,XMM3)
389324c233c2SKris Buschelman 
389424c233c2SKris Buschelman         SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0)
389524c233c2SKris Buschelman       SSE_INLINE_END_3
389624c233c2SKris Buschelman 
389724c233c2SKris Buschelman       /* Promote solution from float to double */
389824c233c2SKris Buschelman       CONVERT_FLOAT4_DOUBLE4(&t[idt],tmps);
389924c233c2SKris Buschelman 
390024c233c2SKris Buschelman       /* Apply reordering to t and stream into x.    */
390124c233c2SKris Buschelman       /* This way, x doesn't pollute the cache.      */
390224c233c2SKris Buschelman       /* Be careful with size: 2 doubles = 4 floats! */
390324c233c2SKris Buschelman       idc  = 4*(*c--);
390424c233c2SKris Buschelman       SSE_INLINE_BEGIN_2((float *)&t[idt],(float *)&x[idc])
390524c233c2SKris Buschelman         /*  x[idc]   = t[idt];   x[1+idc] = t[1+idc]; */
390624c233c2SKris Buschelman         SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM0)
390724c233c2SKris Buschelman         SSE_STREAM_PS(SSE_ARG_2,FLOAT_0,XMM0)
390824c233c2SKris Buschelman         /*  x[idc+2] = t[idt+2]; x[3+idc] = t[3+idc]; */
390924c233c2SKris Buschelman         SSE_LOAD_PS(SSE_ARG_1,FLOAT_4,XMM1)
391024c233c2SKris Buschelman         SSE_STREAM_PS(SSE_ARG_2,FLOAT_4,XMM1)
391124c233c2SKris Buschelman       SSE_INLINE_END_2
391224c233c2SKris Buschelman       v    = aa + ai16 + 16;
391324c233c2SKris Buschelman       idt -= 4;
391424c233c2SKris Buschelman     }
391524c233c2SKris Buschelman 
391624c233c2SKris Buschelman     ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
391724c233c2SKris Buschelman     ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
39181ebc52fbSHong Zhang     ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr);
39191ebc52fbSHong Zhang     ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3920dc0b31edSSatish Balay     ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
392124c233c2SKris Buschelman   SSE_SCOPE_END;
392224c233c2SKris Buschelman   PetscFunctionReturn(0);
392324c233c2SKris Buschelman }
392424c233c2SKris Buschelman 
392524c233c2SKris Buschelman #endif
39260ef38995SBarry Smith 
39270ef38995SBarry Smith 
39284e2b4712SSatish Balay /*
39294e2b4712SSatish Balay       Special case where the matrix was ILU(0) factored in the natural
39304e2b4712SSatish Balay    ordering. This eliminates the need for the column and row permutation.
39314e2b4712SSatish Balay */
39324a2ae208SSatish Balay #undef __FUNCT__
393306e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_inplace"
393406e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
39354e2b4712SSatish Balay {
39364e2b4712SSatish Balay   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3937356650c2SBarry Smith   PetscInt          n=a->mbs;
3938356650c2SBarry Smith   const PetscInt    *ai=a->i,*aj=a->j;
3939dfbe8321SBarry Smith   PetscErrorCode    ierr;
3940356650c2SBarry Smith   const PetscInt    *diag = a->diag;
3941d9fead3dSBarry Smith   const MatScalar   *aa=a->a;
3942d9fead3dSBarry Smith   PetscScalar       *x;
3943d9fead3dSBarry Smith   const PetscScalar *b;
39444e2b4712SSatish Balay 
39454e2b4712SSatish Balay   PetscFunctionBegin;
3946d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
39471ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
39484e2b4712SSatish Balay 
3949aa482453SBarry Smith #if defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJBLAS)
39502853dc0eSBarry Smith   {
395187828ca2SBarry Smith     static PetscScalar w[2000]; /* very BAD need to fix */
39522853dc0eSBarry Smith     fortransolvebaij4blas_(&n,x,ai,aj,diag,aa,b,w);
39532853dc0eSBarry Smith   }
3954aa482453SBarry Smith #elif defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
39552853dc0eSBarry Smith   {
395687828ca2SBarry Smith     static PetscScalar w[2000]; /* very BAD need to fix */
39572853dc0eSBarry Smith     fortransolvebaij4_(&n,x,ai,aj,diag,aa,b,w);
39582853dc0eSBarry Smith   }
3959aa482453SBarry Smith #elif defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJUNROLL)
39602853dc0eSBarry Smith   fortransolvebaij4unroll_(&n,x,ai,aj,diag,aa,b);
3961e1293385SBarry Smith #else
396230d4dcafSBarry Smith   {
396387828ca2SBarry Smith     PetscScalar     s1,s2,s3,s4,x1,x2,x3,x4;
3964d9fead3dSBarry Smith     const MatScalar *v;
3965356650c2SBarry Smith     PetscInt        jdx,idt,idx,nz,i,ai16;
3966356650c2SBarry Smith     const PetscInt  *vi;
3967e1293385SBarry Smith 
39684e2b4712SSatish Balay   /* forward solve the lower triangular */
39694e2b4712SSatish Balay   idx    = 0;
3970e1293385SBarry Smith   x[0]   = b[0]; x[1] = b[1]; x[2] = b[2]; x[3] = b[3];
39714e2b4712SSatish Balay   for (i=1; i<n; i++) {
39724e2b4712SSatish Balay     v     =  aa      + 16*ai[i];
39734e2b4712SSatish Balay     vi    =  aj      + ai[i];
39744e2b4712SSatish Balay     nz    =  diag[i] - ai[i];
3975e1293385SBarry Smith     idx   +=  4;
3976f1af5d2fSBarry Smith     s1  =  b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
39774e2b4712SSatish Balay     while (nz--) {
39784e2b4712SSatish Balay       jdx   = 4*(*vi++);
39794e2b4712SSatish Balay       x1    = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx];
3980f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
3981f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
3982f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
3983f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
39844e2b4712SSatish Balay       v    += 16;
39854e2b4712SSatish Balay     }
3986f1af5d2fSBarry Smith     x[idx]   = s1;
3987f1af5d2fSBarry Smith     x[1+idx] = s2;
3988f1af5d2fSBarry Smith     x[2+idx] = s3;
3989f1af5d2fSBarry Smith     x[3+idx] = s4;
39904e2b4712SSatish Balay   }
39914e2b4712SSatish Balay   /* backward solve the upper triangular */
39924e555682SBarry Smith   idt = 4*(n-1);
39934e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
39944e555682SBarry Smith     ai16 = 16*diag[i];
39954e555682SBarry Smith     v    = aa + ai16 + 16;
39964e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
39974e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
3998f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt];
3999f1af5d2fSBarry Smith     s3 = x[2+idt];s4 = x[3+idt];
40004e2b4712SSatish Balay     while (nz--) {
40014e2b4712SSatish Balay       idx   = 4*(*vi++);
40024e2b4712SSatish Balay       x1    = x[idx];   x2 = x[1+idx];x3    = x[2+idx]; x4 = x[3+idx];
4003f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3   + v[12]*x4;
4004f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3   + v[13]*x4;
4005f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3  + v[14]*x4;
4006f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3  + v[15]*x4;
40074e2b4712SSatish Balay       v    += 16;
40084e2b4712SSatish Balay     }
40094e555682SBarry Smith     v        = aa + ai16;
4010f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[4]*s2 + v[8]*s3  + v[12]*s4;
4011f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[5]*s2 + v[9]*s3  + v[13]*s4;
4012f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4;
4013f1af5d2fSBarry Smith     x[3+idt] = v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4;
4014329f5518SBarry Smith     idt -= 4;
40154e2b4712SSatish Balay   }
401630d4dcafSBarry Smith   }
4017e1293385SBarry Smith #endif
40184e2b4712SSatish Balay 
4019d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
40201ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4021dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
40224e2b4712SSatish Balay   PetscFunctionReturn(0);
40234e2b4712SSatish Balay }
40244e2b4712SSatish Balay 
4025b2b2dd24SShri Abhyankar #undef __FUNCT__
40264dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering"
40274dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering(Mat A,Vec bb,Vec xx)
4028b2b2dd24SShri Abhyankar {
4029b2b2dd24SShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
4030*b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
4031*b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,jdx,idt;
4032b2b2dd24SShri Abhyankar     PetscErrorCode    ierr;
4033*b3260449SShri Abhyankar     const PetscInt    bs = A->rmap->bs,bs2 = a->bs2;
4034b2b2dd24SShri Abhyankar     const MatScalar   *aa=a->a,*v;
4035b2b2dd24SShri Abhyankar     PetscScalar       *x;
4036b2b2dd24SShri Abhyankar     const PetscScalar *b;
4037b2b2dd24SShri Abhyankar     PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4;
4038cee9d6f2SShri Abhyankar 
4039b2b2dd24SShri Abhyankar     PetscFunctionBegin;
4040b2b2dd24SShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4041b2b2dd24SShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4042b2b2dd24SShri Abhyankar     /* forward solve the lower triangular */
4043b2b2dd24SShri Abhyankar     idx    = 0;
4044b2b2dd24SShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx];
4045b2b2dd24SShri Abhyankar     for (i=1; i<n; i++) {
4046b2b2dd24SShri Abhyankar        v    = aa + bs2*ai[i];
4047b2b2dd24SShri Abhyankar        vi   = aj + ai[i];
4048b2b2dd24SShri Abhyankar        nz   = ai[i+1] - ai[i];
4049b2b2dd24SShri Abhyankar       idx   = bs*i;
4050b2b2dd24SShri Abhyankar        s1   = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
4051b2b2dd24SShri Abhyankar       for(k=0;k<nz;k++) {
4052b2b2dd24SShri Abhyankar           jdx   = bs*vi[k];
4053b2b2dd24SShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx];
4054b2b2dd24SShri Abhyankar           s1   -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4;
4055b2b2dd24SShri Abhyankar           s2   -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4;
4056b2b2dd24SShri Abhyankar           s3   -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4057b2b2dd24SShri Abhyankar 	  s4   -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
4058b2b2dd24SShri Abhyankar 
4059b2b2dd24SShri Abhyankar           v   +=  bs2;
4060b2b2dd24SShri Abhyankar         }
4061b2b2dd24SShri Abhyankar 
4062b2b2dd24SShri Abhyankar        x[idx]   = s1;
4063b2b2dd24SShri Abhyankar        x[1+idx] = s2;
4064b2b2dd24SShri Abhyankar        x[2+idx] = s3;
4065b2b2dd24SShri Abhyankar        x[3+idx] = s4;
4066b2b2dd24SShri Abhyankar     }
4067b2b2dd24SShri Abhyankar 
4068b2b2dd24SShri Abhyankar    /* backward solve the upper triangular */
4069b2b2dd24SShri Abhyankar   for (i=n-1; i>=0; i--){
4070b2b2dd24SShri Abhyankar     v   = aa + bs2*(adiag[i+1]+1);
4071b2b2dd24SShri Abhyankar      vi  = aj + adiag[i+1]+1;
4072b2b2dd24SShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
4073b2b2dd24SShri Abhyankar      idt = bs*i;
4074b2b2dd24SShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt];
4075b2b2dd24SShri Abhyankar 
4076b2b2dd24SShri Abhyankar     for(k=0;k<nz;k++){
4077b2b2dd24SShri Abhyankar       idx   = bs*vi[k];
4078b2b2dd24SShri Abhyankar        x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx];
4079b2b2dd24SShri Abhyankar        s1   -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4;
4080b2b2dd24SShri Abhyankar        s2   -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4;
4081b2b2dd24SShri Abhyankar        s3   -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4082b2b2dd24SShri Abhyankar        s4   -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
4083b2b2dd24SShri Abhyankar 
4084b2b2dd24SShri Abhyankar         v   +=  bs2;
4085b2b2dd24SShri Abhyankar     }
4086b2b2dd24SShri Abhyankar     /* x = inv_diagonal*x */
4087b2b2dd24SShri Abhyankar    x[idt]   = v[0]*s1 + v[4]*s2 + v[8]*s3 + v[12]*s4;
4088b2b2dd24SShri Abhyankar    x[1+idt] = v[1]*s1 + v[5]*s2 + v[9]*s3 + v[13]*s4;;
4089b2b2dd24SShri Abhyankar    x[2+idt] = v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4;
4090b2b2dd24SShri Abhyankar    x[3+idt] = v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4;
4091b2b2dd24SShri Abhyankar 
4092b2b2dd24SShri Abhyankar   }
4093b2b2dd24SShri Abhyankar 
4094b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4095b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4096b2b2dd24SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
4097b2b2dd24SShri Abhyankar   PetscFunctionReturn(0);
4098b2b2dd24SShri Abhyankar }
4099cee9d6f2SShri Abhyankar 
4100cee9d6f2SShri Abhyankar #undef __FUNCT__
4101f26ec98cSKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_Demotion"
4102dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_Demotion(Mat A,Vec bb,Vec xx)
4103f26ec98cSKris Buschelman {
4104f26ec98cSKris Buschelman   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
4105*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*diag=a->diag;
4106dfbe8321SBarry Smith   PetscErrorCode    ierr;
4107*b3260449SShri Abhyankar   const MatScalar   *aa=a->a;
4108*b3260449SShri Abhyankar   const PetscScalar *b;
4109*b3260449SShri Abhyankar   PetscScalar       *x;
4110f26ec98cSKris Buschelman 
4111f26ec98cSKris Buschelman   PetscFunctionBegin;
4112*b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
41131ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4114f26ec98cSKris Buschelman 
4115f26ec98cSKris Buschelman   {
4116f26ec98cSKris Buschelman     MatScalar        s1,s2,s3,s4,x1,x2,x3,x4;
4117*b3260449SShri Abhyankar     const MatScalar  *v;
4118*b3260449SShri Abhyankar     MatScalar        *t=(MatScalar *)x;
4119*b3260449SShri Abhyankar     PetscInt         jdx,idt,idx,nz,i,ai16;
4120*b3260449SShri Abhyankar     const PetscInt   *vi;
4121f26ec98cSKris Buschelman 
4122f26ec98cSKris Buschelman     /* forward solve the lower triangular */
4123f26ec98cSKris Buschelman     idx  = 0;
4124f26ec98cSKris Buschelman     t[0] = (MatScalar)b[0];
4125f26ec98cSKris Buschelman     t[1] = (MatScalar)b[1];
4126f26ec98cSKris Buschelman     t[2] = (MatScalar)b[2];
4127f26ec98cSKris Buschelman     t[3] = (MatScalar)b[3];
4128f26ec98cSKris Buschelman     for (i=1; i<n; i++) {
4129f26ec98cSKris Buschelman       v     =  aa      + 16*ai[i];
4130f26ec98cSKris Buschelman       vi    =  aj      + ai[i];
4131f26ec98cSKris Buschelman       nz    =  diag[i] - ai[i];
4132f26ec98cSKris Buschelman       idx   +=  4;
4133f26ec98cSKris Buschelman       s1 = (MatScalar)b[idx];
4134f26ec98cSKris Buschelman       s2 = (MatScalar)b[1+idx];
4135f26ec98cSKris Buschelman       s3 = (MatScalar)b[2+idx];
4136f26ec98cSKris Buschelman       s4 = (MatScalar)b[3+idx];
4137f26ec98cSKris Buschelman       while (nz--) {
4138f26ec98cSKris Buschelman         jdx = 4*(*vi++);
4139f26ec98cSKris Buschelman         x1  = t[jdx];
4140f26ec98cSKris Buschelman         x2  = t[1+jdx];
4141f26ec98cSKris Buschelman         x3  = t[2+jdx];
4142f26ec98cSKris Buschelman         x4  = t[3+jdx];
4143f26ec98cSKris Buschelman         s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
4144f26ec98cSKris Buschelman         s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
4145f26ec98cSKris Buschelman         s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4146f26ec98cSKris Buschelman         s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
4147f26ec98cSKris Buschelman         v    += 16;
4148f26ec98cSKris Buschelman       }
4149f26ec98cSKris Buschelman       t[idx]   = s1;
4150f26ec98cSKris Buschelman       t[1+idx] = s2;
4151f26ec98cSKris Buschelman       t[2+idx] = s3;
4152f26ec98cSKris Buschelman       t[3+idx] = s4;
4153f26ec98cSKris Buschelman     }
4154f26ec98cSKris Buschelman     /* backward solve the upper triangular */
4155f26ec98cSKris Buschelman     idt = 4*(n-1);
4156f26ec98cSKris Buschelman     for (i=n-1; i>=0; i--){
4157f26ec98cSKris Buschelman       ai16 = 16*diag[i];
4158f26ec98cSKris Buschelman       v    = aa + ai16 + 16;
4159f26ec98cSKris Buschelman       vi   = aj + diag[i] + 1;
4160f26ec98cSKris Buschelman       nz   = ai[i+1] - diag[i] - 1;
4161f26ec98cSKris Buschelman       s1   = t[idt];
4162f26ec98cSKris Buschelman       s2   = t[1+idt];
4163f26ec98cSKris Buschelman       s3   = t[2+idt];
4164f26ec98cSKris Buschelman       s4   = t[3+idt];
4165f26ec98cSKris Buschelman       while (nz--) {
4166f26ec98cSKris Buschelman         idx = 4*(*vi++);
4167f26ec98cSKris Buschelman         x1  = (MatScalar)x[idx];
4168f26ec98cSKris Buschelman         x2  = (MatScalar)x[1+idx];
4169f26ec98cSKris Buschelman         x3  = (MatScalar)x[2+idx];
4170f26ec98cSKris Buschelman         x4  = (MatScalar)x[3+idx];
4171f26ec98cSKris Buschelman         s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
4172f26ec98cSKris Buschelman         s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
4173f26ec98cSKris Buschelman         s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4174f26ec98cSKris Buschelman         s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
4175f26ec98cSKris Buschelman         v    += 16;
4176f26ec98cSKris Buschelman       }
4177f26ec98cSKris Buschelman       v        = aa + ai16;
4178f26ec98cSKris Buschelman       x[idt]   = (PetscScalar)(v[0]*s1 + v[4]*s2 + v[8]*s3  + v[12]*s4);
4179f26ec98cSKris Buschelman       x[1+idt] = (PetscScalar)(v[1]*s1 + v[5]*s2 + v[9]*s3  + v[13]*s4);
4180f26ec98cSKris Buschelman       x[2+idt] = (PetscScalar)(v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4);
4181f26ec98cSKris Buschelman       x[3+idt] = (PetscScalar)(v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4);
4182f26ec98cSKris Buschelman       idt -= 4;
4183f26ec98cSKris Buschelman     }
4184f26ec98cSKris Buschelman   }
4185f26ec98cSKris Buschelman 
4186*b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
41871ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4188dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
4189f26ec98cSKris Buschelman   PetscFunctionReturn(0);
4190f26ec98cSKris Buschelman }
4191f26ec98cSKris Buschelman 
41923660e330SKris Buschelman #if defined (PETSC_HAVE_SSE)
41933660e330SKris Buschelman 
41943660e330SKris Buschelman #include PETSC_HAVE_SSE
41953660e330SKris Buschelman #undef __FUNCT__
41967cf1b8d3SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion_usj"
4197dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion_usj(Mat A,Vec bb,Vec xx)
41983660e330SKris Buschelman {
41993660e330SKris Buschelman   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ *)A->data;
42002aa5897fSKris Buschelman   unsigned short *aj=(unsigned short *)a->j;
4201dfbe8321SBarry Smith   PetscErrorCode ierr;
4202dfbe8321SBarry Smith   int            *ai=a->i,n=a->mbs,*diag = a->diag;
42033660e330SKris Buschelman   MatScalar      *aa=a->a;
420487828ca2SBarry Smith   PetscScalar    *x,*b;
42053660e330SKris Buschelman 
42063660e330SKris Buschelman   PetscFunctionBegin;
42073660e330SKris Buschelman   SSE_SCOPE_BEGIN;
42083660e330SKris Buschelman   /*
42093660e330SKris Buschelman      Note: This code currently uses demotion of double
42103660e330SKris Buschelman      to float when performing the mixed-mode computation.
42113660e330SKris Buschelman      This may not be numerically reasonable for all applications.
42123660e330SKris Buschelman   */
42133660e330SKris Buschelman   PREFETCH_NTA(aa+16*ai[1]);
42143660e330SKris Buschelman 
42151ebc52fbSHong Zhang   ierr = VecGetArray(bb,&b);CHKERRQ(ierr);
42161ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
42173660e330SKris Buschelman   {
4218eb05f457SKris Buschelman     /* x will first be computed in single precision then promoted inplace to double */
4219eb05f457SKris Buschelman     MatScalar      *v,*t=(MatScalar *)x;
42202aa5897fSKris Buschelman     int            nz,i,idt,ai16;
42212aa5897fSKris Buschelman     unsigned int   jdx,idx;
42222aa5897fSKris Buschelman     unsigned short *vi;
4223eb05f457SKris Buschelman     /* Forward solve the lower triangular factor. */
42243660e330SKris Buschelman 
4225eb05f457SKris Buschelman     /* First block is the identity. */
42263660e330SKris Buschelman     idx  = 0;
4227eb05f457SKris Buschelman     CONVERT_DOUBLE4_FLOAT4(t,b);
42282aa5897fSKris Buschelman     v    =  aa + 16*((unsigned int)ai[1]);
42293660e330SKris Buschelman 
42303660e330SKris Buschelman     for (i=1; i<n;) {
42313660e330SKris Buschelman       PREFETCH_NTA(&v[8]);
42323660e330SKris Buschelman       vi   =  aj      + ai[i];
42333660e330SKris Buschelman       nz   =  diag[i] - ai[i];
42343660e330SKris Buschelman       idx +=  4;
42353660e330SKris Buschelman 
4236eb05f457SKris Buschelman       /* Demote RHS from double to float. */
4237eb05f457SKris Buschelman       CONVERT_DOUBLE4_FLOAT4(&t[idx],&b[idx]);
4238eb05f457SKris Buschelman       LOAD_PS(&t[idx],XMM7);
42393660e330SKris Buschelman 
42403660e330SKris Buschelman       while (nz--) {
42413660e330SKris Buschelman         PREFETCH_NTA(&v[16]);
42422aa5897fSKris Buschelman         jdx = 4*((unsigned int)(*vi++));
42433660e330SKris Buschelman 
42443660e330SKris Buschelman         /* 4x4 Matrix-Vector product with negative accumulation: */
4245eb05f457SKris Buschelman         SSE_INLINE_BEGIN_2(&t[jdx],v)
42463660e330SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
42473660e330SKris Buschelman 
42483660e330SKris Buschelman           /* First Column */
42493660e330SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
42503660e330SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
42513660e330SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
42523660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
42533660e330SKris Buschelman 
42543660e330SKris Buschelman           /* Second Column */
42553660e330SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
42563660e330SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
42573660e330SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
42583660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
42593660e330SKris Buschelman 
42603660e330SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
42613660e330SKris Buschelman 
42623660e330SKris Buschelman           /* Third Column */
42633660e330SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
42643660e330SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
42653660e330SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
42663660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
42673660e330SKris Buschelman 
42683660e330SKris Buschelman           /* Fourth Column */
42693660e330SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
42703660e330SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
42713660e330SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
42723660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
42733660e330SKris Buschelman         SSE_INLINE_END_2
42743660e330SKris Buschelman 
42753660e330SKris Buschelman         v  += 16;
42763660e330SKris Buschelman       }
42773660e330SKris Buschelman       v    =  aa + 16*ai[++i];
42783660e330SKris Buschelman       PREFETCH_NTA(v);
4279eb05f457SKris Buschelman       STORE_PS(&t[idx],XMM7);
42803660e330SKris Buschelman     }
4281eb05f457SKris Buschelman 
4282eb05f457SKris Buschelman     /* Backward solve the upper triangular factor.*/
4283eb05f457SKris Buschelman 
42843660e330SKris Buschelman     idt  = 4*(n-1);
42853660e330SKris Buschelman     ai16 = 16*diag[n-1];
42863660e330SKris Buschelman     v    = aa + ai16 + 16;
42873660e330SKris Buschelman     for (i=n-1; i>=0;){
42883660e330SKris Buschelman       PREFETCH_NTA(&v[8]);
42893660e330SKris Buschelman       vi = aj + diag[i] + 1;
42903660e330SKris Buschelman       nz = ai[i+1] - diag[i] - 1;
42913660e330SKris Buschelman 
4292eb05f457SKris Buschelman       LOAD_PS(&t[idt],XMM7);
42933660e330SKris Buschelman 
42943660e330SKris Buschelman       while (nz--) {
42953660e330SKris Buschelman         PREFETCH_NTA(&v[16]);
42962aa5897fSKris Buschelman         idx = 4*((unsigned int)(*vi++));
42973660e330SKris Buschelman 
42983660e330SKris Buschelman         /* 4x4 Matrix-Vector Product with negative accumulation: */
4299eb05f457SKris Buschelman         SSE_INLINE_BEGIN_2(&t[idx],v)
43003660e330SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
43013660e330SKris Buschelman 
43023660e330SKris Buschelman           /* First Column */
43033660e330SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
43043660e330SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
43053660e330SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
43063660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
43073660e330SKris Buschelman 
43083660e330SKris Buschelman           /* Second Column */
43093660e330SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
43103660e330SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
43113660e330SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
43123660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
43133660e330SKris Buschelman 
43143660e330SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
43153660e330SKris Buschelman 
43163660e330SKris Buschelman           /* Third Column */
43173660e330SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
43183660e330SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
43193660e330SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
43203660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
43213660e330SKris Buschelman 
43223660e330SKris Buschelman           /* Fourth Column */
43233660e330SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
43243660e330SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
43253660e330SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
43263660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
43273660e330SKris Buschelman         SSE_INLINE_END_2
43283660e330SKris Buschelman         v  += 16;
43293660e330SKris Buschelman       }
43303660e330SKris Buschelman       v    = aa + ai16;
43313660e330SKris Buschelman       ai16 = 16*diag[--i];
43323660e330SKris Buschelman       PREFETCH_NTA(aa+ai16+16);
43333660e330SKris Buschelman       /*
43343660e330SKris Buschelman          Scale the result by the diagonal 4x4 block,
43353660e330SKris Buschelman          which was inverted as part of the factorization
43363660e330SKris Buschelman       */
4337eb05f457SKris Buschelman       SSE_INLINE_BEGIN_3(v,&t[idt],aa+ai16)
43383660e330SKris Buschelman         /* First Column */
43393660e330SKris Buschelman         SSE_COPY_PS(XMM0,XMM7)
43403660e330SKris Buschelman         SSE_SHUFFLE(XMM0,XMM0,0x00)
43413660e330SKris Buschelman         SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0)
43423660e330SKris Buschelman 
43433660e330SKris Buschelman         /* Second Column */
43443660e330SKris Buschelman         SSE_COPY_PS(XMM1,XMM7)
43453660e330SKris Buschelman         SSE_SHUFFLE(XMM1,XMM1,0x55)
43463660e330SKris Buschelman         SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4)
43473660e330SKris Buschelman         SSE_ADD_PS(XMM0,XMM1)
43483660e330SKris Buschelman 
43493660e330SKris Buschelman         SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24)
43503660e330SKris Buschelman 
43513660e330SKris Buschelman         /* Third Column */
43523660e330SKris Buschelman         SSE_COPY_PS(XMM2,XMM7)
43533660e330SKris Buschelman         SSE_SHUFFLE(XMM2,XMM2,0xAA)
43543660e330SKris Buschelman         SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8)
43553660e330SKris Buschelman         SSE_ADD_PS(XMM0,XMM2)
43563660e330SKris Buschelman 
43573660e330SKris Buschelman         /* Fourth Column */
43583660e330SKris Buschelman         SSE_COPY_PS(XMM3,XMM7)
43593660e330SKris Buschelman         SSE_SHUFFLE(XMM3,XMM3,0xFF)
43603660e330SKris Buschelman         SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12)
43613660e330SKris Buschelman         SSE_ADD_PS(XMM0,XMM3)
43623660e330SKris Buschelman 
43633660e330SKris Buschelman         SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0)
43643660e330SKris Buschelman       SSE_INLINE_END_3
43653660e330SKris Buschelman 
43663660e330SKris Buschelman       v    = aa + ai16 + 16;
43673660e330SKris Buschelman       idt -= 4;
43683660e330SKris Buschelman     }
4369eb05f457SKris Buschelman 
4370eb05f457SKris Buschelman     /* Convert t from single precision back to double precision (inplace)*/
4371eb05f457SKris Buschelman     idt = 4*(n-1);
4372eb05f457SKris Buschelman     for (i=n-1;i>=0;i--) {
4373eb05f457SKris Buschelman       /*     CONVERT_FLOAT4_DOUBLE4(&x[idt],&t[idt]); */
4374eb05f457SKris Buschelman       /* Unfortunately, CONVERT_ will count from 0 to 3 which doesn't work here. */
4375eb05f457SKris Buschelman       PetscScalar *xtemp=&x[idt];
4376eb05f457SKris Buschelman       MatScalar   *ttemp=&t[idt];
4377eb05f457SKris Buschelman       xtemp[3] = (PetscScalar)ttemp[3];
4378eb05f457SKris Buschelman       xtemp[2] = (PetscScalar)ttemp[2];
4379eb05f457SKris Buschelman       xtemp[1] = (PetscScalar)ttemp[1];
4380eb05f457SKris Buschelman       xtemp[0] = (PetscScalar)ttemp[0];
438154693613SKris Buschelman       idt -= 4;
43823660e330SKris Buschelman     }
4383eb05f457SKris Buschelman 
4384eb05f457SKris Buschelman   } /* End of artificial scope. */
43851ebc52fbSHong Zhang   ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr);
43861ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4387dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
43883660e330SKris Buschelman   SSE_SCOPE_END;
43893660e330SKris Buschelman   PetscFunctionReturn(0);
43903660e330SKris Buschelman }
43913660e330SKris Buschelman 
43927cf1b8d3SKris Buschelman #undef __FUNCT__
43937cf1b8d3SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion"
4394dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion(Mat A,Vec bb,Vec xx)
43957cf1b8d3SKris Buschelman {
43967cf1b8d3SKris Buschelman   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ *)A->data;
43977cf1b8d3SKris Buschelman   int            *aj=a->j;
4398dfbe8321SBarry Smith   PetscErrorCode ierr;
4399dfbe8321SBarry Smith   int            *ai=a->i,n=a->mbs,*diag = a->diag;
44007cf1b8d3SKris Buschelman   MatScalar      *aa=a->a;
44017cf1b8d3SKris Buschelman   PetscScalar    *x,*b;
44027cf1b8d3SKris Buschelman 
44037cf1b8d3SKris Buschelman   PetscFunctionBegin;
44047cf1b8d3SKris Buschelman   SSE_SCOPE_BEGIN;
44057cf1b8d3SKris Buschelman   /*
44067cf1b8d3SKris Buschelman      Note: This code currently uses demotion of double
44077cf1b8d3SKris Buschelman      to float when performing the mixed-mode computation.
44087cf1b8d3SKris Buschelman      This may not be numerically reasonable for all applications.
44097cf1b8d3SKris Buschelman   */
44107cf1b8d3SKris Buschelman   PREFETCH_NTA(aa+16*ai[1]);
44117cf1b8d3SKris Buschelman 
44121ebc52fbSHong Zhang   ierr = VecGetArray(bb,&b);CHKERRQ(ierr);
44131ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
44147cf1b8d3SKris Buschelman   {
44157cf1b8d3SKris Buschelman     /* x will first be computed in single precision then promoted inplace to double */
44167cf1b8d3SKris Buschelman     MatScalar *v,*t=(MatScalar *)x;
44177cf1b8d3SKris Buschelman     int       nz,i,idt,ai16;
44187cf1b8d3SKris Buschelman     int       jdx,idx;
44197cf1b8d3SKris Buschelman     int       *vi;
44207cf1b8d3SKris Buschelman     /* Forward solve the lower triangular factor. */
44217cf1b8d3SKris Buschelman 
44227cf1b8d3SKris Buschelman     /* First block is the identity. */
44237cf1b8d3SKris Buschelman     idx  = 0;
44247cf1b8d3SKris Buschelman     CONVERT_DOUBLE4_FLOAT4(t,b);
44257cf1b8d3SKris Buschelman     v    =  aa + 16*ai[1];
44267cf1b8d3SKris Buschelman 
44277cf1b8d3SKris Buschelman     for (i=1; i<n;) {
44287cf1b8d3SKris Buschelman       PREFETCH_NTA(&v[8]);
44297cf1b8d3SKris Buschelman       vi   =  aj      + ai[i];
44307cf1b8d3SKris Buschelman       nz   =  diag[i] - ai[i];
44317cf1b8d3SKris Buschelman       idx +=  4;
44327cf1b8d3SKris Buschelman 
44337cf1b8d3SKris Buschelman       /* Demote RHS from double to float. */
44347cf1b8d3SKris Buschelman       CONVERT_DOUBLE4_FLOAT4(&t[idx],&b[idx]);
44357cf1b8d3SKris Buschelman       LOAD_PS(&t[idx],XMM7);
44367cf1b8d3SKris Buschelman 
44377cf1b8d3SKris Buschelman       while (nz--) {
44387cf1b8d3SKris Buschelman         PREFETCH_NTA(&v[16]);
44397cf1b8d3SKris Buschelman         jdx = 4*(*vi++);
44407cf1b8d3SKris Buschelman /*          jdx = *vi++; */
44417cf1b8d3SKris Buschelman 
44427cf1b8d3SKris Buschelman         /* 4x4 Matrix-Vector product with negative accumulation: */
44437cf1b8d3SKris Buschelman         SSE_INLINE_BEGIN_2(&t[jdx],v)
44447cf1b8d3SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
44457cf1b8d3SKris Buschelman 
44467cf1b8d3SKris Buschelman           /* First Column */
44477cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
44487cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
44497cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
44507cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
44517cf1b8d3SKris Buschelman 
44527cf1b8d3SKris Buschelman           /* Second Column */
44537cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
44547cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
44557cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
44567cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
44577cf1b8d3SKris Buschelman 
44587cf1b8d3SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
44597cf1b8d3SKris Buschelman 
44607cf1b8d3SKris Buschelman           /* Third Column */
44617cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
44627cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
44637cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
44647cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
44657cf1b8d3SKris Buschelman 
44667cf1b8d3SKris Buschelman           /* Fourth Column */
44677cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
44687cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
44697cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
44707cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
44717cf1b8d3SKris Buschelman         SSE_INLINE_END_2
44727cf1b8d3SKris Buschelman 
44737cf1b8d3SKris Buschelman         v  += 16;
44747cf1b8d3SKris Buschelman       }
44757cf1b8d3SKris Buschelman       v    =  aa + 16*ai[++i];
44767cf1b8d3SKris Buschelman       PREFETCH_NTA(v);
44777cf1b8d3SKris Buschelman       STORE_PS(&t[idx],XMM7);
44787cf1b8d3SKris Buschelman     }
44797cf1b8d3SKris Buschelman 
44807cf1b8d3SKris Buschelman     /* Backward solve the upper triangular factor.*/
44817cf1b8d3SKris Buschelman 
44827cf1b8d3SKris Buschelman     idt  = 4*(n-1);
44837cf1b8d3SKris Buschelman     ai16 = 16*diag[n-1];
44847cf1b8d3SKris Buschelman     v    = aa + ai16 + 16;
44857cf1b8d3SKris Buschelman     for (i=n-1; i>=0;){
44867cf1b8d3SKris Buschelman       PREFETCH_NTA(&v[8]);
44877cf1b8d3SKris Buschelman       vi = aj + diag[i] + 1;
44887cf1b8d3SKris Buschelman       nz = ai[i+1] - diag[i] - 1;
44897cf1b8d3SKris Buschelman 
44907cf1b8d3SKris Buschelman       LOAD_PS(&t[idt],XMM7);
44917cf1b8d3SKris Buschelman 
44927cf1b8d3SKris Buschelman       while (nz--) {
44937cf1b8d3SKris Buschelman         PREFETCH_NTA(&v[16]);
44947cf1b8d3SKris Buschelman         idx = 4*(*vi++);
44957cf1b8d3SKris Buschelman /*          idx = *vi++; */
44967cf1b8d3SKris Buschelman 
44977cf1b8d3SKris Buschelman         /* 4x4 Matrix-Vector Product with negative accumulation: */
44987cf1b8d3SKris Buschelman         SSE_INLINE_BEGIN_2(&t[idx],v)
44997cf1b8d3SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
45007cf1b8d3SKris Buschelman 
45017cf1b8d3SKris Buschelman           /* First Column */
45027cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
45037cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
45047cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
45057cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
45067cf1b8d3SKris Buschelman 
45077cf1b8d3SKris Buschelman           /* Second Column */
45087cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
45097cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
45107cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
45117cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
45127cf1b8d3SKris Buschelman 
45137cf1b8d3SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
45147cf1b8d3SKris Buschelman 
45157cf1b8d3SKris Buschelman           /* Third Column */
45167cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
45177cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
45187cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
45197cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
45207cf1b8d3SKris Buschelman 
45217cf1b8d3SKris Buschelman           /* Fourth Column */
45227cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
45237cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
45247cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
45257cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
45267cf1b8d3SKris Buschelman         SSE_INLINE_END_2
45277cf1b8d3SKris Buschelman         v  += 16;
45287cf1b8d3SKris Buschelman       }
45297cf1b8d3SKris Buschelman       v    = aa + ai16;
45307cf1b8d3SKris Buschelman       ai16 = 16*diag[--i];
45317cf1b8d3SKris Buschelman       PREFETCH_NTA(aa+ai16+16);
45327cf1b8d3SKris Buschelman       /*
45337cf1b8d3SKris Buschelman          Scale the result by the diagonal 4x4 block,
45347cf1b8d3SKris Buschelman          which was inverted as part of the factorization
45357cf1b8d3SKris Buschelman       */
45367cf1b8d3SKris Buschelman       SSE_INLINE_BEGIN_3(v,&t[idt],aa+ai16)
45377cf1b8d3SKris Buschelman         /* First Column */
45387cf1b8d3SKris Buschelman         SSE_COPY_PS(XMM0,XMM7)
45397cf1b8d3SKris Buschelman         SSE_SHUFFLE(XMM0,XMM0,0x00)
45407cf1b8d3SKris Buschelman         SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0)
45417cf1b8d3SKris Buschelman 
45427cf1b8d3SKris Buschelman         /* Second Column */
45437cf1b8d3SKris Buschelman         SSE_COPY_PS(XMM1,XMM7)
45447cf1b8d3SKris Buschelman         SSE_SHUFFLE(XMM1,XMM1,0x55)
45457cf1b8d3SKris Buschelman         SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4)
45467cf1b8d3SKris Buschelman         SSE_ADD_PS(XMM0,XMM1)
45477cf1b8d3SKris Buschelman 
45487cf1b8d3SKris Buschelman         SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24)
45497cf1b8d3SKris Buschelman 
45507cf1b8d3SKris Buschelman         /* Third Column */
45517cf1b8d3SKris Buschelman         SSE_COPY_PS(XMM2,XMM7)
45527cf1b8d3SKris Buschelman         SSE_SHUFFLE(XMM2,XMM2,0xAA)
45537cf1b8d3SKris Buschelman         SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8)
45547cf1b8d3SKris Buschelman         SSE_ADD_PS(XMM0,XMM2)
45557cf1b8d3SKris Buschelman 
45567cf1b8d3SKris Buschelman         /* Fourth Column */
45577cf1b8d3SKris Buschelman         SSE_COPY_PS(XMM3,XMM7)
45587cf1b8d3SKris Buschelman         SSE_SHUFFLE(XMM3,XMM3,0xFF)
45597cf1b8d3SKris Buschelman         SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12)
45607cf1b8d3SKris Buschelman         SSE_ADD_PS(XMM0,XMM3)
45617cf1b8d3SKris Buschelman 
45627cf1b8d3SKris Buschelman         SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0)
45637cf1b8d3SKris Buschelman       SSE_INLINE_END_3
45647cf1b8d3SKris Buschelman 
45657cf1b8d3SKris Buschelman       v    = aa + ai16 + 16;
45667cf1b8d3SKris Buschelman       idt -= 4;
45677cf1b8d3SKris Buschelman     }
45687cf1b8d3SKris Buschelman 
45697cf1b8d3SKris Buschelman     /* Convert t from single precision back to double precision (inplace)*/
45707cf1b8d3SKris Buschelman     idt = 4*(n-1);
45717cf1b8d3SKris Buschelman     for (i=n-1;i>=0;i--) {
45727cf1b8d3SKris Buschelman       /*     CONVERT_FLOAT4_DOUBLE4(&x[idt],&t[idt]); */
45737cf1b8d3SKris Buschelman       /* Unfortunately, CONVERT_ will count from 0 to 3 which doesn't work here. */
45747cf1b8d3SKris Buschelman       PetscScalar *xtemp=&x[idt];
45757cf1b8d3SKris Buschelman       MatScalar   *ttemp=&t[idt];
45767cf1b8d3SKris Buschelman       xtemp[3] = (PetscScalar)ttemp[3];
45777cf1b8d3SKris Buschelman       xtemp[2] = (PetscScalar)ttemp[2];
45787cf1b8d3SKris Buschelman       xtemp[1] = (PetscScalar)ttemp[1];
45797cf1b8d3SKris Buschelman       xtemp[0] = (PetscScalar)ttemp[0];
45807cf1b8d3SKris Buschelman       idt -= 4;
45817cf1b8d3SKris Buschelman     }
45827cf1b8d3SKris Buschelman 
45837cf1b8d3SKris Buschelman   } /* End of artificial scope. */
45841ebc52fbSHong Zhang   ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr);
45851ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4586dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
45877cf1b8d3SKris Buschelman   SSE_SCOPE_END;
45887cf1b8d3SKris Buschelman   PetscFunctionReturn(0);
45897cf1b8d3SKris Buschelman }
45907cf1b8d3SKris Buschelman 
45913660e330SKris Buschelman #endif
45928f690400SShri Abhyankar 
45934a2ae208SSatish Balay #undef __FUNCT__
459406e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_3_inplace"
459506e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_3_inplace(Mat A,Vec bb,Vec xx)
45964e2b4712SSatish Balay {
45974e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
45984e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
45996849ba73SBarry Smith   PetscErrorCode    ierr;
4600*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
4601*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
46025d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
4603d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
4604d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,x1,x2,x3,*t;
4605d9fead3dSBarry Smith   const PetscScalar *b;
46064e2b4712SSatish Balay 
46074e2b4712SSatish Balay   PetscFunctionBegin;
4608d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
46091ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4610f1af5d2fSBarry Smith   t  = a->solve_work;
46114e2b4712SSatish Balay 
46124e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
46134e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
46144e2b4712SSatish Balay 
46154e2b4712SSatish Balay   /* forward solve the lower triangular */
46164e2b4712SSatish Balay   idx    = 3*(*r++);
4617f1af5d2fSBarry Smith   t[0] = b[idx]; t[1] = b[1+idx]; t[2] = b[2+idx];
46184e2b4712SSatish Balay   for (i=1; i<n; i++) {
46194e2b4712SSatish Balay     v     = aa + 9*ai[i];
46204e2b4712SSatish Balay     vi    = aj + ai[i];
46214e2b4712SSatish Balay     nz    = diag[i] - ai[i];
46224e2b4712SSatish Balay     idx   = 3*(*r++);
4623f1af5d2fSBarry Smith     s1  = b[idx]; s2 = b[1+idx]; s3 = b[2+idx];
46244e2b4712SSatish Balay     while (nz--) {
46254e2b4712SSatish Balay       idx   = 3*(*vi++);
4626f1af5d2fSBarry Smith       x1    = t[idx]; x2 = t[1+idx]; x3 = t[2+idx];
4627f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4628f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4629f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
46304e2b4712SSatish Balay       v += 9;
46314e2b4712SSatish Balay     }
46324e2b4712SSatish Balay     idx = 3*i;
4633f1af5d2fSBarry Smith     t[idx] = s1; t[1+idx] = s2; t[2+idx] = s3;
46344e2b4712SSatish Balay   }
46354e2b4712SSatish Balay   /* backward solve the upper triangular */
46364e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
46374e2b4712SSatish Balay     v    = aa + 9*diag[i] + 9;
46384e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
46394e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
46404e2b4712SSatish Balay     idt  = 3*i;
4641f1af5d2fSBarry Smith     s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt];
46424e2b4712SSatish Balay     while (nz--) {
46434e2b4712SSatish Balay       idx   = 3*(*vi++);
4644f1af5d2fSBarry Smith       x1    = t[idx]; x2 = t[1+idx]; x3 = t[2+idx];
4645f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4646f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4647f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
46484e2b4712SSatish Balay       v += 9;
46494e2b4712SSatish Balay     }
46504e2b4712SSatish Balay     idc = 3*(*c--);
46514e2b4712SSatish Balay     v   = aa + 9*diag[i];
4652f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1 + v[3]*s2 + v[6]*s3;
4653f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3;
4654f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3;
46554e2b4712SSatish Balay   }
46564e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
46574e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
4658d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
46591ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4660dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr);
46614e2b4712SSatish Balay   PetscFunctionReturn(0);
46624e2b4712SSatish Balay }
46634e2b4712SSatish Balay 
46640c4413a7SShri Abhyankar #undef __FUNCT__
46654dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_3"
46664dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_3(Mat A,Vec bb,Vec xx)
46670c4413a7SShri Abhyankar {
46680c4413a7SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
46690c4413a7SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
46700c4413a7SShri Abhyankar   PetscErrorCode    ierr;
4671*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
4672*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
46730c4413a7SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
46740c4413a7SShri Abhyankar   const MatScalar   *aa=a->a,*v;
46750c4413a7SShri Abhyankar   PetscScalar       *x,s1,s2,s3,x1,x2,x3,*t;
46760c4413a7SShri Abhyankar   const PetscScalar *b;
46770c4413a7SShri Abhyankar 
46780c4413a7SShri Abhyankar   PetscFunctionBegin;
46790c4413a7SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
46800c4413a7SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
46810c4413a7SShri Abhyankar   t  = a->solve_work;
46820c4413a7SShri Abhyankar 
46830c4413a7SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
46840c4413a7SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
46850c4413a7SShri Abhyankar 
46860c4413a7SShri Abhyankar   /* forward solve the lower triangular */
46870c4413a7SShri Abhyankar   idx    = 3*r[0];
46880c4413a7SShri Abhyankar   t[0] = b[idx]; t[1] = b[1+idx]; t[2] = b[2+idx];
46890c4413a7SShri Abhyankar   for (i=1; i<n; i++) {
46900c4413a7SShri Abhyankar     v     = aa + 9*ai[i];
46910c4413a7SShri Abhyankar     vi    = aj + ai[i];
46920c4413a7SShri Abhyankar     nz    = ai[i+1] - ai[i];
46930c4413a7SShri Abhyankar     idx   = 3*r[i];
46940c4413a7SShri Abhyankar     s1  = b[idx]; s2 = b[1+idx]; s3 = b[2+idx];
46950c4413a7SShri Abhyankar     for(m=0;m<nz;m++){
46960c4413a7SShri Abhyankar       idx   = 3*vi[m];
46970c4413a7SShri Abhyankar       x1    = t[idx]; x2 = t[1+idx]; x3 = t[2+idx];
46980c4413a7SShri Abhyankar       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
46990c4413a7SShri Abhyankar       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
47000c4413a7SShri Abhyankar       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
47010c4413a7SShri Abhyankar       v += 9;
47020c4413a7SShri Abhyankar     }
47030c4413a7SShri Abhyankar     idx = 3*i;
47040c4413a7SShri Abhyankar     t[idx] = s1; t[1+idx] = s2; t[2+idx] = s3;
47050c4413a7SShri Abhyankar   }
47060c4413a7SShri Abhyankar   /* backward solve the upper triangular */
47070c4413a7SShri Abhyankar   for (i=n-1; i>=0; i--){
47080c4413a7SShri Abhyankar     v    = aa + 9*(adiag[i+1]+1);
47090c4413a7SShri Abhyankar     vi   = aj + adiag[i+1]+1;
47100c4413a7SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
47110c4413a7SShri Abhyankar     idt  = 3*i;
47120c4413a7SShri Abhyankar     s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt];
47130c4413a7SShri Abhyankar     for(m=0;m<nz;m++){
47140c4413a7SShri Abhyankar       idx   = 3*vi[m];
47150c4413a7SShri Abhyankar       x1    = t[idx]; x2 = t[1+idx]; x3 = t[2+idx];
47160c4413a7SShri Abhyankar       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
47170c4413a7SShri Abhyankar       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
47180c4413a7SShri Abhyankar       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
47190c4413a7SShri Abhyankar       v += 9;
47200c4413a7SShri Abhyankar     }
47210c4413a7SShri Abhyankar     idc = 3*c[i];
47220c4413a7SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1 + v[3]*s2 + v[6]*s3;
47230c4413a7SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3;
47240c4413a7SShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3;
47250c4413a7SShri Abhyankar   }
47260c4413a7SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
47270c4413a7SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
47280c4413a7SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
47290c4413a7SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
47300c4413a7SShri Abhyankar   ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr);
47310c4413a7SShri Abhyankar   PetscFunctionReturn(0);
47320c4413a7SShri Abhyankar }
47330c4413a7SShri Abhyankar 
473415091d37SBarry Smith /*
473515091d37SBarry Smith       Special case where the matrix was ILU(0) factored in the natural
473615091d37SBarry Smith    ordering. This eliminates the need for the column and row permutation.
473715091d37SBarry Smith */
47384a2ae208SSatish Balay #undef __FUNCT__
473906e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_3_NaturalOrdering_inplace"
474006e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_3_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
474115091d37SBarry Smith {
474215091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
47430b68f018SBarry Smith   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j;
4744dfbe8321SBarry Smith   PetscErrorCode    ierr;
47450b68f018SBarry Smith   const PetscInt    *diag = a->diag,*vi;
4746d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
4747d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,x1,x2,x3;
4748d9fead3dSBarry Smith   const PetscScalar *b;
47490b68f018SBarry Smith   PetscInt          jdx,idt,idx,nz,i;
475015091d37SBarry Smith 
475115091d37SBarry Smith   PetscFunctionBegin;
4752d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
47531ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
475415091d37SBarry Smith 
475515091d37SBarry Smith   /* forward solve the lower triangular */
475615091d37SBarry Smith   idx    = 0;
475715091d37SBarry Smith   x[0]   = b[0]; x[1] = b[1]; x[2] = b[2];
475815091d37SBarry Smith   for (i=1; i<n; i++) {
475915091d37SBarry Smith     v     =  aa      + 9*ai[i];
476015091d37SBarry Smith     vi    =  aj      + ai[i];
476115091d37SBarry Smith     nz    =  diag[i] - ai[i];
476215091d37SBarry Smith     idx   +=  3;
4763f1af5d2fSBarry Smith     s1  =  b[idx];s2 = b[1+idx];s3 = b[2+idx];
476415091d37SBarry Smith     while (nz--) {
476515091d37SBarry Smith       jdx   = 3*(*vi++);
476615091d37SBarry Smith       x1    = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];
4767f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4768f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4769f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
477015091d37SBarry Smith       v    += 9;
477115091d37SBarry Smith     }
4772f1af5d2fSBarry Smith     x[idx]   = s1;
4773f1af5d2fSBarry Smith     x[1+idx] = s2;
4774f1af5d2fSBarry Smith     x[2+idx] = s3;
477515091d37SBarry Smith   }
477615091d37SBarry Smith   /* backward solve the upper triangular */
477715091d37SBarry Smith   for (i=n-1; i>=0; i--){
477815091d37SBarry Smith     v    = aa + 9*diag[i] + 9;
477915091d37SBarry Smith     vi   = aj + diag[i] + 1;
478015091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
478115091d37SBarry Smith     idt  = 3*i;
4782f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt];
4783f1af5d2fSBarry Smith     s3 = x[2+idt];
478415091d37SBarry Smith     while (nz--) {
478515091d37SBarry Smith       idx   = 3*(*vi++);
478615091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx];x3    = x[2+idx];
4787f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4788f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4789f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
479015091d37SBarry Smith       v    += 9;
479115091d37SBarry Smith     }
479215091d37SBarry Smith     v        = aa +  9*diag[i];
4793f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[3]*s2 + v[6]*s3;
4794f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3;
4795f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3;
479615091d37SBarry Smith   }
479715091d37SBarry Smith 
4798d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
47991ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4800dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr);
480115091d37SBarry Smith   PetscFunctionReturn(0);
480215091d37SBarry Smith }
480315091d37SBarry Smith 
4804cee9d6f2SShri Abhyankar #undef __FUNCT__
48054dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_3_NaturalOrdering"
48064dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_3_NaturalOrdering(Mat A,Vec bb,Vec xx)
4807b2b2dd24SShri Abhyankar {
4808b2b2dd24SShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
4809*b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
4810b2b2dd24SShri Abhyankar     PetscErrorCode    ierr;
4811*b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,jdx,idt;
4812*b3260449SShri Abhyankar     const PetscInt    bs = A->rmap->bs,bs2 = a->bs2;
4813b2b2dd24SShri Abhyankar     const MatScalar   *aa=a->a,*v;
4814b2b2dd24SShri Abhyankar     PetscScalar       *x;
4815b2b2dd24SShri Abhyankar     const PetscScalar *b;
4816b2b2dd24SShri Abhyankar     PetscScalar        s1,s2,s3,x1,x2,x3;
4817b2b2dd24SShri Abhyankar 
4818b2b2dd24SShri Abhyankar     PetscFunctionBegin;
4819b2b2dd24SShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4820b2b2dd24SShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4821b2b2dd24SShri Abhyankar     /* forward solve the lower triangular */
4822b2b2dd24SShri Abhyankar     idx    = 0;
4823b2b2dd24SShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];
4824b2b2dd24SShri Abhyankar     for (i=1; i<n; i++) {
4825b2b2dd24SShri Abhyankar        v    = aa + bs2*ai[i];
4826b2b2dd24SShri Abhyankar        vi   = aj + ai[i];
4827b2b2dd24SShri Abhyankar        nz   = ai[i+1] - ai[i];
4828b2b2dd24SShri Abhyankar       idx   = bs*i;
4829b2b2dd24SShri Abhyankar        s1   = b[idx];s2 = b[1+idx];s3 = b[2+idx];
4830b2b2dd24SShri Abhyankar       for(k=0;k<nz;k++){
4831b2b2dd24SShri Abhyankar          jdx   = bs*vi[k];
4832b2b2dd24SShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];
4833b2b2dd24SShri Abhyankar           s1   -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4834b2b2dd24SShri Abhyankar           s2   -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4835b2b2dd24SShri Abhyankar           s3   -= v[2]*x1 + v[5]*x2 + v[8]*x3;
4836b2b2dd24SShri Abhyankar 
4837b2b2dd24SShri Abhyankar           v   +=  bs2;
4838b2b2dd24SShri Abhyankar         }
4839b2b2dd24SShri Abhyankar 
4840b2b2dd24SShri Abhyankar        x[idx]   = s1;
4841b2b2dd24SShri Abhyankar        x[1+idx] = s2;
4842b2b2dd24SShri Abhyankar        x[2+idx] = s3;
4843b2b2dd24SShri Abhyankar     }
4844b2b2dd24SShri Abhyankar 
4845b2b2dd24SShri Abhyankar    /* backward solve the upper triangular */
4846b2b2dd24SShri Abhyankar   for (i=n-1; i>=0; i--){
4847b2b2dd24SShri Abhyankar     v   = aa + bs2*(adiag[i+1]+1);
4848b2b2dd24SShri Abhyankar      vi  = aj + adiag[i+1]+1;
4849b2b2dd24SShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
4850b2b2dd24SShri Abhyankar      idt = bs*i;
4851b2b2dd24SShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];s3 = x[2+idt];
4852b2b2dd24SShri Abhyankar 
4853b2b2dd24SShri Abhyankar      for(k=0;k<nz;k++){
4854b2b2dd24SShri Abhyankar        idx   = bs*vi[k];
4855b2b2dd24SShri Abhyankar        x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];
4856b2b2dd24SShri Abhyankar        s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4857b2b2dd24SShri Abhyankar        s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4858b2b2dd24SShri Abhyankar        s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
4859b2b2dd24SShri Abhyankar 
4860b2b2dd24SShri Abhyankar         v   +=  bs2;
4861b2b2dd24SShri Abhyankar     }
4862b2b2dd24SShri Abhyankar     /* x = inv_diagonal*x */
4863b2b2dd24SShri Abhyankar    x[idt]   = v[0]*s1 + v[3]*s2 + v[6]*s3;
4864b2b2dd24SShri Abhyankar    x[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3;
4865b2b2dd24SShri Abhyankar    x[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3;
4866b2b2dd24SShri Abhyankar 
4867b2b2dd24SShri Abhyankar   }
4868b2b2dd24SShri Abhyankar 
4869b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4870b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4871b2b2dd24SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
4872b2b2dd24SShri Abhyankar   PetscFunctionReturn(0);
4873b2b2dd24SShri Abhyankar }
4874b2b2dd24SShri Abhyankar 
4875b2b2dd24SShri Abhyankar #undef __FUNCT__
487606e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_2_inplace"
487706e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_2_inplace(Mat A,Vec bb,Vec xx)
48784e2b4712SSatish Balay {
48794e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
48804e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
48816849ba73SBarry Smith   PetscErrorCode    ierr;
4882*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
4883*b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
48845d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
4885d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
4886d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,x1,x2,*t;
4887d9fead3dSBarry Smith   const PetscScalar *b;
48884e2b4712SSatish Balay 
48894e2b4712SSatish Balay   PetscFunctionBegin;
4890d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
48911ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4892f1af5d2fSBarry Smith   t  = a->solve_work;
48934e2b4712SSatish Balay 
48944e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
48954e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
48964e2b4712SSatish Balay 
48974e2b4712SSatish Balay   /* forward solve the lower triangular */
48984e2b4712SSatish Balay   idx    = 2*(*r++);
4899f1af5d2fSBarry Smith   t[0] = b[idx]; t[1] = b[1+idx];
49004e2b4712SSatish Balay   for (i=1; i<n; i++) {
49014e2b4712SSatish Balay     v     = aa + 4*ai[i];
49024e2b4712SSatish Balay     vi    = aj + ai[i];
49034e2b4712SSatish Balay     nz    = diag[i] - ai[i];
49044e2b4712SSatish Balay     idx   = 2*(*r++);
4905f1af5d2fSBarry Smith     s1  = b[idx]; s2 = b[1+idx];
49064e2b4712SSatish Balay     while (nz--) {
49074e2b4712SSatish Balay       idx   = 2*(*vi++);
4908f1af5d2fSBarry Smith       x1    = t[idx]; x2 = t[1+idx];
4909f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[2]*x2;
4910f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[3]*x2;
49114e2b4712SSatish Balay       v += 4;
49124e2b4712SSatish Balay     }
49134e2b4712SSatish Balay     idx = 2*i;
4914f1af5d2fSBarry Smith     t[idx] = s1; t[1+idx] = s2;
49154e2b4712SSatish Balay   }
49164e2b4712SSatish Balay   /* backward solve the upper triangular */
49174e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
49184e2b4712SSatish Balay     v    = aa + 4*diag[i] + 4;
49194e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
49204e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
49214e2b4712SSatish Balay     idt  = 2*i;
4922f1af5d2fSBarry Smith     s1 = t[idt]; s2 = t[1+idt];
49234e2b4712SSatish Balay     while (nz--) {
49244e2b4712SSatish Balay       idx   = 2*(*vi++);
4925f1af5d2fSBarry Smith       x1    = t[idx]; x2 = t[1+idx];
4926f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[2]*x2;
4927f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[3]*x2;
49284e2b4712SSatish Balay       v += 4;
49294e2b4712SSatish Balay     }
49304e2b4712SSatish Balay     idc = 2*(*c--);
49314e2b4712SSatish Balay     v   = aa + 4*diag[i];
4932f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1 + v[2]*s2;
4933f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1 + v[3]*s2;
49344e2b4712SSatish Balay   }
49354e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
49364e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
4937d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
49381ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4939dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
49404e2b4712SSatish Balay   PetscFunctionReturn(0);
49414e2b4712SSatish Balay }
49424e2b4712SSatish Balay 
49430c4413a7SShri Abhyankar #undef __FUNCT__
49444dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_2"
49454dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_2(Mat A,Vec bb,Vec xx)
49460c4413a7SShri Abhyankar {
49470c4413a7SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
49480c4413a7SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
49490c4413a7SShri Abhyankar   PetscErrorCode    ierr;
4950*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
4951*b3260449SShri Abhyankar   PetscInt          i,nz,idx,jdx,idt,idc,m;
49520c4413a7SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
49530c4413a7SShri Abhyankar   const MatScalar   *aa=a->a,*v;
49540c4413a7SShri Abhyankar   PetscScalar       *x,s1,s2,x1,x2,*t;
49550c4413a7SShri Abhyankar   const PetscScalar *b;
49560c4413a7SShri Abhyankar 
49570c4413a7SShri Abhyankar   PetscFunctionBegin;
49580c4413a7SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
49590c4413a7SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
49600c4413a7SShri Abhyankar   t  = a->solve_work;
49610c4413a7SShri Abhyankar 
49620c4413a7SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
49630c4413a7SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
49640c4413a7SShri Abhyankar 
49650c4413a7SShri Abhyankar   /* forward solve the lower triangular */
49660c4413a7SShri Abhyankar   idx    = 2*r[0];
49670c4413a7SShri Abhyankar   t[0] = b[idx]; t[1] = b[1+idx];
49680c4413a7SShri Abhyankar   for (i=1; i<n; i++) {
49690c4413a7SShri Abhyankar     v     = aa + 4*ai[i];
49700c4413a7SShri Abhyankar     vi    = aj + ai[i];
49710c4413a7SShri Abhyankar     nz    = ai[i+1] - ai[i];
49720c4413a7SShri Abhyankar     idx   = 2*r[i];
49730c4413a7SShri Abhyankar     s1  = b[idx]; s2 = b[1+idx];
49740c4413a7SShri Abhyankar     for(m=0;m<nz;m++){
49750c4413a7SShri Abhyankar       jdx   = 2*vi[m];
49760c4413a7SShri Abhyankar       x1    = t[jdx]; x2 = t[1+jdx];
49770c4413a7SShri Abhyankar       s1 -= v[0]*x1 + v[2]*x2;
49780c4413a7SShri Abhyankar       s2 -= v[1]*x1 + v[3]*x2;
49790c4413a7SShri Abhyankar       v += 4;
49800c4413a7SShri Abhyankar     }
49810c4413a7SShri Abhyankar     idx = 2*i;
49820c4413a7SShri Abhyankar     t[idx] = s1; t[1+idx] = s2;
49830c4413a7SShri Abhyankar   }
49840c4413a7SShri Abhyankar   /* backward solve the upper triangular */
49850c4413a7SShri Abhyankar   for (i=n-1; i>=0; i--){
49860c4413a7SShri Abhyankar     v    = aa + 4*(adiag[i+1]+1);
49870c4413a7SShri Abhyankar     vi   = aj + adiag[i+1]+1;
49880c4413a7SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
49890c4413a7SShri Abhyankar     idt  = 2*i;
49900c4413a7SShri Abhyankar     s1 = t[idt]; s2 = t[1+idt];
49910c4413a7SShri Abhyankar     for(m=0;m<nz;m++){
49920c4413a7SShri Abhyankar       idx   = 2*vi[m];
49930c4413a7SShri Abhyankar       x1    = t[idx]; x2 = t[1+idx];
49940c4413a7SShri Abhyankar       s1 -= v[0]*x1 + v[2]*x2;
49950c4413a7SShri Abhyankar       s2 -= v[1]*x1 + v[3]*x2;
49960c4413a7SShri Abhyankar       v += 4;
49970c4413a7SShri Abhyankar     }
49980c4413a7SShri Abhyankar     idc = 2*c[i];
49990c4413a7SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1 + v[2]*s2;
50000c4413a7SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1 + v[3]*s2;
50010c4413a7SShri Abhyankar   }
50020c4413a7SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
50030c4413a7SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
50040c4413a7SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
50050c4413a7SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
50060c4413a7SShri Abhyankar   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
50070c4413a7SShri Abhyankar   PetscFunctionReturn(0);
50080c4413a7SShri Abhyankar }
50098f690400SShri Abhyankar 
501015091d37SBarry Smith /*
501115091d37SBarry Smith       Special case where the matrix was ILU(0) factored in the natural
501215091d37SBarry Smith    ordering. This eliminates the need for the column and row permutation.
501315091d37SBarry Smith */
50144a2ae208SSatish Balay #undef __FUNCT__
501506e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_2_NaturalOrdering_inplace"
501606e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_2_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
501715091d37SBarry Smith {
501815091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
5019*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
5020dfbe8321SBarry Smith   PetscErrorCode    ierr;
5021d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
5022d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,x1,x2;
5023d9fead3dSBarry Smith   const PetscScalar *b;
5024*b3260449SShri Abhyankar   PetscInt          jdx,idt,idx,nz,i;
502515091d37SBarry Smith 
502615091d37SBarry Smith   PetscFunctionBegin;
5027d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
50281ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
502915091d37SBarry Smith 
503015091d37SBarry Smith   /* forward solve the lower triangular */
503115091d37SBarry Smith   idx    = 0;
503215091d37SBarry Smith   x[0]   = b[0]; x[1] = b[1];
503315091d37SBarry Smith   for (i=1; i<n; i++) {
503415091d37SBarry Smith     v     =  aa      + 4*ai[i];
503515091d37SBarry Smith     vi    =  aj      + ai[i];
503615091d37SBarry Smith     nz    =  diag[i] - ai[i];
503715091d37SBarry Smith     idx   +=  2;
5038f1af5d2fSBarry Smith     s1  =  b[idx];s2 = b[1+idx];
503915091d37SBarry Smith     while (nz--) {
504015091d37SBarry Smith       jdx   = 2*(*vi++);
504115091d37SBarry Smith       x1    = x[jdx];x2 = x[1+jdx];
5042f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[2]*x2;
5043f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[3]*x2;
504415091d37SBarry Smith       v    += 4;
504515091d37SBarry Smith     }
5046f1af5d2fSBarry Smith     x[idx]   = s1;
5047f1af5d2fSBarry Smith     x[1+idx] = s2;
504815091d37SBarry Smith   }
504915091d37SBarry Smith   /* backward solve the upper triangular */
505015091d37SBarry Smith   for (i=n-1; i>=0; i--){
505115091d37SBarry Smith     v    = aa + 4*diag[i] + 4;
505215091d37SBarry Smith     vi   = aj + diag[i] + 1;
505315091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
505415091d37SBarry Smith     idt  = 2*i;
5055f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt];
505615091d37SBarry Smith     while (nz--) {
505715091d37SBarry Smith       idx   = 2*(*vi++);
505815091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx];
5059f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[2]*x2;
5060f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[3]*x2;
506115091d37SBarry Smith       v    += 4;
506215091d37SBarry Smith     }
506315091d37SBarry Smith     v        = aa +  4*diag[i];
5064f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[2]*s2;
5065f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[3]*s2;
506615091d37SBarry Smith   }
506715091d37SBarry Smith 
5068d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
50691ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5070dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
507115091d37SBarry Smith   PetscFunctionReturn(0);
507215091d37SBarry Smith }
507315091d37SBarry Smith 
5074cee9d6f2SShri Abhyankar #undef __FUNCT__
50754dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_2_NaturalOrdering"
50764dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_2_NaturalOrdering(Mat A,Vec bb,Vec xx)
5077b2b2dd24SShri Abhyankar {
5078b2b2dd24SShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
5079*b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
5080*b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,idt,jdx;
5081b2b2dd24SShri Abhyankar     PetscErrorCode    ierr;
5082b2b2dd24SShri Abhyankar     const MatScalar   *aa=a->a,*v;
5083b2b2dd24SShri Abhyankar     PetscScalar       *x,s1,s2,x1,x2;
5084b2b2dd24SShri Abhyankar     const PetscScalar *b;
5085b2b2dd24SShri Abhyankar 
5086b2b2dd24SShri Abhyankar     PetscFunctionBegin;
5087b2b2dd24SShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
5088b2b2dd24SShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
5089b2b2dd24SShri Abhyankar     /* forward solve the lower triangular */
5090b2b2dd24SShri Abhyankar     idx    = 0;
5091b2b2dd24SShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];
5092b2b2dd24SShri Abhyankar     for (i=1; i<n; i++) {
5093b2b2dd24SShri Abhyankar         v   = aa + 4*ai[i];
5094b2b2dd24SShri Abhyankar        vi   = aj + ai[i];
5095b2b2dd24SShri Abhyankar        nz   = ai[i+1] - ai[i];
5096b2b2dd24SShri Abhyankar        idx  = 2*i;
5097b2b2dd24SShri Abhyankar        s1   = b[idx];s2 = b[1+idx];
5098b2b2dd24SShri Abhyankar       for(k=0;k<nz;k++){
5099b2b2dd24SShri Abhyankar          jdx   = 2*vi[k];
5100b2b2dd24SShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx];
5101b2b2dd24SShri Abhyankar           s1   -= v[0]*x1 + v[2]*x2;
5102b2b2dd24SShri Abhyankar           s2   -= v[1]*x1 + v[3]*x2;
5103b2b2dd24SShri Abhyankar            v   +=  4;
5104b2b2dd24SShri Abhyankar         }
5105b2b2dd24SShri Abhyankar        x[idx]   = s1;
5106b2b2dd24SShri Abhyankar        x[1+idx] = s2;
5107b2b2dd24SShri Abhyankar     }
5108b2b2dd24SShri Abhyankar 
5109b2b2dd24SShri Abhyankar    /* backward solve the upper triangular */
5110b2b2dd24SShri Abhyankar   for (i=n-1; i>=0; i--){
5111b2b2dd24SShri Abhyankar      v   = aa + 4*(adiag[i+1]+1);
5112b2b2dd24SShri Abhyankar      vi  = aj + adiag[i+1]+1;
5113b2b2dd24SShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
5114b2b2dd24SShri Abhyankar      idt = 2*i;
5115b2b2dd24SShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];
5116b2b2dd24SShri Abhyankar      for(k=0;k<nz;k++){
5117b2b2dd24SShri Abhyankar       idx   = 2*vi[k];
5118b2b2dd24SShri Abhyankar        x1    = x[idx];   x2 = x[1+idx];
5119b2b2dd24SShri Abhyankar        s1 -= v[0]*x1 + v[2]*x2;
5120b2b2dd24SShri Abhyankar        s2 -= v[1]*x1 + v[3]*x2;
5121b2b2dd24SShri Abhyankar          v    += 4;
5122b2b2dd24SShri Abhyankar     }
5123b2b2dd24SShri Abhyankar     /* x = inv_diagonal*x */
5124b2b2dd24SShri Abhyankar    x[idt]   = v[0]*s1 + v[2]*s2;
5125b2b2dd24SShri Abhyankar    x[1+idt] = v[1]*s1 + v[3]*s2;
5126b2b2dd24SShri Abhyankar   }
5127b2b2dd24SShri Abhyankar 
5128b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
5129b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5130b2b2dd24SShri Abhyankar   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
5131b2b2dd24SShri Abhyankar   PetscFunctionReturn(0);
5132b2b2dd24SShri Abhyankar }
5133b2b2dd24SShri Abhyankar 
5134b2b2dd24SShri Abhyankar #undef __FUNCT__
513506e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_1_inplace"
513606e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_1_inplace(Mat A,Vec bb,Vec xx)
51374e2b4712SSatish Balay {
51384e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
51394e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
51406849ba73SBarry Smith   PetscErrorCode    ierr;
5141*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
5142*b3260449SShri Abhyankar   PetscInt          i,nz;
51435d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
5144*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
5145*b3260449SShri Abhyankar   PetscScalar       *x,s1,*t;
5146*b3260449SShri Abhyankar   const PetscScalar *b;
51474e2b4712SSatish Balay 
51484e2b4712SSatish Balay   PetscFunctionBegin;
51494e2b4712SSatish Balay   if (!n) PetscFunctionReturn(0);
51504e2b4712SSatish Balay 
5151*b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
51521ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
5153f1af5d2fSBarry Smith   t  = a->solve_work;
51544e2b4712SSatish Balay 
51554e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
51564e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
51574e2b4712SSatish Balay 
51584e2b4712SSatish Balay   /* forward solve the lower triangular */
5159f1af5d2fSBarry Smith   t[0] = b[*r++];
51604e2b4712SSatish Balay   for (i=1; i<n; i++) {
51614e2b4712SSatish Balay     v     = aa + ai[i];
51624e2b4712SSatish Balay     vi    = aj + ai[i];
51634e2b4712SSatish Balay     nz    = diag[i] - ai[i];
5164f1af5d2fSBarry Smith     s1  = b[*r++];
51654e2b4712SSatish Balay     while (nz--) {
5166f1af5d2fSBarry Smith       s1 -= (*v++)*t[*vi++];
51674e2b4712SSatish Balay     }
5168f1af5d2fSBarry Smith     t[i] = s1;
51694e2b4712SSatish Balay   }
51704e2b4712SSatish Balay   /* backward solve the upper triangular */
51714e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
51724e2b4712SSatish Balay     v    = aa + diag[i] + 1;
51734e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
51744e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
5175f1af5d2fSBarry Smith     s1 = t[i];
51764e2b4712SSatish Balay     while (nz--) {
5177f1af5d2fSBarry Smith       s1 -= (*v++)*t[*vi++];
51784e2b4712SSatish Balay     }
5179f1af5d2fSBarry Smith     x[*c--] = t[i] = aa[diag[i]]*s1;
51804e2b4712SSatish Balay   }
51814e2b4712SSatish Balay 
51824e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
51834e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
5184*b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
51851ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5186dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*1*(a->nz) - A->cmap->n);CHKERRQ(ierr);
51874e2b4712SSatish Balay   PetscFunctionReturn(0);
51884e2b4712SSatish Balay }
518915091d37SBarry Smith /*
519015091d37SBarry Smith       Special case where the matrix was ILU(0) factored in the natural
519115091d37SBarry Smith    ordering. This eliminates the need for the column and row permutation.
519215091d37SBarry Smith */
51934a2ae208SSatish Balay #undef __FUNCT__
519406e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_1_NaturalOrdering_inplace"
519506e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_1_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
519615091d37SBarry Smith {
519715091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
5198*b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
5199dfbe8321SBarry Smith   PetscErrorCode    ierr;
5200*b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
5201*b3260449SShri Abhyankar   PetscScalar       *x;
5202*b3260449SShri Abhyankar   const PetscScalar *b;
520387828ca2SBarry Smith   PetscScalar       s1,x1;
5204*b3260449SShri Abhyankar   PetscInt          jdx,idt,idx,nz,i;
520515091d37SBarry Smith 
520615091d37SBarry Smith   PetscFunctionBegin;
5207*b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
52081ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
520915091d37SBarry Smith 
521015091d37SBarry Smith   /* forward solve the lower triangular */
521115091d37SBarry Smith   idx    = 0;
521215091d37SBarry Smith   x[0]   = b[0];
521315091d37SBarry Smith   for (i=1; i<n; i++) {
521415091d37SBarry Smith     v     =  aa      + ai[i];
521515091d37SBarry Smith     vi    =  aj      + ai[i];
521615091d37SBarry Smith     nz    =  diag[i] - ai[i];
521715091d37SBarry Smith     idx   +=  1;
5218f1af5d2fSBarry Smith     s1  =  b[idx];
521915091d37SBarry Smith     while (nz--) {
522015091d37SBarry Smith       jdx   = *vi++;
522115091d37SBarry Smith       x1    = x[jdx];
5222f1af5d2fSBarry Smith       s1 -= v[0]*x1;
522315091d37SBarry Smith       v    += 1;
522415091d37SBarry Smith     }
5225f1af5d2fSBarry Smith     x[idx]   = s1;
522615091d37SBarry Smith   }
522715091d37SBarry Smith   /* backward solve the upper triangular */
522815091d37SBarry Smith   for (i=n-1; i>=0; i--){
522915091d37SBarry Smith     v    = aa + diag[i] + 1;
523015091d37SBarry Smith     vi   = aj + diag[i] + 1;
523115091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
523215091d37SBarry Smith     idt  = i;
5233f1af5d2fSBarry Smith     s1 = x[idt];
523415091d37SBarry Smith     while (nz--) {
523515091d37SBarry Smith       idx   = *vi++;
523615091d37SBarry Smith       x1    = x[idx];
5237f1af5d2fSBarry Smith       s1 -= v[0]*x1;
523815091d37SBarry Smith       v    += 1;
523915091d37SBarry Smith     }
524015091d37SBarry Smith     v        = aa +  diag[i];
5241f1af5d2fSBarry Smith     x[idt]   = v[0]*s1;
524215091d37SBarry Smith   }
5243*b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
52441ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5245dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*(a->nz) - A->cmap->n);CHKERRQ(ierr);
524615091d37SBarry Smith   PetscFunctionReturn(0);
524715091d37SBarry Smith }
52484e2b4712SSatish Balay 
52494e2b4712SSatish Balay /* ----------------------------------------------------------------*/
525016a2bf60SHong Zhang EXTERN PetscErrorCode MatDuplicateNoCreate_SeqBAIJ(Mat,Mat,MatDuplicateOption,PetscTruth);
52516bce7ff8SHong Zhang 
52522b0b2ea7SShri Abhyankar #undef __FUNCT__
525329a97285SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_15_NaturalOrdering"
5254766f9fbaSBarry Smith /*
5255766f9fbaSBarry Smith    This is not much faster than MatLUFactorNumeric_SeqBAIJ_N() but the solve is faster at least sometimes
5256766f9fbaSBarry Smith */
525729a97285SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_15_NaturalOrdering(Mat B,Mat A,const MatFactorInfo *info)
52582b0b2ea7SShri Abhyankar {
52592b0b2ea7SShri Abhyankar   Mat             C=B;
52602b0b2ea7SShri Abhyankar   Mat_SeqBAIJ     *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data;
52612b0b2ea7SShri Abhyankar   PetscErrorCode  ierr;
5262766f9fbaSBarry Smith   PetscInt        i,j,k,ipvt[15];
5263766f9fbaSBarry Smith   const PetscInt  n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j,*ajtmp,*bjtmp,*bdiag=b->diag,*pj;
5264766f9fbaSBarry Smith   PetscInt        nz,nzL,row;
5265766f9fbaSBarry Smith   MatScalar       *rtmp,*pc,*mwork,*pv,*vv,work[225];
5266766f9fbaSBarry Smith   const MatScalar *v,*aa=a->a;
52672b0b2ea7SShri Abhyankar   PetscInt        bs2 = a->bs2,bs=A->rmap->bs,flg;
52682b0b2ea7SShri Abhyankar 
52692b0b2ea7SShri Abhyankar   PetscFunctionBegin;
52702b0b2ea7SShri Abhyankar 
52712b0b2ea7SShri Abhyankar   /* generate work space needed by the factorization */
52722b0b2ea7SShri Abhyankar   ierr = PetscMalloc2(bs2*n,MatScalar,&rtmp,bs2,MatScalar,&mwork);CHKERRQ(ierr);
52732b0b2ea7SShri Abhyankar   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
52742b0b2ea7SShri Abhyankar 
52752b0b2ea7SShri Abhyankar   for (i=0; i<n; i++){
52762b0b2ea7SShri Abhyankar     /* zero rtmp */
52772b0b2ea7SShri Abhyankar     /* L part */
52782b0b2ea7SShri Abhyankar     nz    = bi[i+1] - bi[i];
52792b0b2ea7SShri Abhyankar     bjtmp = bj + bi[i];
52802b0b2ea7SShri Abhyankar     for  (j=0; j<nz; j++){
52812b0b2ea7SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
52822b0b2ea7SShri Abhyankar     }
52832b0b2ea7SShri Abhyankar 
52842b0b2ea7SShri Abhyankar     /* U part */
52852b0b2ea7SShri Abhyankar     nz = bdiag[i] - bdiag[i+1];
52862b0b2ea7SShri Abhyankar     bjtmp = bj + bdiag[i+1]+1;
52872b0b2ea7SShri Abhyankar     for  (j=0; j<nz; j++){
52882b0b2ea7SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
52892b0b2ea7SShri Abhyankar     }
52902b0b2ea7SShri Abhyankar 
52912b0b2ea7SShri Abhyankar     /* load in initial (unfactored row) */
529229a97285SShri Abhyankar     nz    = ai[i+1] - ai[i];
529329a97285SShri Abhyankar     ajtmp = aj + ai[i];
529429a97285SShri Abhyankar     v     = aa + bs2*ai[i];
52952b0b2ea7SShri Abhyankar     for (j=0; j<nz; j++) {
529629a97285SShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ajtmp[j],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
52972b0b2ea7SShri Abhyankar     }
52982b0b2ea7SShri Abhyankar 
52992b0b2ea7SShri Abhyankar     /* elimination */
53002b0b2ea7SShri Abhyankar     bjtmp = bj + bi[i];
53012b0b2ea7SShri Abhyankar     nzL   = bi[i+1] - bi[i];
53022b0b2ea7SShri Abhyankar     for(k=0;k < nzL;k++) {
53032b0b2ea7SShri Abhyankar       row = bjtmp[k];
53042b0b2ea7SShri Abhyankar       pc = rtmp + bs2*row;
53052b0b2ea7SShri Abhyankar       for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }}
53062b0b2ea7SShri Abhyankar       if (flg) {
53072b0b2ea7SShri Abhyankar         pv = b->a + bs2*bdiag[row];
5308766f9fbaSBarry Smith 	Kernel_A_gets_A_times_B(bs,pc,pv,mwork);
5309766f9fbaSBarry Smith 	/*ierr = Kernel_A_gets_A_times_B_15(pc,pv,mwork);CHKERRQ(ierr);*/
53102b0b2ea7SShri Abhyankar 	pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
53112b0b2ea7SShri Abhyankar         pv = b->a + bs2*(bdiag[row+1]+1);
53122b0b2ea7SShri Abhyankar         nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
53132b0b2ea7SShri Abhyankar         for (j=0; j<nz; j++) {
5314766f9fbaSBarry Smith           vv   = rtmp + bs2*pj[j];
5315766f9fbaSBarry Smith           Kernel_A_gets_A_minus_B_times_C(bs,vv,pc,pv);
5316766f9fbaSBarry Smith 	  /* ierr = Kernel_A_gets_A_minus_B_times_C_15(vv,pc,pv);CHKERRQ(ierr); */
53172b0b2ea7SShri Abhyankar 	  pv  += bs2;
53182b0b2ea7SShri Abhyankar         }
5319766f9fbaSBarry Smith         ierr = PetscLogFlops(2*bs2*bs*(nz+1)-bs2);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
53202b0b2ea7SShri Abhyankar       }
53212b0b2ea7SShri Abhyankar     }
53222b0b2ea7SShri Abhyankar 
53232b0b2ea7SShri Abhyankar     /* finished row so stick it into b->a */
53242b0b2ea7SShri Abhyankar     /* L part */
53252b0b2ea7SShri Abhyankar     pv   = b->a + bs2*bi[i] ;
53262b0b2ea7SShri Abhyankar     pj   = b->j + bi[i] ;
53272b0b2ea7SShri Abhyankar     nz   = bi[i+1] - bi[i];
53282b0b2ea7SShri Abhyankar     for (j=0; j<nz; j++) {
53292b0b2ea7SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
53302b0b2ea7SShri Abhyankar     }
53312b0b2ea7SShri Abhyankar 
53322b0b2ea7SShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
53332b0b2ea7SShri Abhyankar     pv   = b->a + bs2*bdiag[i];
53342b0b2ea7SShri Abhyankar     pj   = b->j + bdiag[i];
53352b0b2ea7SShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
5336766f9fbaSBarry Smith     /* Kernel_A_gets_inverse_A(bs,pv,pivots,work); */
5337766f9fbaSBarry Smith     ierr = Kernel_A_gets_inverse_A_15(pv,ipvt,work,info->shiftinblocks);CHKERRQ(ierr);
53382b0b2ea7SShri Abhyankar 
53392b0b2ea7SShri Abhyankar     /* U part */
53402b0b2ea7SShri Abhyankar     pv = b->a + bs2*(bdiag[i+1]+1);
53412b0b2ea7SShri Abhyankar     pj = b->j + bdiag[i+1]+1;
53422b0b2ea7SShri Abhyankar     nz = bdiag[i] - bdiag[i+1] - 1;
53432b0b2ea7SShri Abhyankar     for (j=0; j<nz; j++){
53442b0b2ea7SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
53452b0b2ea7SShri Abhyankar     }
53462b0b2ea7SShri Abhyankar   }
53472b0b2ea7SShri Abhyankar 
53482b0b2ea7SShri Abhyankar   ierr = PetscFree2(rtmp,mwork);CHKERRQ(ierr);
534929a97285SShri Abhyankar   C->ops->solve          = MatSolve_SeqBAIJ_15_NaturalOrdering;
5350766f9fbaSBarry Smith   C->ops->solvetranspose = MatSolve_SeqBAIJ_N_NaturalOrdering;
53512b0b2ea7SShri Abhyankar   C->assembled = PETSC_TRUE;
5352766f9fbaSBarry Smith   ierr = PetscLogFlops(1.333333333333*bs*bs2*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */
53532b0b2ea7SShri Abhyankar   PetscFunctionReturn(0);
53542b0b2ea7SShri Abhyankar }
53552b0b2ea7SShri Abhyankar 
53566bce7ff8SHong Zhang #undef __FUNCT__
53574dd39f65SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_N"
53584dd39f65SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_N(Mat B,Mat A,const MatFactorInfo *info)
53596bce7ff8SHong Zhang {
53606bce7ff8SHong Zhang   Mat            C=B;
53616bce7ff8SHong Zhang   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data;
53626bce7ff8SHong Zhang   IS             isrow = b->row,isicol = b->icol;
53636bce7ff8SHong Zhang   PetscErrorCode ierr;
53646bce7ff8SHong Zhang   const PetscInt *r,*ic,*ics;
53656bce7ff8SHong Zhang   PetscInt       i,j,k,n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
53666bce7ff8SHong Zhang   PetscInt       *ajtmp,*bjtmp,nz,nzL,row,*bdiag=b->diag,*pj;
5367b588c5a2SHong Zhang   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
5368914a18a2SHong Zhang   PetscInt       bs=A->rmap->bs,bs2 = a->bs2,*v_pivots,flg;
5369914a18a2SHong Zhang   MatScalar      *v_work;
5370ae3d28f0SHong Zhang   PetscTruth     col_identity,row_identity,both_identity;
53716bce7ff8SHong Zhang 
53726bce7ff8SHong Zhang   PetscFunctionBegin;
53736bce7ff8SHong Zhang   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
53746bce7ff8SHong Zhang   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
5375ae3d28f0SHong Zhang 
5376fca92195SBarry Smith   ierr = PetscMalloc(bs2*n*sizeof(MatScalar),&rtmp);CHKERRQ(ierr);
5377fca92195SBarry Smith   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
53786bce7ff8SHong Zhang   ics  = ic;
53796bce7ff8SHong Zhang 
5380914a18a2SHong Zhang   /* generate work space needed by dense LU factorization */
5381fca92195SBarry Smith   ierr  = PetscMalloc3(bs,MatScalar,&v_work,bs2,MatScalar,&mwork,bs,PetscInt,&v_pivots);CHKERRQ(ierr);
5382914a18a2SHong Zhang 
53836bce7ff8SHong Zhang   for (i=0; i<n; i++){
53846bce7ff8SHong Zhang     /* zero rtmp */
53856bce7ff8SHong Zhang     /* L part */
53866bce7ff8SHong Zhang     nz    = bi[i+1] - bi[i];
53876bce7ff8SHong Zhang     bjtmp = bj + bi[i];
5388914a18a2SHong Zhang     for  (j=0; j<nz; j++){
5389914a18a2SHong Zhang       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
5390914a18a2SHong Zhang     }
53916bce7ff8SHong Zhang 
53926bce7ff8SHong Zhang     /* U part */
53931a83e813SShri Abhyankar     nz = bdiag[i] - bdiag[i+1];
53941a83e813SShri Abhyankar     bjtmp = bj + bdiag[i+1]+1;
53951a83e813SShri Abhyankar     for  (j=0; j<nz; j++){
53961a83e813SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
53971a83e813SShri Abhyankar     }
53981a83e813SShri Abhyankar 
53991a83e813SShri Abhyankar     /* load in initial (unfactored row) */
54001a83e813SShri Abhyankar     nz    = ai[r[i]+1] - ai[r[i]];
54011a83e813SShri Abhyankar     ajtmp = aj + ai[r[i]];
54021a83e813SShri Abhyankar     v     = aa + bs2*ai[r[i]];
54031a83e813SShri Abhyankar     for (j=0; j<nz; j++) {
54041a83e813SShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ic[ajtmp[j]],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
54051a83e813SShri Abhyankar     }
54061a83e813SShri Abhyankar 
54071a83e813SShri Abhyankar     /* elimination */
54081a83e813SShri Abhyankar     bjtmp = bj + bi[i];
54091a83e813SShri Abhyankar     nzL   = bi[i+1] - bi[i];
54101a83e813SShri Abhyankar     for(k=0;k < nzL;k++) {
54111a83e813SShri Abhyankar       row = bjtmp[k];
54121a83e813SShri Abhyankar       pc = rtmp + bs2*row;
54131a83e813SShri Abhyankar       for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }}
54141a83e813SShri Abhyankar       if (flg) {
54151a83e813SShri Abhyankar         pv         = b->a + bs2*bdiag[row];
54161a83e813SShri Abhyankar         Kernel_A_gets_A_times_B(bs,pc,pv,mwork); /* *pc = *pc * (*pv); */
54171a83e813SShri Abhyankar         pj         = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
54181a83e813SShri Abhyankar         pv         = b->a + bs2*(bdiag[row+1]+1);
54191a83e813SShri Abhyankar         nz         = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
54201a83e813SShri Abhyankar         for (j=0; j<nz; j++) {
54211a83e813SShri Abhyankar           Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j);
54221a83e813SShri Abhyankar         }
54231a83e813SShri Abhyankar         ierr = PetscLogFlops(2*bs2*bs*(nz+1)-bs2);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
54241a83e813SShri Abhyankar       }
54251a83e813SShri Abhyankar     }
54261a83e813SShri Abhyankar 
54271a83e813SShri Abhyankar     /* finished row so stick it into b->a */
54281a83e813SShri Abhyankar     /* L part */
54291a83e813SShri Abhyankar     pv   = b->a + bs2*bi[i] ;
54301a83e813SShri Abhyankar     pj   = b->j + bi[i] ;
54311a83e813SShri Abhyankar     nz   = bi[i+1] - bi[i];
54321a83e813SShri Abhyankar     for (j=0; j<nz; j++) {
54331a83e813SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
54341a83e813SShri Abhyankar     }
54351a83e813SShri Abhyankar 
54361a83e813SShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
54371a83e813SShri Abhyankar     pv  = b->a + bs2*bdiag[i];
54381a83e813SShri Abhyankar     pj  = b->j + bdiag[i];
54391a83e813SShri Abhyankar     /* if (*pj != i)SETERRQ2(PETSC_ERR_SUP,"row %d != *pj %d",i,*pj); */
54401a83e813SShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
54411a83e813SShri Abhyankar     ierr = Kernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr);
54421a83e813SShri Abhyankar 
54431a83e813SShri Abhyankar     /* U part */
54441a83e813SShri Abhyankar     pv = b->a + bs2*(bdiag[i+1]+1);
54451a83e813SShri Abhyankar     pj = b->j + bdiag[i+1]+1;
54461a83e813SShri Abhyankar     nz = bdiag[i] - bdiag[i+1] - 1;
54471a83e813SShri Abhyankar     for (j=0; j<nz; j++){
54481a83e813SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
54491a83e813SShri Abhyankar     }
54501a83e813SShri Abhyankar   }
54511a83e813SShri Abhyankar 
54521a83e813SShri Abhyankar   ierr = PetscFree(rtmp);CHKERRQ(ierr);
5453fca92195SBarry Smith   ierr = PetscFree3(v_work,mwork,v_pivots);CHKERRQ(ierr);
54541a83e813SShri Abhyankar   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
54551a83e813SShri Abhyankar   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
54561a83e813SShri Abhyankar 
5457ae3d28f0SHong Zhang   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
5458ae3d28f0SHong Zhang   ierr = ISIdentity(isicol,&col_identity);CHKERRQ(ierr);
5459ae3d28f0SHong Zhang   both_identity = (PetscTruth) (row_identity && col_identity);
5460ae3d28f0SHong Zhang   if (both_identity){
54614dd39f65SShri Abhyankar     C->ops->solve = MatSolve_SeqBAIJ_N_NaturalOrdering;
5462ae3d28f0SHong Zhang   } else {
54634dd39f65SShri Abhyankar     C->ops->solve = MatSolve_SeqBAIJ_N;
5464ae3d28f0SHong Zhang   }
54654dd39f65SShri Abhyankar   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_N;
5466ae3d28f0SHong Zhang 
54671a83e813SShri Abhyankar   C->assembled = PETSC_TRUE;
5468766f9fbaSBarry Smith   ierr = PetscLogFlops(1.333333333333*bs*bs2*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */
54691a83e813SShri Abhyankar   PetscFunctionReturn(0);
54701a83e813SShri Abhyankar }
54711a83e813SShri Abhyankar 
54726bce7ff8SHong Zhang /*
54736bce7ff8SHong Zhang    ilu(0) with natural ordering under new data structure.
54744dd39f65SShri Abhyankar    See MatILUFactorSymbolic_SeqAIJ_ilu0() for detailed description
54754dd39f65SShri Abhyankar    because this code is almost identical to MatILUFactorSymbolic_SeqAIJ_ilu0_inplace().
54766bce7ff8SHong Zhang */
5477c0c7eb62SShri Abhyankar 
54786bce7ff8SHong Zhang #undef __FUNCT__
54794dd39f65SShri Abhyankar #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ_ilu0"
54804dd39f65SShri Abhyankar PetscErrorCode MatILUFactorSymbolic_SeqBAIJ_ilu0(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
54816bce7ff8SHong Zhang {
54826bce7ff8SHong Zhang 
54836bce7ff8SHong Zhang   Mat_SeqBAIJ        *a = (Mat_SeqBAIJ*)A->data,*b;
54846bce7ff8SHong Zhang   PetscErrorCode     ierr;
548516a2bf60SHong Zhang   PetscInt           n=a->mbs,*ai=a->i,*aj,*adiag=a->diag,bs2 = a->bs2;
548635aa4fcfSShri Abhyankar   PetscInt           i,j,nz,*bi,*bj,*bdiag,bi_temp;
548735aa4fcfSShri Abhyankar 
548835aa4fcfSShri Abhyankar   PetscFunctionBegin;
548935aa4fcfSShri Abhyankar   ierr = MatDuplicateNoCreate_SeqBAIJ(fact,A,MAT_DO_NOT_COPY_VALUES,PETSC_FALSE);CHKERRQ(ierr);
549035aa4fcfSShri Abhyankar   b    = (Mat_SeqBAIJ*)(fact)->data;
549135aa4fcfSShri Abhyankar 
549235aa4fcfSShri Abhyankar   /* allocate matrix arrays for new data structure */
549335aa4fcfSShri Abhyankar   ierr = PetscMalloc3(bs2*ai[n]+1,PetscScalar,&b->a,ai[n]+1,PetscInt,&b->j,n+1,PetscInt,&b->i);CHKERRQ(ierr);
549435aa4fcfSShri Abhyankar   ierr = PetscLogObjectMemory(fact,ai[n]*(bs2*sizeof(PetscScalar)+sizeof(PetscInt))+(n+1)*sizeof(PetscInt));CHKERRQ(ierr);
549535aa4fcfSShri Abhyankar   b->singlemalloc = PETSC_TRUE;
549635aa4fcfSShri Abhyankar   if (!b->diag){
549735aa4fcfSShri Abhyankar     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&b->diag);CHKERRQ(ierr);
549835aa4fcfSShri Abhyankar     ierr = PetscLogObjectMemory(fact,(n+1)*sizeof(PetscInt));CHKERRQ(ierr);
549935aa4fcfSShri Abhyankar   }
550035aa4fcfSShri Abhyankar   bdiag = b->diag;
550135aa4fcfSShri Abhyankar 
550235aa4fcfSShri Abhyankar   if (n > 0) {
550335aa4fcfSShri Abhyankar     ierr = PetscMemzero(b->a,bs2*ai[n]*sizeof(MatScalar));CHKERRQ(ierr);
550435aa4fcfSShri Abhyankar   }
550535aa4fcfSShri Abhyankar 
550635aa4fcfSShri Abhyankar   /* set bi and bj with new data structure */
550735aa4fcfSShri Abhyankar   bi = b->i;
550835aa4fcfSShri Abhyankar   bj = b->j;
550935aa4fcfSShri Abhyankar 
551035aa4fcfSShri Abhyankar   /* L part */
551135aa4fcfSShri Abhyankar   bi[0] = 0;
551235aa4fcfSShri Abhyankar   for (i=0; i<n; i++){
551335aa4fcfSShri Abhyankar     nz = adiag[i] - ai[i];
551435aa4fcfSShri Abhyankar     bi[i+1] = bi[i] + nz;
551535aa4fcfSShri Abhyankar     aj = a->j + ai[i];
551635aa4fcfSShri Abhyankar     for (j=0; j<nz; j++){
551735aa4fcfSShri Abhyankar       *bj = aj[j]; bj++;
551835aa4fcfSShri Abhyankar     }
551935aa4fcfSShri Abhyankar   }
552035aa4fcfSShri Abhyankar 
552135aa4fcfSShri Abhyankar   /* U part */
552235aa4fcfSShri Abhyankar   bi_temp = bi[n];
552335aa4fcfSShri Abhyankar   bdiag[n] = bi[n]-1;
552435aa4fcfSShri Abhyankar   for (i=n-1; i>=0; i--){
552535aa4fcfSShri Abhyankar     nz = ai[i+1] - adiag[i] - 1;
552635aa4fcfSShri Abhyankar     bi_temp = bi_temp + nz + 1;
552735aa4fcfSShri Abhyankar     aj = a->j + adiag[i] + 1;
552835aa4fcfSShri Abhyankar     for (j=0; j<nz; j++){
552935aa4fcfSShri Abhyankar       *bj = aj[j]; bj++;
553035aa4fcfSShri Abhyankar     }
553135aa4fcfSShri Abhyankar     /* diag[i] */
553235aa4fcfSShri Abhyankar     *bj = i; bj++;
553335aa4fcfSShri Abhyankar     bdiag[i] = bi_temp - 1;
553435aa4fcfSShri Abhyankar   }
553535aa4fcfSShri Abhyankar   PetscFunctionReturn(0);
553635aa4fcfSShri Abhyankar }
553735aa4fcfSShri Abhyankar 
553835aa4fcfSShri Abhyankar #undef __FUNCT__
55394dd39f65SShri Abhyankar #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ"
55404dd39f65SShri Abhyankar PetscErrorCode MatILUFactorSymbolic_SeqBAIJ(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
554116a2bf60SHong Zhang {
554216a2bf60SHong Zhang   Mat_SeqBAIJ        *a = (Mat_SeqBAIJ*)A->data,*b;
554316a2bf60SHong Zhang   IS                 isicol;
554416a2bf60SHong Zhang   PetscErrorCode     ierr;
554516a2bf60SHong Zhang   const PetscInt     *r,*ic;
55467fa3a6a0SHong Zhang   PetscInt           n=a->mbs,*ai=a->i,*aj=a->j,d;
554716a2bf60SHong Zhang   PetscInt           *bi,*cols,nnz,*cols_lvl;
554816a2bf60SHong Zhang   PetscInt           *bdiag,prow,fm,nzbd,reallocs=0,dcount=0;
554916a2bf60SHong Zhang   PetscInt           i,levels,diagonal_fill;
55507fa3a6a0SHong Zhang   PetscTruth         col_identity,row_identity,both_identity;
555116a2bf60SHong Zhang   PetscReal          f;
555216a2bf60SHong Zhang   PetscInt           nlnk,*lnk,*lnk_lvl=PETSC_NULL;
555316a2bf60SHong Zhang   PetscBT            lnkbt;
555416a2bf60SHong Zhang   PetscInt           nzi,*bj,**bj_ptr,**bjlvl_ptr;
555516a2bf60SHong Zhang   PetscFreeSpaceList free_space=PETSC_NULL,current_space=PETSC_NULL;
555616a2bf60SHong Zhang   PetscFreeSpaceList free_space_lvl=PETSC_NULL,current_space_lvl=PETSC_NULL;
555716a2bf60SHong Zhang   PetscTruth         missing;
55587fa3a6a0SHong Zhang   PetscInt           bs=A->rmap->bs,bs2=a->bs2;
55594dd39f65SShri Abhyankar   PetscTruth         olddatastruct = PETSC_FALSE;
556016a2bf60SHong Zhang 
556116a2bf60SHong Zhang   PetscFunctionBegin;
55624dd39f65SShri Abhyankar   ierr = PetscOptionsGetTruth(PETSC_NULL,"-ilu_old",&olddatastruct,PETSC_NULL);CHKERRQ(ierr);
55634dd39f65SShri Abhyankar   if (olddatastruct){
556406e38f1dSHong Zhang     ierr = MatILUFactorSymbolic_SeqBAIJ_inplace(fact,A,isrow,iscol,info);CHKERRQ(ierr);
556506e38f1dSHong Zhang     PetscFunctionReturn(0);
556606e38f1dSHong Zhang   }
556716a2bf60SHong 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);
556816a2bf60SHong Zhang   ierr = MatMissingDiagonal(A,&missing,&d);CHKERRQ(ierr);
556916a2bf60SHong Zhang   if (missing) SETERRQ1(PETSC_ERR_ARG_WRONGSTATE,"Matrix is missing diagonal entry %D",d);
557016a2bf60SHong Zhang 
557116a2bf60SHong Zhang   f             = info->fill;
557216a2bf60SHong Zhang   levels        = (PetscInt)info->levels;
557316a2bf60SHong Zhang   diagonal_fill = (PetscInt)info->diagonal_fill;
557416a2bf60SHong Zhang   ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr);
557516a2bf60SHong Zhang 
557616a2bf60SHong Zhang   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
557716a2bf60SHong Zhang   ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr);
55787fa3a6a0SHong Zhang   both_identity = (PetscTruth) (row_identity && col_identity);
557916a2bf60SHong Zhang 
55807fa3a6a0SHong Zhang   if (!levels && both_identity) {
558116a2bf60SHong Zhang     /* special case: ilu(0) with natural ordering */
55824dd39f65SShri Abhyankar     ierr = MatILUFactorSymbolic_SeqBAIJ_ilu0(fact,A,isrow,iscol,info);CHKERRQ(ierr);
55834dd39f65SShri Abhyankar     ierr = MatSeqBAIJSetNumericFactorization(fact,both_identity);CHKERRQ(ierr);
558435aa4fcfSShri Abhyankar 
558535aa4fcfSShri Abhyankar     fact->factor = MAT_FACTOR_ILU;
558635aa4fcfSShri Abhyankar     (fact)->info.factor_mallocs    = 0;
558735aa4fcfSShri Abhyankar     (fact)->info.fill_ratio_given  = info->fill;
558835aa4fcfSShri Abhyankar     (fact)->info.fill_ratio_needed = 1.0;
558935aa4fcfSShri Abhyankar     b                = (Mat_SeqBAIJ*)(fact)->data;
559035aa4fcfSShri Abhyankar     b->row           = isrow;
559135aa4fcfSShri Abhyankar     b->col           = iscol;
559235aa4fcfSShri Abhyankar     b->icol          = isicol;
559335aa4fcfSShri Abhyankar     ierr             = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
559435aa4fcfSShri Abhyankar     ierr             = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
559535aa4fcfSShri Abhyankar     b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
559635aa4fcfSShri Abhyankar     ierr = PetscMalloc((n+1)*bs*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
559735aa4fcfSShri Abhyankar     PetscFunctionReturn(0);
559835aa4fcfSShri Abhyankar   }
559935aa4fcfSShri Abhyankar 
560035aa4fcfSShri Abhyankar   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
560135aa4fcfSShri Abhyankar   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
560235aa4fcfSShri Abhyankar 
560335aa4fcfSShri Abhyankar   /* get new row pointers */
560435aa4fcfSShri Abhyankar   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bi);CHKERRQ(ierr);
560535aa4fcfSShri Abhyankar   bi[0] = 0;
560635aa4fcfSShri Abhyankar   /* bdiag is location of diagonal in factor */
560735aa4fcfSShri Abhyankar   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bdiag);CHKERRQ(ierr);
560835aa4fcfSShri Abhyankar   bdiag[0]  = 0;
560935aa4fcfSShri Abhyankar 
5610fca92195SBarry Smith   ierr = PetscMalloc2(n,PetscInt*,&bj_ptr,n,PetscInt*,&bjlvl_ptr);CHKERRQ(ierr);
561135aa4fcfSShri Abhyankar 
561235aa4fcfSShri Abhyankar   /* create a linked list for storing column indices of the active row */
561335aa4fcfSShri Abhyankar   nlnk = n + 1;
561435aa4fcfSShri Abhyankar   ierr = PetscIncompleteLLCreate(n,n,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr);
561535aa4fcfSShri Abhyankar 
561635aa4fcfSShri Abhyankar   /* initial FreeSpace size is f*(ai[n]+1) */
561735aa4fcfSShri Abhyankar   ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space);CHKERRQ(ierr);
561835aa4fcfSShri Abhyankar   current_space = free_space;
561935aa4fcfSShri Abhyankar   ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space_lvl);CHKERRQ(ierr);
562035aa4fcfSShri Abhyankar   current_space_lvl = free_space_lvl;
562135aa4fcfSShri Abhyankar 
562235aa4fcfSShri Abhyankar   for (i=0; i<n; i++) {
562335aa4fcfSShri Abhyankar     nzi = 0;
562435aa4fcfSShri Abhyankar     /* copy current row into linked list */
562535aa4fcfSShri Abhyankar     nnz  = ai[r[i]+1] - ai[r[i]];
562635aa4fcfSShri 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);
562735aa4fcfSShri Abhyankar     cols = aj + ai[r[i]];
562835aa4fcfSShri Abhyankar     lnk[i] = -1; /* marker to indicate if diagonal exists */
562935aa4fcfSShri Abhyankar     ierr = PetscIncompleteLLInit(nnz,cols,n,ic,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr);
563035aa4fcfSShri Abhyankar     nzi += nlnk;
563135aa4fcfSShri Abhyankar 
563235aa4fcfSShri Abhyankar     /* make sure diagonal entry is included */
563335aa4fcfSShri Abhyankar     if (diagonal_fill && lnk[i] == -1) {
563435aa4fcfSShri Abhyankar       fm = n;
563535aa4fcfSShri Abhyankar       while (lnk[fm] < i) fm = lnk[fm];
563635aa4fcfSShri Abhyankar       lnk[i]     = lnk[fm]; /* insert diagonal into linked list */
563735aa4fcfSShri Abhyankar       lnk[fm]    = i;
563835aa4fcfSShri Abhyankar       lnk_lvl[i] = 0;
563935aa4fcfSShri Abhyankar       nzi++; dcount++;
564035aa4fcfSShri Abhyankar     }
564135aa4fcfSShri Abhyankar 
564235aa4fcfSShri Abhyankar     /* add pivot rows into the active row */
564335aa4fcfSShri Abhyankar     nzbd = 0;
564435aa4fcfSShri Abhyankar     prow = lnk[n];
564535aa4fcfSShri Abhyankar     while (prow < i) {
564635aa4fcfSShri Abhyankar       nnz      = bdiag[prow];
564735aa4fcfSShri Abhyankar       cols     = bj_ptr[prow] + nnz + 1;
564835aa4fcfSShri Abhyankar       cols_lvl = bjlvl_ptr[prow] + nnz + 1;
564935aa4fcfSShri Abhyankar       nnz      = bi[prow+1] - bi[prow] - nnz - 1;
565035aa4fcfSShri Abhyankar       ierr = PetscILULLAddSorted(nnz,cols,levels,cols_lvl,prow,nlnk,lnk,lnk_lvl,lnkbt,prow);CHKERRQ(ierr);
565135aa4fcfSShri Abhyankar       nzi += nlnk;
565235aa4fcfSShri Abhyankar       prow = lnk[prow];
565335aa4fcfSShri Abhyankar       nzbd++;
565435aa4fcfSShri Abhyankar     }
565535aa4fcfSShri Abhyankar     bdiag[i] = nzbd;
565635aa4fcfSShri Abhyankar     bi[i+1]  = bi[i] + nzi;
565735aa4fcfSShri Abhyankar 
565835aa4fcfSShri Abhyankar     /* if free space is not available, make more free space */
565935aa4fcfSShri Abhyankar     if (current_space->local_remaining<nzi) {
566035aa4fcfSShri Abhyankar       nnz = 2*nzi*(n - i); /* estimated and max additional space needed */
566135aa4fcfSShri Abhyankar       ierr = PetscFreeSpaceGet(nnz,&current_space);CHKERRQ(ierr);
566235aa4fcfSShri Abhyankar       ierr = PetscFreeSpaceGet(nnz,&current_space_lvl);CHKERRQ(ierr);
566335aa4fcfSShri Abhyankar       reallocs++;
566435aa4fcfSShri Abhyankar     }
566535aa4fcfSShri Abhyankar 
566635aa4fcfSShri Abhyankar     /* copy data into free_space and free_space_lvl, then initialize lnk */
566735aa4fcfSShri Abhyankar     ierr = PetscIncompleteLLClean(n,n,nzi,lnk,lnk_lvl,current_space->array,current_space_lvl->array,lnkbt);CHKERRQ(ierr);
566835aa4fcfSShri Abhyankar     bj_ptr[i]    = current_space->array;
566935aa4fcfSShri Abhyankar     bjlvl_ptr[i] = current_space_lvl->array;
567035aa4fcfSShri Abhyankar 
567135aa4fcfSShri Abhyankar     /* make sure the active row i has diagonal entry */
567235aa4fcfSShri Abhyankar     if (*(bj_ptr[i]+bdiag[i]) != i) {
567335aa4fcfSShri Abhyankar       SETERRQ1(PETSC_ERR_MAT_LU_ZRPVT,"Row %D has missing diagonal in factored matrix\n\
567435aa4fcfSShri Abhyankar     try running with -pc_factor_nonzeros_along_diagonal or -pc_factor_diagonal_fill",i);
567535aa4fcfSShri Abhyankar     }
567635aa4fcfSShri Abhyankar 
567735aa4fcfSShri Abhyankar     current_space->array           += nzi;
567835aa4fcfSShri Abhyankar     current_space->local_used      += nzi;
567935aa4fcfSShri Abhyankar     current_space->local_remaining -= nzi;
568035aa4fcfSShri Abhyankar     current_space_lvl->array           += nzi;
568135aa4fcfSShri Abhyankar     current_space_lvl->local_used      += nzi;
568235aa4fcfSShri Abhyankar     current_space_lvl->local_remaining -= nzi;
568335aa4fcfSShri Abhyankar   }
568435aa4fcfSShri Abhyankar 
568535aa4fcfSShri Abhyankar   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
568635aa4fcfSShri Abhyankar   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
568735aa4fcfSShri Abhyankar 
568835aa4fcfSShri Abhyankar   /* destroy list of free space and other temporary arrays */
568935aa4fcfSShri Abhyankar   ierr = PetscMalloc((bi[n]+1)*sizeof(PetscInt),&bj);CHKERRQ(ierr);
569035aa4fcfSShri Abhyankar 
569135aa4fcfSShri Abhyankar   /* copy free_space into bj and free free_space; set bi, bj, bdiag in new datastructure; */
56922ce24eb6SHong Zhang   ierr = PetscFreeSpaceContiguous_LU(&free_space,bj,n,bi,bdiag);CHKERRQ(ierr);
569335aa4fcfSShri Abhyankar 
569435aa4fcfSShri Abhyankar   ierr = PetscIncompleteLLDestroy(lnk,lnkbt);CHKERRQ(ierr);
569535aa4fcfSShri Abhyankar   ierr = PetscFreeSpaceDestroy(free_space_lvl);CHKERRQ(ierr);
5696fca92195SBarry Smith   ierr = PetscFree2(bj_ptr,bjlvl_ptr);CHKERRQ(ierr);
569735aa4fcfSShri Abhyankar 
569835aa4fcfSShri Abhyankar #if defined(PETSC_USE_INFO)
569935aa4fcfSShri Abhyankar   {
570035aa4fcfSShri Abhyankar     PetscReal af = ((PetscReal)bi[n])/((PetscReal)ai[n]);
570135aa4fcfSShri Abhyankar     ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocs,f,af);CHKERRQ(ierr);
570235aa4fcfSShri Abhyankar     ierr = PetscInfo1(A,"Run with -[sub_]pc_factor_fill %G or use \n",af);CHKERRQ(ierr);
570335aa4fcfSShri Abhyankar     ierr = PetscInfo1(A,"PCFactorSetFill([sub]pc,%G);\n",af);CHKERRQ(ierr);
570435aa4fcfSShri Abhyankar     ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr);
570535aa4fcfSShri Abhyankar     if (diagonal_fill) {
570635aa4fcfSShri Abhyankar       ierr = PetscInfo1(A,"Detected and replaced %D missing diagonals",dcount);CHKERRQ(ierr);
570735aa4fcfSShri Abhyankar     }
570835aa4fcfSShri Abhyankar   }
570935aa4fcfSShri Abhyankar #endif
571035aa4fcfSShri Abhyankar 
571135aa4fcfSShri Abhyankar   /* put together the new matrix */
571235aa4fcfSShri Abhyankar   ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(fact,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr);
571335aa4fcfSShri Abhyankar   ierr = PetscLogObjectParent(fact,isicol);CHKERRQ(ierr);
571435aa4fcfSShri Abhyankar   b = (Mat_SeqBAIJ*)(fact)->data;
571535aa4fcfSShri Abhyankar   b->free_a       = PETSC_TRUE;
571635aa4fcfSShri Abhyankar   b->free_ij      = PETSC_TRUE;
571735aa4fcfSShri Abhyankar   b->singlemalloc = PETSC_FALSE;
571835aa4fcfSShri Abhyankar   ierr = PetscMalloc( (bs2*(bdiag[0]+1) )*sizeof(MatScalar),&b->a);CHKERRQ(ierr);
571935aa4fcfSShri Abhyankar   b->j          = bj;
572035aa4fcfSShri Abhyankar   b->i          = bi;
572135aa4fcfSShri Abhyankar   b->diag       = bdiag;
572235aa4fcfSShri Abhyankar   b->free_diag  = PETSC_TRUE;
572335aa4fcfSShri Abhyankar   b->ilen       = 0;
572435aa4fcfSShri Abhyankar   b->imax       = 0;
572535aa4fcfSShri Abhyankar   b->row        = isrow;
572635aa4fcfSShri Abhyankar   b->col        = iscol;
572735aa4fcfSShri Abhyankar   ierr          = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
572835aa4fcfSShri Abhyankar   ierr          = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
572935aa4fcfSShri Abhyankar   b->icol       = isicol;
573035aa4fcfSShri Abhyankar   ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
573135aa4fcfSShri Abhyankar   /* In b structure:  Free imax, ilen, old a, old j.
573235aa4fcfSShri Abhyankar      Allocate bdiag, solve_work, new a, new j */
573335aa4fcfSShri Abhyankar   ierr = PetscLogObjectMemory(fact,(bdiag[0]+1) * (sizeof(PetscInt)+bs2*sizeof(PetscScalar)));CHKERRQ(ierr);
573435aa4fcfSShri Abhyankar   b->maxnz = b->nz = bdiag[0]+1;
5735ae3d28f0SHong Zhang   fact->info.factor_mallocs    = reallocs;
5736ae3d28f0SHong Zhang   fact->info.fill_ratio_given  = f;
5737ae3d28f0SHong Zhang   fact->info.fill_ratio_needed = ((PetscReal)(bdiag[0]+1))/((PetscReal)ai[n]);
57384dd39f65SShri Abhyankar   ierr = MatSeqBAIJSetNumericFactorization(fact,both_identity);CHKERRQ(ierr);
573935aa4fcfSShri Abhyankar   PetscFunctionReturn(0);
574035aa4fcfSShri Abhyankar }
574135aa4fcfSShri Abhyankar 
574235aa4fcfSShri Abhyankar 
57434e2b4712SSatish Balay /*
57444e2b4712SSatish Balay      This code is virtually identical to MatILUFactorSymbolic_SeqAIJ
57454e2b4712SSatish Balay    except that the data structure of Mat_SeqAIJ is slightly different.
57464e2b4712SSatish Balay    Not a good example of code reuse.
57474e2b4712SSatish Balay */
57484a2ae208SSatish Balay #undef __FUNCT__
574906e38f1dSHong Zhang #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ_inplace"
575006e38f1dSHong Zhang PetscErrorCode MatILUFactorSymbolic_SeqBAIJ_inplace(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
57514e2b4712SSatish Balay {
57524e2b4712SSatish Balay   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ*)A->data,*b;
57534e2b4712SSatish Balay   IS             isicol;
57546849ba73SBarry Smith   PetscErrorCode ierr;
57555d0c19d7SBarry Smith   const PetscInt *r,*ic,*ai = a->i,*aj = a->j,*xi;
57565d0c19d7SBarry Smith   PetscInt       prow,n = a->mbs,*ainew,*ajnew,jmax,*fill,nz,*im,*ajfill,*flev,*xitmp;
5757a96a251dSBarry Smith   PetscInt       *dloc,idx,row,m,fm,nzf,nzi,reallocate = 0,dcount = 0;
5758d0f46423SBarry Smith   PetscInt       incrlev,nnz,i,bs = A->rmap->bs,bs2 = a->bs2,levels,diagonal_fill,dd;
575941df41f0SMatthew Knepley   PetscTruth     col_identity,row_identity,both_identity,flg;
5760329f5518SBarry Smith   PetscReal      f;
57614e2b4712SSatish Balay 
57624e2b4712SSatish Balay   PetscFunctionBegin;
57636bce7ff8SHong Zhang   ierr = MatMissingDiagonal_SeqBAIJ(A,&flg,&dd);CHKERRQ(ierr);
57646bce7ff8SHong Zhang   if (flg) SETERRQ1(PETSC_ERR_ARG_WRONGSTATE,"Matrix A is missing diagonal entry in row %D",dd);
57656bce7ff8SHong Zhang 
5766435faa5fSBarry Smith   f             = info->fill;
5767690b6cddSBarry Smith   levels        = (PetscInt)info->levels;
5768690b6cddSBarry Smith   diagonal_fill = (PetscInt)info->diagonal_fill;
57694c49b128SBarry Smith   ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr);
577016a2bf60SHong Zhang 
5771667159a5SBarry Smith   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
5772667159a5SBarry Smith   ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr);
57737d18ce8fSMatthew Knepley   both_identity = (PetscTruth) (row_identity && col_identity);
5774309c388cSBarry Smith 
577541df41f0SMatthew Knepley   if (!levels && both_identity) {  /* special case copy the nonzero structure */
577616a2bf60SHong Zhang     ierr = MatDuplicateNoCreate_SeqBAIJ(fact,A,MAT_DO_NOT_COPY_VALUES,PETSC_TRUE);CHKERRQ(ierr);
57778b1456e3SHong Zhang     ierr = MatSeqBAIJSetNumericFactorization_inplace(fact,both_identity);CHKERRQ(ierr);
57786bce7ff8SHong Zhang 
5779719d5645SBarry Smith     fact->factor = MAT_FACTOR_ILU;
5780ae3d28f0SHong Zhang     b            = (Mat_SeqBAIJ*)fact->data;
5781bb3d539aSBarry Smith     b->row       = isrow;
5782bb3d539aSBarry Smith     b->col       = iscol;
5783bb3d539aSBarry Smith     ierr         = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
5784bb3d539aSBarry Smith     ierr         = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
5785bb3d539aSBarry Smith     b->icol      = isicol;
5786bcd9e38bSBarry Smith     b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
5787b588c5a2SHong Zhang     ierr         = PetscMalloc((n+1)*bs*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
57886bce7ff8SHong Zhang     PetscFunctionReturn(0);
57896bce7ff8SHong Zhang   }
57906bce7ff8SHong Zhang 
57916bce7ff8SHong Zhang   /* general case perform the symbolic factorization */
57924e2b4712SSatish Balay     ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
57934e2b4712SSatish Balay     ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
57944e2b4712SSatish Balay 
57954e2b4712SSatish Balay     /* get new row pointers */
5796690b6cddSBarry Smith     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&ainew);CHKERRQ(ierr);
57974e2b4712SSatish Balay     ainew[0] = 0;
57984e2b4712SSatish Balay     /* don't know how many column pointers are needed so estimate */
5799690b6cddSBarry Smith     jmax = (PetscInt)(f*ai[n] + 1);
5800690b6cddSBarry Smith     ierr = PetscMalloc((jmax)*sizeof(PetscInt),&ajnew);CHKERRQ(ierr);
58014e2b4712SSatish Balay     /* ajfill is level of fill for each fill entry */
5802690b6cddSBarry Smith     ierr = PetscMalloc((jmax)*sizeof(PetscInt),&ajfill);CHKERRQ(ierr);
58034e2b4712SSatish Balay     /* fill is a linked list of nonzeros in active row */
5804690b6cddSBarry Smith     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&fill);CHKERRQ(ierr);
58054e2b4712SSatish Balay     /* im is level for each filled value */
5806690b6cddSBarry Smith     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&im);CHKERRQ(ierr);
58074e2b4712SSatish Balay     /* dloc is location of diagonal in factor */
5808690b6cddSBarry Smith     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&dloc);CHKERRQ(ierr);
58094e2b4712SSatish Balay     dloc[0]  = 0;
58104e2b4712SSatish Balay     for (prow=0; prow<n; prow++) {
5811435faa5fSBarry Smith 
5812435faa5fSBarry Smith       /* copy prow into linked list */
58134e2b4712SSatish Balay       nzf        = nz  = ai[r[prow]+1] - ai[r[prow]];
58143b4a8b6dSBarry 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);
58154e2b4712SSatish Balay       xi         = aj + ai[r[prow]];
58164e2b4712SSatish Balay       fill[n]    = n;
5817435faa5fSBarry Smith       fill[prow] = -1; /* marker for diagonal entry */
58184e2b4712SSatish Balay       while (nz--) {
58194e2b4712SSatish Balay 	fm  = n;
58204e2b4712SSatish Balay 	idx = ic[*xi++];
58214e2b4712SSatish Balay 	do {
58224e2b4712SSatish Balay 	  m  = fm;
58234e2b4712SSatish Balay 	  fm = fill[m];
58244e2b4712SSatish Balay 	} while (fm < idx);
58254e2b4712SSatish Balay 	fill[m]   = idx;
58264e2b4712SSatish Balay 	fill[idx] = fm;
58274e2b4712SSatish Balay 	im[idx]   = 0;
58284e2b4712SSatish Balay       }
5829435faa5fSBarry Smith 
5830435faa5fSBarry Smith       /* make sure diagonal entry is included */
5831435faa5fSBarry Smith       if (diagonal_fill && fill[prow] == -1) {
5832435faa5fSBarry Smith 	fm = n;
5833435faa5fSBarry Smith 	while (fill[fm] < prow) fm = fill[fm];
5834435faa5fSBarry Smith 	fill[prow] = fill[fm];  /* insert diagonal into linked list */
5835435faa5fSBarry Smith 	fill[fm]   = prow;
5836435faa5fSBarry Smith 	im[prow]   = 0;
5837435faa5fSBarry Smith 	nzf++;
5838335d9088SBarry Smith 	dcount++;
5839435faa5fSBarry Smith       }
5840435faa5fSBarry Smith 
58414e2b4712SSatish Balay       nzi = 0;
58424e2b4712SSatish Balay       row = fill[n];
58434e2b4712SSatish Balay       while (row < prow) {
58444e2b4712SSatish Balay 	incrlev = im[row] + 1;
58454e2b4712SSatish Balay 	nz      = dloc[row];
5846435faa5fSBarry Smith 	xi      = ajnew  + ainew[row] + nz + 1;
58474e2b4712SSatish Balay 	flev    = ajfill + ainew[row] + nz + 1;
58484e2b4712SSatish Balay 	nnz     = ainew[row+1] - ainew[row] - nz - 1;
58494e2b4712SSatish Balay 	fm      = row;
58504e2b4712SSatish Balay 	while (nnz-- > 0) {
58514e2b4712SSatish Balay 	  idx = *xi++;
58524e2b4712SSatish Balay 	  if (*flev + incrlev > levels) {
58534e2b4712SSatish Balay 	    flev++;
58544e2b4712SSatish Balay 	    continue;
58554e2b4712SSatish Balay 	  }
58564e2b4712SSatish Balay 	  do {
58574e2b4712SSatish Balay 	    m  = fm;
58584e2b4712SSatish Balay 	    fm = fill[m];
58594e2b4712SSatish Balay 	  } while (fm < idx);
58604e2b4712SSatish Balay 	  if (fm != idx) {
58614e2b4712SSatish Balay 	    im[idx]   = *flev + incrlev;
58624e2b4712SSatish Balay 	    fill[m]   = idx;
58634e2b4712SSatish Balay 	    fill[idx] = fm;
58644e2b4712SSatish Balay 	    fm        = idx;
58654e2b4712SSatish Balay 	    nzf++;
5866ecf371e4SBarry Smith 	  } else {
58674e2b4712SSatish Balay 	    if (im[idx] > *flev + incrlev) im[idx] = *flev+incrlev;
58684e2b4712SSatish Balay 	  }
58694e2b4712SSatish Balay 	  flev++;
58704e2b4712SSatish Balay 	}
58714e2b4712SSatish Balay 	row = fill[row];
58724e2b4712SSatish Balay 	nzi++;
58734e2b4712SSatish Balay       }
58744e2b4712SSatish Balay       /* copy new filled row into permanent storage */
58754e2b4712SSatish Balay       ainew[prow+1] = ainew[prow] + nzf;
58764e2b4712SSatish Balay       if (ainew[prow+1] > jmax) {
5877ecf371e4SBarry Smith 
5878ecf371e4SBarry Smith 	/* estimate how much additional space we will need */
5879ecf371e4SBarry Smith 	/* use the strategy suggested by David Hysom <hysom@perch-t.icase.edu> */
5880ecf371e4SBarry Smith 	/* just double the memory each time */
5881690b6cddSBarry Smith 	PetscInt maxadd = jmax;
5882ecf371e4SBarry Smith 	/* maxadd = (int)(((f*ai[n]+1)*(n-prow+5))/n); */
58834e2b4712SSatish Balay 	if (maxadd < nzf) maxadd = (n-prow)*(nzf+1);
58844e2b4712SSatish Balay 	jmax += maxadd;
5885ecf371e4SBarry Smith 
5886ecf371e4SBarry Smith 	/* allocate a longer ajnew and ajfill */
58875d0c19d7SBarry Smith 	ierr = PetscMalloc(jmax*sizeof(PetscInt),&xitmp);CHKERRQ(ierr);
58885d0c19d7SBarry Smith 	ierr = PetscMemcpy(xitmp,ajnew,ainew[prow]*sizeof(PetscInt));CHKERRQ(ierr);
5889606d414cSSatish Balay 	ierr = PetscFree(ajnew);CHKERRQ(ierr);
58905d0c19d7SBarry Smith 	ajnew = xitmp;
58915d0c19d7SBarry Smith 	ierr = PetscMalloc(jmax*sizeof(PetscInt),&xitmp);CHKERRQ(ierr);
58925d0c19d7SBarry Smith 	ierr = PetscMemcpy(xitmp,ajfill,ainew[prow]*sizeof(PetscInt));CHKERRQ(ierr);
5893606d414cSSatish Balay 	ierr = PetscFree(ajfill);CHKERRQ(ierr);
58945d0c19d7SBarry Smith 	ajfill = xitmp;
5895eb150c5cSKris Buschelman 	reallocate++; /* count how many reallocations are needed */
58964e2b4712SSatish Balay       }
58975d0c19d7SBarry Smith       xitmp       = ajnew + ainew[prow];
58984e2b4712SSatish Balay       flev        = ajfill + ainew[prow];
58994e2b4712SSatish Balay       dloc[prow]  = nzi;
59004e2b4712SSatish Balay       fm          = fill[n];
59014e2b4712SSatish Balay       while (nzf--) {
59025d0c19d7SBarry Smith 	*xitmp++ = fm;
59034e2b4712SSatish Balay 	*flev++ = im[fm];
59044e2b4712SSatish Balay 	fm      = fill[fm];
59054e2b4712SSatish Balay       }
5906435faa5fSBarry Smith       /* make sure row has diagonal entry */
5907435faa5fSBarry Smith       if (ajnew[ainew[prow]+dloc[prow]] != prow) {
590877431f27SBarry Smith 	SETERRQ1(PETSC_ERR_MAT_LU_ZRPVT,"Row %D has missing diagonal in factored matrix\n\
59092401956bSBarry Smith     try running with -pc_factor_nonzeros_along_diagonal or -pc_factor_diagonal_fill",prow);
5910435faa5fSBarry Smith       }
59114e2b4712SSatish Balay     }
5912606d414cSSatish Balay     ierr = PetscFree(ajfill);CHKERRQ(ierr);
59134e2b4712SSatish Balay     ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
59144e2b4712SSatish Balay     ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
5915606d414cSSatish Balay     ierr = PetscFree(fill);CHKERRQ(ierr);
5916606d414cSSatish Balay     ierr = PetscFree(im);CHKERRQ(ierr);
59174e2b4712SSatish Balay 
59186cf91177SBarry Smith #if defined(PETSC_USE_INFO)
59194e2b4712SSatish Balay     {
5920329f5518SBarry Smith       PetscReal af = ((PetscReal)ainew[n])/((PetscReal)ai[n]);
5921ae15b995SBarry Smith       ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocate,f,af);CHKERRQ(ierr);
5922ae15b995SBarry Smith       ierr = PetscInfo1(A,"Run with -pc_factor_fill %G or use \n",af);CHKERRQ(ierr);
5923ae15b995SBarry Smith       ierr = PetscInfo1(A,"PCFactorSetFill(pc,%G);\n",af);CHKERRQ(ierr);
5924ae15b995SBarry Smith       ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr);
5925335d9088SBarry Smith       if (diagonal_fill) {
5926ae15b995SBarry Smith 	ierr = PetscInfo1(A,"Detected and replaced %D missing diagonals\n",dcount);CHKERRQ(ierr);
5927335d9088SBarry Smith       }
59284e2b4712SSatish Balay     }
592963ba0a88SBarry Smith #endif
59304e2b4712SSatish Balay 
59314e2b4712SSatish Balay     /* put together the new matrix */
5932719d5645SBarry Smith     ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(fact,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr);
5933719d5645SBarry Smith     ierr = PetscLogObjectParent(fact,isicol);CHKERRQ(ierr);
5934ae3d28f0SHong Zhang     b    = (Mat_SeqBAIJ*)fact->data;
5935e6b907acSBarry Smith     b->free_a       = PETSC_TRUE;
5936e6b907acSBarry Smith     b->free_ij      = PETSC_TRUE;
59377c922b88SBarry Smith     b->singlemalloc = PETSC_FALSE;
5938a96a251dSBarry Smith     ierr = PetscMalloc(bs2*ainew[n]*sizeof(MatScalar),&b->a);CHKERRQ(ierr);
59394e2b4712SSatish Balay     b->j          = ajnew;
59404e2b4712SSatish Balay     b->i          = ainew;
59414e2b4712SSatish Balay     for (i=0; i<n; i++) dloc[i] += ainew[i];
59424e2b4712SSatish Balay     b->diag       = dloc;
59437f53bb6cSHong Zhang     b->free_diag  = PETSC_TRUE;
59444e2b4712SSatish Balay     b->ilen       = 0;
59454e2b4712SSatish Balay     b->imax       = 0;
59464e2b4712SSatish Balay     b->row        = isrow;
59474e2b4712SSatish Balay     b->col        = iscol;
5948bcd9e38bSBarry Smith     b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
5949c38d4ed2SBarry Smith     ierr          = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
5950c38d4ed2SBarry Smith     ierr          = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
5951e51c0b9cSSatish Balay     b->icol       = isicol;
595287828ca2SBarry Smith     ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
59534e2b4712SSatish Balay     /* In b structure:  Free imax, ilen, old a, old j.
59544e2b4712SSatish Balay        Allocate dloc, solve_work, new a, new j */
5955719d5645SBarry Smith     ierr = PetscLogObjectMemory(fact,(ainew[n]-n)*(sizeof(PetscInt))+bs2*ainew[n]*sizeof(PetscScalar));CHKERRQ(ierr);
59564e2b4712SSatish Balay     b->maxnz          = b->nz = ainew[n];
59574e2b4712SSatish Balay 
5958ae3d28f0SHong Zhang     fact->info.factor_mallocs    = reallocate;
5959ae3d28f0SHong Zhang     fact->info.fill_ratio_given  = f;
5960ae3d28f0SHong Zhang     fact->info.fill_ratio_needed = ((PetscReal)ainew[n])/((PetscReal)ai[prow]);
59616bce7ff8SHong Zhang 
59628b1456e3SHong Zhang   ierr = MatSeqBAIJSetNumericFactorization_inplace(fact,both_identity);CHKERRQ(ierr);
59638661488fSKris Buschelman   PetscFunctionReturn(0);
59648661488fSKris Buschelman }
59658661488fSKris Buschelman 
5966732ee342SKris Buschelman #undef __FUNCT__
59677e7071cdSKris Buschelman #define __FUNCT__ "MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE"
5968dfbe8321SBarry Smith PetscErrorCode MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE(Mat A)
59697e7071cdSKris Buschelman {
597012272027SHong Zhang   /* Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; */
597112272027SHong Zhang   /* int i,*AJ=a->j,nz=a->nz; */
59725a9542e3SKris Buschelman   PetscFunctionBegin;
59737cf1b8d3SKris Buschelman   /* Undo Column scaling */
59747cf1b8d3SKris Buschelman /*    while (nz--) { */
59757cf1b8d3SKris Buschelman /*      AJ[i] = AJ[i]/4; */
59767cf1b8d3SKris Buschelman /*    } */
5977c115a38dSKris Buschelman   /* This should really invoke a push/pop logic, but we don't have that yet. */
5978c115a38dSKris Buschelman   A->ops->setunfactored = PETSC_NULL;
59797cf1b8d3SKris Buschelman   PetscFunctionReturn(0);
59807cf1b8d3SKris Buschelman }
59817cf1b8d3SKris Buschelman 
59827cf1b8d3SKris Buschelman #undef __FUNCT__
59837cf1b8d3SKris Buschelman #define __FUNCT__ "MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE_usj"
5984dfbe8321SBarry Smith PetscErrorCode MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE_usj(Mat A)
59857cf1b8d3SKris Buschelman {
59867cf1b8d3SKris Buschelman   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ *)A->data;
5987b24ad042SBarry Smith   PetscInt       *AJ=a->j,nz=a->nz;
59882aa5897fSKris Buschelman   unsigned short *aj=(unsigned short *)AJ;
59895a9542e3SKris Buschelman   PetscFunctionBegin;
59900b9da03eSKris Buschelman   /* Is this really necessary? */
599120235379SKris Buschelman   while (nz--) {
59920b9da03eSKris Buschelman     AJ[nz] = (int)((unsigned int)aj[nz]); /* First extend, then convert to signed. */
59937e7071cdSKris Buschelman   }
5994c115a38dSKris Buschelman   A->ops->setunfactored = PETSC_NULL;
59957e7071cdSKris Buschelman   PetscFunctionReturn(0);
59967e7071cdSKris Buschelman }
59977e7071cdSKris Buschelman 
5998732ee342SKris Buschelman 
5999