xref: /petsc/src/mat/impls/baij/seq/baijfact2.c (revision 0fa040f91fc0ebe4f74b7f63f2221f0edf4da5a7)
1be1d678aSKris Buschelman #define PETSCMAT_DLL
2be1d678aSKris Buschelman 
34e2b4712SSatish Balay /*
44e2b4712SSatish Balay     Factorization code for BAIJ format.
54e2b4712SSatish Balay */
64e2b4712SSatish Balay 
77c4f633dSBarry Smith #include "../src/mat/impls/baij/seq/baij.h"
8c60f0209SBarry Smith #include "../src/mat/blockinvert.h"
916a2bf60SHong Zhang #include "petscbt.h"
1016a2bf60SHong Zhang #include "../src/mat/utils/freespace.h"
114e2b4712SSatish Balay 
124a2ae208SSatish Balay #undef __FUNCT__
1306e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_1_NaturalOrdering_inplace"
1406e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_1_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
15f1af5d2fSBarry Smith {
16f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
17dfbe8321SBarry Smith   PetscErrorCode    ierr;
180b68f018SBarry Smith   PetscInt          i,nz;
190b68f018SBarry Smith   const PetscInt    *diag = a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
200b68f018SBarry Smith   const MatScalar   *aa=a->a,*v;
210b68f018SBarry Smith   PetscScalar       s1,*x;
220b68f018SBarry Smith   const PetscScalar *b;
23f1af5d2fSBarry Smith 
24f1af5d2fSBarry Smith   PetscFunctionBegin;
25ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
260b68f018SBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
271ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
28f1af5d2fSBarry Smith 
29f1af5d2fSBarry Smith   /* forward solve the U^T */
30f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
31f1af5d2fSBarry Smith 
32f1af5d2fSBarry Smith     v     = aa + diag[i];
33f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
34ef66eb69SBarry Smith     s1    = (*v++)*x[i];
35f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
36f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
37f1af5d2fSBarry Smith     while (nz--) {
38f1af5d2fSBarry Smith       x[*vi++]  -= (*v++)*s1;
39f1af5d2fSBarry Smith     }
40f1af5d2fSBarry Smith     x[i]   = s1;
41f1af5d2fSBarry Smith   }
42f1af5d2fSBarry Smith   /* backward solve the L^T */
43f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
44f1af5d2fSBarry Smith     v    = aa + diag[i] - 1;
45f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
46f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
47f1af5d2fSBarry Smith     s1   = x[i];
48f1af5d2fSBarry Smith     while (nz--) {
49f1af5d2fSBarry Smith       x[*vi--]   -=  (*v--)*s1;
50f1af5d2fSBarry Smith     }
51f1af5d2fSBarry Smith   }
520b68f018SBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
531ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
54dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*(a->nz) - A->cmap->n);CHKERRQ(ierr);
55f1af5d2fSBarry Smith   PetscFunctionReturn(0);
56f1af5d2fSBarry Smith }
57f1af5d2fSBarry Smith 
584a2ae208SSatish Balay #undef __FUNCT__
5906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_2_NaturalOrdering_inplace"
6006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_2_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
61f1af5d2fSBarry Smith {
62f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
63dfbe8321SBarry Smith   PetscErrorCode    ierr;
64b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
65b3260449SShri Abhyankar   const PetscInt    *diag = a->diag,*vi,n=a->mbs,*ai=a->i,*aj=a->j;
66b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
67b3260449SShri Abhyankar   PetscScalar       s1,s2,x1,x2,*x;
68b3260449SShri Abhyankar   const PetscScalar *b;
69f1af5d2fSBarry Smith 
70f1af5d2fSBarry Smith   PetscFunctionBegin;
71ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
72b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
731ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
74f1af5d2fSBarry Smith 
75f1af5d2fSBarry Smith   /* forward solve the U^T */
76f1af5d2fSBarry Smith   idx = 0;
77f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
78f1af5d2fSBarry Smith 
79f1af5d2fSBarry Smith     v     = aa + 4*diag[i];
80f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
81ef66eb69SBarry Smith     x1 = x[idx];   x2 = x[1+idx];
82f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2;
83f1af5d2fSBarry Smith     s2 = v[2]*x1  +  v[3]*x2;
84f1af5d2fSBarry Smith     v += 4;
85f1af5d2fSBarry Smith 
86f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
87f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
88f1af5d2fSBarry Smith     while (nz--) {
89f1af5d2fSBarry Smith       oidx = 2*(*vi++);
90f1af5d2fSBarry Smith       x[oidx]   -= v[0]*s1  +  v[1]*s2;
91f1af5d2fSBarry Smith       x[oidx+1] -= v[2]*s1  +  v[3]*s2;
92f1af5d2fSBarry Smith       v  += 4;
93f1af5d2fSBarry Smith     }
94f1af5d2fSBarry Smith     x[idx]   = s1;x[1+idx] = s2;
95f1af5d2fSBarry Smith     idx += 2;
96f1af5d2fSBarry Smith   }
97f1af5d2fSBarry Smith   /* backward solve the L^T */
98f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
99f1af5d2fSBarry Smith     v    = aa + 4*diag[i] - 4;
100f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
101f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
102f1af5d2fSBarry Smith     idt  = 2*i;
103f1af5d2fSBarry Smith     s1   = x[idt];  s2 = x[1+idt];
104f1af5d2fSBarry Smith     while (nz--) {
105f1af5d2fSBarry Smith       idx   = 2*(*vi--);
106f1af5d2fSBarry Smith       x[idx]   -=  v[0]*s1 +  v[1]*s2;
107f1af5d2fSBarry Smith       x[idx+1] -=  v[2]*s1 +  v[3]*s2;
108f1af5d2fSBarry Smith       v -= 4;
109f1af5d2fSBarry Smith     }
110f1af5d2fSBarry Smith   }
111b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
1121ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
113dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*4.0*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
114f1af5d2fSBarry Smith   PetscFunctionReturn(0);
115f1af5d2fSBarry Smith }
116f1af5d2fSBarry Smith 
1174a2ae208SSatish Balay #undef __FUNCT__
1184dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_2_NaturalOrdering"
1194dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_2_NaturalOrdering(Mat A,Vec bb,Vec xx)
1206929473cSShri Abhyankar {
1216929473cSShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
1226929473cSShri Abhyankar   PetscErrorCode    ierr;
123b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
1246929473cSShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx;
125b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
126b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
127b3260449SShri Abhyankar   PetscScalar       s1,s2,x1,x2,*x;
128b3260449SShri Abhyankar   const PetscScalar *b;
1296929473cSShri Abhyankar 
1306929473cSShri Abhyankar   PetscFunctionBegin;
1316929473cSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
132b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
1336929473cSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
1346929473cSShri Abhyankar 
1356929473cSShri Abhyankar   /* forward solve the U^T */
1366929473cSShri Abhyankar   idx = 0;
1376929473cSShri Abhyankar   for (i=0; i<n; i++) {
1386929473cSShri Abhyankar     v     = aa + bs2*diag[i];
1396929473cSShri Abhyankar     /* multiply by the inverse of the block diagonal */
1406929473cSShri Abhyankar     x1 = x[idx];   x2 = x[1+idx];
1416929473cSShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2;
1426929473cSShri Abhyankar     s2 = v[2]*x1  +  v[3]*x2;
1436929473cSShri Abhyankar     v -= bs2;
1446929473cSShri Abhyankar 
1456929473cSShri Abhyankar     vi    = aj + diag[i] - 1;
1466929473cSShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
1476929473cSShri Abhyankar     for(j=0;j>-nz;j--){
1486929473cSShri Abhyankar       oidx = bs*vi[j];
1496929473cSShri Abhyankar       x[oidx]   -= v[0]*s1  +  v[1]*s2;
1506929473cSShri Abhyankar       x[oidx+1] -= v[2]*s1  +  v[3]*s2;
1516929473cSShri Abhyankar       v  -= bs2;
1526929473cSShri Abhyankar     }
1536929473cSShri Abhyankar     x[idx]   = s1;x[1+idx] = s2;
1546929473cSShri Abhyankar     idx += bs;
1556929473cSShri Abhyankar   }
1566929473cSShri Abhyankar   /* backward solve the L^T */
1576929473cSShri Abhyankar   for (i=n-1; i>=0; i--){
1586929473cSShri Abhyankar     v    = aa + bs2*ai[i];
1596929473cSShri Abhyankar     vi   = aj + ai[i];
1606929473cSShri Abhyankar     nz   = ai[i+1] - ai[i];
1616929473cSShri Abhyankar     idt  = bs*i;
1626929473cSShri Abhyankar     s1   = x[idt];  s2 = x[1+idt];
1636929473cSShri Abhyankar     for(j=0;j<nz;j++){
1646929473cSShri Abhyankar       idx   = bs*vi[j];
1656929473cSShri Abhyankar       x[idx]   -=  v[0]*s1 +  v[1]*s2;
1666929473cSShri Abhyankar       x[idx+1] -=  v[2]*s1 +  v[3]*s2;
1676929473cSShri Abhyankar       v += bs2;
1686929473cSShri Abhyankar     }
1696929473cSShri Abhyankar   }
170b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
1716929473cSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
1726929473cSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
1736929473cSShri Abhyankar   PetscFunctionReturn(0);
1746929473cSShri Abhyankar }
1756929473cSShri Abhyankar 
1766929473cSShri Abhyankar #undef __FUNCT__
17706e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_3_NaturalOrdering_inplace"
17806e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_3_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
179f1af5d2fSBarry Smith {
180f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
181dfbe8321SBarry Smith   PetscErrorCode    ierr;
182b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
183b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
184b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
185b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,x1,x2,x3,*x;
186b3260449SShri Abhyankar   const PetscScalar *b;
187f1af5d2fSBarry Smith 
188f1af5d2fSBarry Smith   PetscFunctionBegin;
189ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
190b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
1911ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
192f1af5d2fSBarry Smith 
193f1af5d2fSBarry Smith   /* forward solve the U^T */
194f1af5d2fSBarry Smith   idx = 0;
195f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
196f1af5d2fSBarry Smith 
197f1af5d2fSBarry Smith     v     = aa + 9*diag[i];
198f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
199ef66eb69SBarry Smith     x1 = x[idx];   x2 = x[1+idx]; x3    = x[2+idx];
200f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3;
201f1af5d2fSBarry Smith     s2 = v[3]*x1  +  v[4]*x2 +  v[5]*x3;
202f1af5d2fSBarry Smith     s3 = v[6]*x1  +  v[7]*x2 + v[8]*x3;
203f1af5d2fSBarry Smith     v += 9;
204f1af5d2fSBarry Smith 
205f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
206f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
207f1af5d2fSBarry Smith     while (nz--) {
208f1af5d2fSBarry Smith       oidx = 3*(*vi++);
209f1af5d2fSBarry Smith       x[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3;
210f1af5d2fSBarry Smith       x[oidx+1] -= v[3]*s1  +  v[4]*s2 +  v[5]*s3;
211f1af5d2fSBarry Smith       x[oidx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3;
212f1af5d2fSBarry Smith       v  += 9;
213f1af5d2fSBarry Smith     }
214f1af5d2fSBarry Smith     x[idx]   = s1;x[1+idx] = s2; x[2+idx] = s3;
215f1af5d2fSBarry Smith     idx += 3;
216f1af5d2fSBarry Smith   }
217f1af5d2fSBarry Smith   /* backward solve the L^T */
218f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
219f1af5d2fSBarry Smith     v    = aa + 9*diag[i] - 9;
220f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
221f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
222f1af5d2fSBarry Smith     idt  = 3*i;
223f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt]; s3 = x[2+idt];
224f1af5d2fSBarry Smith     while (nz--) {
225f1af5d2fSBarry Smith       idx   = 3*(*vi--);
226f1af5d2fSBarry Smith       x[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3;
227f1af5d2fSBarry Smith       x[idx+1] -=  v[3]*s1 +  v[4]*s2 +  v[5]*s3;
228f1af5d2fSBarry Smith       x[idx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3;
229f1af5d2fSBarry Smith       v -= 9;
230f1af5d2fSBarry Smith     }
231f1af5d2fSBarry Smith   }
232b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
2331ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
234dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*9.0*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr);
235f1af5d2fSBarry Smith   PetscFunctionReturn(0);
236f1af5d2fSBarry Smith }
237f1af5d2fSBarry Smith 
2384a2ae208SSatish Balay #undef __FUNCT__
2394dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_3_NaturalOrdering"
2404dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_3_NaturalOrdering(Mat A,Vec bb,Vec xx)
2418499736aSShri Abhyankar {
2428499736aSShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
2438499736aSShri Abhyankar   PetscErrorCode    ierr;
244b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
2458499736aSShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx;
246b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
247b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
248b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,x1,x2,x3,*x;
249b3260449SShri Abhyankar   const PetscScalar *b;
2508499736aSShri Abhyankar 
2518499736aSShri Abhyankar   PetscFunctionBegin;
2528499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
253b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
2548499736aSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
2558499736aSShri Abhyankar 
2568499736aSShri Abhyankar   /* forward solve the U^T */
2578499736aSShri Abhyankar   idx = 0;
2588499736aSShri Abhyankar   for (i=0; i<n; i++) {
2598499736aSShri Abhyankar     v     = aa + bs2*diag[i];
2608499736aSShri Abhyankar     /* multiply by the inverse of the block diagonal */
2618499736aSShri Abhyankar     x1 = x[idx];   x2 = x[1+idx];  x3 = x[2+idx];
2628499736aSShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2  + v[2]*x3;
2638499736aSShri Abhyankar     s2 = v[3]*x1  +  v[4]*x2  + v[5]*x3;
2648499736aSShri Abhyankar     s3 = v[6]*x1  +  v[7]*x2  + v[8]*x3;
2658499736aSShri Abhyankar     v -= bs2;
2668499736aSShri Abhyankar 
2678499736aSShri Abhyankar     vi    = aj + diag[i] - 1;
2688499736aSShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
2698499736aSShri Abhyankar     for(j=0;j>-nz;j--){
2708499736aSShri Abhyankar       oidx = bs*vi[j];
2718499736aSShri Abhyankar       x[oidx]   -= v[0]*s1  +  v[1]*s2  + v[2]*s3;
2728499736aSShri Abhyankar       x[oidx+1] -= v[3]*s1  +  v[4]*s2  + v[5]*s3;
2738499736aSShri Abhyankar       x[oidx+2] -= v[6]*s1  +  v[7]*s2  + v[8]*s3;
2748499736aSShri Abhyankar       v  -= bs2;
2758499736aSShri Abhyankar     }
2768499736aSShri Abhyankar     x[idx]   = s1;x[1+idx] = s2;  x[2+idx] = s3;
2778499736aSShri Abhyankar     idx += bs;
2788499736aSShri Abhyankar   }
2798499736aSShri Abhyankar   /* backward solve the L^T */
2808499736aSShri Abhyankar   for (i=n-1; i>=0; i--){
2818499736aSShri Abhyankar     v    = aa + bs2*ai[i];
2828499736aSShri Abhyankar     vi   = aj + ai[i];
2838499736aSShri Abhyankar     nz   = ai[i+1] - ai[i];
2848499736aSShri Abhyankar     idt  = bs*i;
2858499736aSShri Abhyankar     s1   = x[idt];  s2 = x[1+idt];  s3 = x[2+idt];
2868499736aSShri Abhyankar     for(j=0;j<nz;j++){
2878499736aSShri Abhyankar       idx   = bs*vi[j];
2888499736aSShri Abhyankar       x[idx]   -= v[0]*s1  +  v[1]*s2  + v[2]*s3;
2898499736aSShri Abhyankar       x[idx+1] -= v[3]*s1  +  v[4]*s2  + v[5]*s3;
2908499736aSShri Abhyankar       x[idx+2] -= v[6]*s1  +  v[7]*s2  + v[8]*s3;
2918499736aSShri Abhyankar       v += bs2;
2928499736aSShri Abhyankar     }
2938499736aSShri Abhyankar   }
294b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
2958499736aSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
2968499736aSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
2978499736aSShri Abhyankar   PetscFunctionReturn(0);
2988499736aSShri Abhyankar }
2998499736aSShri Abhyankar 
3008499736aSShri Abhyankar #undef __FUNCT__
30106e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_4_NaturalOrdering_inplace"
30206e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_4_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
303f1af5d2fSBarry Smith {
304f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
305dfbe8321SBarry Smith   PetscErrorCode    ierr;
306b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
307b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
308b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
309b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4,*x;
310b3260449SShri Abhyankar   const PetscScalar *b;
311f1af5d2fSBarry Smith 
312f1af5d2fSBarry Smith   PetscFunctionBegin;
313ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
314b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
3151ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
316f1af5d2fSBarry Smith 
317f1af5d2fSBarry Smith   /* forward solve the U^T */
318f1af5d2fSBarry Smith   idx = 0;
319f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
320f1af5d2fSBarry Smith 
321f1af5d2fSBarry Smith     v     = aa + 16*diag[i];
322f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
323ef66eb69SBarry Smith     x1    = x[idx];   x2 = x[1+idx]; x3    = x[2+idx]; x4 = x[3+idx];
324f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4;
325f1af5d2fSBarry Smith     s2 = v[4]*x1  +  v[5]*x2 +  v[6]*x3 +  v[7]*x4;
326f1af5d2fSBarry Smith     s3 = v[8]*x1  +  v[9]*x2 + v[10]*x3 + v[11]*x4;
327f1af5d2fSBarry Smith     s4 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4;
328f1af5d2fSBarry Smith     v += 16;
329f1af5d2fSBarry Smith 
330f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
331f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
332f1af5d2fSBarry Smith     while (nz--) {
333f1af5d2fSBarry Smith       oidx = 4*(*vi++);
334f1af5d2fSBarry Smith       x[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4;
335f1af5d2fSBarry Smith       x[oidx+1] -= v[4]*s1  +  v[5]*s2 +  v[6]*s3 +  v[7]*s4;
336f1af5d2fSBarry Smith       x[oidx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4;
337f1af5d2fSBarry Smith       x[oidx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4;
338f1af5d2fSBarry Smith       v  += 16;
339f1af5d2fSBarry Smith     }
340f1af5d2fSBarry Smith     x[idx]   = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4;
341f1af5d2fSBarry Smith     idx += 4;
342f1af5d2fSBarry Smith   }
343f1af5d2fSBarry Smith   /* backward solve the L^T */
344f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
345f1af5d2fSBarry Smith     v    = aa + 16*diag[i] - 16;
346f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
347f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
348f1af5d2fSBarry Smith     idt  = 4*i;
349f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt];
350f1af5d2fSBarry Smith     while (nz--) {
351f1af5d2fSBarry Smith       idx   = 4*(*vi--);
352f1af5d2fSBarry Smith       x[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4;
353f1af5d2fSBarry Smith       x[idx+1] -=  v[4]*s1 +  v[5]*s2 +  v[6]*s3 +  v[7]*s4;
354f1af5d2fSBarry Smith       x[idx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4;
355f1af5d2fSBarry Smith       x[idx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4;
356f1af5d2fSBarry Smith       v -= 16;
357f1af5d2fSBarry Smith     }
358f1af5d2fSBarry Smith   }
359b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
3601ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
361dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
362f1af5d2fSBarry Smith   PetscFunctionReturn(0);
363f1af5d2fSBarry Smith }
364f1af5d2fSBarry Smith 
3654a2ae208SSatish Balay #undef __FUNCT__
3664dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_4_NaturalOrdering"
3674dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_4_NaturalOrdering(Mat A,Vec bb,Vec xx)
3688499736aSShri Abhyankar {
3698499736aSShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
3708499736aSShri Abhyankar   PetscErrorCode    ierr;
371b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
3728499736aSShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx;
373b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
374b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
375b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4,*x;
376b3260449SShri Abhyankar   const PetscScalar *b;
3778499736aSShri Abhyankar 
3788499736aSShri Abhyankar   PetscFunctionBegin;
3798499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
380b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
3818499736aSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
3828499736aSShri Abhyankar 
3838499736aSShri Abhyankar   /* forward solve the U^T */
3848499736aSShri Abhyankar   idx = 0;
3858499736aSShri Abhyankar   for (i=0; i<n; i++) {
3868499736aSShri Abhyankar     v     = aa + bs2*diag[i];
3878499736aSShri Abhyankar     /* multiply by the inverse of the block diagonal */
3888499736aSShri Abhyankar     x1 = x[idx];   x2 = x[1+idx];  x3 = x[2+idx];  x4 = x[3+idx];
3898499736aSShri Abhyankar     s1 =  v[0]*x1  +  v[1]*x2  + v[2]*x3  + v[3]*x4;
3908499736aSShri Abhyankar     s2 =  v[4]*x1  +  v[5]*x2  + v[6]*x3  + v[7]*x4;
3918499736aSShri Abhyankar     s3 =  v[8]*x1  +  v[9]*x2  + v[10]*x3 + v[11]*x4;
3928499736aSShri Abhyankar     s4 =  v[12]*x1 +  v[13]*x2 + v[14]*x3 + v[15]*x4;
3938499736aSShri Abhyankar     v -= bs2;
3948499736aSShri Abhyankar 
3958499736aSShri Abhyankar     vi    = aj + diag[i] - 1;
3968499736aSShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
3978499736aSShri Abhyankar     for(j=0;j>-nz;j--){
3988499736aSShri Abhyankar       oidx = bs*vi[j];
3998499736aSShri Abhyankar       x[oidx]   -=  v[0]*s1  +  v[1]*s2  + v[2]*s3  + v[3]*s4;
4008499736aSShri Abhyankar       x[oidx+1] -=  v[4]*s1  +  v[5]*s2  + v[6]*s3  + v[7]*s4;
4018499736aSShri Abhyankar       x[oidx+2] -=  v[8]*s1  +  v[9]*s2  + v[10]*s3 + v[11]*s4;
4028499736aSShri Abhyankar       x[oidx+3] -=  v[12]*s1 +  v[13]*s2 + v[14]*s3 + v[15]*s4;
4038499736aSShri Abhyankar       v  -= bs2;
4048499736aSShri Abhyankar     }
4058499736aSShri Abhyankar     x[idx]   = s1;x[1+idx] = s2;  x[2+idx] = s3;  x[3+idx] = s4;
4068499736aSShri Abhyankar     idx += bs;
4078499736aSShri Abhyankar   }
4088499736aSShri Abhyankar   /* backward solve the L^T */
4098499736aSShri Abhyankar   for (i=n-1; i>=0; i--){
4108499736aSShri Abhyankar     v    = aa + bs2*ai[i];
4118499736aSShri Abhyankar     vi   = aj + ai[i];
4128499736aSShri Abhyankar     nz   = ai[i+1] - ai[i];
4138499736aSShri Abhyankar     idt  = bs*i;
4148499736aSShri Abhyankar     s1   = x[idt];  s2 = x[1+idt];  s3 = x[2+idt];  s4 = x[3+idt];
4158499736aSShri Abhyankar     for(j=0;j<nz;j++){
4168499736aSShri Abhyankar       idx   = bs*vi[j];
4178499736aSShri Abhyankar       x[idx]   -=  v[0]*s1  +  v[1]*s2  + v[2]*s3  + v[3]*s4;
4188499736aSShri Abhyankar       x[idx+1] -=  v[4]*s1  +  v[5]*s2  + v[6]*s3  + v[7]*s4;
4198499736aSShri Abhyankar       x[idx+2] -=  v[8]*s1  +  v[9]*s2  + v[10]*s3 + v[11]*s4;
4208499736aSShri Abhyankar       x[idx+3] -=  v[12]*s1 +  v[13]*s2 + v[14]*s3 + v[15]*s4;
4218499736aSShri Abhyankar       v += bs2;
4228499736aSShri Abhyankar     }
4238499736aSShri Abhyankar   }
424b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4258499736aSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4268499736aSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
4278499736aSShri Abhyankar   PetscFunctionReturn(0);
4288499736aSShri Abhyankar }
4298499736aSShri Abhyankar 
4308499736aSShri Abhyankar #undef __FUNCT__
43106e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_5_NaturalOrdering_inplace"
43206e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_5_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
433f1af5d2fSBarry Smith {
434f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
435dfbe8321SBarry Smith   PetscErrorCode    ierr;
436b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
437b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
438b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
439b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x;
440b3260449SShri Abhyankar   const PetscScalar *b;
441f1af5d2fSBarry Smith 
442f1af5d2fSBarry Smith   PetscFunctionBegin;
443ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
444b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4451ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
446f1af5d2fSBarry Smith 
447f1af5d2fSBarry Smith   /* forward solve the U^T */
448f1af5d2fSBarry Smith   idx = 0;
449f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
450f1af5d2fSBarry Smith 
451f1af5d2fSBarry Smith     v     = aa + 25*diag[i];
452f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
453ef66eb69SBarry Smith     x1    = x[idx];   x2 = x[1+idx]; x3    = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx];
454f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5;
455f1af5d2fSBarry Smith     s2 = v[5]*x1  +  v[6]*x2 +  v[7]*x3 +  v[8]*x4 +  v[9]*x5;
456f1af5d2fSBarry Smith     s3 = v[10]*x1 + v[11]*x2 + v[12]*x3 + v[13]*x4 + v[14]*x5;
457f1af5d2fSBarry Smith     s4 = v[15]*x1 + v[16]*x2 + v[17]*x3 + v[18]*x4 + v[19]*x5;
458f1af5d2fSBarry Smith     s5 = v[20]*x1 + v[21]*x2 + v[22]*x3 + v[23]*x4 + v[24]*x5;
459f1af5d2fSBarry Smith     v += 25;
460f1af5d2fSBarry Smith 
461f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
462f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
463f1af5d2fSBarry Smith     while (nz--) {
464f1af5d2fSBarry Smith       oidx = 5*(*vi++);
465f1af5d2fSBarry Smith       x[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5;
466f1af5d2fSBarry Smith       x[oidx+1] -= v[5]*s1  +  v[6]*s2 +  v[7]*s3 +  v[8]*s4 +  v[9]*s5;
467f1af5d2fSBarry Smith       x[oidx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5;
468f1af5d2fSBarry Smith       x[oidx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5;
469f1af5d2fSBarry Smith       x[oidx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5;
470f1af5d2fSBarry Smith       v  += 25;
471f1af5d2fSBarry Smith     }
472f1af5d2fSBarry Smith     x[idx]   = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4; x[4+idx] = s5;
473f1af5d2fSBarry Smith     idx += 5;
474f1af5d2fSBarry Smith   }
475f1af5d2fSBarry Smith   /* backward solve the L^T */
476f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
477f1af5d2fSBarry Smith     v    = aa + 25*diag[i] - 25;
478f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
479f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
480f1af5d2fSBarry Smith     idt  = 5*i;
481f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt];
482f1af5d2fSBarry Smith     while (nz--) {
483f1af5d2fSBarry Smith       idx   = 5*(*vi--);
484f1af5d2fSBarry Smith       x[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5;
485f1af5d2fSBarry Smith       x[idx+1] -=  v[5]*s1 +  v[6]*s2 +  v[7]*s3 +  v[8]*s4 +  v[9]*s5;
486f1af5d2fSBarry Smith       x[idx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5;
487f1af5d2fSBarry Smith       x[idx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5;
488f1af5d2fSBarry Smith       x[idx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5;
489f1af5d2fSBarry Smith       v -= 25;
490f1af5d2fSBarry Smith     }
491f1af5d2fSBarry Smith   }
492b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4931ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
494dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
495f1af5d2fSBarry Smith   PetscFunctionReturn(0);
496f1af5d2fSBarry Smith }
497f1af5d2fSBarry Smith 
4984a2ae208SSatish Balay #undef __FUNCT__
4994dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_5_NaturalOrdering"
5004dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_5_NaturalOrdering(Mat A,Vec bb,Vec xx)
5018499736aSShri Abhyankar {
5028499736aSShri Abhyankar   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ *)A->data;
5038499736aSShri Abhyankar   PetscErrorCode ierr;
504b3260449SShri Abhyankar   const PetscInt       n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
5058499736aSShri Abhyankar   PetscInt       nz,idx,idt,j,i,oidx;
506b3260449SShri Abhyankar   const PetscInt       bs=A->rmap->bs,bs2=a->bs2;
507b3260449SShri Abhyankar   const MatScalar      *aa=a->a,*v;
508b3260449SShri Abhyankar   PetscScalar    s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x;
509b3260449SShri Abhyankar   const PetscScalar    *b;
5108499736aSShri Abhyankar 
5118499736aSShri Abhyankar   PetscFunctionBegin;
5128499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
513b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
5148499736aSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
5158499736aSShri Abhyankar 
5168499736aSShri Abhyankar   /* forward solve the U^T */
5178499736aSShri Abhyankar   idx = 0;
5188499736aSShri Abhyankar   for (i=0; i<n; i++) {
5198499736aSShri Abhyankar     v     = aa + bs2*diag[i];
5208499736aSShri Abhyankar     /* multiply by the inverse of the block diagonal */
5218499736aSShri Abhyankar     x1 = x[idx];   x2 = x[1+idx];  x3 = x[2+idx];  x4 = x[3+idx];
5228499736aSShri Abhyankar     x5 = x[4+idx];
5238499736aSShri Abhyankar     s1 =  v[0]*x1   +  v[1]*x2   + v[2]*x3   + v[3]*x4   + v[4]*x5;
5248499736aSShri Abhyankar     s2 =  v[5]*x1   +  v[6]*x2   + v[7]*x3   + v[8]*x4   + v[9]*x5;
5258499736aSShri Abhyankar     s3 =  v[10]*x1  +  v[11]*x2  + v[12]*x3  + v[13]*x4  + v[14]*x5;
5268499736aSShri Abhyankar     s4 =  v[15]*x1  +  v[16]*x2  + v[17]*x3  + v[18]*x4  + v[19]*x5;
5278499736aSShri Abhyankar     s5 =  v[20]*x1  +  v[21]*x2  + v[22]*x3  + v[23]*x4   + v[24]*x5;
5288499736aSShri Abhyankar     v -= bs2;
5298499736aSShri Abhyankar 
5308499736aSShri Abhyankar     vi    = aj + diag[i] - 1;
5318499736aSShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
5328499736aSShri Abhyankar     for(j=0;j>-nz;j--){
5338499736aSShri Abhyankar       oidx = bs*vi[j];
5348499736aSShri Abhyankar       x[oidx]   -=  v[0]*s1   +  v[1]*s2   + v[2]*s3   + v[3]*s4   + v[4]*s5;
5358499736aSShri Abhyankar       x[oidx+1] -=  v[5]*s1   +  v[6]*s2   + v[7]*s3   + v[8]*s4   + v[9]*s5;
5368499736aSShri Abhyankar       x[oidx+2] -=  v[10]*s1  +  v[11]*s2  + v[12]*s3  + v[13]*s4  + v[14]*s5;
5378499736aSShri Abhyankar       x[oidx+3] -=  v[15]*s1  +  v[16]*s2  + v[17]*s3  + v[18]*s4  + v[19]*s5;
5388499736aSShri Abhyankar       x[oidx+4] -=  v[20]*s1  +  v[21]*s2  + v[22]*s3  + v[23]*s4   + v[24]*s5;
5398499736aSShri Abhyankar       v  -= bs2;
5408499736aSShri Abhyankar     }
5418499736aSShri Abhyankar     x[idx]   = s1;x[1+idx] = s2;  x[2+idx] = s3;  x[3+idx] = s4; x[4+idx] = s5;
5428499736aSShri Abhyankar     idx += bs;
5438499736aSShri Abhyankar   }
5448499736aSShri Abhyankar   /* backward solve the L^T */
5458499736aSShri Abhyankar   for (i=n-1; i>=0; i--){
5468499736aSShri Abhyankar     v    = aa + bs2*ai[i];
5478499736aSShri Abhyankar     vi   = aj + ai[i];
5488499736aSShri Abhyankar     nz   = ai[i+1] - ai[i];
5498499736aSShri Abhyankar     idt  = bs*i;
5508499736aSShri Abhyankar     s1   = x[idt];  s2 = x[1+idt];  s3 = x[2+idt];  s4 = x[3+idt];  s5 = x[4+idt];
5518499736aSShri Abhyankar     for(j=0;j<nz;j++){
5528499736aSShri Abhyankar       idx   = bs*vi[j];
5538499736aSShri Abhyankar       x[idx]   -=  v[0]*s1   +  v[1]*s2   + v[2]*s3   + v[3]*s4   + v[4]*s5;
5548499736aSShri Abhyankar       x[idx+1] -=  v[5]*s1   +  v[6]*s2   + v[7]*s3   + v[8]*s4   + v[9]*s5;
5558499736aSShri Abhyankar       x[idx+2] -=  v[10]*s1  +  v[11]*s2  + v[12]*s3  + v[13]*s4  + v[14]*s5;
5568499736aSShri Abhyankar       x[idx+3] -=  v[15]*s1  +  v[16]*s2  + v[17]*s3  + v[18]*s4  + v[19]*s5;
5578499736aSShri Abhyankar       x[idx+4] -=  v[20]*s1  +  v[21]*s2  + v[22]*s3  + v[23]*s4   + v[24]*s5;
5588499736aSShri Abhyankar       v += bs2;
5598499736aSShri Abhyankar     }
5608499736aSShri Abhyankar   }
561b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
5628499736aSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5638499736aSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
5648499736aSShri Abhyankar   PetscFunctionReturn(0);
5658499736aSShri Abhyankar }
5668499736aSShri Abhyankar 
5678499736aSShri Abhyankar #undef __FUNCT__
56806e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_6_NaturalOrdering_inplace"
56906e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_6_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
570f1af5d2fSBarry Smith {
571f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
572dfbe8321SBarry Smith   PetscErrorCode    ierr;
573b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
574b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
575b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
576b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x;
577b3260449SShri Abhyankar   const PetscScalar *b;
578f1af5d2fSBarry Smith 
579f1af5d2fSBarry Smith   PetscFunctionBegin;
580ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
581b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
5821ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
583f1af5d2fSBarry Smith 
584f1af5d2fSBarry Smith   /* forward solve the U^T */
585f1af5d2fSBarry Smith   idx = 0;
586f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
587f1af5d2fSBarry Smith 
588f1af5d2fSBarry Smith     v     = aa + 36*diag[i];
589f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
590ef66eb69SBarry Smith     x1    = x[idx];   x2 = x[1+idx]; x3    = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx];
591ef66eb69SBarry Smith     x6    = x[5+idx];
592f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5 +  v[5]*x6;
593f1af5d2fSBarry Smith     s2 = v[6]*x1  +  v[7]*x2 +  v[8]*x3 +  v[9]*x4 + v[10]*x5 + v[11]*x6;
594f1af5d2fSBarry Smith     s3 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4 + v[16]*x5 + v[17]*x6;
595f1af5d2fSBarry Smith     s4 = v[18]*x1 + v[19]*x2 + v[20]*x3 + v[21]*x4 + v[22]*x5 + v[23]*x6;
596f1af5d2fSBarry Smith     s5 = v[24]*x1 + v[25]*x2 + v[26]*x3 + v[27]*x4 + v[28]*x5 + v[29]*x6;
597f1af5d2fSBarry Smith     s6 = v[30]*x1 + v[31]*x2 + v[32]*x3 + v[33]*x4 + v[34]*x5 + v[35]*x6;
598f1af5d2fSBarry Smith     v += 36;
599f1af5d2fSBarry Smith 
600f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
601f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
602f1af5d2fSBarry Smith     while (nz--) {
603f1af5d2fSBarry Smith       oidx = 6*(*vi++);
604f1af5d2fSBarry Smith       x[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6;
605f1af5d2fSBarry Smith       x[oidx+1] -= v[6]*s1  +  v[7]*s2 +  v[8]*s3 +  v[9]*s4 + v[10]*s5 + v[11]*s6;
606f1af5d2fSBarry Smith       x[oidx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6;
607f1af5d2fSBarry Smith       x[oidx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6;
608f1af5d2fSBarry Smith       x[oidx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6;
609f1af5d2fSBarry Smith       x[oidx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6;
610f1af5d2fSBarry Smith       v  += 36;
611f1af5d2fSBarry Smith     }
612f1af5d2fSBarry Smith     x[idx]   = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4; x[4+idx] = s5;
613f1af5d2fSBarry Smith     x[5+idx] = s6;
614f1af5d2fSBarry Smith     idx += 6;
615f1af5d2fSBarry Smith   }
616f1af5d2fSBarry Smith   /* backward solve the L^T */
617f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
618f1af5d2fSBarry Smith     v    = aa + 36*diag[i] - 36;
619f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
620f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
621f1af5d2fSBarry Smith     idt  = 6*i;
622f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt];
623f1af5d2fSBarry Smith     s6 = x[5+idt];
624f1af5d2fSBarry Smith     while (nz--) {
625f1af5d2fSBarry Smith       idx   = 6*(*vi--);
626f1af5d2fSBarry Smith       x[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6;
627f1af5d2fSBarry Smith       x[idx+1] -=  v[6]*s1 +  v[7]*s2 +  v[8]*s3 +  v[9]*s4 + v[10]*s5 + v[11]*s6;
628f1af5d2fSBarry Smith       x[idx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6;
629f1af5d2fSBarry Smith       x[idx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6;
630f1af5d2fSBarry Smith       x[idx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6;
631f1af5d2fSBarry Smith       x[idx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6;
632f1af5d2fSBarry Smith       v -= 36;
633f1af5d2fSBarry Smith     }
634f1af5d2fSBarry Smith   }
635b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
6361ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
637dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
638f1af5d2fSBarry Smith   PetscFunctionReturn(0);
639f1af5d2fSBarry Smith }
640f1af5d2fSBarry Smith 
6414a2ae208SSatish Balay #undef __FUNCT__
6424dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_6_NaturalOrdering"
6434dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_6_NaturalOrdering(Mat A,Vec bb,Vec xx)
6448499736aSShri Abhyankar {
6458499736aSShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
6468499736aSShri Abhyankar   PetscErrorCode    ierr;
647b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
6488499736aSShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx;
649b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
650b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
651b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x;
652b3260449SShri Abhyankar   const PetscScalar *b;
6538499736aSShri Abhyankar 
6548499736aSShri Abhyankar   PetscFunctionBegin;
6558499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
656b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
6578499736aSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
6588499736aSShri Abhyankar 
6598499736aSShri Abhyankar   /* forward solve the U^T */
6608499736aSShri Abhyankar   idx = 0;
6618499736aSShri Abhyankar   for (i=0; i<n; i++) {
6628499736aSShri Abhyankar     v     = aa + bs2*diag[i];
6638499736aSShri Abhyankar     /* multiply by the inverse of the block diagonal */
6648499736aSShri Abhyankar     x1 = x[idx];   x2 = x[1+idx];  x3 = x[2+idx];  x4 = x[3+idx];
6658499736aSShri Abhyankar     x5 = x[4+idx]; x6 = x[5+idx];
6668499736aSShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5 +  v[5]*x6;
6678499736aSShri Abhyankar     s2 = v[6]*x1  +  v[7]*x2 +  v[8]*x3 +  v[9]*x4 + v[10]*x5 + v[11]*x6;
6688499736aSShri Abhyankar     s3 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4 + v[16]*x5 + v[17]*x6;
6698499736aSShri Abhyankar     s4 = v[18]*x1 + v[19]*x2 + v[20]*x3 + v[21]*x4 + v[22]*x5 + v[23]*x6;
6708499736aSShri Abhyankar     s5 = v[24]*x1 + v[25]*x2 + v[26]*x3 + v[27]*x4 + v[28]*x5 + v[29]*x6;
6718499736aSShri Abhyankar     s6 = v[30]*x1 + v[31]*x2 + v[32]*x3 + v[33]*x4 + v[34]*x5 + v[35]*x6;
6728499736aSShri Abhyankar     v -= bs2;
6738499736aSShri Abhyankar 
6748499736aSShri Abhyankar     vi    = aj + diag[i] - 1;
6758499736aSShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
6768499736aSShri Abhyankar     for(j=0;j>-nz;j--){
6778499736aSShri Abhyankar       oidx = bs*vi[j];
6788499736aSShri Abhyankar       x[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6;
6798499736aSShri Abhyankar       x[oidx+1] -= v[6]*s1  +  v[7]*s2 +  v[8]*s3 +  v[9]*s4 + v[10]*s5 + v[11]*s6;
6808499736aSShri Abhyankar       x[oidx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6;
6818499736aSShri Abhyankar       x[oidx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6;
6828499736aSShri Abhyankar       x[oidx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6;
6838499736aSShri Abhyankar       x[oidx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6;
6848499736aSShri Abhyankar       v  -= bs2;
6858499736aSShri Abhyankar     }
6868499736aSShri Abhyankar     x[idx]   = s1;x[1+idx] = s2;  x[2+idx] = s3;  x[3+idx] = s4; x[4+idx] = s5;
6878499736aSShri Abhyankar     x[5+idx] = s6;
6888499736aSShri Abhyankar     idx += bs;
6898499736aSShri Abhyankar   }
6908499736aSShri Abhyankar   /* backward solve the L^T */
6918499736aSShri Abhyankar   for (i=n-1; i>=0; i--){
6928499736aSShri Abhyankar     v    = aa + bs2*ai[i];
6938499736aSShri Abhyankar     vi   = aj + ai[i];
6948499736aSShri Abhyankar     nz   = ai[i+1] - ai[i];
6958499736aSShri Abhyankar     idt  = bs*i;
6968499736aSShri Abhyankar     s1   = x[idt];  s2 = x[1+idt];  s3 = x[2+idt];  s4 = x[3+idt];  s5 = x[4+idt];
6978499736aSShri Abhyankar     s6   = x[5+idt];
6988499736aSShri Abhyankar     for(j=0;j<nz;j++){
6998499736aSShri Abhyankar       idx   = bs*vi[j];
7008499736aSShri Abhyankar       x[idx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6;
7018499736aSShri Abhyankar       x[idx+1] -= v[6]*s1  +  v[7]*s2 +  v[8]*s3 +  v[9]*s4 + v[10]*s5 + v[11]*s6;
7028499736aSShri Abhyankar       x[idx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6;
7038499736aSShri Abhyankar       x[idx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6;
7048499736aSShri Abhyankar       x[idx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6;
7058499736aSShri Abhyankar       x[idx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6;
7068499736aSShri Abhyankar       v += bs2;
7078499736aSShri Abhyankar     }
7088499736aSShri Abhyankar   }
709b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
7108499736aSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
7118499736aSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
7128499736aSShri Abhyankar   PetscFunctionReturn(0);
7138499736aSShri Abhyankar }
7148499736aSShri Abhyankar 
7158499736aSShri Abhyankar #undef __FUNCT__
71606e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_7_NaturalOrdering_inplace"
71706e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_7_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
718f1af5d2fSBarry Smith {
719f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
720dfbe8321SBarry Smith   PetscErrorCode    ierr;
721b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
722b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,oidx;
723b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
724b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x;
725b3260449SShri Abhyankar   const PetscScalar *b;
726f1af5d2fSBarry Smith 
727f1af5d2fSBarry Smith   PetscFunctionBegin;
728ef66eb69SBarry Smith   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
729b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
7301ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
731f1af5d2fSBarry Smith 
732f1af5d2fSBarry Smith   /* forward solve the U^T */
733f1af5d2fSBarry Smith   idx = 0;
734f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
735f1af5d2fSBarry Smith 
736f1af5d2fSBarry Smith     v     = aa + 49*diag[i];
737f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
738ef66eb69SBarry Smith     x1    = x[idx];   x2 = x[1+idx]; x3    = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx];
739ef66eb69SBarry Smith     x6    = x[5+idx]; x7 = x[6+idx];
740f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5 +  v[5]*x6 +  v[6]*x7;
741f1af5d2fSBarry Smith     s2 = v[7]*x1  +  v[8]*x2 +  v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7;
742f1af5d2fSBarry Smith     s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7;
743f1af5d2fSBarry Smith     s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7;
744f1af5d2fSBarry Smith     s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7;
745f1af5d2fSBarry Smith     s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7;
746f1af5d2fSBarry Smith     s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7;
747f1af5d2fSBarry Smith     v += 49;
748f1af5d2fSBarry Smith 
749f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
750f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
751f1af5d2fSBarry Smith     while (nz--) {
752f1af5d2fSBarry Smith       oidx = 7*(*vi++);
753f1af5d2fSBarry Smith       x[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6 +  v[6]*s7;
754f1af5d2fSBarry Smith       x[oidx+1] -= v[7]*s1  +  v[8]*s2 +  v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7;
755f1af5d2fSBarry Smith       x[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7;
756f1af5d2fSBarry Smith       x[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7;
757f1af5d2fSBarry Smith       x[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7;
758f1af5d2fSBarry Smith       x[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7;
759f1af5d2fSBarry Smith       x[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7;
760f1af5d2fSBarry Smith       v  += 49;
761f1af5d2fSBarry Smith     }
762f1af5d2fSBarry Smith     x[idx]   = s1;x[1+idx] = s2; x[2+idx] = s3;x[3+idx] = s4; x[4+idx] = s5;
763f1af5d2fSBarry Smith     x[5+idx] = s6;x[6+idx] = s7;
764f1af5d2fSBarry Smith     idx += 7;
765f1af5d2fSBarry Smith   }
766f1af5d2fSBarry Smith   /* backward solve the L^T */
767f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
768f1af5d2fSBarry Smith     v    = aa + 49*diag[i] - 49;
769f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
770f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
771f1af5d2fSBarry Smith     idt  = 7*i;
772f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt]; s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt];
773f1af5d2fSBarry Smith     s6 = x[5+idt];s7 = x[6+idt];
774f1af5d2fSBarry Smith     while (nz--) {
775f1af5d2fSBarry Smith       idx   = 7*(*vi--);
776f1af5d2fSBarry Smith       x[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6 +  v[6]*s7;
777f1af5d2fSBarry Smith       x[idx+1] -=  v[7]*s1 +  v[8]*s2 +  v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7;
778f1af5d2fSBarry Smith       x[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7;
779f1af5d2fSBarry Smith       x[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7;
780f1af5d2fSBarry Smith       x[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7;
781f1af5d2fSBarry Smith       x[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7;
782f1af5d2fSBarry Smith       x[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7;
783f1af5d2fSBarry Smith       v -= 49;
784f1af5d2fSBarry Smith     }
785f1af5d2fSBarry Smith   }
786b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
7871ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
788dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr);
789f1af5d2fSBarry Smith   PetscFunctionReturn(0);
790f1af5d2fSBarry Smith }
7918499736aSShri Abhyankar #undef __FUNCT__
7924dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_7_NaturalOrdering"
7934dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_7_NaturalOrdering(Mat A,Vec bb,Vec xx)
7948499736aSShri Abhyankar {
7958499736aSShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
7968499736aSShri Abhyankar   PetscErrorCode    ierr;
797b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
7988499736aSShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx;
799b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
800b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
801b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x;
802b3260449SShri Abhyankar   const PetscScalar *b;
8038499736aSShri Abhyankar 
8048499736aSShri Abhyankar   PetscFunctionBegin;
8058499736aSShri Abhyankar   ierr = VecCopy(bb,xx);CHKERRQ(ierr);
806b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
8078499736aSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
8088499736aSShri Abhyankar 
8098499736aSShri Abhyankar   /* forward solve the U^T */
8108499736aSShri Abhyankar   idx = 0;
8118499736aSShri Abhyankar   for (i=0; i<n; i++) {
8128499736aSShri Abhyankar     v     = aa + bs2*diag[i];
8138499736aSShri Abhyankar     /* multiply by the inverse of the block diagonal */
8148499736aSShri Abhyankar     x1 = x[idx];   x2 = x[1+idx];  x3 = x[2+idx];  x4 = x[3+idx];
8158499736aSShri Abhyankar     x5 = x[4+idx]; x6 = x[5+idx];  x7 = x[6+idx];
8168499736aSShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5 +  v[5]*x6 +  v[6]*x7;
8178499736aSShri Abhyankar     s2 = v[7]*x1  +  v[8]*x2 +  v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7;
8188499736aSShri Abhyankar     s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7;
8198499736aSShri Abhyankar     s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7;
8208499736aSShri Abhyankar     s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7;
8218499736aSShri Abhyankar     s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7;
8228499736aSShri Abhyankar     s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7;
8238499736aSShri Abhyankar     v -= bs2;
8248499736aSShri Abhyankar     vi    = aj + diag[i] - 1;
8258499736aSShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
8268499736aSShri Abhyankar     for(j=0;j>-nz;j--){
8278499736aSShri Abhyankar       oidx = bs*vi[j];
8288499736aSShri Abhyankar       x[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6 +  v[6]*s7;
8298499736aSShri Abhyankar       x[oidx+1] -= v[7]*s1  +  v[8]*s2 +  v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7;
8308499736aSShri Abhyankar       x[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7;
8318499736aSShri Abhyankar       x[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7;
8328499736aSShri Abhyankar       x[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7;
8338499736aSShri Abhyankar       x[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7;
8348499736aSShri Abhyankar       x[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7;
8358499736aSShri Abhyankar       v  -= bs2;
8368499736aSShri Abhyankar     }
8378499736aSShri Abhyankar     x[idx]   = s1;  x[1+idx] = s2;  x[2+idx] = s3;  x[3+idx] = s4; x[4+idx] = s5;
8388499736aSShri Abhyankar     x[5+idx] = s6;  x[6+idx] = s7;
8398499736aSShri Abhyankar     idx += bs;
8408499736aSShri Abhyankar   }
8418499736aSShri Abhyankar   /* backward solve the L^T */
8428499736aSShri Abhyankar   for (i=n-1; i>=0; i--){
8438499736aSShri Abhyankar     v    = aa + bs2*ai[i];
8448499736aSShri Abhyankar     vi   = aj + ai[i];
8458499736aSShri Abhyankar     nz   = ai[i+1] - ai[i];
8468499736aSShri Abhyankar     idt  = bs*i;
8478499736aSShri Abhyankar     s1   = x[idt];    s2 = x[1+idt];  s3 = x[2+idt];  s4 = x[3+idt];  s5 = x[4+idt];
8488499736aSShri Abhyankar     s6   = x[5+idt];  s7 = x[6+idt];
8498499736aSShri Abhyankar     for(j=0;j<nz;j++){
8508499736aSShri Abhyankar       idx   = bs*vi[j];
8518499736aSShri Abhyankar       x[idx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6 +  v[6]*s7;
8528499736aSShri Abhyankar       x[idx+1] -= v[7]*s1  +  v[8]*s2 +  v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7;
8538499736aSShri Abhyankar       x[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7;
8548499736aSShri Abhyankar       x[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7;
8558499736aSShri Abhyankar       x[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7;
8568499736aSShri Abhyankar       x[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7;
8578499736aSShri Abhyankar       x[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7;
8588499736aSShri Abhyankar       v += bs2;
8598499736aSShri Abhyankar     }
8608499736aSShri Abhyankar   }
861b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
8628499736aSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
8638499736aSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
8648499736aSShri Abhyankar   PetscFunctionReturn(0);
8658499736aSShri Abhyankar }
866f1af5d2fSBarry Smith 
867f1af5d2fSBarry Smith /*---------------------------------------------------------------------------------------------*/
8684a2ae208SSatish Balay #undef __FUNCT__
86906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_1_inplace"
87006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_1_inplace(Mat A,Vec bb,Vec xx)
871f1af5d2fSBarry Smith {
872f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
873f1af5d2fSBarry Smith   IS                iscol=a->col,isrow=a->row;
8746849ba73SBarry Smith   PetscErrorCode    ierr;
8755d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
876b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
877b3260449SShri Abhyankar   PetscInt          i,nz;
878b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
879b3260449SShri Abhyankar   PetscScalar       s1,*x,*t;
880b3260449SShri Abhyankar   const PetscScalar *b;
881f1af5d2fSBarry Smith 
882f1af5d2fSBarry Smith   PetscFunctionBegin;
883b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
8841ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
885f1af5d2fSBarry Smith   t  = a->solve_work;
886f1af5d2fSBarry Smith 
887f1af5d2fSBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
888f1af5d2fSBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
889f1af5d2fSBarry Smith 
890f1af5d2fSBarry Smith   /* copy the b into temp work space according to permutation */
891f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
892f1af5d2fSBarry Smith     t[i] = b[c[i]];
893f1af5d2fSBarry Smith   }
894f1af5d2fSBarry Smith 
895f1af5d2fSBarry Smith   /* forward solve the U^T */
896f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
897f1af5d2fSBarry Smith 
898f1af5d2fSBarry Smith     v     = aa + diag[i];
899f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
900f1af5d2fSBarry Smith     s1    = (*v++)*t[i];
901f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
902f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
903f1af5d2fSBarry Smith     while (nz--) {
904f1af5d2fSBarry Smith       t[*vi++]  -= (*v++)*s1;
905f1af5d2fSBarry Smith     }
906f1af5d2fSBarry Smith     t[i]   = s1;
907f1af5d2fSBarry Smith   }
908f1af5d2fSBarry Smith   /* backward solve the L^T */
909f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
910f1af5d2fSBarry Smith     v    = aa + diag[i] - 1;
911f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
912f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
913f1af5d2fSBarry Smith     s1   = t[i];
914f1af5d2fSBarry Smith     while (nz--) {
915f1af5d2fSBarry Smith       t[*vi--]   -=  (*v--)*s1;
916f1af5d2fSBarry Smith     }
917f1af5d2fSBarry Smith   }
918f1af5d2fSBarry Smith 
919f1af5d2fSBarry Smith   /* copy t into x according to permutation */
920f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
921f1af5d2fSBarry Smith     x[r[i]]   = t[i];
922f1af5d2fSBarry Smith   }
923f1af5d2fSBarry Smith 
924f1af5d2fSBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
925f1af5d2fSBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
926b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
9271ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
928dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*(a->nz) - A->cmap->n);CHKERRQ(ierr);
929f1af5d2fSBarry Smith   PetscFunctionReturn(0);
930f1af5d2fSBarry Smith }
931f1af5d2fSBarry Smith 
9324a2ae208SSatish Balay #undef __FUNCT__
93306e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_2_inplace"
93406e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_2_inplace(Mat A,Vec bb,Vec xx)
935f1af5d2fSBarry Smith {
936f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
937f1af5d2fSBarry Smith   IS                iscol=a->col,isrow=a->row;
9386849ba73SBarry Smith   PetscErrorCode    ierr;
9395d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
940b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
941b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
942b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
943b3260449SShri Abhyankar   PetscScalar       s1,s2,x1,x2,*x,*t;
944b3260449SShri Abhyankar   const PetscScalar *b;
945f1af5d2fSBarry Smith 
946f1af5d2fSBarry Smith   PetscFunctionBegin;
947b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
9481ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
949f1af5d2fSBarry Smith   t  = a->solve_work;
950f1af5d2fSBarry Smith 
951f1af5d2fSBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
952f1af5d2fSBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
953f1af5d2fSBarry Smith 
954f1af5d2fSBarry Smith   /* copy the b into temp work space according to permutation */
955f1af5d2fSBarry Smith   ii = 0;
956f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
957f1af5d2fSBarry Smith     ic      = 2*c[i];
958f1af5d2fSBarry Smith     t[ii]   = b[ic];
959f1af5d2fSBarry Smith     t[ii+1] = b[ic+1];
960f1af5d2fSBarry Smith     ii += 2;
961f1af5d2fSBarry Smith   }
962f1af5d2fSBarry Smith 
963f1af5d2fSBarry Smith   /* forward solve the U^T */
964f1af5d2fSBarry Smith   idx = 0;
965f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
966f1af5d2fSBarry Smith 
967f1af5d2fSBarry Smith     v     = aa + 4*diag[i];
968f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
969f1af5d2fSBarry Smith     x1    = t[idx];   x2 = t[1+idx];
970f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2;
971f1af5d2fSBarry Smith     s2 = v[2]*x1  +  v[3]*x2;
972f1af5d2fSBarry Smith     v += 4;
973f1af5d2fSBarry Smith 
974f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
975f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
976f1af5d2fSBarry Smith     while (nz--) {
977f1af5d2fSBarry Smith       oidx = 2*(*vi++);
978f1af5d2fSBarry Smith       t[oidx]   -= v[0]*s1  +  v[1]*s2;
979f1af5d2fSBarry Smith       t[oidx+1] -= v[2]*s1  +  v[3]*s2;
980f1af5d2fSBarry Smith       v  += 4;
981f1af5d2fSBarry Smith     }
982f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
983f1af5d2fSBarry Smith     idx += 2;
984f1af5d2fSBarry Smith   }
985f1af5d2fSBarry Smith   /* backward solve the L^T */
986f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
987f1af5d2fSBarry Smith     v    = aa + 4*diag[i] - 4;
988f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
989f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
990f1af5d2fSBarry Smith     idt  = 2*i;
991f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
992f1af5d2fSBarry Smith     while (nz--) {
993f1af5d2fSBarry Smith       idx   = 2*(*vi--);
994f1af5d2fSBarry Smith       t[idx]   -=  v[0]*s1 +  v[1]*s2;
995f1af5d2fSBarry Smith       t[idx+1] -=  v[2]*s1 +  v[3]*s2;
996f1af5d2fSBarry Smith       v -= 4;
997f1af5d2fSBarry Smith     }
998f1af5d2fSBarry Smith   }
999f1af5d2fSBarry Smith 
1000f1af5d2fSBarry Smith   /* copy t into x according to permutation */
1001f1af5d2fSBarry Smith   ii = 0;
1002f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1003f1af5d2fSBarry Smith     ir      = 2*r[i];
1004f1af5d2fSBarry Smith     x[ir]   = t[ii];
1005f1af5d2fSBarry Smith     x[ir+1] = t[ii+1];
1006f1af5d2fSBarry Smith     ii += 2;
1007f1af5d2fSBarry Smith   }
1008f1af5d2fSBarry Smith 
1009f1af5d2fSBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
1010f1af5d2fSBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1011b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
10121ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
1013dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
1014f1af5d2fSBarry Smith   PetscFunctionReturn(0);
1015f1af5d2fSBarry Smith }
1016f1af5d2fSBarry Smith 
10174a2ae208SSatish Balay #undef __FUNCT__
10184dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_2"
10194dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_2(Mat A,Vec bb,Vec xx)
102032121132SShri Abhyankar {
102132121132SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
102232121132SShri Abhyankar   PetscErrorCode    ierr;
102332121132SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
1024b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
102532121132SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
102632121132SShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx,ii,ic,ir;
1027b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1028b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1029b3260449SShri Abhyankar   PetscScalar       s1,s2,x1,x2,*x,*t;
1030b3260449SShri Abhyankar   const PetscScalar *b;
103132121132SShri Abhyankar 
103232121132SShri Abhyankar   PetscFunctionBegin;
1033b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
103432121132SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
103532121132SShri Abhyankar   t = a->solve_work;
103632121132SShri Abhyankar 
103732121132SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
103832121132SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
103932121132SShri Abhyankar 
104032121132SShri Abhyankar   /* copy b into temp work space according to permutation */
104132121132SShri Abhyankar   for(i=0;i<n;i++){
104232121132SShri Abhyankar     ii = bs*i; ic = bs*c[i];
104332121132SShri Abhyankar     t[ii] = b[ic]; t[ii+1] = b[ic+1];
104432121132SShri Abhyankar   }
104532121132SShri Abhyankar 
104632121132SShri Abhyankar   /* forward solve the U^T */
104732121132SShri Abhyankar   idx = 0;
104832121132SShri Abhyankar   for (i=0; i<n; i++) {
104932121132SShri Abhyankar     v     = aa + bs2*diag[i];
105032121132SShri Abhyankar     /* multiply by the inverse of the block diagonal */
105132121132SShri Abhyankar     x1 = t[idx];   x2 = t[1+idx];
105232121132SShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2;
105332121132SShri Abhyankar     s2 = v[2]*x1  +  v[3]*x2;
105432121132SShri Abhyankar     v -= bs2;
105532121132SShri Abhyankar 
105632121132SShri Abhyankar     vi    = aj + diag[i] - 1;
105732121132SShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
105832121132SShri Abhyankar     for(j=0;j>-nz;j--){
105932121132SShri Abhyankar       oidx = bs*vi[j];
106032121132SShri Abhyankar       t[oidx]   -= v[0]*s1  +  v[1]*s2;
106132121132SShri Abhyankar       t[oidx+1] -= v[2]*s1  +  v[3]*s2;
106232121132SShri Abhyankar       v  -= bs2;
106332121132SShri Abhyankar     }
106432121132SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
106532121132SShri Abhyankar     idx += bs;
106632121132SShri Abhyankar   }
106732121132SShri Abhyankar   /* backward solve the L^T */
106832121132SShri Abhyankar   for (i=n-1; i>=0; i--){
106932121132SShri Abhyankar     v    = aa + bs2*ai[i];
107032121132SShri Abhyankar     vi   = aj + ai[i];
107132121132SShri Abhyankar     nz   = ai[i+1] - ai[i];
107232121132SShri Abhyankar     idt  = bs*i;
107332121132SShri Abhyankar     s1   = t[idt];  s2 = t[1+idt];
107432121132SShri Abhyankar     for(j=0;j<nz;j++){
107532121132SShri Abhyankar       idx   = bs*vi[j];
107632121132SShri Abhyankar       t[idx]   -=  v[0]*s1 +  v[1]*s2;
107732121132SShri Abhyankar       t[idx+1] -=  v[2]*s1 +  v[3]*s2;
107832121132SShri Abhyankar       v += bs2;
107932121132SShri Abhyankar     }
108032121132SShri Abhyankar   }
108132121132SShri Abhyankar 
108232121132SShri Abhyankar   /* copy t into x according to permutation */
108332121132SShri Abhyankar   for(i=0;i<n;i++){
108432121132SShri Abhyankar     ii = bs*i;  ir = bs*r[i];
108532121132SShri Abhyankar     x[ir] = t[ii];  x[ir+1] = t[ii+1];
108632121132SShri Abhyankar   }
108732121132SShri Abhyankar 
108832121132SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
108932121132SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1090b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
109132121132SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
109232121132SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
109332121132SShri Abhyankar   PetscFunctionReturn(0);
109432121132SShri Abhyankar }
109532121132SShri Abhyankar 
109632121132SShri Abhyankar #undef __FUNCT__
109706e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_3_inplace"
109806e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_3_inplace(Mat A,Vec bb,Vec xx)
1099f1af5d2fSBarry Smith {
1100f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
1101f1af5d2fSBarry Smith   IS                iscol=a->col,isrow=a->row;
11026849ba73SBarry Smith   PetscErrorCode    ierr;
11035d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
1104b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1105b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1106b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1107b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,x1,x2,x3,*x,*t;
1108b3260449SShri Abhyankar   const PetscScalar *b;
1109f1af5d2fSBarry Smith 
1110f1af5d2fSBarry Smith   PetscFunctionBegin;
1111b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
11121ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
1113f1af5d2fSBarry Smith   t  = a->solve_work;
1114f1af5d2fSBarry Smith 
1115f1af5d2fSBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
1116f1af5d2fSBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
1117f1af5d2fSBarry Smith 
1118f1af5d2fSBarry Smith   /* copy the b into temp work space according to permutation */
1119f1af5d2fSBarry Smith   ii = 0;
1120f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1121f1af5d2fSBarry Smith     ic      = 3*c[i];
1122f1af5d2fSBarry Smith     t[ii]   = b[ic];
1123f1af5d2fSBarry Smith     t[ii+1] = b[ic+1];
1124f1af5d2fSBarry Smith     t[ii+2] = b[ic+2];
1125f1af5d2fSBarry Smith     ii += 3;
1126f1af5d2fSBarry Smith   }
1127f1af5d2fSBarry Smith 
1128f1af5d2fSBarry Smith   /* forward solve the U^T */
1129f1af5d2fSBarry Smith   idx = 0;
1130f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1131f1af5d2fSBarry Smith 
1132f1af5d2fSBarry Smith     v     = aa + 9*diag[i];
1133f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
1134f1af5d2fSBarry Smith     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx];
1135f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3;
1136f1af5d2fSBarry Smith     s2 = v[3]*x1  +  v[4]*x2 +  v[5]*x3;
1137f1af5d2fSBarry Smith     s3 = v[6]*x1  +  v[7]*x2 + v[8]*x3;
1138f1af5d2fSBarry Smith     v += 9;
1139f1af5d2fSBarry Smith 
1140f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
1141f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
1142f1af5d2fSBarry Smith     while (nz--) {
1143f1af5d2fSBarry Smith       oidx = 3*(*vi++);
1144f1af5d2fSBarry Smith       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3;
1145f1af5d2fSBarry Smith       t[oidx+1] -= v[3]*s1  +  v[4]*s2 +  v[5]*s3;
1146f1af5d2fSBarry Smith       t[oidx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3;
1147f1af5d2fSBarry Smith       v  += 9;
1148f1af5d2fSBarry Smith     }
1149f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2; t[2+idx] = s3;
1150f1af5d2fSBarry Smith     idx += 3;
1151f1af5d2fSBarry Smith   }
1152f1af5d2fSBarry Smith   /* backward solve the L^T */
1153f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
1154f1af5d2fSBarry Smith     v    = aa + 9*diag[i] - 9;
1155f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
1156f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
1157f1af5d2fSBarry Smith     idt  = 3*i;
1158f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt]; s3 = t[2+idt];
1159f1af5d2fSBarry Smith     while (nz--) {
1160f1af5d2fSBarry Smith       idx   = 3*(*vi--);
1161f1af5d2fSBarry Smith       t[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3;
1162f1af5d2fSBarry Smith       t[idx+1] -=  v[3]*s1 +  v[4]*s2 +  v[5]*s3;
1163f1af5d2fSBarry Smith       t[idx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3;
1164f1af5d2fSBarry Smith       v -= 9;
1165f1af5d2fSBarry Smith     }
1166f1af5d2fSBarry Smith   }
1167f1af5d2fSBarry Smith 
1168f1af5d2fSBarry Smith   /* copy t into x according to permutation */
1169f1af5d2fSBarry Smith   ii = 0;
1170f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1171f1af5d2fSBarry Smith     ir      = 3*r[i];
1172f1af5d2fSBarry Smith     x[ir]   = t[ii];
1173f1af5d2fSBarry Smith     x[ir+1] = t[ii+1];
1174f1af5d2fSBarry Smith     x[ir+2] = t[ii+2];
1175f1af5d2fSBarry Smith     ii += 3;
1176f1af5d2fSBarry Smith   }
1177f1af5d2fSBarry Smith 
1178f1af5d2fSBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
1179f1af5d2fSBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1180b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
11811ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
1182dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr);
1183f1af5d2fSBarry Smith   PetscFunctionReturn(0);
1184f1af5d2fSBarry Smith }
1185f1af5d2fSBarry Smith 
11864a2ae208SSatish Balay #undef __FUNCT__
11874dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_3"
11884dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_3(Mat A,Vec bb,Vec xx)
118932121132SShri Abhyankar {
119032121132SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
119132121132SShri Abhyankar   PetscErrorCode    ierr;
119232121132SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
1193b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
119432121132SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
119532121132SShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx,ii,ic,ir;
1196b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1197b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1198b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,x1,x2,x3,*x,*t;
1199b3260449SShri Abhyankar   const PetscScalar *b;
120032121132SShri Abhyankar 
120132121132SShri Abhyankar   PetscFunctionBegin;
1202b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
120332121132SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
120432121132SShri Abhyankar   t = a->solve_work;
120532121132SShri Abhyankar 
120632121132SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
120732121132SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
120832121132SShri Abhyankar 
120932121132SShri Abhyankar   /* copy b into temp work space according to permutation */
121032121132SShri Abhyankar   for(i=0;i<n;i++){
121132121132SShri Abhyankar     ii = bs*i; ic = bs*c[i];
121232121132SShri Abhyankar     t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2];
121332121132SShri Abhyankar   }
121432121132SShri Abhyankar 
121532121132SShri Abhyankar   /* forward solve the U^T */
121632121132SShri Abhyankar   idx = 0;
121732121132SShri Abhyankar   for (i=0; i<n; i++) {
121832121132SShri Abhyankar     v     = aa + bs2*diag[i];
121932121132SShri Abhyankar     /* multiply by the inverse of the block diagonal */
122032121132SShri Abhyankar     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx];
122132121132SShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3;
122232121132SShri Abhyankar     s2 = v[3]*x1  +  v[4]*x2 +  v[5]*x3;
122332121132SShri Abhyankar     s3 = v[6]*x1  +  v[7]*x2 + v[8]*x3;
122432121132SShri Abhyankar     v -= bs2;
122532121132SShri Abhyankar 
122632121132SShri Abhyankar     vi    = aj + diag[i] - 1;
122732121132SShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
122832121132SShri Abhyankar     for(j=0;j>-nz;j--){
122932121132SShri Abhyankar       oidx = bs*vi[j];
123032121132SShri Abhyankar       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3;
123132121132SShri Abhyankar       t[oidx+1] -= v[3]*s1  +  v[4]*s2 +  v[5]*s3;
123232121132SShri Abhyankar       t[oidx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3;
123332121132SShri Abhyankar       v  -= bs2;
123432121132SShri Abhyankar     }
123532121132SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;  t[2+idx] = s3;
123632121132SShri Abhyankar     idx += bs;
123732121132SShri Abhyankar   }
123832121132SShri Abhyankar   /* backward solve the L^T */
123932121132SShri Abhyankar   for (i=n-1; i>=0; i--){
124032121132SShri Abhyankar     v    = aa + bs2*ai[i];
124132121132SShri Abhyankar     vi   = aj + ai[i];
124232121132SShri Abhyankar     nz   = ai[i+1] - ai[i];
124332121132SShri Abhyankar     idt  = bs*i;
124432121132SShri Abhyankar     s1   = t[idt];  s2 = t[1+idt];  s3 = t[2+idt];
124532121132SShri Abhyankar     for(j=0;j<nz;j++){
124632121132SShri Abhyankar       idx   = bs*vi[j];
124732121132SShri Abhyankar       t[idx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3;
124832121132SShri Abhyankar       t[idx+1] -= v[3]*s1  +  v[4]*s2 +  v[5]*s3;
124932121132SShri Abhyankar       t[idx+2] -= v[6]*s1 + v[7]*s2 + v[8]*s3;
125032121132SShri Abhyankar       v += bs2;
125132121132SShri Abhyankar     }
125232121132SShri Abhyankar   }
125332121132SShri Abhyankar 
125432121132SShri Abhyankar   /* copy t into x according to permutation */
125532121132SShri Abhyankar   for(i=0;i<n;i++){
125632121132SShri Abhyankar     ii = bs*i;  ir = bs*r[i];
125732121132SShri Abhyankar     x[ir] = t[ii];  x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2];
125832121132SShri Abhyankar   }
125932121132SShri Abhyankar 
126032121132SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
126132121132SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1262b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
126332121132SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
126432121132SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
126532121132SShri Abhyankar   PetscFunctionReturn(0);
126632121132SShri Abhyankar }
126732121132SShri Abhyankar 
126832121132SShri Abhyankar #undef __FUNCT__
126906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_4_inplace"
127006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_4_inplace(Mat A,Vec bb,Vec xx)
1271f1af5d2fSBarry Smith {
1272f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
1273f1af5d2fSBarry Smith   IS                iscol=a->col,isrow=a->row;
12746849ba73SBarry Smith   PetscErrorCode    ierr;
12755d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
1276b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1277b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1278b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1279b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4,*x,*t;
1280b3260449SShri Abhyankar   const PetscScalar *b;
1281f1af5d2fSBarry Smith 
1282f1af5d2fSBarry Smith   PetscFunctionBegin;
1283b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
12841ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
1285f1af5d2fSBarry Smith   t  = a->solve_work;
1286f1af5d2fSBarry Smith 
1287f1af5d2fSBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
1288f1af5d2fSBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
1289f1af5d2fSBarry Smith 
1290f1af5d2fSBarry Smith   /* copy the b into temp work space according to permutation */
1291f1af5d2fSBarry Smith   ii = 0;
1292f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1293f1af5d2fSBarry Smith     ic      = 4*c[i];
1294f1af5d2fSBarry Smith     t[ii]   = b[ic];
1295f1af5d2fSBarry Smith     t[ii+1] = b[ic+1];
1296f1af5d2fSBarry Smith     t[ii+2] = b[ic+2];
1297f1af5d2fSBarry Smith     t[ii+3] = b[ic+3];
1298f1af5d2fSBarry Smith     ii += 4;
1299f1af5d2fSBarry Smith   }
1300f1af5d2fSBarry Smith 
1301f1af5d2fSBarry Smith   /* forward solve the U^T */
1302f1af5d2fSBarry Smith   idx = 0;
1303f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1304f1af5d2fSBarry Smith 
1305f1af5d2fSBarry Smith     v     = aa + 16*diag[i];
1306f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
1307f1af5d2fSBarry Smith     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx]; x4 = t[3+idx];
1308f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4;
1309f1af5d2fSBarry Smith     s2 = v[4]*x1  +  v[5]*x2 +  v[6]*x3 +  v[7]*x4;
1310f1af5d2fSBarry Smith     s3 = v[8]*x1  +  v[9]*x2 + v[10]*x3 + v[11]*x4;
1311f1af5d2fSBarry Smith     s4 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4;
1312f1af5d2fSBarry Smith     v += 16;
1313f1af5d2fSBarry Smith 
1314f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
1315f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
1316f1af5d2fSBarry Smith     while (nz--) {
1317f1af5d2fSBarry Smith       oidx = 4*(*vi++);
1318f1af5d2fSBarry Smith       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4;
1319f1af5d2fSBarry Smith       t[oidx+1] -= v[4]*s1  +  v[5]*s2 +  v[6]*s3 +  v[7]*s4;
1320f1af5d2fSBarry Smith       t[oidx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4;
1321f1af5d2fSBarry Smith       t[oidx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4;
1322f1af5d2fSBarry Smith       v  += 16;
1323f1af5d2fSBarry Smith     }
1324f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2; t[2+idx] = s3;t[3+idx] = s4;
1325f1af5d2fSBarry Smith     idx += 4;
1326f1af5d2fSBarry Smith   }
1327f1af5d2fSBarry Smith   /* backward solve the L^T */
1328f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
1329f1af5d2fSBarry Smith     v    = aa + 16*diag[i] - 16;
1330f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
1331f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
1332f1af5d2fSBarry Smith     idt  = 4*i;
1333f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt]; s3 = t[2+idt];s4 = t[3+idt];
1334f1af5d2fSBarry Smith     while (nz--) {
1335f1af5d2fSBarry Smith       idx   = 4*(*vi--);
1336f1af5d2fSBarry Smith       t[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4;
1337f1af5d2fSBarry Smith       t[idx+1] -=  v[4]*s1 +  v[5]*s2 +  v[6]*s3 +  v[7]*s4;
1338f1af5d2fSBarry Smith       t[idx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4;
1339f1af5d2fSBarry Smith       t[idx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4;
1340f1af5d2fSBarry Smith       v -= 16;
1341f1af5d2fSBarry Smith     }
1342f1af5d2fSBarry Smith   }
1343f1af5d2fSBarry Smith 
1344f1af5d2fSBarry Smith   /* copy t into x according to permutation */
1345f1af5d2fSBarry Smith   ii = 0;
1346f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1347f1af5d2fSBarry Smith     ir      = 4*r[i];
1348f1af5d2fSBarry Smith     x[ir]   = t[ii];
1349f1af5d2fSBarry Smith     x[ir+1] = t[ii+1];
1350f1af5d2fSBarry Smith     x[ir+2] = t[ii+2];
1351f1af5d2fSBarry Smith     x[ir+3] = t[ii+3];
1352f1af5d2fSBarry Smith     ii += 4;
1353f1af5d2fSBarry Smith   }
1354f1af5d2fSBarry Smith 
1355f1af5d2fSBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
1356f1af5d2fSBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1357b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
13581ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
1359dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
1360f1af5d2fSBarry Smith   PetscFunctionReturn(0);
1361f1af5d2fSBarry Smith }
1362f1af5d2fSBarry Smith 
13634a2ae208SSatish Balay #undef __FUNCT__
13644dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_4"
13654dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_4(Mat A,Vec bb,Vec xx)
136632121132SShri Abhyankar {
136732121132SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
136832121132SShri Abhyankar   PetscErrorCode    ierr;
136932121132SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
1370b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
137132121132SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
137232121132SShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx,ii,ic,ir;
1373b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1374b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1375b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4,*x,*t;
1376b3260449SShri Abhyankar   const PetscScalar *b;
137732121132SShri Abhyankar 
137832121132SShri Abhyankar   PetscFunctionBegin;
1379b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
138032121132SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
138132121132SShri Abhyankar   t = a->solve_work;
138232121132SShri Abhyankar 
138332121132SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
138432121132SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
138532121132SShri Abhyankar 
138632121132SShri Abhyankar   /* copy b into temp work space according to permutation */
138732121132SShri Abhyankar   for(i=0;i<n;i++){
138832121132SShri Abhyankar     ii = bs*i; ic = bs*c[i];
138932121132SShri Abhyankar     t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; t[ii+3] = b[ic+3];
139032121132SShri Abhyankar   }
139132121132SShri Abhyankar 
139232121132SShri Abhyankar   /* forward solve the U^T */
139332121132SShri Abhyankar   idx = 0;
139432121132SShri Abhyankar   for (i=0; i<n; i++) {
139532121132SShri Abhyankar     v     = aa + bs2*diag[i];
139632121132SShri Abhyankar     /* multiply by the inverse of the block diagonal */
139732121132SShri Abhyankar     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx];  x4 = t[3+idx];
139832121132SShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4;
139932121132SShri Abhyankar     s2 = v[4]*x1  +  v[5]*x2 +  v[6]*x3 +  v[7]*x4;
140032121132SShri Abhyankar     s3 = v[8]*x1  +  v[9]*x2 + v[10]*x3 + v[11]*x4;
140132121132SShri Abhyankar     s4 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4;
140232121132SShri Abhyankar     v -= bs2;
140332121132SShri Abhyankar 
140432121132SShri Abhyankar     vi    = aj + diag[i] - 1;
140532121132SShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
140632121132SShri Abhyankar     for(j=0;j>-nz;j--){
140732121132SShri Abhyankar       oidx = bs*vi[j];
140832121132SShri Abhyankar       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4;
140932121132SShri Abhyankar       t[oidx+1] -= v[4]*s1  +  v[5]*s2 +  v[6]*s3 +  v[7]*s4;
141032121132SShri Abhyankar       t[oidx+2] -= v[8]*s1 + v[9]*s2 + v[10]*s3 + v[11]*s4;
141132121132SShri Abhyankar       t[oidx+3] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4;
141232121132SShri Abhyankar       v  -= bs2;
141332121132SShri Abhyankar     }
141432121132SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;  t[2+idx] = s3;  t[3+idx] = s4;
141532121132SShri Abhyankar     idx += bs;
141632121132SShri Abhyankar   }
141732121132SShri Abhyankar   /* backward solve the L^T */
141832121132SShri Abhyankar   for (i=n-1; i>=0; i--){
141932121132SShri Abhyankar     v    = aa + bs2*ai[i];
142032121132SShri Abhyankar     vi   = aj + ai[i];
142132121132SShri Abhyankar     nz   = ai[i+1] - ai[i];
142232121132SShri Abhyankar     idt  = bs*i;
142332121132SShri Abhyankar     s1   = t[idt];  s2 = t[1+idt];  s3 = t[2+idt];  s4 = t[3+idt];
142432121132SShri Abhyankar     for(j=0;j<nz;j++){
142532121132SShri Abhyankar       idx   = bs*vi[j];
142632121132SShri Abhyankar       t[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3  +  v[3]*s4;
142732121132SShri Abhyankar       t[idx+1] -=  v[4]*s1 +  v[5]*s2 +  v[6]*s3  +  v[7]*s4;
142832121132SShri Abhyankar       t[idx+2] -=  v[8]*s1 +  v[9]*s2 +  v[10]*s3 + v[11]*s4;
142932121132SShri Abhyankar       t[idx+3] -= v[12]*s1 +  v[13]*s2 + v[14]*s3 + v[15]*s4;
143032121132SShri Abhyankar       v += bs2;
143132121132SShri Abhyankar     }
143232121132SShri Abhyankar   }
143332121132SShri Abhyankar 
143432121132SShri Abhyankar   /* copy t into x according to permutation */
143532121132SShri Abhyankar   for(i=0;i<n;i++){
143632121132SShri Abhyankar     ii = bs*i;  ir = bs*r[i];
143732121132SShri Abhyankar     x[ir] = t[ii];  x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2];  x[ir+3] = t[ii+3];
143832121132SShri Abhyankar   }
143932121132SShri Abhyankar 
144032121132SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
144132121132SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1442b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
144332121132SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
144432121132SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
144532121132SShri Abhyankar   PetscFunctionReturn(0);
144632121132SShri Abhyankar }
144732121132SShri Abhyankar 
144832121132SShri Abhyankar #undef __FUNCT__
144906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_5_inplace"
145006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_5_inplace(Mat A,Vec bb,Vec xx)
1451f1af5d2fSBarry Smith {
1452f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
1453f1af5d2fSBarry Smith   IS                iscol=a->col,isrow=a->row;
14546849ba73SBarry Smith   PetscErrorCode    ierr;
14555d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
1456b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1457b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1458b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1459b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x,*t;
1460b3260449SShri Abhyankar   const PetscScalar *b;
1461f1af5d2fSBarry Smith 
1462f1af5d2fSBarry Smith   PetscFunctionBegin;
1463b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
14641ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
1465f1af5d2fSBarry Smith   t  = a->solve_work;
1466f1af5d2fSBarry Smith 
1467f1af5d2fSBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
1468f1af5d2fSBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
1469f1af5d2fSBarry Smith 
1470f1af5d2fSBarry Smith   /* copy the b into temp work space according to permutation */
1471f1af5d2fSBarry Smith   ii = 0;
1472f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1473f1af5d2fSBarry Smith     ic      = 5*c[i];
1474f1af5d2fSBarry Smith     t[ii]   = b[ic];
1475f1af5d2fSBarry Smith     t[ii+1] = b[ic+1];
1476f1af5d2fSBarry Smith     t[ii+2] = b[ic+2];
1477f1af5d2fSBarry Smith     t[ii+3] = b[ic+3];
1478f1af5d2fSBarry Smith     t[ii+4] = b[ic+4];
1479f1af5d2fSBarry Smith     ii += 5;
1480f1af5d2fSBarry Smith   }
1481f1af5d2fSBarry Smith 
1482f1af5d2fSBarry Smith   /* forward solve the U^T */
1483f1af5d2fSBarry Smith   idx = 0;
1484f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1485f1af5d2fSBarry Smith 
1486f1af5d2fSBarry Smith     v     = aa + 25*diag[i];
1487f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
1488f1af5d2fSBarry Smith     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
1489f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5;
1490f1af5d2fSBarry Smith     s2 = v[5]*x1  +  v[6]*x2 +  v[7]*x3 +  v[8]*x4 +  v[9]*x5;
1491f1af5d2fSBarry Smith     s3 = v[10]*x1 + v[11]*x2 + v[12]*x3 + v[13]*x4 + v[14]*x5;
1492f1af5d2fSBarry Smith     s4 = v[15]*x1 + v[16]*x2 + v[17]*x3 + v[18]*x4 + v[19]*x5;
1493f1af5d2fSBarry Smith     s5 = v[20]*x1 + v[21]*x2 + v[22]*x3 + v[23]*x4 + v[24]*x5;
1494f1af5d2fSBarry Smith     v += 25;
1495f1af5d2fSBarry Smith 
1496f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
1497f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
1498f1af5d2fSBarry Smith     while (nz--) {
1499f1af5d2fSBarry Smith       oidx = 5*(*vi++);
1500f1af5d2fSBarry Smith       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5;
1501f1af5d2fSBarry Smith       t[oidx+1] -= v[5]*s1  +  v[6]*s2 +  v[7]*s3 +  v[8]*s4 +  v[9]*s5;
1502f1af5d2fSBarry Smith       t[oidx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5;
1503f1af5d2fSBarry Smith       t[oidx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5;
1504f1af5d2fSBarry Smith       t[oidx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5;
1505f1af5d2fSBarry Smith       v  += 25;
1506f1af5d2fSBarry Smith     }
1507f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2; t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
1508f1af5d2fSBarry Smith     idx += 5;
1509f1af5d2fSBarry Smith   }
1510f1af5d2fSBarry Smith   /* backward solve the L^T */
1511f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
1512f1af5d2fSBarry Smith     v    = aa + 25*diag[i] - 25;
1513f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
1514f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
1515f1af5d2fSBarry Smith     idt  = 5*i;
1516f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt]; s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
1517f1af5d2fSBarry Smith     while (nz--) {
1518f1af5d2fSBarry Smith       idx   = 5*(*vi--);
1519f1af5d2fSBarry Smith       t[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5;
1520f1af5d2fSBarry Smith       t[idx+1] -=  v[5]*s1 +  v[6]*s2 +  v[7]*s3 +  v[8]*s4 +  v[9]*s5;
1521f1af5d2fSBarry Smith       t[idx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5;
1522f1af5d2fSBarry Smith       t[idx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5;
1523f1af5d2fSBarry Smith       t[idx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5;
1524f1af5d2fSBarry Smith       v -= 25;
1525f1af5d2fSBarry Smith     }
1526f1af5d2fSBarry Smith   }
1527f1af5d2fSBarry Smith 
1528f1af5d2fSBarry Smith   /* copy t into x according to permutation */
1529f1af5d2fSBarry Smith   ii = 0;
1530f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1531f1af5d2fSBarry Smith     ir      = 5*r[i];
1532f1af5d2fSBarry Smith     x[ir]   = t[ii];
1533f1af5d2fSBarry Smith     x[ir+1] = t[ii+1];
1534f1af5d2fSBarry Smith     x[ir+2] = t[ii+2];
1535f1af5d2fSBarry Smith     x[ir+3] = t[ii+3];
1536f1af5d2fSBarry Smith     x[ir+4] = t[ii+4];
1537f1af5d2fSBarry Smith     ii += 5;
1538f1af5d2fSBarry Smith   }
1539f1af5d2fSBarry Smith 
1540f1af5d2fSBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
1541f1af5d2fSBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1542b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
15431ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
1544dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
1545f1af5d2fSBarry Smith   PetscFunctionReturn(0);
1546f1af5d2fSBarry Smith }
1547f1af5d2fSBarry Smith 
15484a2ae208SSatish Balay #undef __FUNCT__
15494dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_5"
15504dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_5(Mat A,Vec bb,Vec xx)
155132121132SShri Abhyankar {
155232121132SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
155332121132SShri Abhyankar   PetscErrorCode    ierr;
155432121132SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
1555b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
155632121132SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
155732121132SShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx,ii,ic,ir;
1558b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1559b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1560b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*x,*t;
1561b3260449SShri Abhyankar   const PetscScalar *b;
156232121132SShri Abhyankar 
156332121132SShri Abhyankar   PetscFunctionBegin;
1564b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
156532121132SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
156632121132SShri Abhyankar   t = a->solve_work;
156732121132SShri Abhyankar 
156832121132SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
156932121132SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
157032121132SShri Abhyankar 
157132121132SShri Abhyankar   /* copy b into temp work space according to permutation */
157232121132SShri Abhyankar   for(i=0;i<n;i++){
157332121132SShri Abhyankar     ii = bs*i; ic = bs*c[i];
157432121132SShri Abhyankar     t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; t[ii+3] = b[ic+3];
157532121132SShri Abhyankar     t[ii+4] = b[ic+4];
157632121132SShri Abhyankar   }
157732121132SShri Abhyankar 
157832121132SShri Abhyankar   /* forward solve the U^T */
157932121132SShri Abhyankar   idx = 0;
158032121132SShri Abhyankar   for (i=0; i<n; i++) {
158132121132SShri Abhyankar     v     = aa + bs2*diag[i];
158232121132SShri Abhyankar     /* multiply by the inverse of the block diagonal */
158332121132SShri Abhyankar     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
158432121132SShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5;
158532121132SShri Abhyankar     s2 = v[5]*x1  +  v[6]*x2 +  v[7]*x3 +  v[8]*x4 +  v[9]*x5;
158632121132SShri Abhyankar     s3 = v[10]*x1 + v[11]*x2 + v[12]*x3 + v[13]*x4 + v[14]*x5;
158732121132SShri Abhyankar     s4 = v[15]*x1 + v[16]*x2 + v[17]*x3 + v[18]*x4 + v[19]*x5;
158832121132SShri Abhyankar     s5 = v[20]*x1 + v[21]*x2 + v[22]*x3 + v[23]*x4 + v[24]*x5;
158932121132SShri Abhyankar     v -= bs2;
159032121132SShri Abhyankar 
159132121132SShri Abhyankar     vi    = aj + diag[i] - 1;
159232121132SShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
159332121132SShri Abhyankar     for(j=0;j>-nz;j--){
159432121132SShri Abhyankar       oidx = bs*vi[j];
159532121132SShri Abhyankar       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5;
159632121132SShri Abhyankar       t[oidx+1] -= v[5]*s1  +  v[6]*s2 +  v[7]*s3 +  v[8]*s4 +  v[9]*s5;
159732121132SShri Abhyankar       t[oidx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5;
159832121132SShri Abhyankar       t[oidx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5;
159932121132SShri Abhyankar       t[oidx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5;
160032121132SShri Abhyankar       v  -= bs2;
160132121132SShri Abhyankar     }
160232121132SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;  t[2+idx] = s3;  t[3+idx] = s4; t[4+idx] =s5;
160332121132SShri Abhyankar     idx += bs;
160432121132SShri Abhyankar   }
160532121132SShri Abhyankar   /* backward solve the L^T */
160632121132SShri Abhyankar   for (i=n-1; i>=0; i--){
160732121132SShri Abhyankar     v    = aa + bs2*ai[i];
160832121132SShri Abhyankar     vi   = aj + ai[i];
160932121132SShri Abhyankar     nz   = ai[i+1] - ai[i];
161032121132SShri Abhyankar     idt  = bs*i;
161132121132SShri Abhyankar     s1   = t[idt];  s2 = t[1+idt];  s3 = t[2+idt];  s4 = t[3+idt]; s5 = t[4+idt];
161232121132SShri Abhyankar     for(j=0;j<nz;j++){
161332121132SShri Abhyankar       idx   = bs*vi[j];
161432121132SShri Abhyankar       t[idx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5;
161532121132SShri Abhyankar       t[idx+1] -= v[5]*s1  +  v[6]*s2 +  v[7]*s3 +  v[8]*s4 +  v[9]*s5;
161632121132SShri Abhyankar       t[idx+2] -= v[10]*s1 + v[11]*s2 + v[12]*s3 + v[13]*s4 + v[14]*s5;
161732121132SShri Abhyankar       t[idx+3] -= v[15]*s1 + v[16]*s2 + v[17]*s3 + v[18]*s4 + v[19]*s5;
161832121132SShri Abhyankar       t[idx+4] -= v[20]*s1 + v[21]*s2 + v[22]*s3 + v[23]*s4 + v[24]*s5;
161932121132SShri Abhyankar       v += bs2;
162032121132SShri Abhyankar     }
162132121132SShri Abhyankar   }
162232121132SShri Abhyankar 
162332121132SShri Abhyankar   /* copy t into x according to permutation */
162432121132SShri Abhyankar   for(i=0;i<n;i++){
162532121132SShri Abhyankar     ii = bs*i;  ir = bs*r[i];
162632121132SShri Abhyankar     x[ir] = t[ii];  x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2];  x[ir+3] = t[ii+3];
162732121132SShri Abhyankar     x[ir+4] = t[ii+4];
162832121132SShri Abhyankar   }
162932121132SShri Abhyankar 
163032121132SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
163132121132SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1632b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
163332121132SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
163432121132SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
163532121132SShri Abhyankar   PetscFunctionReturn(0);
163632121132SShri Abhyankar }
163732121132SShri Abhyankar 
163832121132SShri Abhyankar #undef __FUNCT__
163906e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_6_inplace"
164006e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_6_inplace(Mat A,Vec bb,Vec xx)
1641f1af5d2fSBarry Smith {
1642f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
1643f1af5d2fSBarry Smith   IS                iscol=a->col,isrow=a->row;
16446849ba73SBarry Smith   PetscErrorCode    ierr;
16455d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
1646b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1647b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1648b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1649b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x,*t;
1650b3260449SShri Abhyankar   const PetscScalar *b;
1651f1af5d2fSBarry Smith 
1652f1af5d2fSBarry Smith   PetscFunctionBegin;
1653b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
16541ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
1655f1af5d2fSBarry Smith   t  = a->solve_work;
1656f1af5d2fSBarry Smith 
1657f1af5d2fSBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
1658f1af5d2fSBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
1659f1af5d2fSBarry Smith 
1660f1af5d2fSBarry Smith   /* copy the b into temp work space according to permutation */
1661f1af5d2fSBarry Smith   ii = 0;
1662f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1663f1af5d2fSBarry Smith     ic      = 6*c[i];
1664f1af5d2fSBarry Smith     t[ii]   = b[ic];
1665f1af5d2fSBarry Smith     t[ii+1] = b[ic+1];
1666f1af5d2fSBarry Smith     t[ii+2] = b[ic+2];
1667f1af5d2fSBarry Smith     t[ii+3] = b[ic+3];
1668f1af5d2fSBarry Smith     t[ii+4] = b[ic+4];
1669f1af5d2fSBarry Smith     t[ii+5] = b[ic+5];
1670f1af5d2fSBarry Smith     ii += 6;
1671f1af5d2fSBarry Smith   }
1672f1af5d2fSBarry Smith 
1673f1af5d2fSBarry Smith   /* forward solve the U^T */
1674f1af5d2fSBarry Smith   idx = 0;
1675f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1676f1af5d2fSBarry Smith 
1677f1af5d2fSBarry Smith     v     = aa + 36*diag[i];
1678f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
1679f1af5d2fSBarry Smith     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
1680f1af5d2fSBarry Smith     x6    = t[5+idx];
1681f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5 +  v[5]*x6;
1682f1af5d2fSBarry Smith     s2 = v[6]*x1  +  v[7]*x2 +  v[8]*x3 +  v[9]*x4 + v[10]*x5 + v[11]*x6;
1683f1af5d2fSBarry Smith     s3 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4 + v[16]*x5 + v[17]*x6;
1684f1af5d2fSBarry Smith     s4 = v[18]*x1 + v[19]*x2 + v[20]*x3 + v[21]*x4 + v[22]*x5 + v[23]*x6;
1685f1af5d2fSBarry Smith     s5 = v[24]*x1 + v[25]*x2 + v[26]*x3 + v[27]*x4 + v[28]*x5 + v[29]*x6;
1686f1af5d2fSBarry Smith     s6 = v[30]*x1 + v[31]*x2 + v[32]*x3 + v[33]*x4 + v[34]*x5 + v[35]*x6;
1687f1af5d2fSBarry Smith     v += 36;
1688f1af5d2fSBarry Smith 
1689f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
1690f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
1691f1af5d2fSBarry Smith     while (nz--) {
1692f1af5d2fSBarry Smith       oidx = 6*(*vi++);
1693f1af5d2fSBarry Smith       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6;
1694f1af5d2fSBarry Smith       t[oidx+1] -= v[6]*s1  +  v[7]*s2 +  v[8]*s3 +  v[9]*s4 + v[10]*s5 + v[11]*s6;
1695f1af5d2fSBarry Smith       t[oidx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6;
1696f1af5d2fSBarry Smith       t[oidx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6;
1697f1af5d2fSBarry Smith       t[oidx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6;
1698f1af5d2fSBarry Smith       t[oidx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6;
1699f1af5d2fSBarry Smith       v  += 36;
1700f1af5d2fSBarry Smith     }
1701f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2; t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
1702f1af5d2fSBarry Smith     t[5+idx] = s6;
1703f1af5d2fSBarry Smith     idx += 6;
1704f1af5d2fSBarry Smith   }
1705f1af5d2fSBarry Smith   /* backward solve the L^T */
1706f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
1707f1af5d2fSBarry Smith     v    = aa + 36*diag[i] - 36;
1708f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
1709f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
1710f1af5d2fSBarry Smith     idt  = 6*i;
1711f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt]; s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
1712f1af5d2fSBarry Smith     s6 = t[5+idt];
1713f1af5d2fSBarry Smith     while (nz--) {
1714f1af5d2fSBarry Smith       idx   = 6*(*vi--);
1715f1af5d2fSBarry Smith       t[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6;
1716f1af5d2fSBarry Smith       t[idx+1] -=  v[6]*s1 +  v[7]*s2 +  v[8]*s3 +  v[9]*s4 + v[10]*s5 + v[11]*s6;
1717f1af5d2fSBarry Smith       t[idx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6;
1718f1af5d2fSBarry Smith       t[idx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6;
1719f1af5d2fSBarry Smith       t[idx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6;
1720f1af5d2fSBarry Smith       t[idx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6;
1721f1af5d2fSBarry Smith       v -= 36;
1722f1af5d2fSBarry Smith     }
1723f1af5d2fSBarry Smith   }
1724f1af5d2fSBarry Smith 
1725f1af5d2fSBarry Smith   /* copy t into x according to permutation */
1726f1af5d2fSBarry Smith   ii = 0;
1727f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1728f1af5d2fSBarry Smith     ir      = 6*r[i];
1729f1af5d2fSBarry Smith     x[ir]   = t[ii];
1730f1af5d2fSBarry Smith     x[ir+1] = t[ii+1];
1731f1af5d2fSBarry Smith     x[ir+2] = t[ii+2];
1732f1af5d2fSBarry Smith     x[ir+3] = t[ii+3];
1733f1af5d2fSBarry Smith     x[ir+4] = t[ii+4];
1734f1af5d2fSBarry Smith     x[ir+5] = t[ii+5];
1735f1af5d2fSBarry Smith     ii += 6;
1736f1af5d2fSBarry Smith   }
1737f1af5d2fSBarry Smith 
1738f1af5d2fSBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
1739f1af5d2fSBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1740b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
17411ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
1742dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
1743f1af5d2fSBarry Smith   PetscFunctionReturn(0);
1744f1af5d2fSBarry Smith }
1745f1af5d2fSBarry Smith 
17464a2ae208SSatish Balay #undef __FUNCT__
17474dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_6"
17484dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_6(Mat A,Vec bb,Vec xx)
174932121132SShri Abhyankar {
175032121132SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
175132121132SShri Abhyankar   PetscErrorCode    ierr;
175232121132SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
1753b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
175432121132SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
175532121132SShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx,ii,ic,ir;
1756b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1757b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1758b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*x,*t;
1759b3260449SShri Abhyankar   const PetscScalar *b;
176032121132SShri Abhyankar 
176132121132SShri Abhyankar   PetscFunctionBegin;
1762b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
176332121132SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
176432121132SShri Abhyankar   t = a->solve_work;
176532121132SShri Abhyankar 
176632121132SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
176732121132SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
176832121132SShri Abhyankar 
176932121132SShri Abhyankar   /* copy b into temp work space according to permutation */
177032121132SShri Abhyankar   for(i=0;i<n;i++){
177132121132SShri Abhyankar     ii = bs*i; ic = bs*c[i];
177232121132SShri Abhyankar     t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; t[ii+3] = b[ic+3];
177332121132SShri Abhyankar     t[ii+4] = b[ic+4];  t[ii+5] = b[ic+5];
177432121132SShri Abhyankar   }
177532121132SShri Abhyankar 
177632121132SShri Abhyankar   /* forward solve the U^T */
177732121132SShri Abhyankar   idx = 0;
177832121132SShri Abhyankar   for (i=0; i<n; i++) {
177932121132SShri Abhyankar     v     = aa + bs2*diag[i];
178032121132SShri Abhyankar     /* multiply by the inverse of the block diagonal */
178132121132SShri Abhyankar     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
178232121132SShri Abhyankar     x6    = t[5+idx];
178332121132SShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5 +  v[5]*x6;
178432121132SShri Abhyankar     s2 = v[6]*x1  +  v[7]*x2 +  v[8]*x3 +  v[9]*x4 + v[10]*x5 + v[11]*x6;
178532121132SShri Abhyankar     s3 = v[12]*x1 + v[13]*x2 + v[14]*x3 + v[15]*x4 + v[16]*x5 + v[17]*x6;
178632121132SShri Abhyankar     s4 = v[18]*x1 + v[19]*x2 + v[20]*x3 + v[21]*x4 + v[22]*x5 + v[23]*x6;
178732121132SShri Abhyankar     s5 = v[24]*x1 + v[25]*x2 + v[26]*x3 + v[27]*x4 + v[28]*x5 + v[29]*x6;
178832121132SShri Abhyankar     s6 = v[30]*x1 + v[31]*x2 + v[32]*x3 + v[33]*x4 + v[34]*x5 + v[35]*x6;
178932121132SShri Abhyankar     v -= bs2;
179032121132SShri Abhyankar 
179132121132SShri Abhyankar     vi    = aj + diag[i] - 1;
179232121132SShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
179332121132SShri Abhyankar     for(j=0;j>-nz;j--){
179432121132SShri Abhyankar       oidx = bs*vi[j];
179532121132SShri Abhyankar       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6;
179632121132SShri Abhyankar       t[oidx+1] -= v[6]*s1  +  v[7]*s2 +  v[8]*s3 +  v[9]*s4 + v[10]*s5 + v[11]*s6;
179732121132SShri Abhyankar       t[oidx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6;
179832121132SShri Abhyankar       t[oidx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6;
179932121132SShri Abhyankar       t[oidx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6;
180032121132SShri Abhyankar       t[oidx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6;
180132121132SShri Abhyankar       v  -= bs2;
180232121132SShri Abhyankar     }
180332121132SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;  t[2+idx] = s3;  t[3+idx] = s4; t[4+idx] =s5;
180432121132SShri Abhyankar     t[5+idx] = s6;
180532121132SShri Abhyankar     idx += bs;
180632121132SShri Abhyankar   }
180732121132SShri Abhyankar   /* backward solve the L^T */
180832121132SShri Abhyankar   for (i=n-1; i>=0; i--){
180932121132SShri Abhyankar     v    = aa + bs2*ai[i];
181032121132SShri Abhyankar     vi   = aj + ai[i];
181132121132SShri Abhyankar     nz   = ai[i+1] - ai[i];
181232121132SShri Abhyankar     idt  = bs*i;
181332121132SShri Abhyankar     s1   = t[idt];  s2 = t[1+idt];  s3 = t[2+idt];  s4 = t[3+idt]; s5 = t[4+idt];
181432121132SShri Abhyankar     s6   = t[5+idt];
181532121132SShri Abhyankar    for(j=0;j<nz;j++){
181632121132SShri Abhyankar       idx   = bs*vi[j];
181732121132SShri Abhyankar       t[idx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6;
181832121132SShri Abhyankar       t[idx+1] -= v[6]*s1  +  v[7]*s2 +  v[8]*s3 +  v[9]*s4 + v[10]*s5 + v[11]*s6;
181932121132SShri Abhyankar       t[idx+2] -= v[12]*s1 + v[13]*s2 + v[14]*s3 + v[15]*s4 + v[16]*s5 + v[17]*s6;
182032121132SShri Abhyankar       t[idx+3] -= v[18]*s1 + v[19]*s2 + v[20]*s3 + v[21]*s4 + v[22]*s5 + v[23]*s6;
182132121132SShri Abhyankar       t[idx+4] -= v[24]*s1 + v[25]*s2 + v[26]*s3 + v[27]*s4 + v[28]*s5 + v[29]*s6;
182232121132SShri Abhyankar       t[idx+5] -= v[30]*s1 + v[31]*s2 + v[32]*s3 + v[33]*s4 + v[34]*s5 + v[35]*s6;
182332121132SShri Abhyankar       v += bs2;
182432121132SShri Abhyankar     }
182532121132SShri Abhyankar   }
182632121132SShri Abhyankar 
182732121132SShri Abhyankar   /* copy t into x according to permutation */
182832121132SShri Abhyankar   for(i=0;i<n;i++){
182932121132SShri Abhyankar     ii = bs*i;  ir = bs*r[i];
183032121132SShri Abhyankar     x[ir] = t[ii];  x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2];  x[ir+3] = t[ii+3];
183132121132SShri Abhyankar     x[ir+4] = t[ii+4];  x[ir+5] = t[ii+5];
183232121132SShri Abhyankar   }
183332121132SShri Abhyankar 
183432121132SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
183532121132SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1836b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
183732121132SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
183832121132SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
183932121132SShri Abhyankar   PetscFunctionReturn(0);
184032121132SShri Abhyankar }
184132121132SShri Abhyankar 
184232121132SShri Abhyankar #undef __FUNCT__
184306e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_7_inplace"
184406e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_7_inplace(Mat A,Vec bb,Vec xx)
1845f1af5d2fSBarry Smith {
1846f1af5d2fSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
1847f1af5d2fSBarry Smith   IS                iscol=a->col,isrow=a->row;
18486849ba73SBarry Smith   PetscErrorCode    ierr;
18495d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
1850b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
1851b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,ii,ic,ir,oidx;
1852b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1853b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t;
1854b3260449SShri Abhyankar   const PetscScalar *b;
1855f1af5d2fSBarry Smith 
1856f1af5d2fSBarry Smith   PetscFunctionBegin;
1857b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
18581ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
1859f1af5d2fSBarry Smith   t  = a->solve_work;
1860f1af5d2fSBarry Smith 
1861f1af5d2fSBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
1862f1af5d2fSBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
1863f1af5d2fSBarry Smith 
1864f1af5d2fSBarry Smith   /* copy the b into temp work space according to permutation */
1865f1af5d2fSBarry Smith   ii = 0;
1866f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1867f1af5d2fSBarry Smith     ic      = 7*c[i];
1868f1af5d2fSBarry Smith     t[ii]   = b[ic];
1869f1af5d2fSBarry Smith     t[ii+1] = b[ic+1];
1870f1af5d2fSBarry Smith     t[ii+2] = b[ic+2];
1871f1af5d2fSBarry Smith     t[ii+3] = b[ic+3];
1872f1af5d2fSBarry Smith     t[ii+4] = b[ic+4];
1873f1af5d2fSBarry Smith     t[ii+5] = b[ic+5];
1874f1af5d2fSBarry Smith     t[ii+6] = b[ic+6];
1875f1af5d2fSBarry Smith     ii += 7;
1876f1af5d2fSBarry Smith   }
1877f1af5d2fSBarry Smith 
1878f1af5d2fSBarry Smith   /* forward solve the U^T */
1879f1af5d2fSBarry Smith   idx = 0;
1880f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1881f1af5d2fSBarry Smith 
1882f1af5d2fSBarry Smith     v     = aa + 49*diag[i];
1883f1af5d2fSBarry Smith     /* multiply by the inverse of the block diagonal */
1884f1af5d2fSBarry Smith     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
1885f1af5d2fSBarry Smith     x6    = t[5+idx]; x7 = t[6+idx];
1886f1af5d2fSBarry Smith     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5 +  v[5]*x6 +  v[6]*x7;
1887f1af5d2fSBarry Smith     s2 = v[7]*x1  +  v[8]*x2 +  v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7;
1888f1af5d2fSBarry Smith     s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7;
1889f1af5d2fSBarry Smith     s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7;
1890f1af5d2fSBarry Smith     s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7;
1891f1af5d2fSBarry Smith     s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7;
1892f1af5d2fSBarry Smith     s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7;
1893f1af5d2fSBarry Smith     v += 49;
1894f1af5d2fSBarry Smith 
1895f1af5d2fSBarry Smith     vi    = aj + diag[i] + 1;
1896f1af5d2fSBarry Smith     nz    = ai[i+1] - diag[i] - 1;
1897f1af5d2fSBarry Smith     while (nz--) {
1898f1af5d2fSBarry Smith       oidx = 7*(*vi++);
1899f1af5d2fSBarry Smith       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6 +  v[6]*s7;
1900f1af5d2fSBarry Smith       t[oidx+1] -= v[7]*s1  +  v[8]*s2 +  v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7;
1901f1af5d2fSBarry Smith       t[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7;
1902f1af5d2fSBarry Smith       t[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7;
1903f1af5d2fSBarry Smith       t[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7;
1904f1af5d2fSBarry Smith       t[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7;
1905f1af5d2fSBarry Smith       t[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7;
1906f1af5d2fSBarry Smith       v  += 49;
1907f1af5d2fSBarry Smith     }
1908f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2; t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
1909f1af5d2fSBarry Smith     t[5+idx] = s6;t[6+idx] = s7;
1910f1af5d2fSBarry Smith     idx += 7;
1911f1af5d2fSBarry Smith   }
1912f1af5d2fSBarry Smith   /* backward solve the L^T */
1913f1af5d2fSBarry Smith   for (i=n-1; i>=0; i--){
1914f1af5d2fSBarry Smith     v    = aa + 49*diag[i] - 49;
1915f1af5d2fSBarry Smith     vi   = aj + diag[i] - 1;
1916f1af5d2fSBarry Smith     nz   = diag[i] - ai[i];
1917f1af5d2fSBarry Smith     idt  = 7*i;
1918f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt]; s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
1919f1af5d2fSBarry Smith     s6 = t[5+idt];s7 = t[6+idt];
1920f1af5d2fSBarry Smith     while (nz--) {
1921f1af5d2fSBarry Smith       idx   = 7*(*vi--);
1922f1af5d2fSBarry Smith       t[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6 +  v[6]*s7;
1923f1af5d2fSBarry Smith       t[idx+1] -=  v[7]*s1 +  v[8]*s2 +  v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7;
1924f1af5d2fSBarry Smith       t[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7;
1925f1af5d2fSBarry Smith       t[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7;
1926f1af5d2fSBarry Smith       t[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7;
1927f1af5d2fSBarry Smith       t[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7;
1928f1af5d2fSBarry Smith       t[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7;
1929f1af5d2fSBarry Smith       v -= 49;
1930f1af5d2fSBarry Smith     }
1931f1af5d2fSBarry Smith   }
1932f1af5d2fSBarry Smith 
1933f1af5d2fSBarry Smith   /* copy t into x according to permutation */
1934f1af5d2fSBarry Smith   ii = 0;
1935f1af5d2fSBarry Smith   for (i=0; i<n; i++) {
1936f1af5d2fSBarry Smith     ir      = 7*r[i];
1937f1af5d2fSBarry Smith     x[ir]   = t[ii];
1938f1af5d2fSBarry Smith     x[ir+1] = t[ii+1];
1939f1af5d2fSBarry Smith     x[ir+2] = t[ii+2];
1940f1af5d2fSBarry Smith     x[ir+3] = t[ii+3];
1941f1af5d2fSBarry Smith     x[ir+4] = t[ii+4];
1942f1af5d2fSBarry Smith     x[ir+5] = t[ii+5];
1943f1af5d2fSBarry Smith     x[ir+6] = t[ii+6];
1944f1af5d2fSBarry Smith     ii += 7;
1945f1af5d2fSBarry Smith   }
1946f1af5d2fSBarry Smith 
1947f1af5d2fSBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
1948f1af5d2fSBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
1949b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
19501ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
1951dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr);
1952f1af5d2fSBarry Smith   PetscFunctionReturn(0);
1953f1af5d2fSBarry Smith }
195432121132SShri Abhyankar #undef __FUNCT__
19554dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_7"
19564dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_7(Mat A,Vec bb,Vec xx)
195732121132SShri Abhyankar {
195832121132SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
195932121132SShri Abhyankar   PetscErrorCode    ierr;
196032121132SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
1961b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
196232121132SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
196332121132SShri Abhyankar   PetscInt          nz,idx,idt,j,i,oidx,ii,ic,ir;
1964b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
1965b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
1966b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t;
1967b3260449SShri Abhyankar   const PetscScalar *b;
196832121132SShri Abhyankar 
196932121132SShri Abhyankar   PetscFunctionBegin;
1970b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
197132121132SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
197232121132SShri Abhyankar   t = a->solve_work;
197332121132SShri Abhyankar 
197432121132SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
197532121132SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
197632121132SShri Abhyankar 
197732121132SShri Abhyankar   /* copy b into temp work space according to permutation */
197832121132SShri Abhyankar   for(i=0;i<n;i++){
197932121132SShri Abhyankar     ii = bs*i; ic = bs*c[i];
198032121132SShri Abhyankar     t[ii] = b[ic]; t[ii+1] = b[ic+1]; t[ii+2] = b[ic+2]; t[ii+3] = b[ic+3];
198132121132SShri Abhyankar     t[ii+4] = b[ic+4];  t[ii+5] = b[ic+5];  t[ii+6] = b[ic+6];
198232121132SShri Abhyankar   }
198332121132SShri Abhyankar 
198432121132SShri Abhyankar   /* forward solve the U^T */
198532121132SShri Abhyankar   idx = 0;
198632121132SShri Abhyankar   for (i=0; i<n; i++) {
198732121132SShri Abhyankar     v     = aa + bs2*diag[i];
198832121132SShri Abhyankar     /* multiply by the inverse of the block diagonal */
198932121132SShri Abhyankar     x1    = t[idx];   x2 = t[1+idx]; x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
199032121132SShri Abhyankar     x6    = t[5+idx]; x7 = t[6+idx];
199132121132SShri Abhyankar     s1 = v[0]*x1  +  v[1]*x2 +  v[2]*x3 +  v[3]*x4 +  v[4]*x5 +  v[5]*x6 +  v[6]*x7;
199232121132SShri Abhyankar     s2 = v[7]*x1  +  v[8]*x2 +  v[9]*x3 + v[10]*x4 + v[11]*x5 + v[12]*x6 + v[13]*x7;
199332121132SShri Abhyankar     s3 = v[14]*x1 + v[15]*x2 + v[16]*x3 + v[17]*x4 + v[18]*x5 + v[19]*x6 + v[20]*x7;
199432121132SShri Abhyankar     s4 = v[21]*x1 + v[22]*x2 + v[23]*x3 + v[24]*x4 + v[25]*x5 + v[26]*x6 + v[27]*x7;
199532121132SShri Abhyankar     s5 = v[28]*x1 + v[29]*x2 + v[30]*x3 + v[31]*x4 + v[32]*x5 + v[33]*x6 + v[34]*x7;
199632121132SShri Abhyankar     s6 = v[35]*x1 + v[36]*x2 + v[37]*x3 + v[38]*x4 + v[39]*x5 + v[40]*x6 + v[41]*x7;
199732121132SShri Abhyankar     s7 = v[42]*x1 + v[43]*x2 + v[44]*x3 + v[45]*x4 + v[46]*x5 + v[47]*x6 + v[48]*x7;
199832121132SShri Abhyankar     v -= bs2;
199932121132SShri Abhyankar 
200032121132SShri Abhyankar     vi    = aj + diag[i] - 1;
200132121132SShri Abhyankar     nz    = diag[i] - diag[i+1] - 1;
200232121132SShri Abhyankar     for(j=0;j>-nz;j--){
200332121132SShri Abhyankar       oidx = bs*vi[j];
200432121132SShri Abhyankar       t[oidx]   -= v[0]*s1  +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6 +  v[6]*s7;
200532121132SShri Abhyankar       t[oidx+1] -= v[7]*s1  +  v[8]*s2 +  v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7;
200632121132SShri Abhyankar       t[oidx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7;
200732121132SShri Abhyankar       t[oidx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7;
200832121132SShri Abhyankar       t[oidx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7;
200932121132SShri Abhyankar       t[oidx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7;
201032121132SShri Abhyankar       t[oidx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7;
201132121132SShri Abhyankar       v  -= bs2;
201232121132SShri Abhyankar     }
201332121132SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;  t[2+idx] = s3;  t[3+idx] = s4; t[4+idx] =s5;
201432121132SShri Abhyankar     t[5+idx] = s6;  t[6+idx] = s7;
201532121132SShri Abhyankar     idx += bs;
201632121132SShri Abhyankar   }
201732121132SShri Abhyankar   /* backward solve the L^T */
201832121132SShri Abhyankar   for (i=n-1; i>=0; i--){
201932121132SShri Abhyankar     v    = aa + bs2*ai[i];
202032121132SShri Abhyankar     vi   = aj + ai[i];
202132121132SShri Abhyankar     nz   = ai[i+1] - ai[i];
202232121132SShri Abhyankar     idt  = bs*i;
202332121132SShri Abhyankar     s1   = t[idt];  s2 = t[1+idt];  s3 = t[2+idt];  s4 = t[3+idt]; s5 = t[4+idt];
202432121132SShri Abhyankar     s6   = t[5+idt];  s7 = t[6+idt];
202532121132SShri Abhyankar    for(j=0;j<nz;j++){
202632121132SShri Abhyankar       idx   = bs*vi[j];
202732121132SShri Abhyankar       t[idx]   -=  v[0]*s1 +  v[1]*s2 +  v[2]*s3 +  v[3]*s4 +  v[4]*s5 +  v[5]*s6 +  v[6]*s7;
202832121132SShri Abhyankar       t[idx+1] -=  v[7]*s1 +  v[8]*s2 +  v[9]*s3 + v[10]*s4 + v[11]*s5 + v[12]*s6 + v[13]*s7;
202932121132SShri Abhyankar       t[idx+2] -= v[14]*s1 + v[15]*s2 + v[16]*s3 + v[17]*s4 + v[18]*s5 + v[19]*s6 + v[20]*s7;
203032121132SShri Abhyankar       t[idx+3] -= v[21]*s1 + v[22]*s2 + v[23]*s3 + v[24]*s4 + v[25]*s5 + v[26]*s6 + v[27]*s7;
203132121132SShri Abhyankar       t[idx+4] -= v[28]*s1 + v[29]*s2 + v[30]*s3 + v[31]*s4 + v[32]*s5 + v[33]*s6 + v[34]*s7;
203232121132SShri Abhyankar       t[idx+5] -= v[35]*s1 + v[36]*s2 + v[37]*s3 + v[38]*s4 + v[39]*s5 + v[40]*s6 + v[41]*s7;
203332121132SShri Abhyankar       t[idx+6] -= v[42]*s1 + v[43]*s2 + v[44]*s3 + v[45]*s4 + v[46]*s5 + v[47]*s6 + v[48]*s7;
203432121132SShri Abhyankar       v += bs2;
203532121132SShri Abhyankar     }
203632121132SShri Abhyankar   }
203732121132SShri Abhyankar 
203832121132SShri Abhyankar   /* copy t into x according to permutation */
203932121132SShri Abhyankar   for(i=0;i<n;i++){
204032121132SShri Abhyankar     ii = bs*i;  ir = bs*r[i];
204132121132SShri Abhyankar     x[ir] = t[ii];  x[ir+1] = t[ii+1]; x[ir+2] = t[ii+2];  x[ir+3] = t[ii+3];
204232121132SShri Abhyankar     x[ir+4] = t[ii+4];  x[ir+5] = t[ii+5];  x[ir+6] = t[ii+6];
204332121132SShri Abhyankar   }
204432121132SShri Abhyankar 
204532121132SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
204632121132SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
2047b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
204832121132SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
204932121132SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
205032121132SShri Abhyankar   PetscFunctionReturn(0);
205132121132SShri Abhyankar }
2052f1af5d2fSBarry Smith 
20534e2b4712SSatish Balay /* ----------------------------------------------------------- */
20544a2ae208SSatish Balay #undef __FUNCT__
205506e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_N_inplace"
205606e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_N_inplace(Mat A,Vec bb,Vec xx)
20574e2b4712SSatish Balay {
20584e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
20594e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
20606849ba73SBarry Smith   PetscErrorCode    ierr;
2061b3260449SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
2062b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*vi;
2063b3260449SShri Abhyankar   PetscInt          i,nz;
2064b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
2065b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
2066b3260449SShri Abhyankar   PetscScalar       *x,*s,*t,*ls;
2067b3260449SShri Abhyankar   const PetscScalar *b;
20684e2b4712SSatish Balay 
20694e2b4712SSatish Balay   PetscFunctionBegin;
2070b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
20711ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
2072f1af5d2fSBarry Smith   t  = a->solve_work;
20734e2b4712SSatish Balay 
20744e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
20754e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
20764e2b4712SSatish Balay 
20774e2b4712SSatish Balay   /* forward solve the lower triangular */
207887828ca2SBarry Smith   ierr = PetscMemcpy(t,b+bs*(*r++),bs*sizeof(PetscScalar));CHKERRQ(ierr);
20794e2b4712SSatish Balay   for (i=1; i<n; i++) {
20804e2b4712SSatish Balay     v   = aa + bs2*ai[i];
20814e2b4712SSatish Balay     vi  = aj + ai[i];
20824e2b4712SSatish Balay     nz  = a->diag[i] - ai[i];
2083f1af5d2fSBarry Smith     s = t + bs*i;
208487828ca2SBarry Smith     ierr = PetscMemcpy(s,b+bs*(*r++),bs*sizeof(PetscScalar));CHKERRQ(ierr);
20854e2b4712SSatish Balay     while (nz--) {
2086f1af5d2fSBarry Smith       Kernel_v_gets_v_minus_A_times_w(bs,s,v,t+bs*(*vi++));
20874e2b4712SSatish Balay       v += bs2;
20884e2b4712SSatish Balay     }
20894e2b4712SSatish Balay   }
20904e2b4712SSatish Balay   /* backward solve the upper triangular */
2091d0f46423SBarry Smith   ls = a->solve_work + A->cmap->n;
20924e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
20934e2b4712SSatish Balay     v   = aa + bs2*(a->diag[i] + 1);
20944e2b4712SSatish Balay     vi  = aj + a->diag[i] + 1;
20954e2b4712SSatish Balay     nz  = ai[i+1] - a->diag[i] - 1;
209687828ca2SBarry Smith     ierr = PetscMemcpy(ls,t+i*bs,bs*sizeof(PetscScalar));CHKERRQ(ierr);
20974e2b4712SSatish Balay     while (nz--) {
2098f1af5d2fSBarry Smith       Kernel_v_gets_v_minus_A_times_w(bs,ls,v,t+bs*(*vi++));
20994e2b4712SSatish Balay       v += bs2;
21004e2b4712SSatish Balay     }
2101f1af5d2fSBarry Smith     Kernel_w_gets_A_times_v(bs,ls,aa+bs2*a->diag[i],t+i*bs);
210287828ca2SBarry Smith     ierr = PetscMemcpy(x + bs*(*c--),t+i*bs,bs*sizeof(PetscScalar));CHKERRQ(ierr);
21034e2b4712SSatish Balay   }
21044e2b4712SSatish Balay 
21054e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
21064e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
2107b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
21081ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
2109dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*(a->bs2)*(a->nz) - A->rmap->bs*A->cmap->n);CHKERRQ(ierr);
21104e2b4712SSatish Balay   PetscFunctionReturn(0);
21114e2b4712SSatish Balay }
21124e2b4712SSatish Balay 
21135c42ef9dSBarry Smith /* ----------------------------------------------------------- */
21145c42ef9dSBarry Smith #undef __FUNCT__
211506e38f1dSHong Zhang #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_N_inplace"
211606e38f1dSHong Zhang PetscErrorCode MatSolveTranspose_SeqBAIJ_N_inplace(Mat A,Vec bb,Vec xx)
21175c42ef9dSBarry Smith {
21185c42ef9dSBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
21195c42ef9dSBarry Smith   IS                iscol=a->col,isrow=a->row;
21205c42ef9dSBarry Smith   PetscErrorCode    ierr;
21215c42ef9dSBarry Smith   const PetscInt    *r,*c,*rout,*cout,*ai=a->i,*aj=a->j,*vi;
2122b3260449SShri Abhyankar   PetscInt          i,nz,j;
2123b3260449SShri Abhyankar   const PetscInt    n=a->mbs,bs=A->rmap->bs,bs2=a->bs2;
21245c42ef9dSBarry Smith   const MatScalar   *aa=a->a,*v;
21255c42ef9dSBarry Smith   PetscScalar       *x,*t,*ls;
21265c42ef9dSBarry Smith   const PetscScalar *b;
21275c42ef9dSBarry Smith   PetscFunctionBegin;
21285c42ef9dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
21295c42ef9dSBarry Smith   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
21305c42ef9dSBarry Smith   t    = a->solve_work;
21315c42ef9dSBarry Smith 
21325c42ef9dSBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
21335c42ef9dSBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
21345c42ef9dSBarry Smith 
21355c42ef9dSBarry Smith   /* copy the b into temp work space according to permutation */
21365c42ef9dSBarry Smith   for (i=0; i<n; i++) {
21375c42ef9dSBarry Smith     for (j=0; j<bs; j++) {
21385c42ef9dSBarry Smith       t[i*bs+j] = b[c[i]*bs+j];
21395c42ef9dSBarry Smith     }
21405c42ef9dSBarry Smith   }
21415c42ef9dSBarry Smith 
21425c42ef9dSBarry Smith 
21435c42ef9dSBarry Smith   /* forward solve the upper triangular transpose */
21445c42ef9dSBarry Smith   ls = a->solve_work + A->cmap->n;
21455c42ef9dSBarry Smith   for (i=0; i<n; i++){
21465c42ef9dSBarry Smith     ierr = PetscMemcpy(ls,t+i*bs,bs*sizeof(PetscScalar));CHKERRQ(ierr);
21475c42ef9dSBarry Smith     Kernel_w_gets_transA_times_v(bs,ls,aa+bs2*a->diag[i],t+i*bs);
21485c42ef9dSBarry Smith     v   = aa + bs2*(a->diag[i] + 1);
21495c42ef9dSBarry Smith     vi  = aj + a->diag[i] + 1;
21505c42ef9dSBarry Smith     nz  = ai[i+1] - a->diag[i] - 1;
21515c42ef9dSBarry Smith     while (nz--) {
21525c42ef9dSBarry Smith       Kernel_v_gets_v_minus_transA_times_w(bs,t+bs*(*vi++),v,t+i*bs);
21535c42ef9dSBarry Smith       v += bs2;
21545c42ef9dSBarry Smith     }
21555c42ef9dSBarry Smith   }
21565c42ef9dSBarry Smith 
21575c42ef9dSBarry Smith   /* backward solve the lower triangular transpose */
21585c42ef9dSBarry Smith   for (i=n-1; i>=0; i--) {
21595c42ef9dSBarry Smith     v   = aa + bs2*ai[i];
21605c42ef9dSBarry Smith     vi  = aj + ai[i];
21615c42ef9dSBarry Smith     nz  = a->diag[i] - ai[i];
21625c42ef9dSBarry Smith     while (nz--) {
21635c42ef9dSBarry Smith       Kernel_v_gets_v_minus_transA_times_w(bs,t+bs*(*vi++),v,t+i*bs);
21645c42ef9dSBarry Smith       v += bs2;
21655c42ef9dSBarry Smith     }
21665c42ef9dSBarry Smith   }
21675c42ef9dSBarry Smith 
21685c42ef9dSBarry Smith   /* copy t into x according to permutation */
21695c42ef9dSBarry Smith   for (i=0; i<n; i++) {
21705c42ef9dSBarry Smith     for (j=0; j<bs; j++) {
21715c42ef9dSBarry Smith       x[bs*r[i]+j]   = t[bs*i+j];
21725c42ef9dSBarry Smith     }
21735c42ef9dSBarry Smith   }
21745c42ef9dSBarry Smith 
21755c42ef9dSBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
21765c42ef9dSBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
21775c42ef9dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
21785c42ef9dSBarry Smith   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
21795c42ef9dSBarry Smith   ierr = PetscLogFlops(2.0*(a->bs2)*(a->nz) - A->rmap->bs*A->cmap->n);CHKERRQ(ierr);
21805c42ef9dSBarry Smith   PetscFunctionReturn(0);
21815c42ef9dSBarry Smith }
21825c42ef9dSBarry Smith 
21834a2ae208SSatish Balay #undef __FUNCT__
21844dd39f65SShri Abhyankar #define __FUNCT__ "MatSolveTranspose_SeqBAIJ_N"
21854dd39f65SShri Abhyankar PetscErrorCode MatSolveTranspose_SeqBAIJ_N(Mat A,Vec bb,Vec xx)
21868499736aSShri Abhyankar {
21878499736aSShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
21888499736aSShri Abhyankar   IS                iscol=a->col,isrow=a->row;
21898499736aSShri Abhyankar   PetscErrorCode    ierr;
2190b3260449SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
2191b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*vi,*diag=a->diag;
2192b3260449SShri Abhyankar   PetscInt          i,j,nz;
2193b3260449SShri Abhyankar   const PetscInt    bs=A->rmap->bs,bs2=a->bs2;
21948499736aSShri Abhyankar   const MatScalar   *aa=a->a,*v;
21958499736aSShri Abhyankar   PetscScalar       *x,*t,*ls;
21968499736aSShri Abhyankar   const PetscScalar *b;
2197b3260449SShri Abhyankar 
21988499736aSShri Abhyankar   PetscFunctionBegin;
21998499736aSShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
22008499736aSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
22018499736aSShri Abhyankar   t    = a->solve_work;
22028499736aSShri Abhyankar 
22038499736aSShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
22048499736aSShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
22058499736aSShri Abhyankar 
22068499736aSShri Abhyankar   /* copy the b into temp work space according to permutation */
22078499736aSShri Abhyankar   for (i=0; i<n; i++) {
22088499736aSShri Abhyankar     for (j=0; j<bs; j++) {
22098499736aSShri Abhyankar       t[i*bs+j] = b[c[i]*bs+j];
22108499736aSShri Abhyankar     }
22118499736aSShri Abhyankar   }
22128499736aSShri Abhyankar 
22138499736aSShri Abhyankar 
22148499736aSShri Abhyankar   /* forward solve the upper triangular transpose */
22158499736aSShri Abhyankar   ls = a->solve_work + A->cmap->n;
22168499736aSShri Abhyankar   for (i=0; i<n; i++){
22178499736aSShri Abhyankar     ierr = PetscMemcpy(ls,t+i*bs,bs*sizeof(PetscScalar));CHKERRQ(ierr);
22188499736aSShri Abhyankar     Kernel_w_gets_transA_times_v(bs,ls,aa+bs2*diag[i],t+i*bs);
22198499736aSShri Abhyankar     v   = aa + bs2*(diag[i] - 1);
22208499736aSShri Abhyankar     vi  = aj + diag[i] - 1;
22218499736aSShri Abhyankar     nz  = diag[i] - diag[i+1] - 1;
22228499736aSShri Abhyankar     for(j=0;j>-nz;j--){
22238499736aSShri Abhyankar       Kernel_v_gets_v_minus_transA_times_w(bs,t+bs*(vi[j]),v,t+i*bs);
22248499736aSShri Abhyankar       v -= bs2;
22258499736aSShri Abhyankar     }
22268499736aSShri Abhyankar   }
22278499736aSShri Abhyankar 
22288499736aSShri Abhyankar   /* backward solve the lower triangular transpose */
22298499736aSShri Abhyankar   for (i=n-1; i>=0; i--) {
22308499736aSShri Abhyankar     v   = aa + bs2*ai[i];
22318499736aSShri Abhyankar     vi  = aj + ai[i];
22328499736aSShri Abhyankar     nz  = ai[i+1] - ai[i];
22338499736aSShri Abhyankar     for(j=0;j<nz;j++){
22348499736aSShri Abhyankar       Kernel_v_gets_v_minus_transA_times_w(bs,t+bs*(vi[j]),v,t+i*bs);
22358499736aSShri Abhyankar       v += bs2;
22368499736aSShri Abhyankar     }
22378499736aSShri Abhyankar   }
22388499736aSShri Abhyankar 
22398499736aSShri Abhyankar   /* copy t into x according to permutation */
22408499736aSShri Abhyankar   for (i=0; i<n; i++) {
22418499736aSShri Abhyankar     for (j=0; j<bs; j++) {
22428499736aSShri Abhyankar       x[bs*r[i]+j]   = t[bs*i+j];
22438499736aSShri Abhyankar     }
22448499736aSShri Abhyankar   }
22458499736aSShri Abhyankar 
22468499736aSShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
22478499736aSShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
22488499736aSShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
22498499736aSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
22508499736aSShri Abhyankar   ierr = PetscLogFlops(2.0*(a->bs2)*(a->nz) - A->rmap->bs*A->cmap->n);CHKERRQ(ierr);
22518499736aSShri Abhyankar   PetscFunctionReturn(0);
22528499736aSShri Abhyankar }
22538499736aSShri Abhyankar 
22542b0b2ea7SShri Abhyankar /* bs = 15 for PFLOTRAN */
225529a97285SShri Abhyankar 
22562b0b2ea7SShri Abhyankar #undef __FUNCT__
225729a97285SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_15_NaturalOrdering"
225829a97285SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_15_NaturalOrdering(Mat A,Vec bb,Vec xx)
22592b0b2ea7SShri Abhyankar {
22602b0b2ea7SShri Abhyankar   Mat_SeqBAIJ      *a=(Mat_SeqBAIJ *)A->data;
22612b0b2ea7SShri Abhyankar   PetscErrorCode    ierr;
2262b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*adiag=a->diag,*vi,bs=A->rmap->bs,bs2=a->bs2;
2263*0fa040f9SShri Abhyankar   PetscInt          i,nz,idx,idt,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;
2267*0fa040f9SShri Abhyankar   PetscScalar       *x;
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 
22742b0b2ea7SShri Abhyankar   /* forward solve the lower triangular */
227529a97285SShri Abhyankar   idx    = 0;
2276*0fa040f9SShri 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];
2277*0fa040f9SShri Abhyankar   x[5]  = b[5+idx];  x[6]  = b[6+idx];  x[7]  = b[7+idx];  x[8]  = b[8+idx];  x[9]  = b[9+idx];
2278*0fa040f9SShri Abhyankar   x[10] = b[10+idx]; x[11] = b[11+idx]; x[12] = b[12+idx]; x[13] = b[13+idx]; x[14] = b[14+idx];
22792b0b2ea7SShri Abhyankar 
22802b0b2ea7SShri Abhyankar   for (i=1; i<n; i++) {
22812b0b2ea7SShri Abhyankar     v     = aa + bs2*ai[i];
22822b0b2ea7SShri Abhyankar     vi    = aj + ai[i];
22832b0b2ea7SShri Abhyankar     nz    = ai[i+1] - ai[i];
2284*0fa040f9SShri Abhyankar     idt   = bs*i;
2285*0fa040f9SShri Abhyankar     s1   = b[idt];    s2  = b[1+idt];  s3  = b[2+idt];  s4  = b[3+idt];  s5  = b[4+idt];
2286*0fa040f9SShri Abhyankar     s6   = b[5+idt];  s7  = b[6+idt];  s8  = b[7+idt];  s9  = b[8+idt];  s10 = b[9+idt];
2287*0fa040f9SShri Abhyankar     s11  = b[10+idt]; s12 = b[11+idt]; s13 = b[12+idt]; s14 = b[13+idt]; s15 = b[14+idt];
22882b0b2ea7SShri Abhyankar     for(m=0;m<nz;m++){
22892b0b2ea7SShri Abhyankar       idx   = bs*vi[m];
2290*0fa040f9SShri Abhyankar       x1   = x[idx];     x2  = x[1+idx];  x3  = x[2+idx];  x4  = x[3+idx];  x5  = x[4+idx];
2291*0fa040f9SShri Abhyankar       x6   = x[5+idx];   x7  = x[6+idx];  x8  = x[7+idx];  x9  = x[8+idx];  x10 = x[9+idx];
2292*0fa040f9SShri Abhyankar       x11  = x[10+idx]; x12  = x[11+idx]; x13 = x[12+idx]; x14 = x[13+idx]; x15 = x[14+idx];
22932b0b2ea7SShri Abhyankar 
22940b8f6341SShri 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     }
2313*0fa040f9SShri Abhyankar     x[idt]    = s1;  x[1+idt]  = s2;  x[2+idt]  = s3;  x[3+idt]  = s4;  x[4+idt]  = s5;
2314*0fa040f9SShri Abhyankar     x[5+idt]  = s6;  x[6+idt]  = s7;  x[7+idt]  = s8;  x[8+idt]  = s9;  x[9+idt]  = s10;
2315*0fa040f9SShri Abhyankar     x[10+idt] = s11; x[11+idt] = s12; x[12+idt] = s13; x[13+idt] = s14; x[14+idt] = s15;
23162b0b2ea7SShri Abhyankar 
23172b0b2ea7SShri Abhyankar   }
23182b0b2ea7SShri Abhyankar   /* backward solve the upper triangular */
23192b0b2ea7SShri Abhyankar   for (i=n-1; i>=0; i--){
23202b0b2ea7SShri Abhyankar     v    = aa + bs2*(adiag[i+1]+1);
23212b0b2ea7SShri Abhyankar     vi   = aj + adiag[i+1]+1;
23222b0b2ea7SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
23232b0b2ea7SShri Abhyankar     idt  = bs*i;
2324*0fa040f9SShri Abhyankar     s1   = x[idt];     s2  = x[1+idt];  s3  = x[2+idt];  s4  = x[3+idt];  s5  = x[4+idt];
2325*0fa040f9SShri Abhyankar     s6   = x[5+idt];   s7  = x[6+idt];  s8  = x[7+idt];  s9  = x[8+idt];  s10 = x[9+idt];
2326*0fa040f9SShri Abhyankar     s11  = x[10+idt]; s12  = x[11+idt]; s13 = x[12+idt]; s14 = x[13+idt]; s15 = x[14+idt];
23272b0b2ea7SShri Abhyankar 
23282b0b2ea7SShri Abhyankar     for(m=0;m<nz;m++){
23292b0b2ea7SShri Abhyankar       idx   = bs*vi[m];
2330*0fa040f9SShri Abhyankar       x1   = x[idx];     x2  = x[1+idx];  x3  = x[2+idx];  x4  = x[3+idx];  x5  = x[4+idx];
2331*0fa040f9SShri Abhyankar       x6   = x[5+idx];   x7  = x[6+idx];  x8  = x[7+idx];  x9  = x[8+idx];  x10 = x[9+idx];
2332*0fa040f9SShri Abhyankar       x11  = x[10+idx]; x12  = x[11+idx]; x13 = x[12+idx]; x14 = x[13+idx]; x15 = x[14+idx];
23332b0b2ea7SShri Abhyankar 
23342b0b2ea7SShri 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;
23352b0b2ea7SShri 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;
23362b0b2ea7SShri 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;
23372b0b2ea7SShri 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;
23382b0b2ea7SShri 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;
23392b0b2ea7SShri 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;
23402b0b2ea7SShri 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;
23412b0b2ea7SShri 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;
23422b0b2ea7SShri 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;
23432b0b2ea7SShri 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;
23442b0b2ea7SShri 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;
23452b0b2ea7SShri 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;
23462b0b2ea7SShri 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;
23472b0b2ea7SShri 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;
23482b0b2ea7SShri 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;
23492b0b2ea7SShri Abhyankar 
23502b0b2ea7SShri Abhyankar       v += bs2;
23512b0b2ea7SShri Abhyankar     }
23522b0b2ea7SShri Abhyankar 
2353*0fa040f9SShri Abhyankar     x[idt] = v[0]*s1  + v[15]*s2 + v[30]*s3 + v[45]*s4 + v[60]*s5 + v[75]*s6 + v[90]*s7  + v[105]*s8 + v[120]*s9 + v[135]*s10 + v[150]*s11 + v[165]*s12 + v[180]*s13 + v[195]*s14 + v[210]*s15;
2354*0fa040f9SShri Abhyankar     x[1+idt] = v[1]*s1  + v[16]*s2 + v[31]*s3 + v[46]*s4 + v[61]*s5 + v[76]*s6 + v[91]*s7  + v[106]*s8 + v[121]*s9 + v[136]*s10 + v[151]*s11 + v[166]*s12 + v[181]*s13 + v[196]*s14 + v[211]*s15;
2355*0fa040f9SShri Abhyankar     x[2+idt] = v[2]*s1  + v[17]*s2 + v[32]*s3 + v[47]*s4 + v[62]*s5 + v[77]*s6 + v[92]*s7  + v[107]*s8 + v[122]*s9 + v[137]*s10 + v[152]*s11 + v[167]*s12 + v[182]*s13 + v[197]*s14 + v[212]*s15;
2356*0fa040f9SShri Abhyankar     x[3+idt] = v[3]*s1  + v[18]*s2 + v[33]*s3 + v[48]*s4 + v[63]*s5 + v[78]*s6 + v[93]*s7  + v[108]*s8 + v[123]*s9 + v[138]*s10 + v[153]*s11 + v[168]*s12 + v[183]*s13 + v[198]*s14 + v[213]*s15;
2357*0fa040f9SShri Abhyankar     x[4+idt] = v[4]*s1  + v[19]*s2 + v[34]*s3 + v[49]*s4 + v[64]*s5 + v[79]*s6 + v[94]*s7  + v[109]*s8 + v[124]*s9 + v[139]*s10 + v[154]*s11 + v[169]*s12 + v[184]*s13 + v[199]*s14 + v[214]*s15;
2358*0fa040f9SShri Abhyankar     x[5+idt] = v[5]*s1  + v[20]*s2 + v[35]*s3 + v[50]*s4 + v[65]*s5 + v[80]*s6 + v[95]*s7  + v[110]*s8 + v[125]*s9 + v[140]*s10 + v[155]*s11 + v[170]*s12 + v[185]*s13 + v[200]*s14 + v[215]*s15;
2359*0fa040f9SShri Abhyankar     x[6+idt] = v[6]*s1  + v[21]*s2 + v[36]*s3 + v[51]*s4 + v[66]*s5 + v[81]*s6 + v[96]*s7  + v[111]*s8 + v[126]*s9 + v[141]*s10 + v[156]*s11 + v[171]*s12 + v[186]*s13 + v[201]*s14 + v[216]*s15;
2360*0fa040f9SShri Abhyankar     x[7+idt] = v[7]*s1  + v[22]*s2 + v[37]*s3 + v[52]*s4 + v[67]*s5 + v[82]*s6 + v[97]*s7  + v[112]*s8 + v[127]*s9 + v[142]*s10 + v[157]*s11 + v[172]*s12 + v[187]*s13 + v[202]*s14 + v[217]*s15;
2361*0fa040f9SShri Abhyankar     x[8+idt] = v[8]*s1  + v[23]*s2 + v[38]*s3 + v[53]*s4 + v[68]*s5 + v[83]*s6 + v[98]*s7  + v[113]*s8 + v[128]*s9 + v[143]*s10 + v[158]*s11 + v[173]*s12 + v[188]*s13 + v[203]*s14 + v[218]*s15;
2362*0fa040f9SShri Abhyankar     x[9+idt] = v[9]*s1  + v[24]*s2 + v[39]*s3 + v[54]*s4 + v[69]*s5 + v[84]*s6 + v[99]*s7  + v[114]*s8 + v[129]*s9 + v[144]*s10 + v[159]*s11 + v[174]*s12 + v[189]*s13 + v[204]*s14 + v[219]*s15;
2363*0fa040f9SShri Abhyankar     x[10+idt] = v[10]*s1 + v[25]*s2 + v[40]*s3 + v[55]*s4 + v[70]*s5 + v[85]*s6 + v[100]*s7 + v[115]*s8 + v[130]*s9 + v[145]*s10 + v[160]*s11 + v[175]*s12 + v[190]*s13 + v[205]*s14 + v[220]*s15;
2364*0fa040f9SShri Abhyankar     x[11+idt] = v[11]*s1 + v[26]*s2 + v[41]*s3 + v[56]*s4 + v[71]*s5 + v[86]*s6 + v[101]*s7 + v[116]*s8 + v[131]*s9 + v[146]*s10 + v[161]*s11 + v[176]*s12 + v[191]*s13 + v[206]*s14 + v[221]*s15;
2365*0fa040f9SShri Abhyankar     x[12+idt] = v[12]*s1 + v[27]*s2 + v[42]*s3 + v[57]*s4 + v[72]*s5 + v[87]*s6 + v[102]*s7 + v[117]*s8 + v[132]*s9 + v[147]*s10 + v[162]*s11 + v[177]*s12 + v[192]*s13 + v[207]*s14 + v[222]*s15;
2366*0fa040f9SShri Abhyankar     x[13+idt] = v[13]*s1 + v[28]*s2 + v[43]*s3 + v[58]*s4 + v[73]*s5 + v[88]*s6 + v[103]*s7 + v[118]*s8 + v[133]*s9 + v[148]*s10 + v[163]*s11 + v[178]*s12 + v[193]*s13 + v[208]*s14 + v[223]*s15;
2367*0fa040f9SShri Abhyankar     x[14+idt] = v[14]*s1 + v[29]*s2 + v[44]*s3 + v[59]*s4 + v[74]*s5 + v[89]*s6 + v[104]*s7 + v[119]*s8 + v[134]*s9 + v[149]*s10 + v[164]*s11 + v[179]*s12 + v[194]*s13 + v[209]*s14 + v[224]*s15;
23682b0b2ea7SShri Abhyankar 
23692b0b2ea7SShri Abhyankar   }
23702b0b2ea7SShri Abhyankar 
23710b68f018SBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
23722b0b2ea7SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
23732b0b2ea7SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
23742b0b2ea7SShri Abhyankar   PetscFunctionReturn(0);
23752b0b2ea7SShri Abhyankar }
23762b0b2ea7SShri Abhyankar 
23778499736aSShri Abhyankar #undef __FUNCT__
23780b8f6341SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_15_NaturalOrdering_ver2"
23790b8f6341SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_15_NaturalOrdering_ver2(Mat A,Vec bb,Vec xx)
23800b8f6341SShri Abhyankar {
23810b8f6341SShri Abhyankar   Mat_SeqBAIJ      *a=(Mat_SeqBAIJ *)A->data;
23820b8f6341SShri Abhyankar   PetscErrorCode    ierr;
23830b8f6341SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*adiag=a->diag,*vi,bs=A->rmap->bs,bs2=a->bs2;
2384*0fa040f9SShri Abhyankar   PetscInt          i,k,nz,kdx,idx,idt,m;
23850b8f6341SShri Abhyankar   const MatScalar   *aa=a->a,*v;
23860b8f6341SShri Abhyankar   PetscScalar       s[15];
2387*0fa040f9SShri Abhyankar   PetscScalar       *x;
23880b8f6341SShri Abhyankar   const PetscScalar *b;
23890b8f6341SShri Abhyankar 
23900b8f6341SShri Abhyankar   PetscFunctionBegin;
23910b8f6341SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
23920b8f6341SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
23930b8f6341SShri Abhyankar 
23940b8f6341SShri Abhyankar   /* forward solve the lower triangular */
23950b8f6341SShri Abhyankar   idx    = 0;
2396*0fa040f9SShri 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];
2397*0fa040f9SShri Abhyankar   x[5]  = b[5+idx];  x[6]  = b[6+idx];  x[7]  = b[7+idx];  x[8]  = b[8+idx];  x[9]  = b[9+idx];
2398*0fa040f9SShri Abhyankar   x[10] = b[10+idx]; x[11] = b[11+idx]; x[12] = b[12+idx]; x[13] = b[13+idx]; x[14] = b[14+idx];
23990b8f6341SShri Abhyankar 
24000b8f6341SShri Abhyankar   for (i=1; i<n; i++) {
24010b8f6341SShri Abhyankar     v     = aa + bs2*ai[i];
24020b8f6341SShri Abhyankar     vi    = aj + ai[i];
24030b8f6341SShri Abhyankar     nz    = ai[i+1] - ai[i];
2404*0fa040f9SShri Abhyankar     idt   = bs*i;
2405*0fa040f9SShri Abhyankar     s[0]   = b[idt];    s[1]  = b[1+idt];  s[2]  = b[2+idt];  s[3]  = b[3+idt];  s[4]  = b[4+idt];
2406*0fa040f9SShri Abhyankar     s[5]   = b[5+idt];  s[6]  = b[6+idt];  s[7]  = b[7+idt];  s[8]  = b[8+idt];  s[9] = b[9+idt];
2407*0fa040f9SShri Abhyankar     s[10]  = b[10+idt]; s[11] = b[11+idt]; s[12] = b[12+idt]; s[13] = b[13+idt]; s[14] = b[14+idt];
24080b8f6341SShri Abhyankar     for(m=0;m<nz;m++){
24090b8f6341SShri Abhyankar       idx   = bs*vi[m];
24100b8f6341SShri Abhyankar 
24110b8f6341SShri Abhyankar       for(k=0;k<15;k++){
2412*0fa040f9SShri Abhyankar 	kdx = k + idx;
2413*0fa040f9SShri Abhyankar 	s[0]  -= v[0]*x[kdx];
2414*0fa040f9SShri Abhyankar 	s[1]  -= v[1]*x[kdx];
2415*0fa040f9SShri Abhyankar 	s[2]  -= v[2]*x[kdx];
2416*0fa040f9SShri Abhyankar         s[3]  -= v[3]*x[kdx];
2417*0fa040f9SShri Abhyankar 	s[4]  -= v[4]*x[kdx];
2418*0fa040f9SShri Abhyankar 	s[5]  -= v[5]*x[kdx];
2419*0fa040f9SShri Abhyankar 	s[6]  -= v[6]*x[kdx];
2420*0fa040f9SShri Abhyankar         s[7]  -= v[7]*x[kdx];
2421*0fa040f9SShri Abhyankar 	s[8]  -= v[8]*x[kdx];
2422*0fa040f9SShri Abhyankar 	s[9]  -= v[9]*x[kdx];
2423*0fa040f9SShri Abhyankar 	s[10] -= v[10]*x[kdx];
2424*0fa040f9SShri Abhyankar         s[11] -= v[11]*x[kdx];
2425*0fa040f9SShri Abhyankar 	s[12] -= v[12]*x[kdx];
2426*0fa040f9SShri Abhyankar 	s[13] -= v[13]*x[kdx];
2427*0fa040f9SShri Abhyankar 	s[14] -= v[14]*x[kdx];
24280b8f6341SShri Abhyankar 	v += 15;
24290b8f6341SShri Abhyankar       }
24300b8f6341SShri Abhyankar     }
2431*0fa040f9SShri Abhyankar     x[idt]    = s[0];  x[1+idt]  = s[1];  x[2+idt]  = s[2];  x[3+idt]  = s[3];  x[4+idt]  = s[4];
2432*0fa040f9SShri Abhyankar     x[5+idt]  = s[5];  x[6+idt]  = s[6];  x[7+idt]  = s[7];  x[8+idt]  = s[8];  x[9+idt]  = s[9];
2433*0fa040f9SShri Abhyankar     x[10+idt] = s[10]; x[11+idt] = s[11]; x[12+idt] = s[12]; x[13+idt] = s[13]; x[14+idt] = s[14];
24340b8f6341SShri Abhyankar 
24350b8f6341SShri Abhyankar   }
24360b8f6341SShri Abhyankar   /* backward solve the upper triangular */
24370b8f6341SShri Abhyankar   for (i=n-1; i>=0; i--){
24380b8f6341SShri Abhyankar     v    = aa + bs2*(adiag[i+1]+1);
24390b8f6341SShri Abhyankar     vi   = aj + adiag[i+1]+1;
24400b8f6341SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
24410b8f6341SShri Abhyankar     idt  = bs*i;
2442*0fa040f9SShri Abhyankar     s[0]   = x[idt];    s[1]  = x[1+idt];  s[2]  = x[2+idt];  s[3]  = x[3+idt];  s[4]  = x[4+idt];
2443*0fa040f9SShri Abhyankar     s[5]   = x[5+idt];  s[6]  = x[6+idt];  s[7]  = x[7+idt];  s[8]  = x[8+idt];  s[9]  = x[9+idt];
2444*0fa040f9SShri Abhyankar     s[10]  = x[10+idt]; s[11] = x[11+idt]; s[12] = x[12+idt]; s[13] = x[13+idt]; s[14] = x[14+idt];
24450b8f6341SShri Abhyankar 
24460b8f6341SShri Abhyankar     for(m=0;m<nz;m++){
24470b8f6341SShri Abhyankar       idx   = bs*vi[m];
24480b8f6341SShri Abhyankar       for(k=0;k<15;k++){
2449*0fa040f9SShri Abhyankar 	kdx = k + idx;
2450*0fa040f9SShri Abhyankar 	s[0]  -= v[0]*x[kdx];
2451*0fa040f9SShri Abhyankar 	s[1]  -= v[1]*x[kdx];
2452*0fa040f9SShri Abhyankar 	s[2]  -= v[2]*x[kdx];
2453*0fa040f9SShri Abhyankar         s[3]  -= v[3]*x[kdx];
2454*0fa040f9SShri Abhyankar 	s[4]  -= v[4]*x[kdx];
2455*0fa040f9SShri Abhyankar 	s[5]  -= v[5]*x[kdx];
2456*0fa040f9SShri Abhyankar 	s[6]  -= v[6]*x[kdx];
2457*0fa040f9SShri Abhyankar         s[7]  -= v[7]*x[kdx];
2458*0fa040f9SShri Abhyankar 	s[8]  -= v[8]*x[kdx];
2459*0fa040f9SShri Abhyankar 	s[9]  -= v[9]*x[kdx];
2460*0fa040f9SShri Abhyankar 	s[10] -= v[10]*x[kdx];
2461*0fa040f9SShri Abhyankar         s[11] -= v[11]*x[kdx];
2462*0fa040f9SShri Abhyankar 	s[12] -= v[12]*x[kdx];
2463*0fa040f9SShri Abhyankar 	s[13] -= v[13]*x[kdx];
2464*0fa040f9SShri Abhyankar 	s[14] -= v[14]*x[kdx];
24650b8f6341SShri Abhyankar 	v += 15;
24660b8f6341SShri Abhyankar       }
24670b8f6341SShri Abhyankar     }
2468*0fa040f9SShri Abhyankar     ierr = PetscMemzero(x+idt,bs*sizeof(MatScalar));CHKERRQ(ierr);
24690b8f6341SShri Abhyankar     for(k=0;k<15;k++){
2470*0fa040f9SShri Abhyankar       x[idt]    += v[0]*s[k];
2471*0fa040f9SShri Abhyankar       x[1+idt]  += v[1]*s[k];
2472*0fa040f9SShri Abhyankar       x[2+idt]  += v[2]*s[k];
2473*0fa040f9SShri Abhyankar       x[3+idt]  += v[3]*s[k];
2474*0fa040f9SShri Abhyankar       x[4+idt]  += v[4]*s[k];
2475*0fa040f9SShri Abhyankar       x[5+idt]  += v[5]*s[k];
2476*0fa040f9SShri Abhyankar       x[6+idt]  += v[6]*s[k];
2477*0fa040f9SShri Abhyankar       x[7+idt]  += v[7]*s[k];
2478*0fa040f9SShri Abhyankar       x[8+idt]  += v[8]*s[k];
2479*0fa040f9SShri Abhyankar       x[9+idt]  += v[9]*s[k];
2480*0fa040f9SShri Abhyankar       x[10+idt] += v[10]*s[k];
2481*0fa040f9SShri Abhyankar       x[11+idt] += v[11]*s[k];
2482*0fa040f9SShri Abhyankar       x[12+idt] += v[12]*s[k];
2483*0fa040f9SShri Abhyankar       x[13+idt] += v[13]*s[k];
2484*0fa040f9SShri Abhyankar       x[14+idt] += v[14]*s[k];
24850b8f6341SShri Abhyankar       v += 15;
24860b8f6341SShri Abhyankar     }
24870b8f6341SShri Abhyankar   }
24880b8f6341SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
24890b8f6341SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
24900b8f6341SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
24910b8f6341SShri Abhyankar   PetscFunctionReturn(0);
24920b8f6341SShri Abhyankar }
24930b8f6341SShri Abhyankar 
24940b8f6341SShri Abhyankar 
24950b8f6341SShri Abhyankar #undef __FUNCT__
249606e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_7_inplace"
249706e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_7_inplace(Mat A,Vec bb,Vec xx)
24984e2b4712SSatish Balay {
24994e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
25004e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
25016849ba73SBarry Smith   PetscErrorCode    ierr;
2502b3260449SShri Abhyankar   const PetscInt    *r,*c,*ai=a->i,*aj=a->j;
2503b3260449SShri Abhyankar   const PetscInt    *rout,*cout,*diag = a->diag,*vi,n=a->mbs;
2504b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
2505b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
2506b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t;
2507b3260449SShri Abhyankar   const PetscScalar *b;
25084e2b4712SSatish Balay 
25094e2b4712SSatish Balay   PetscFunctionBegin;
2510b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
25111ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
2512f1af5d2fSBarry Smith   t  = a->solve_work;
25134e2b4712SSatish Balay 
25144e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
25154e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
25164e2b4712SSatish Balay 
25174e2b4712SSatish Balay   /* forward solve the lower triangular */
25184e2b4712SSatish Balay   idx    = 7*(*r++);
2519f1af5d2fSBarry Smith   t[0] = b[idx];   t[1] = b[1+idx];
2520f1af5d2fSBarry Smith   t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx];
2521f1af5d2fSBarry Smith   t[5] = b[5+idx]; t[6] = b[6+idx];
25224e2b4712SSatish Balay 
25234e2b4712SSatish Balay   for (i=1; i<n; i++) {
25244e2b4712SSatish Balay     v     = aa + 49*ai[i];
25254e2b4712SSatish Balay     vi    = aj + ai[i];
25264e2b4712SSatish Balay     nz    = diag[i] - ai[i];
25274e2b4712SSatish Balay     idx   = 7*(*r++);
2528f1af5d2fSBarry Smith     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
2529f1af5d2fSBarry Smith     s5  = b[4+idx];s6 = b[5+idx];s7 = b[6+idx];
25304e2b4712SSatish Balay     while (nz--) {
25314e2b4712SSatish Balay       idx   = 7*(*vi++);
2532f1af5d2fSBarry Smith       x1    = t[idx];  x2 = t[1+idx];x3 = t[2+idx];
2533f1af5d2fSBarry Smith       x4    = t[3+idx];x5 = t[4+idx];
2534f1af5d2fSBarry Smith       x6    = t[5+idx];x7 = t[6+idx];
2535f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
2536f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
2537f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
2538f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
2539f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
2540f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
2541f1af5d2fSBarry Smith       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
25424e2b4712SSatish Balay       v += 49;
25434e2b4712SSatish Balay     }
25444e2b4712SSatish Balay     idx = 7*i;
2545f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
2546f1af5d2fSBarry Smith     t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
2547f1af5d2fSBarry Smith     t[5+idx] = s6;t[6+idx] = s7;
25484e2b4712SSatish Balay   }
25494e2b4712SSatish Balay   /* backward solve the upper triangular */
25504e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
25514e2b4712SSatish Balay     v    = aa + 49*diag[i] + 49;
25524e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
25534e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
25544e2b4712SSatish Balay     idt  = 7*i;
2555f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
2556f1af5d2fSBarry Smith     s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
2557f1af5d2fSBarry Smith     s6 = t[5+idt];s7 = t[6+idt];
25584e2b4712SSatish Balay     while (nz--) {
25594e2b4712SSatish Balay       idx   = 7*(*vi++);
2560f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx];
2561f1af5d2fSBarry Smith       x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
2562f1af5d2fSBarry Smith       x6    = t[5+idx]; x7 = t[6+idx];
2563f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
2564f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
2565f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
2566f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
2567f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
2568f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
2569f1af5d2fSBarry Smith       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
25704e2b4712SSatish Balay       v += 49;
25714e2b4712SSatish Balay     }
25724e2b4712SSatish Balay     idc = 7*(*c--);
25734e2b4712SSatish Balay     v   = aa + 49*diag[i];
2574f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1+v[7]*s2+v[14]*s3+
2575f1af5d2fSBarry Smith                                  v[21]*s4+v[28]*s5+v[35]*s6+v[42]*s7;
2576f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1+v[8]*s2+v[15]*s3+
2577f1af5d2fSBarry Smith                                  v[22]*s4+v[29]*s5+v[36]*s6+v[43]*s7;
2578f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1+v[9]*s2+v[16]*s3+
2579f1af5d2fSBarry Smith                                  v[23]*s4+v[30]*s5+v[37]*s6+v[44]*s7;
2580f1af5d2fSBarry Smith     x[3+idc] = t[3+idt] = v[3]*s1+v[10]*s2+v[17]*s3+
2581f1af5d2fSBarry Smith                                  v[24]*s4+v[31]*s5+v[38]*s6+v[45]*s7;
2582f1af5d2fSBarry Smith     x[4+idc] = t[4+idt] = v[4]*s1+v[11]*s2+v[18]*s3+
2583f1af5d2fSBarry Smith                                  v[25]*s4+v[32]*s5+v[39]*s6+v[46]*s7;
2584f1af5d2fSBarry Smith     x[5+idc] = t[5+idt] = v[5]*s1+v[12]*s2+v[19]*s3+
2585f1af5d2fSBarry Smith                                  v[26]*s4+v[33]*s5+v[40]*s6+v[47]*s7;
2586f1af5d2fSBarry Smith     x[6+idc] = t[6+idt] = v[6]*s1+v[13]*s2+v[20]*s3+
2587f1af5d2fSBarry Smith                                  v[27]*s4+v[34]*s5+v[41]*s6+v[48]*s7;
25884e2b4712SSatish Balay   }
25894e2b4712SSatish Balay 
25904e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
25914e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
2592b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
25931ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
2594dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr);
25954e2b4712SSatish Balay   PetscFunctionReturn(0);
25964e2b4712SSatish Balay }
25974e2b4712SSatish Balay 
25988f690400SShri Abhyankar #undef __FUNCT__
25994dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_7"
26004dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_7(Mat A,Vec bb,Vec xx)
260135aa4fcfSShri Abhyankar {
260235aa4fcfSShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
260335aa4fcfSShri Abhyankar   IS                iscol=a->col,isrow=a->row;
260435aa4fcfSShri Abhyankar   PetscErrorCode    ierr;
2605b3260449SShri Abhyankar   const PetscInt    *r,*c,*ai=a->i,*aj=a->j,*adiag=a->diag;
2606b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*rout,*cout,*vi;
2607b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
2608b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
2609b3260449SShri Abhyankar   PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7,*x,*t;
2610b3260449SShri Abhyankar   const PetscScalar *b;
261135aa4fcfSShri Abhyankar 
261235aa4fcfSShri Abhyankar   PetscFunctionBegin;
2613b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
261435aa4fcfSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
261535aa4fcfSShri Abhyankar   t  = a->solve_work;
261635aa4fcfSShri Abhyankar 
261735aa4fcfSShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
261835aa4fcfSShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
261935aa4fcfSShri Abhyankar 
262035aa4fcfSShri Abhyankar   /* forward solve the lower triangular */
262135aa4fcfSShri Abhyankar   idx    = 7*r[0];
262235aa4fcfSShri Abhyankar   t[0] = b[idx];   t[1] = b[1+idx];
262335aa4fcfSShri Abhyankar   t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx];
262435aa4fcfSShri Abhyankar   t[5] = b[5+idx]; t[6] = b[6+idx];
262535aa4fcfSShri Abhyankar 
262635aa4fcfSShri Abhyankar   for (i=1; i<n; i++) {
262735aa4fcfSShri Abhyankar     v     = aa + 49*ai[i];
262835aa4fcfSShri Abhyankar     vi    = aj + ai[i];
262935aa4fcfSShri Abhyankar     nz    = ai[i+1] - ai[i];
263035aa4fcfSShri Abhyankar     idx   = 7*r[i];
263135aa4fcfSShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
263235aa4fcfSShri Abhyankar     s5  = b[4+idx];s6 = b[5+idx];s7 = b[6+idx];
263335aa4fcfSShri Abhyankar     for(m=0;m<nz;m++){
263435aa4fcfSShri Abhyankar       idx   = 7*vi[m];
263535aa4fcfSShri Abhyankar       x1    = t[idx];  x2 = t[1+idx];x3 = t[2+idx];
263635aa4fcfSShri Abhyankar       x4    = t[3+idx];x5 = t[4+idx];
263735aa4fcfSShri Abhyankar       x6    = t[5+idx];x7 = t[6+idx];
263835aa4fcfSShri Abhyankar       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
263935aa4fcfSShri Abhyankar       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
264035aa4fcfSShri Abhyankar       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
264135aa4fcfSShri Abhyankar       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
264235aa4fcfSShri Abhyankar       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
264335aa4fcfSShri Abhyankar       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
264435aa4fcfSShri Abhyankar       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
264535aa4fcfSShri Abhyankar       v += 49;
264635aa4fcfSShri Abhyankar     }
264735aa4fcfSShri Abhyankar     idx = 7*i;
264835aa4fcfSShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
264935aa4fcfSShri Abhyankar     t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
265035aa4fcfSShri Abhyankar     t[5+idx] = s6;t[6+idx] = s7;
265135aa4fcfSShri Abhyankar   }
265235aa4fcfSShri Abhyankar   /* backward solve the upper triangular */
265335aa4fcfSShri Abhyankar   for (i=n-1; i>=0; i--){
265435aa4fcfSShri Abhyankar     v    = aa + 49*(adiag[i+1]+1);
265535aa4fcfSShri Abhyankar     vi   = aj + adiag[i+1]+1;
265635aa4fcfSShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
265735aa4fcfSShri Abhyankar     idt  = 7*i;
265835aa4fcfSShri Abhyankar     s1 = t[idt];  s2 = t[1+idt];
265935aa4fcfSShri Abhyankar     s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
266035aa4fcfSShri Abhyankar     s6 = t[5+idt];s7 = t[6+idt];
266135aa4fcfSShri Abhyankar     for(m=0;m<nz;m++){
266235aa4fcfSShri Abhyankar       idx   = 7*vi[m];
266335aa4fcfSShri Abhyankar       x1    = t[idx];   x2 = t[1+idx];
266435aa4fcfSShri Abhyankar       x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
266535aa4fcfSShri Abhyankar       x6    = t[5+idx]; x7 = t[6+idx];
266635aa4fcfSShri Abhyankar       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
266735aa4fcfSShri Abhyankar       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
266835aa4fcfSShri Abhyankar       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
266935aa4fcfSShri Abhyankar       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
267035aa4fcfSShri Abhyankar       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
267135aa4fcfSShri Abhyankar       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
267235aa4fcfSShri Abhyankar       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
267335aa4fcfSShri Abhyankar       v += 49;
267435aa4fcfSShri Abhyankar     }
267535aa4fcfSShri Abhyankar     idc = 7*c[i];
267635aa4fcfSShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1+v[7]*s2+v[14]*s3+
267735aa4fcfSShri Abhyankar                                  v[21]*s4+v[28]*s5+v[35]*s6+v[42]*s7;
267835aa4fcfSShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1+v[8]*s2+v[15]*s3+
267935aa4fcfSShri Abhyankar                                  v[22]*s4+v[29]*s5+v[36]*s6+v[43]*s7;
268035aa4fcfSShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1+v[9]*s2+v[16]*s3+
268135aa4fcfSShri Abhyankar                                  v[23]*s4+v[30]*s5+v[37]*s6+v[44]*s7;
268235aa4fcfSShri Abhyankar     x[3+idc] = t[3+idt] = v[3]*s1+v[10]*s2+v[17]*s3+
268335aa4fcfSShri Abhyankar                                  v[24]*s4+v[31]*s5+v[38]*s6+v[45]*s7;
268435aa4fcfSShri Abhyankar     x[4+idc] = t[4+idt] = v[4]*s1+v[11]*s2+v[18]*s3+
268535aa4fcfSShri Abhyankar                                  v[25]*s4+v[32]*s5+v[39]*s6+v[46]*s7;
268635aa4fcfSShri Abhyankar     x[5+idc] = t[5+idt] = v[5]*s1+v[12]*s2+v[19]*s3+
268735aa4fcfSShri Abhyankar                                  v[26]*s4+v[33]*s5+v[40]*s6+v[47]*s7;
268835aa4fcfSShri Abhyankar     x[6+idc] = t[6+idt] = v[6]*s1+v[13]*s2+v[20]*s3+
268935aa4fcfSShri Abhyankar                                  v[27]*s4+v[34]*s5+v[41]*s6+v[48]*s7;
269035aa4fcfSShri Abhyankar   }
269135aa4fcfSShri Abhyankar 
269235aa4fcfSShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
269335aa4fcfSShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
2694b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
269535aa4fcfSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
269635aa4fcfSShri Abhyankar   ierr = PetscLogFlops(2.0*49*(a->nz) - 7.0*A->cmap->n);CHKERRQ(ierr);
269735aa4fcfSShri Abhyankar   PetscFunctionReturn(0);
269835aa4fcfSShri Abhyankar }
269935aa4fcfSShri Abhyankar 
270035aa4fcfSShri Abhyankar #undef __FUNCT__
270106e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_7_NaturalOrdering_inplace"
270206e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_7_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
270315091d37SBarry Smith {
270415091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
2705b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
2706dfbe8321SBarry Smith   PetscErrorCode    ierr;
2707b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,jdx;
2708d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
2709d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7;
2710d9fead3dSBarry Smith   const PetscScalar *b;
271115091d37SBarry Smith 
271215091d37SBarry Smith   PetscFunctionBegin;
2713d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
27141ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
271515091d37SBarry Smith   /* forward solve the lower triangular */
271615091d37SBarry Smith   idx    = 0;
271715091d37SBarry Smith   x[0] = b[idx];   x[1] = b[1+idx]; x[2] = b[2+idx];
271815091d37SBarry Smith   x[3] = b[3+idx]; x[4] = b[4+idx]; x[5] = b[5+idx];
271915091d37SBarry Smith   x[6] = b[6+idx];
272015091d37SBarry Smith   for (i=1; i<n; i++) {
272115091d37SBarry Smith     v     =  aa + 49*ai[i];
272215091d37SBarry Smith     vi    =  aj + ai[i];
272315091d37SBarry Smith     nz    =  diag[i] - ai[i];
272415091d37SBarry Smith     idx   =  7*i;
2725f1af5d2fSBarry Smith     s1  =  b[idx];   s2 = b[1+idx]; s3 = b[2+idx];
2726f1af5d2fSBarry Smith     s4  =  b[3+idx]; s5 = b[4+idx]; s6 = b[5+idx];
2727f1af5d2fSBarry Smith     s7  =  b[6+idx];
272815091d37SBarry Smith     while (nz--) {
272915091d37SBarry Smith       jdx   = 7*(*vi++);
273015091d37SBarry Smith       x1    = x[jdx];   x2 = x[1+jdx]; x3 = x[2+jdx];
273115091d37SBarry Smith       x4    = x[3+jdx]; x5 = x[4+jdx]; x6 = x[5+jdx];
273215091d37SBarry Smith       x7    = x[6+jdx];
2733f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
2734f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
2735f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
2736f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
2737f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
2738f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
2739f1af5d2fSBarry Smith       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
274015091d37SBarry Smith       v += 49;
274115091d37SBarry Smith      }
2742f1af5d2fSBarry Smith     x[idx]   = s1;
2743f1af5d2fSBarry Smith     x[1+idx] = s2;
2744f1af5d2fSBarry Smith     x[2+idx] = s3;
2745f1af5d2fSBarry Smith     x[3+idx] = s4;
2746f1af5d2fSBarry Smith     x[4+idx] = s5;
2747f1af5d2fSBarry Smith     x[5+idx] = s6;
2748f1af5d2fSBarry Smith     x[6+idx] = s7;
274915091d37SBarry Smith   }
275015091d37SBarry Smith   /* backward solve the upper triangular */
275115091d37SBarry Smith   for (i=n-1; i>=0; i--){
275215091d37SBarry Smith     v    = aa + 49*diag[i] + 49;
275315091d37SBarry Smith     vi   = aj + diag[i] + 1;
275415091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
275515091d37SBarry Smith     idt  = 7*i;
2756f1af5d2fSBarry Smith     s1 = x[idt];   s2 = x[1+idt];
2757f1af5d2fSBarry Smith     s3 = x[2+idt]; s4 = x[3+idt];
2758f1af5d2fSBarry Smith     s5 = x[4+idt]; s6 = x[5+idt];
2759f1af5d2fSBarry Smith     s7 = x[6+idt];
276015091d37SBarry Smith     while (nz--) {
276115091d37SBarry Smith       idx   = 7*(*vi++);
276215091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];
276315091d37SBarry Smith       x4    = x[3+idx]; x5 = x[4+idx]; x6 = x[5+idx];
276415091d37SBarry Smith       x7    = x[6+idx];
2765f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[7]*x2  + v[14]*x3 + v[21]*x4 + v[28]*x5 + v[35]*x6 + v[42]*x7;
2766f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[8]*x2  + v[15]*x3 + v[22]*x4 + v[29]*x5 + v[36]*x6 + v[43]*x7;
2767f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[9]*x2  + v[16]*x3 + v[23]*x4 + v[30]*x5 + v[37]*x6 + v[44]*x7;
2768f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4 + v[31]*x5 + v[38]*x6 + v[45]*x7;
2769f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4 + v[32]*x5 + v[39]*x6 + v[46]*x7;
2770f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4 + v[33]*x5 + v[40]*x6 + v[47]*x7;
2771f1af5d2fSBarry Smith       s7 -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4 + v[34]*x5 + v[41]*x6 + v[48]*x7;
277215091d37SBarry Smith       v += 49;
277315091d37SBarry Smith     }
277415091d37SBarry Smith     v        = aa + 49*diag[i];
2775f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[7]*s2  + v[14]*s3 + v[21]*s4
2776f1af5d2fSBarry Smith                          + v[28]*s5 + v[35]*s6 + v[42]*s7;
2777f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[8]*s2  + v[15]*s3 + v[22]*s4
2778f1af5d2fSBarry Smith                          + v[29]*s5 + v[36]*s6 + v[43]*s7;
2779f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[9]*s2  + v[16]*s3 + v[23]*s4
2780f1af5d2fSBarry Smith                          + v[30]*s5 + v[37]*s6 + v[44]*s7;
2781f1af5d2fSBarry Smith     x[3+idt] = v[3]*s1 + v[10]*s2  + v[17]*s3 + v[24]*s4
2782f1af5d2fSBarry Smith                          + v[31]*s5 + v[38]*s6 + v[45]*s7;
2783f1af5d2fSBarry Smith     x[4+idt] = v[4]*s1 + v[11]*s2  + v[18]*s3 + v[25]*s4
2784f1af5d2fSBarry Smith                          + v[32]*s5 + v[39]*s6 + v[46]*s7;
2785f1af5d2fSBarry Smith     x[5+idt] = v[5]*s1 + v[12]*s2  + v[19]*s3 + v[26]*s4
2786f1af5d2fSBarry Smith                          + v[33]*s5 + v[40]*s6 + v[47]*s7;
2787f1af5d2fSBarry Smith     x[6+idt] = v[6]*s1 + v[13]*s2  + v[20]*s3 + v[27]*s4
2788f1af5d2fSBarry Smith                          + v[34]*s5 + v[41]*s6 + v[48]*s7;
278915091d37SBarry Smith   }
279015091d37SBarry Smith 
2791d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
27921ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
2793dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
279415091d37SBarry Smith   PetscFunctionReturn(0);
279515091d37SBarry Smith }
279615091d37SBarry Smith 
2797cee9d6f2SShri Abhyankar #undef __FUNCT__
27984dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_7_NaturalOrdering"
27994dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_7_NaturalOrdering(Mat A,Vec bb,Vec xx)
280053cca76cSShri Abhyankar {
280153cca76cSShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
2802b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
280353cca76cSShri Abhyankar     PetscErrorCode    ierr;
2804b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,jdx,idt;
2805b3260449SShri Abhyankar     const PetscInt    bs = A->rmap->bs,bs2 = a->bs2;
280653cca76cSShri Abhyankar     const MatScalar   *aa=a->a,*v;
280753cca76cSShri Abhyankar     PetscScalar       *x;
280853cca76cSShri Abhyankar     const PetscScalar *b;
280953cca76cSShri Abhyankar     PetscScalar       s1,s2,s3,s4,s5,s6,s7,x1,x2,x3,x4,x5,x6,x7;
281053cca76cSShri Abhyankar 
281153cca76cSShri Abhyankar     PetscFunctionBegin;
281253cca76cSShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
281353cca76cSShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
281453cca76cSShri Abhyankar     /* forward solve the lower triangular */
281553cca76cSShri Abhyankar     idx    = 0;
281653cca76cSShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx];
281753cca76cSShri Abhyankar     x[4] = b[4+idx];x[5] = b[5+idx];x[6] = b[6+idx];
281853cca76cSShri Abhyankar     for (i=1; i<n; i++) {
281953cca76cSShri Abhyankar        v    = aa + bs2*ai[i];
282053cca76cSShri Abhyankar        vi   = aj + ai[i];
282153cca76cSShri Abhyankar        nz   = ai[i+1] - ai[i];
282253cca76cSShri Abhyankar       idx   = bs*i;
282353cca76cSShri Abhyankar        s1   = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
282453cca76cSShri Abhyankar        s5   = b[4+idx];s6 = b[5+idx];s7 = b[6+idx];
282553cca76cSShri Abhyankar        for(k=0;k<nz;k++) {
282653cca76cSShri Abhyankar           jdx   = bs*vi[k];
282753cca76cSShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx];
282853cca76cSShri Abhyankar 	  x5    = x[4+jdx]; x6 = x[5+jdx];x7 = x[6+jdx];
282953cca76cSShri Abhyankar           s1   -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4  + v[28]*x5 + v[35]*x6 + v[42]*x7;
283053cca76cSShri Abhyankar           s2   -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4  + v[29]*x5 + v[36]*x6 + v[43]*x7;
283153cca76cSShri Abhyankar           s3   -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4  + v[30]*x5 + v[37]*x6 + v[44]*x7;
283253cca76cSShri Abhyankar 	  s4   -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4  + v[31]*x5 + v[38]*x6 + v[45]*x7;
283353cca76cSShri Abhyankar           s5   -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4  + v[32]*x5 + v[39]*x6 + v[46]*x7;
283453cca76cSShri Abhyankar 	  s6   -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4  + v[33]*x5 + v[40]*x6 + v[47]*x7;
283553cca76cSShri Abhyankar 	  s7   -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4  + v[34]*x5 + v[41]*x6 + v[48]*x7;
283653cca76cSShri Abhyankar           v   +=  bs2;
283753cca76cSShri Abhyankar         }
283853cca76cSShri Abhyankar 
283953cca76cSShri Abhyankar        x[idx]   = s1;
284053cca76cSShri Abhyankar        x[1+idx] = s2;
284153cca76cSShri Abhyankar        x[2+idx] = s3;
284253cca76cSShri Abhyankar        x[3+idx] = s4;
284353cca76cSShri Abhyankar        x[4+idx] = s5;
284453cca76cSShri Abhyankar        x[5+idx] = s6;
284553cca76cSShri Abhyankar        x[6+idx] = s7;
284653cca76cSShri Abhyankar     }
284753cca76cSShri Abhyankar 
284853cca76cSShri Abhyankar    /* backward solve the upper triangular */
284953cca76cSShri Abhyankar   for (i=n-1; i>=0; i--){
285053cca76cSShri Abhyankar     v   = aa + bs2*(adiag[i+1]+1);
285153cca76cSShri Abhyankar      vi  = aj + adiag[i+1]+1;
285253cca76cSShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
285353cca76cSShri Abhyankar      idt = bs*i;
285453cca76cSShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt];
285553cca76cSShri Abhyankar      s5 = x[4+idt];s6 = x[5+idt];s7 = x[6+idt];
285653cca76cSShri Abhyankar     for(k=0;k<nz;k++) {
285753cca76cSShri Abhyankar       idx   = bs*vi[k];
285853cca76cSShri Abhyankar        x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx];
285953cca76cSShri Abhyankar        x5    = x[4+idx];x6 = x[5+idx];x7 = x[6+idx];
286053cca76cSShri Abhyankar        s1   -= v[0]*x1 + v[7]*x2 + v[14]*x3 + v[21]*x4  + v[28]*x5 + v[35]*x6 + v[42]*x7;
286153cca76cSShri Abhyankar        s2   -= v[1]*x1 + v[8]*x2 + v[15]*x3 + v[22]*x4  + v[29]*x5 + v[36]*x6 + v[43]*x7;
286253cca76cSShri Abhyankar        s3   -= v[2]*x1 + v[9]*x2 + v[16]*x3 + v[23]*x4  + v[30]*x5 + v[37]*x6 + v[44]*x7;
286353cca76cSShri Abhyankar        s4   -= v[3]*x1 + v[10]*x2 + v[17]*x3 + v[24]*x4  + v[31]*x5 + v[38]*x6 + v[45]*x7;
286453cca76cSShri Abhyankar        s5   -= v[4]*x1 + v[11]*x2 + v[18]*x3 + v[25]*x4  + v[32]*x5 + v[39]*x6 + v[46]*x7;
286553cca76cSShri Abhyankar        s6   -= v[5]*x1 + v[12]*x2 + v[19]*x3 + v[26]*x4  + v[33]*x5 + v[40]*x6 + v[47]*x7;
286653cca76cSShri Abhyankar        s7   -= v[6]*x1 + v[13]*x2 + v[20]*x3 + v[27]*x4  + v[34]*x5 + v[41]*x6 + v[48]*x7;
286753cca76cSShri Abhyankar         v   +=  bs2;
286853cca76cSShri Abhyankar     }
286953cca76cSShri Abhyankar     /* x = inv_diagonal*x */
287053cca76cSShri Abhyankar     x[idt]   = v[0]*s1 + v[7]*s2 + v[14]*s3 + v[21]*s4  + v[28]*s5 + v[35]*s6 + v[42]*s7;
287153cca76cSShri 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;
287253cca76cSShri 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;
287353cca76cSShri 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;
287453cca76cSShri 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;
287553cca76cSShri 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;
287653cca76cSShri 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;
287753cca76cSShri Abhyankar   }
287853cca76cSShri Abhyankar 
287953cca76cSShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
288053cca76cSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
288153cca76cSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
288253cca76cSShri Abhyankar   PetscFunctionReturn(0);
288353cca76cSShri Abhyankar }
288453cca76cSShri Abhyankar 
288553cca76cSShri Abhyankar #undef __FUNCT__
288606e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_6_inplace"
288706e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_6_inplace(Mat A,Vec bb,Vec xx)
288815091d37SBarry Smith {
288915091d37SBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
289015091d37SBarry Smith   IS                iscol=a->col,isrow=a->row;
28916849ba73SBarry Smith   PetscErrorCode    ierr;
28925d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout;
2893b3260449SShri Abhyankar   const PetscInt    *diag = a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
2894b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
2895d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
2896d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*t;
2897d9fead3dSBarry Smith   const PetscScalar *b;
2898b3260449SShri Abhyankar 
289915091d37SBarry Smith   PetscFunctionBegin;
2900d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
29011ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
2902f1af5d2fSBarry Smith   t  = a->solve_work;
290315091d37SBarry Smith 
290415091d37SBarry Smith   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
290515091d37SBarry Smith   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
290615091d37SBarry Smith 
290715091d37SBarry Smith   /* forward solve the lower triangular */
290815091d37SBarry Smith   idx    = 6*(*r++);
2909f1af5d2fSBarry Smith   t[0] = b[idx];   t[1] = b[1+idx];
2910f1af5d2fSBarry Smith   t[2] = b[2+idx]; t[3] = b[3+idx];
2911f1af5d2fSBarry Smith   t[4] = b[4+idx]; t[5] = b[5+idx];
291215091d37SBarry Smith   for (i=1; i<n; i++) {
291315091d37SBarry Smith     v     = aa + 36*ai[i];
291415091d37SBarry Smith     vi    = aj + ai[i];
291515091d37SBarry Smith     nz    = diag[i] - ai[i];
291615091d37SBarry Smith     idx   = 6*(*r++);
2917f1af5d2fSBarry Smith     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
2918f1af5d2fSBarry Smith     s5  = b[4+idx]; s6 = b[5+idx];
291915091d37SBarry Smith     while (nz--) {
292015091d37SBarry Smith       idx   = 6*(*vi++);
2921f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx]; x3 = t[2+idx];
2922f1af5d2fSBarry Smith       x4    = t[3+idx]; x5 = t[4+idx]; x6 = t[5+idx];
2923f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
2924f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
2925f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
2926f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
2927f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
2928f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
292915091d37SBarry Smith       v += 36;
293015091d37SBarry Smith     }
293115091d37SBarry Smith     idx = 6*i;
2932f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
2933f1af5d2fSBarry Smith     t[2+idx] = s3;t[3+idx] = s4;
2934f1af5d2fSBarry Smith     t[4+idx] = s5;t[5+idx] = s6;
293515091d37SBarry Smith   }
293615091d37SBarry Smith   /* backward solve the upper triangular */
293715091d37SBarry Smith   for (i=n-1; i>=0; i--){
293815091d37SBarry Smith     v    = aa + 36*diag[i] + 36;
293915091d37SBarry Smith     vi   = aj + diag[i] + 1;
294015091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
294115091d37SBarry Smith     idt  = 6*i;
2942f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
2943f1af5d2fSBarry Smith     s3 = t[2+idt];s4 = t[3+idt];
2944f1af5d2fSBarry Smith     s5 = t[4+idt];s6 = t[5+idt];
294515091d37SBarry Smith     while (nz--) {
294615091d37SBarry Smith       idx   = 6*(*vi++);
2947f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx];
2948f1af5d2fSBarry Smith       x3    = t[2+idx]; x4 = t[3+idx];
2949f1af5d2fSBarry Smith       x5    = t[4+idx]; x6 = t[5+idx];
2950f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
2951f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
2952f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
2953f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
2954f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
2955f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
295615091d37SBarry Smith       v += 36;
295715091d37SBarry Smith     }
295815091d37SBarry Smith     idc = 6*(*c--);
295915091d37SBarry Smith     v   = aa + 36*diag[i];
2960f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1+v[6]*s2+v[12]*s3+
2961f1af5d2fSBarry Smith                                  v[18]*s4+v[24]*s5+v[30]*s6;
2962f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1+v[7]*s2+v[13]*s3+
2963f1af5d2fSBarry Smith                                  v[19]*s4+v[25]*s5+v[31]*s6;
2964f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1+v[8]*s2+v[14]*s3+
2965f1af5d2fSBarry Smith                                  v[20]*s4+v[26]*s5+v[32]*s6;
2966f1af5d2fSBarry Smith     x[3+idc] = t[3+idt] = v[3]*s1+v[9]*s2+v[15]*s3+
2967f1af5d2fSBarry Smith                                  v[21]*s4+v[27]*s5+v[33]*s6;
2968f1af5d2fSBarry Smith     x[4+idc] = t[4+idt] = v[4]*s1+v[10]*s2+v[16]*s3+
2969f1af5d2fSBarry Smith                                  v[22]*s4+v[28]*s5+v[34]*s6;
2970f1af5d2fSBarry Smith     x[5+idc] = t[5+idt] = v[5]*s1+v[11]*s2+v[17]*s3+
2971f1af5d2fSBarry Smith                                  v[23]*s4+v[29]*s5+v[35]*s6;
297215091d37SBarry Smith   }
297315091d37SBarry Smith 
297415091d37SBarry Smith   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
297515091d37SBarry Smith   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
2976d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
29771ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
2978dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
297915091d37SBarry Smith   PetscFunctionReturn(0);
298015091d37SBarry Smith }
298115091d37SBarry Smith 
29826506fda5SShri Abhyankar #undef __FUNCT__
29834dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_6"
29844dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_6(Mat A,Vec bb,Vec xx)
29856506fda5SShri Abhyankar {
29866506fda5SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
29876506fda5SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
29886506fda5SShri Abhyankar   PetscErrorCode    ierr;
29896506fda5SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
2990b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
2991b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
29926506fda5SShri Abhyankar   const MatScalar   *aa=a->a,*v;
29936506fda5SShri Abhyankar   PetscScalar       *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6,*t;
29946506fda5SShri Abhyankar   const PetscScalar *b;
2995b3260449SShri Abhyankar 
29966506fda5SShri Abhyankar   PetscFunctionBegin;
29976506fda5SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
29986506fda5SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
29996506fda5SShri Abhyankar   t  = a->solve_work;
30006506fda5SShri Abhyankar 
30016506fda5SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
30026506fda5SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
30036506fda5SShri Abhyankar 
30046506fda5SShri Abhyankar   /* forward solve the lower triangular */
30056506fda5SShri Abhyankar   idx    = 6*r[0];
30066506fda5SShri Abhyankar   t[0] = b[idx];   t[1] = b[1+idx];
30076506fda5SShri Abhyankar   t[2] = b[2+idx]; t[3] = b[3+idx];
30086506fda5SShri Abhyankar   t[4] = b[4+idx]; t[5] = b[5+idx];
30096506fda5SShri Abhyankar   for (i=1; i<n; i++) {
30106506fda5SShri Abhyankar     v     = aa + 36*ai[i];
30116506fda5SShri Abhyankar     vi    = aj + ai[i];
30126506fda5SShri Abhyankar     nz    = ai[i+1] - ai[i];
30136506fda5SShri Abhyankar     idx   = 6*r[i];
30146506fda5SShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
30156506fda5SShri Abhyankar     s5  = b[4+idx]; s6 = b[5+idx];
30166506fda5SShri Abhyankar     for(m=0;m<nz;m++){
30176506fda5SShri Abhyankar       idx   = 6*vi[m];
30186506fda5SShri Abhyankar       x1    = t[idx];   x2 = t[1+idx]; x3 = t[2+idx];
30196506fda5SShri Abhyankar       x4    = t[3+idx]; x5 = t[4+idx]; x6 = t[5+idx];
30206506fda5SShri Abhyankar       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
30216506fda5SShri Abhyankar       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
30226506fda5SShri Abhyankar       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
30236506fda5SShri Abhyankar       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
30246506fda5SShri Abhyankar       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
30256506fda5SShri Abhyankar       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
30266506fda5SShri Abhyankar       v += 36;
30276506fda5SShri Abhyankar     }
30286506fda5SShri Abhyankar     idx = 6*i;
30296506fda5SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
30306506fda5SShri Abhyankar     t[2+idx] = s3;t[3+idx] = s4;
30316506fda5SShri Abhyankar     t[4+idx] = s5;t[5+idx] = s6;
30326506fda5SShri Abhyankar   }
30336506fda5SShri Abhyankar   /* backward solve the upper triangular */
30346506fda5SShri Abhyankar   for (i=n-1; i>=0; i--){
30356506fda5SShri Abhyankar     v    = aa + 36*(adiag[i+1]+1);
30366506fda5SShri Abhyankar     vi   = aj + adiag[i+1]+1;
30376506fda5SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
30386506fda5SShri Abhyankar     idt  = 6*i;
30396506fda5SShri Abhyankar     s1 = t[idt];  s2 = t[1+idt];
30406506fda5SShri Abhyankar     s3 = t[2+idt];s4 = t[3+idt];
30416506fda5SShri Abhyankar     s5 = t[4+idt];s6 = t[5+idt];
30426506fda5SShri Abhyankar     for(m=0;m<nz;m++){
30436506fda5SShri Abhyankar       idx   = 6*vi[m];
30446506fda5SShri Abhyankar       x1    = t[idx];   x2 = t[1+idx];
30456506fda5SShri Abhyankar       x3    = t[2+idx]; x4 = t[3+idx];
30466506fda5SShri Abhyankar       x5    = t[4+idx]; x6 = t[5+idx];
30476506fda5SShri Abhyankar       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
30486506fda5SShri Abhyankar       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
30496506fda5SShri Abhyankar       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
30506506fda5SShri Abhyankar       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
30516506fda5SShri Abhyankar       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
30526506fda5SShri Abhyankar       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
30536506fda5SShri Abhyankar       v += 36;
30546506fda5SShri Abhyankar     }
30556506fda5SShri Abhyankar     idc = 6*c[i];
30566506fda5SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1+v[6]*s2+v[12]*s3+
30576506fda5SShri Abhyankar                                  v[18]*s4+v[24]*s5+v[30]*s6;
30586506fda5SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1+v[7]*s2+v[13]*s3+
30596506fda5SShri Abhyankar                                  v[19]*s4+v[25]*s5+v[31]*s6;
30606506fda5SShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1+v[8]*s2+v[14]*s3+
30616506fda5SShri Abhyankar                                  v[20]*s4+v[26]*s5+v[32]*s6;
30626506fda5SShri Abhyankar     x[3+idc] = t[3+idt] = v[3]*s1+v[9]*s2+v[15]*s3+
30636506fda5SShri Abhyankar                                  v[21]*s4+v[27]*s5+v[33]*s6;
30646506fda5SShri Abhyankar     x[4+idc] = t[4+idt] = v[4]*s1+v[10]*s2+v[16]*s3+
30656506fda5SShri Abhyankar                                  v[22]*s4+v[28]*s5+v[34]*s6;
30666506fda5SShri Abhyankar     x[5+idc] = t[5+idt] = v[5]*s1+v[11]*s2+v[17]*s3+
30676506fda5SShri Abhyankar                                  v[23]*s4+v[29]*s5+v[35]*s6;
30686506fda5SShri Abhyankar   }
30696506fda5SShri Abhyankar 
30706506fda5SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
30716506fda5SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
30726506fda5SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
30736506fda5SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
30746506fda5SShri Abhyankar   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
30756506fda5SShri Abhyankar   PetscFunctionReturn(0);
30766506fda5SShri Abhyankar }
30778f690400SShri Abhyankar 
30788f690400SShri Abhyankar #undef __FUNCT__
307906e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_6_NaturalOrdering_inplace"
308006e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_6_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
308115091d37SBarry Smith {
308215091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3083b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,jdx;
3084dfbe8321SBarry Smith   PetscErrorCode    ierr;
3085b3260449SShri Abhyankar   const PetscInt    *diag = a->diag,*vi,n=a->mbs,*ai=a->i,*aj=a->j;
3086d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3087d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6;
3088d9fead3dSBarry Smith   const PetscScalar *b;
308915091d37SBarry Smith 
309015091d37SBarry Smith   PetscFunctionBegin;
3091d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
30921ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
309315091d37SBarry Smith   /* forward solve the lower triangular */
309415091d37SBarry Smith   idx    = 0;
309515091d37SBarry Smith   x[0] = b[idx];   x[1] = b[1+idx]; x[2] = b[2+idx];
309615091d37SBarry Smith   x[3] = b[3+idx]; x[4] = b[4+idx]; x[5] = b[5+idx];
309715091d37SBarry Smith   for (i=1; i<n; i++) {
309815091d37SBarry Smith     v     =  aa + 36*ai[i];
309915091d37SBarry Smith     vi    =  aj + ai[i];
310015091d37SBarry Smith     nz    =  diag[i] - ai[i];
310115091d37SBarry Smith     idx   =  6*i;
3102f1af5d2fSBarry Smith     s1  =  b[idx];   s2 = b[1+idx]; s3 = b[2+idx];
3103f1af5d2fSBarry Smith     s4  =  b[3+idx]; s5 = b[4+idx]; s6 = b[5+idx];
310415091d37SBarry Smith     while (nz--) {
310515091d37SBarry Smith       jdx   = 6*(*vi++);
310615091d37SBarry Smith       x1    = x[jdx];   x2 = x[1+jdx]; x3 = x[2+jdx];
310715091d37SBarry Smith       x4    = x[3+jdx]; x5 = x[4+jdx]; x6 = x[5+jdx];
3108f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
3109f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
3110f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
3111f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
3112f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
3113f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
311415091d37SBarry Smith       v += 36;
311515091d37SBarry Smith      }
3116f1af5d2fSBarry Smith     x[idx]   = s1;
3117f1af5d2fSBarry Smith     x[1+idx] = s2;
3118f1af5d2fSBarry Smith     x[2+idx] = s3;
3119f1af5d2fSBarry Smith     x[3+idx] = s4;
3120f1af5d2fSBarry Smith     x[4+idx] = s5;
3121f1af5d2fSBarry Smith     x[5+idx] = s6;
312215091d37SBarry Smith   }
312315091d37SBarry Smith   /* backward solve the upper triangular */
312415091d37SBarry Smith   for (i=n-1; i>=0; i--){
312515091d37SBarry Smith     v    = aa + 36*diag[i] + 36;
312615091d37SBarry Smith     vi   = aj + diag[i] + 1;
312715091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
312815091d37SBarry Smith     idt  = 6*i;
3129f1af5d2fSBarry Smith     s1 = x[idt];   s2 = x[1+idt];
3130f1af5d2fSBarry Smith     s3 = x[2+idt]; s4 = x[3+idt];
3131f1af5d2fSBarry Smith     s5 = x[4+idt]; s6 = x[5+idt];
313215091d37SBarry Smith     while (nz--) {
313315091d37SBarry Smith       idx   = 6*(*vi++);
313415091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];
313515091d37SBarry Smith       x4    = x[3+idx]; x5 = x[4+idx]; x6 = x[5+idx];
3136f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[6]*x2  + v[12]*x3 + v[18]*x4 + v[24]*x5 + v[30]*x6;
3137f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[7]*x2  + v[13]*x3 + v[19]*x4 + v[25]*x5 + v[31]*x6;
3138f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[8]*x2  + v[14]*x3 + v[20]*x4 + v[26]*x5 + v[32]*x6;
3139f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[9]*x2  + v[15]*x3 + v[21]*x4 + v[27]*x5 + v[33]*x6;
3140f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4 + v[28]*x5 + v[34]*x6;
3141f1af5d2fSBarry Smith       s6 -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4 + v[29]*x5 + v[35]*x6;
314215091d37SBarry Smith       v += 36;
314315091d37SBarry Smith     }
314415091d37SBarry Smith     v        = aa + 36*diag[i];
3145f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[6]*s2  + v[12]*s3 + v[18]*s4 + v[24]*s5 + v[30]*s6;
3146f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[7]*s2  + v[13]*s3 + v[19]*s4 + v[25]*s5 + v[31]*s6;
3147f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[8]*s2  + v[14]*s3 + v[20]*s4 + v[26]*s5 + v[32]*s6;
3148f1af5d2fSBarry Smith     x[3+idt] = v[3]*s1 + v[9]*s2  + v[15]*s3 + v[21]*s4 + v[27]*s5 + v[33]*s6;
3149f1af5d2fSBarry Smith     x[4+idt] = v[4]*s1 + v[10]*s2 + v[16]*s3 + v[22]*s4 + v[28]*s5 + v[34]*s6;
3150f1af5d2fSBarry Smith     x[5+idt] = v[5]*s1 + v[11]*s2 + v[17]*s3 + v[23]*s4 + v[29]*s5 + v[35]*s6;
315115091d37SBarry Smith   }
315215091d37SBarry Smith 
3153d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
31541ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3155dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*36*(a->nz) - 6.0*A->cmap->n);CHKERRQ(ierr);
315615091d37SBarry Smith   PetscFunctionReturn(0);
315715091d37SBarry Smith }
315815091d37SBarry Smith 
3159cee9d6f2SShri Abhyankar #undef __FUNCT__
31604dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_6_NaturalOrdering"
31614dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_6_NaturalOrdering(Mat A,Vec bb,Vec xx)
316253cca76cSShri Abhyankar {
316353cca76cSShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3164b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
316553cca76cSShri Abhyankar     PetscErrorCode    ierr;
3166b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,jdx,idt;
3167b3260449SShri Abhyankar     const PetscInt    bs = A->rmap->bs,bs2 = a->bs2;
316853cca76cSShri Abhyankar     const MatScalar   *aa=a->a,*v;
316953cca76cSShri Abhyankar     PetscScalar       *x;
317053cca76cSShri Abhyankar     const PetscScalar *b;
317153cca76cSShri Abhyankar     PetscScalar       s1,s2,s3,s4,s5,s6,x1,x2,x3,x4,x5,x6;
317253cca76cSShri Abhyankar 
317353cca76cSShri Abhyankar     PetscFunctionBegin;
317453cca76cSShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
317553cca76cSShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
317653cca76cSShri Abhyankar     /* forward solve the lower triangular */
317753cca76cSShri Abhyankar     idx    = 0;
317853cca76cSShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx];
317953cca76cSShri Abhyankar     x[4] = b[4+idx];x[5] = b[5+idx];
318053cca76cSShri Abhyankar     for (i=1; i<n; i++) {
318153cca76cSShri Abhyankar        v    = aa + bs2*ai[i];
318253cca76cSShri Abhyankar        vi   = aj + ai[i];
318353cca76cSShri Abhyankar        nz   = ai[i+1] - ai[i];
318453cca76cSShri Abhyankar       idx   = bs*i;
318553cca76cSShri Abhyankar        s1   = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
318653cca76cSShri Abhyankar        s5   = b[4+idx];s6 = b[5+idx];
318753cca76cSShri Abhyankar        for(k=0;k<nz;k++){
318853cca76cSShri Abhyankar           jdx   = bs*vi[k];
318953cca76cSShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx];
319053cca76cSShri Abhyankar 	  x5    = x[4+jdx]; x6 = x[5+jdx];
319153cca76cSShri Abhyankar           s1   -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4  + v[24]*x5 + v[30]*x6;
319253cca76cSShri Abhyankar           s2   -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4  + v[25]*x5 + v[31]*x6;;
319353cca76cSShri Abhyankar           s3   -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4  + v[26]*x5 + v[32]*x6;
319453cca76cSShri Abhyankar 	  s4   -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4  + v[27]*x5 + v[33]*x6;
319553cca76cSShri Abhyankar           s5   -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4  + v[28]*x5 + v[34]*x6;
319653cca76cSShri Abhyankar 	  s6   -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4  + v[29]*x5 + v[35]*x6;
319753cca76cSShri Abhyankar           v   +=  bs2;
319853cca76cSShri Abhyankar         }
319953cca76cSShri Abhyankar 
320053cca76cSShri Abhyankar        x[idx]   = s1;
320153cca76cSShri Abhyankar        x[1+idx] = s2;
320253cca76cSShri Abhyankar        x[2+idx] = s3;
320353cca76cSShri Abhyankar        x[3+idx] = s4;
320453cca76cSShri Abhyankar        x[4+idx] = s5;
320553cca76cSShri Abhyankar        x[5+idx] = s6;
320653cca76cSShri Abhyankar     }
320753cca76cSShri Abhyankar 
320853cca76cSShri Abhyankar    /* backward solve the upper triangular */
320953cca76cSShri Abhyankar   for (i=n-1; i>=0; i--){
321053cca76cSShri Abhyankar     v   = aa + bs2*(adiag[i+1]+1);
321153cca76cSShri Abhyankar      vi  = aj + adiag[i+1]+1;
321253cca76cSShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
321353cca76cSShri Abhyankar      idt = bs*i;
321453cca76cSShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt];
321553cca76cSShri Abhyankar      s5 = x[4+idt];s6 = x[5+idt];
321653cca76cSShri Abhyankar      for(k=0;k<nz;k++){
321753cca76cSShri Abhyankar       idx   = bs*vi[k];
321853cca76cSShri Abhyankar        x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx];
321953cca76cSShri Abhyankar        x5    = x[4+idx];x6 = x[5+idx];
322053cca76cSShri Abhyankar        s1   -= v[0]*x1 + v[6]*x2 + v[12]*x3 + v[18]*x4  + v[24]*x5 + v[30]*x6;
322153cca76cSShri Abhyankar        s2   -= v[1]*x1 + v[7]*x2 + v[13]*x3 + v[19]*x4  + v[25]*x5 + v[31]*x6;;
322253cca76cSShri Abhyankar        s3   -= v[2]*x1 + v[8]*x2 + v[14]*x3 + v[20]*x4  + v[26]*x5 + v[32]*x6;
322353cca76cSShri Abhyankar        s4   -= v[3]*x1 + v[9]*x2 + v[15]*x3 + v[21]*x4  + v[27]*x5 + v[33]*x6;
322453cca76cSShri Abhyankar        s5   -= v[4]*x1 + v[10]*x2 + v[16]*x3 + v[22]*x4  + v[28]*x5 + v[34]*x6;
322553cca76cSShri Abhyankar        s6   -= v[5]*x1 + v[11]*x2 + v[17]*x3 + v[23]*x4  + v[29]*x5 + v[35]*x6;
322653cca76cSShri Abhyankar         v   +=  bs2;
322753cca76cSShri Abhyankar     }
322853cca76cSShri Abhyankar     /* x = inv_diagonal*x */
322953cca76cSShri Abhyankar    x[idt]   = v[0]*s1 + v[6]*s2 + v[12]*s3 + v[18]*s4 + v[24]*s5 + v[30]*s6;
323053cca76cSShri Abhyankar    x[1+idt] = v[1]*s1 + v[7]*s2 + v[13]*s3 + v[19]*s4 + v[25]*s5 + v[31]*s6;
323153cca76cSShri Abhyankar    x[2+idt] = v[2]*s1 + v[8]*s2 + v[14]*s3 + v[20]*s4 + v[26]*s5 + v[32]*s6;
323253cca76cSShri Abhyankar    x[3+idt] = v[3]*s1 + v[9]*s2 + v[15]*s3 + v[21]*s4 + v[27]*s5 + v[33]*s6;
323353cca76cSShri Abhyankar    x[4+idt] = v[4]*s1 + v[10]*s2 + v[16]*s3 + v[22]*s4 + v[28]*s5 + v[34]*s6;
323453cca76cSShri Abhyankar    x[5+idt] = v[5]*s1 + v[11]*s2 + v[17]*s3 + v[23]*s4 + v[29]*s5 + v[35]*s6;
323553cca76cSShri Abhyankar   }
323653cca76cSShri Abhyankar 
323753cca76cSShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
323853cca76cSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
323953cca76cSShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
324053cca76cSShri Abhyankar   PetscFunctionReturn(0);
324153cca76cSShri Abhyankar }
324253cca76cSShri Abhyankar 
324353cca76cSShri Abhyankar #undef __FUNCT__
324406e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_5_inplace"
324506e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_5_inplace(Mat A,Vec bb,Vec xx)
32464e2b4712SSatish Balay {
32474e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
32484e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
32496849ba73SBarry Smith   PetscErrorCode    ierr;
32505d0c19d7SBarry Smith   const PetscInt    *r,*c,*rout,*cout,*diag = a->diag;
3251b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
3252b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
3253d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3254d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*t;
3255d9fead3dSBarry Smith   const PetscScalar *b;
32564e2b4712SSatish Balay 
32574e2b4712SSatish Balay   PetscFunctionBegin;
3258d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
32591ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
3260f1af5d2fSBarry Smith   t  = a->solve_work;
32614e2b4712SSatish Balay 
32624e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
32634e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
32644e2b4712SSatish Balay 
32654e2b4712SSatish Balay   /* forward solve the lower triangular */
32664e2b4712SSatish Balay   idx    = 5*(*r++);
3267f1af5d2fSBarry Smith   t[0] = b[idx];   t[1] = b[1+idx];
3268f1af5d2fSBarry Smith   t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx];
32694e2b4712SSatish Balay   for (i=1; i<n; i++) {
32704e2b4712SSatish Balay     v     = aa + 25*ai[i];
32714e2b4712SSatish Balay     vi    = aj + ai[i];
32724e2b4712SSatish Balay     nz    = diag[i] - ai[i];
32734e2b4712SSatish Balay     idx   = 5*(*r++);
3274f1af5d2fSBarry Smith     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
3275f1af5d2fSBarry Smith     s5  = b[4+idx];
32764e2b4712SSatish Balay     while (nz--) {
32774e2b4712SSatish Balay       idx   = 5*(*vi++);
3278f1af5d2fSBarry Smith       x1    = t[idx];  x2 = t[1+idx];x3 = t[2+idx];
3279f1af5d2fSBarry Smith       x4    = t[3+idx];x5 = t[4+idx];
3280f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5;
3281f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5;
3282f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5;
3283f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5;
3284f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5;
32854e2b4712SSatish Balay       v += 25;
32864e2b4712SSatish Balay     }
32874e2b4712SSatish Balay     idx = 5*i;
3288f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
3289f1af5d2fSBarry Smith     t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
32904e2b4712SSatish Balay   }
32914e2b4712SSatish Balay   /* backward solve the upper triangular */
32924e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
32934e2b4712SSatish Balay     v    = aa + 25*diag[i] + 25;
32944e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
32954e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
32964e2b4712SSatish Balay     idt  = 5*i;
3297f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
3298f1af5d2fSBarry Smith     s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
32994e2b4712SSatish Balay     while (nz--) {
33004e2b4712SSatish Balay       idx   = 5*(*vi++);
3301f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx];
3302f1af5d2fSBarry Smith       x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
3303f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5;
3304f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5;
3305f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5;
3306f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5;
3307f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5;
33084e2b4712SSatish Balay       v += 25;
33094e2b4712SSatish Balay     }
33104e2b4712SSatish Balay     idc = 5*(*c--);
33114e2b4712SSatish Balay     v   = aa + 25*diag[i];
3312f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1+v[5]*s2+v[10]*s3+
3313f1af5d2fSBarry Smith                                  v[15]*s4+v[20]*s5;
3314f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1+v[6]*s2+v[11]*s3+
3315f1af5d2fSBarry Smith                                  v[16]*s4+v[21]*s5;
3316f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1+v[7]*s2+v[12]*s3+
3317f1af5d2fSBarry Smith                                  v[17]*s4+v[22]*s5;
3318f1af5d2fSBarry Smith     x[3+idc] = t[3+idt] = v[3]*s1+v[8]*s2+v[13]*s3+
3319f1af5d2fSBarry Smith                                  v[18]*s4+v[23]*s5;
3320f1af5d2fSBarry Smith     x[4+idc] = t[4+idt] = v[4]*s1+v[9]*s2+v[14]*s3+
3321f1af5d2fSBarry Smith                                  v[19]*s4+v[24]*s5;
33224e2b4712SSatish Balay   }
33234e2b4712SSatish Balay 
33244e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
33254e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
3326d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
33271ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3328dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
33294e2b4712SSatish Balay   PetscFunctionReturn(0);
33304e2b4712SSatish Balay }
33314e2b4712SSatish Balay 
333278bb4007SShri Abhyankar #undef __FUNCT__
33334dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_5"
33344dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_5(Mat A,Vec bb,Vec xx)
333578bb4007SShri Abhyankar {
333678bb4007SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
333778bb4007SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
333878bb4007SShri Abhyankar   PetscErrorCode    ierr;
333978bb4007SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
3340b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
3341b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
334278bb4007SShri Abhyankar   const MatScalar   *aa=a->a,*v;
334378bb4007SShri Abhyankar   PetscScalar       *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5,*t;
334478bb4007SShri Abhyankar   const PetscScalar *b;
334578bb4007SShri Abhyankar 
334678bb4007SShri Abhyankar   PetscFunctionBegin;
334778bb4007SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
334878bb4007SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
334978bb4007SShri Abhyankar   t  = a->solve_work;
335078bb4007SShri Abhyankar 
335178bb4007SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
335278bb4007SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
335378bb4007SShri Abhyankar 
335478bb4007SShri Abhyankar   /* forward solve the lower triangular */
335578bb4007SShri Abhyankar   idx    = 5*r[0];
335678bb4007SShri Abhyankar   t[0] = b[idx];   t[1] = b[1+idx];
335778bb4007SShri Abhyankar   t[2] = b[2+idx]; t[3] = b[3+idx]; t[4] = b[4+idx];
335878bb4007SShri Abhyankar   for (i=1; i<n; i++) {
335978bb4007SShri Abhyankar     v     = aa + 25*ai[i];
336078bb4007SShri Abhyankar     vi    = aj + ai[i];
336178bb4007SShri Abhyankar     nz    = ai[i+1] - ai[i];
336278bb4007SShri Abhyankar     idx   = 5*r[i];
336378bb4007SShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
336478bb4007SShri Abhyankar     s5  = b[4+idx];
336578bb4007SShri Abhyankar     for(m=0;m<nz;m++){
336678bb4007SShri Abhyankar       idx   = 5*vi[m];
336778bb4007SShri Abhyankar       x1    = t[idx];  x2 = t[1+idx];x3 = t[2+idx];
336878bb4007SShri Abhyankar       x4    = t[3+idx];x5 = t[4+idx];
336978bb4007SShri Abhyankar       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5;
337078bb4007SShri Abhyankar       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5;
337178bb4007SShri Abhyankar       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5;
337278bb4007SShri Abhyankar       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5;
337378bb4007SShri Abhyankar       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5;
337478bb4007SShri Abhyankar       v += 25;
337578bb4007SShri Abhyankar     }
337678bb4007SShri Abhyankar     idx = 5*i;
337778bb4007SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
337878bb4007SShri Abhyankar     t[2+idx] = s3;t[3+idx] = s4; t[4+idx] = s5;
337978bb4007SShri Abhyankar   }
338078bb4007SShri Abhyankar   /* backward solve the upper triangular */
338178bb4007SShri Abhyankar   for (i=n-1; i>=0; i--){
338278bb4007SShri Abhyankar     v    = aa + 25*(adiag[i+1]+1);
338378bb4007SShri Abhyankar     vi   = aj + adiag[i+1]+1;
338478bb4007SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
338578bb4007SShri Abhyankar     idt  = 5*i;
338678bb4007SShri Abhyankar     s1 = t[idt];  s2 = t[1+idt];
338778bb4007SShri Abhyankar     s3 = t[2+idt];s4 = t[3+idt]; s5 = t[4+idt];
338878bb4007SShri Abhyankar     for(m=0;m<nz;m++){
338978bb4007SShri Abhyankar       idx   = 5*vi[m];
339078bb4007SShri Abhyankar       x1    = t[idx];   x2 = t[1+idx];
339178bb4007SShri Abhyankar       x3    = t[2+idx]; x4 = t[3+idx]; x5 = t[4+idx];
339278bb4007SShri Abhyankar       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3 + v[15]*x4 + v[20]*x5;
339378bb4007SShri Abhyankar       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3 + v[16]*x4 + v[21]*x5;
339478bb4007SShri Abhyankar       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3 + v[17]*x4 + v[22]*x5;
339578bb4007SShri Abhyankar       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3 + v[18]*x4 + v[23]*x5;
339678bb4007SShri Abhyankar       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3 + v[19]*x4 + v[24]*x5;
339778bb4007SShri Abhyankar       v += 25;
339878bb4007SShri Abhyankar     }
339978bb4007SShri Abhyankar     idc = 5*c[i];
340078bb4007SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1+v[5]*s2+v[10]*s3+
340178bb4007SShri Abhyankar                                  v[15]*s4+v[20]*s5;
340278bb4007SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1+v[6]*s2+v[11]*s3+
340378bb4007SShri Abhyankar                                  v[16]*s4+v[21]*s5;
340478bb4007SShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1+v[7]*s2+v[12]*s3+
340578bb4007SShri Abhyankar                                  v[17]*s4+v[22]*s5;
340678bb4007SShri Abhyankar     x[3+idc] = t[3+idt] = v[3]*s1+v[8]*s2+v[13]*s3+
340778bb4007SShri Abhyankar                                  v[18]*s4+v[23]*s5;
340878bb4007SShri Abhyankar     x[4+idc] = t[4+idt] = v[4]*s1+v[9]*s2+v[14]*s3+
340978bb4007SShri Abhyankar                                  v[19]*s4+v[24]*s5;
341078bb4007SShri Abhyankar   }
341178bb4007SShri Abhyankar 
341278bb4007SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
341378bb4007SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
341478bb4007SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
341578bb4007SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
341678bb4007SShri Abhyankar   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
341778bb4007SShri Abhyankar   PetscFunctionReturn(0);
341878bb4007SShri Abhyankar }
341978bb4007SShri Abhyankar 
34208f690400SShri Abhyankar #undef __FUNCT__
342106e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_5_NaturalOrdering_inplace"
342206e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_5_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
342315091d37SBarry Smith {
342415091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3425b3260449SShri Abhyankar   const PetscInt    *diag=a->diag,n=a->mbs,*vi,*ai=a->i,*aj=a->j;
3426b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,jdx;
3427dfbe8321SBarry Smith   PetscErrorCode    ierr;
3428d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3429d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5;
3430d9fead3dSBarry Smith   const PetscScalar *b;
343115091d37SBarry Smith 
343215091d37SBarry Smith   PetscFunctionBegin;
3433d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
34341ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
343515091d37SBarry Smith   /* forward solve the lower triangular */
343615091d37SBarry Smith   idx    = 0;
343715091d37SBarry 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];
343815091d37SBarry Smith   for (i=1; i<n; i++) {
343915091d37SBarry Smith     v     =  aa + 25*ai[i];
344015091d37SBarry Smith     vi    =  aj + ai[i];
344115091d37SBarry Smith     nz    =  diag[i] - ai[i];
344215091d37SBarry Smith     idx   =  5*i;
3443f1af5d2fSBarry Smith     s1  =  b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];s5 = b[4+idx];
344415091d37SBarry Smith     while (nz--) {
344515091d37SBarry Smith       jdx   = 5*(*vi++);
344615091d37SBarry Smith       x1    = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx];x5 = x[4+jdx];
3447f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3  + v[15]*x4 + v[20]*x5;
3448f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3  + v[16]*x4 + v[21]*x5;
3449f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3  + v[17]*x4 + v[22]*x5;
3450f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3  + v[18]*x4 + v[23]*x5;
3451f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3  + v[19]*x4 + v[24]*x5;
345215091d37SBarry Smith       v    += 25;
345315091d37SBarry Smith     }
3454f1af5d2fSBarry Smith     x[idx]   = s1;
3455f1af5d2fSBarry Smith     x[1+idx] = s2;
3456f1af5d2fSBarry Smith     x[2+idx] = s3;
3457f1af5d2fSBarry Smith     x[3+idx] = s4;
3458f1af5d2fSBarry Smith     x[4+idx] = s5;
345915091d37SBarry Smith   }
346015091d37SBarry Smith   /* backward solve the upper triangular */
346115091d37SBarry Smith   for (i=n-1; i>=0; i--){
346215091d37SBarry Smith     v    = aa + 25*diag[i] + 25;
346315091d37SBarry Smith     vi   = aj + diag[i] + 1;
346415091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
346515091d37SBarry Smith     idt  = 5*i;
3466f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt];
3467f1af5d2fSBarry Smith     s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt];
346815091d37SBarry Smith     while (nz--) {
346915091d37SBarry Smith       idx   = 5*(*vi++);
347015091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx];x3    = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx];
3471f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3  + v[15]*x4 + v[20]*x5;
3472f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3  + v[16]*x4 + v[21]*x5;
3473f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3  + v[17]*x4 + v[22]*x5;
3474f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3  + v[18]*x4 + v[23]*x5;
3475f1af5d2fSBarry Smith       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3  + v[19]*x4 + v[24]*x5;
347615091d37SBarry Smith       v    += 25;
347715091d37SBarry Smith     }
347815091d37SBarry Smith     v        = aa + 25*diag[i];
3479f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[5]*s2 + v[10]*s3  + v[15]*s4 + v[20]*s5;
3480f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[6]*s2 + v[11]*s3  + v[16]*s4 + v[21]*s5;
3481f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[7]*s2 + v[12]*s3  + v[17]*s4 + v[22]*s5;
3482f1af5d2fSBarry Smith     x[3+idt] = v[3]*s1 + v[8]*s2 + v[13]*s3  + v[18]*s4 + v[23]*s5;
3483f1af5d2fSBarry Smith     x[4+idt] = v[4]*s1 + v[9]*s2 + v[14]*s3  + v[19]*s4 + v[24]*s5;
348415091d37SBarry Smith   }
348515091d37SBarry Smith 
3486d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
34871ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3488dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
348915091d37SBarry Smith   PetscFunctionReturn(0);
349015091d37SBarry Smith }
349115091d37SBarry Smith 
3492cee9d6f2SShri Abhyankar #undef __FUNCT__
34934dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_5_NaturalOrdering"
34944dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_5_NaturalOrdering(Mat A,Vec bb,Vec xx)
349553cca76cSShri Abhyankar {
349653cca76cSShri Abhyankar   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3497b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
3498b3260449SShri Abhyankar   PetscInt          i,k,nz,idx,idt,jdx;
349953cca76cSShri Abhyankar   PetscErrorCode    ierr;
350053cca76cSShri Abhyankar   const MatScalar   *aa=a->a,*v;
350153cca76cSShri Abhyankar   PetscScalar       *x,s1,s2,s3,s4,s5,x1,x2,x3,x4,x5;
350253cca76cSShri Abhyankar   const PetscScalar *b;
350353cca76cSShri Abhyankar 
350453cca76cSShri Abhyankar   PetscFunctionBegin;
350553cca76cSShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
350653cca76cSShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
350753cca76cSShri Abhyankar   /* forward solve the lower triangular */
350853cca76cSShri Abhyankar   idx    = 0;
350953cca76cSShri 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];
351053cca76cSShri Abhyankar   for (i=1; i<n; i++) {
351153cca76cSShri Abhyankar     v   = aa + 25*ai[i];
351253cca76cSShri Abhyankar     vi  = aj + ai[i];
351353cca76cSShri Abhyankar     nz  = ai[i+1] - ai[i];
351453cca76cSShri Abhyankar     idx = 5*i;
351553cca76cSShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];s5 = b[4+idx];
351653cca76cSShri Abhyankar     for(k=0;k<nz;k++) {
351753cca76cSShri Abhyankar       jdx   = 5*vi[k];
351853cca76cSShri Abhyankar       x1    = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx];x5 = x[4+jdx];
351953cca76cSShri Abhyankar       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3  + v[15]*x4 + v[20]*x5;
352053cca76cSShri Abhyankar       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3  + v[16]*x4 + v[21]*x5;
352153cca76cSShri Abhyankar       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3  + v[17]*x4 + v[22]*x5;
352253cca76cSShri Abhyankar       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3  + v[18]*x4 + v[23]*x5;
352353cca76cSShri Abhyankar       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3  + v[19]*x4 + v[24]*x5;
352453cca76cSShri Abhyankar       v    += 25;
352553cca76cSShri Abhyankar     }
352653cca76cSShri Abhyankar     x[idx]   = s1;
352753cca76cSShri Abhyankar     x[1+idx] = s2;
352853cca76cSShri Abhyankar     x[2+idx] = s3;
352953cca76cSShri Abhyankar     x[3+idx] = s4;
353053cca76cSShri Abhyankar     x[4+idx] = s5;
353153cca76cSShri Abhyankar   }
353253cca76cSShri Abhyankar 
353353cca76cSShri Abhyankar   /* backward solve the upper triangular */
353453cca76cSShri Abhyankar   for (i=n-1; i>=0; i--){
353553cca76cSShri Abhyankar     v   = aa + 25*(adiag[i+1]+1);
353653cca76cSShri Abhyankar     vi  = aj + adiag[i+1]+1;
353753cca76cSShri Abhyankar     nz  = adiag[i] - adiag[i+1]-1;
353853cca76cSShri Abhyankar     idt = 5*i;
353953cca76cSShri Abhyankar     s1 = x[idt];  s2 = x[1+idt];
354053cca76cSShri Abhyankar     s3 = x[2+idt];s4 = x[3+idt]; s5 = x[4+idt];
354153cca76cSShri Abhyankar     for(k=0;k<nz;k++){
354253cca76cSShri Abhyankar       idx   = 5*vi[k];
354353cca76cSShri Abhyankar       x1    = x[idx];   x2 = x[1+idx];x3    = x[2+idx]; x4 = x[3+idx]; x5 = x[4+idx];
354453cca76cSShri Abhyankar       s1 -= v[0]*x1 + v[5]*x2 + v[10]*x3  + v[15]*x4 + v[20]*x5;
354553cca76cSShri Abhyankar       s2 -= v[1]*x1 + v[6]*x2 + v[11]*x3  + v[16]*x4 + v[21]*x5;
354653cca76cSShri Abhyankar       s3 -= v[2]*x1 + v[7]*x2 + v[12]*x3  + v[17]*x4 + v[22]*x5;
354753cca76cSShri Abhyankar       s4 -= v[3]*x1 + v[8]*x2 + v[13]*x3  + v[18]*x4 + v[23]*x5;
354853cca76cSShri Abhyankar       s5 -= v[4]*x1 + v[9]*x2 + v[14]*x3  + v[19]*x4 + v[24]*x5;
354953cca76cSShri Abhyankar       v    += 25;
355053cca76cSShri Abhyankar     }
355153cca76cSShri Abhyankar     /* x = inv_diagonal*x */
355253cca76cSShri Abhyankar     x[idt]   = v[0]*s1 + v[5]*s2 + v[10]*s3  + v[15]*s4 + v[20]*s5;
355353cca76cSShri Abhyankar     x[1+idt] = v[1]*s1 + v[6]*s2 + v[11]*s3  + v[16]*s4 + v[21]*s5;
355453cca76cSShri Abhyankar     x[2+idt] = v[2]*s1 + v[7]*s2 + v[12]*s3  + v[17]*s4 + v[22]*s5;
355553cca76cSShri Abhyankar     x[3+idt] = v[3]*s1 + v[8]*s2 + v[13]*s3  + v[18]*s4 + v[23]*s5;
355653cca76cSShri Abhyankar     x[4+idt] = v[4]*s1 + v[9]*s2 + v[14]*s3  + v[19]*s4 + v[24]*s5;
355753cca76cSShri Abhyankar   }
355853cca76cSShri Abhyankar 
355953cca76cSShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
356053cca76cSShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
356153cca76cSShri Abhyankar   ierr = PetscLogFlops(2.0*25*(a->nz) - 5.0*A->cmap->n);CHKERRQ(ierr);
356253cca76cSShri Abhyankar   PetscFunctionReturn(0);
356353cca76cSShri Abhyankar }
356453cca76cSShri Abhyankar 
356553cca76cSShri Abhyankar #undef __FUNCT__
356606e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_4_inplace"
356706e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_4_inplace(Mat A,Vec bb,Vec xx)
35684e2b4712SSatish Balay {
35694e2b4712SSatish Balay   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
35704e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
35716849ba73SBarry Smith   PetscErrorCode    ierr;
3572b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
3573b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
35745d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
3575d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3576d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,s4,x1,x2,x3,x4,*t;
3577d9fead3dSBarry Smith   const PetscScalar *b;
35784e2b4712SSatish Balay 
35794e2b4712SSatish Balay   PetscFunctionBegin;
3580d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
35811ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
3582f1af5d2fSBarry Smith   t  = a->solve_work;
35834e2b4712SSatish Balay 
35844e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
35854e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
35864e2b4712SSatish Balay 
35874e2b4712SSatish Balay   /* forward solve the lower triangular */
35884e2b4712SSatish Balay   idx    = 4*(*r++);
3589f1af5d2fSBarry Smith   t[0] = b[idx];   t[1] = b[1+idx];
3590f1af5d2fSBarry Smith   t[2] = b[2+idx]; t[3] = b[3+idx];
35914e2b4712SSatish Balay   for (i=1; i<n; i++) {
35924e2b4712SSatish Balay     v     = aa + 16*ai[i];
35934e2b4712SSatish Balay     vi    = aj + ai[i];
35944e2b4712SSatish Balay     nz    = diag[i] - ai[i];
35954e2b4712SSatish Balay     idx   = 4*(*r++);
3596f1af5d2fSBarry Smith     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
35974e2b4712SSatish Balay     while (nz--) {
35984e2b4712SSatish Balay       idx   = 4*(*vi++);
3599f1af5d2fSBarry Smith       x1    = t[idx];x2 = t[1+idx];x3 = t[2+idx];x4 = t[3+idx];
3600f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
3601f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
3602f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
3603f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
36044e2b4712SSatish Balay       v    += 16;
36054e2b4712SSatish Balay     }
36064e2b4712SSatish Balay     idx        = 4*i;
3607f1af5d2fSBarry Smith     t[idx]   = s1;t[1+idx] = s2;
3608f1af5d2fSBarry Smith     t[2+idx] = s3;t[3+idx] = s4;
36094e2b4712SSatish Balay   }
36104e2b4712SSatish Balay   /* backward solve the upper triangular */
36114e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
36124e2b4712SSatish Balay     v    = aa + 16*diag[i] + 16;
36134e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
36144e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
36154e2b4712SSatish Balay     idt  = 4*i;
3616f1af5d2fSBarry Smith     s1 = t[idt];  s2 = t[1+idt];
3617f1af5d2fSBarry Smith     s3 = t[2+idt];s4 = t[3+idt];
36184e2b4712SSatish Balay     while (nz--) {
36194e2b4712SSatish Balay       idx   = 4*(*vi++);
3620f1af5d2fSBarry Smith       x1    = t[idx];   x2 = t[1+idx];
3621f1af5d2fSBarry Smith       x3    = t[2+idx]; x4 = t[3+idx];
3622f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3   + v[12]*x4;
3623f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3   + v[13]*x4;
3624f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3  + v[14]*x4;
3625f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3  + v[15]*x4;
36264e2b4712SSatish Balay       v += 16;
36274e2b4712SSatish Balay     }
36284e2b4712SSatish Balay     idc      = 4*(*c--);
36294e2b4712SSatish Balay     v        = aa + 16*diag[i];
3630f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4;
3631f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4;
3632f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4;
3633f1af5d2fSBarry Smith     x[3+idc] = t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4;
36344e2b4712SSatish Balay   }
36354e2b4712SSatish Balay 
36364e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
36374e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
3638d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
36391ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3640dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
36414e2b4712SSatish Balay   PetscFunctionReturn(0);
36424e2b4712SSatish Balay }
3643f26ec98cSKris Buschelman 
36448f690400SShri Abhyankar #undef __FUNCT__
36454dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_4"
36464dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_4(Mat A,Vec bb,Vec xx)
364778bb4007SShri Abhyankar {
364878bb4007SShri Abhyankar   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
364978bb4007SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
365078bb4007SShri Abhyankar   PetscErrorCode    ierr;
3651b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
3652b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
365378bb4007SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
365478bb4007SShri Abhyankar   const MatScalar   *aa=a->a,*v;
365578bb4007SShri Abhyankar   PetscScalar       *x,s1,s2,s3,s4,x1,x2,x3,x4,*t;
365678bb4007SShri Abhyankar   const PetscScalar *b;
365778bb4007SShri Abhyankar 
365878bb4007SShri Abhyankar   PetscFunctionBegin;
365978bb4007SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
366078bb4007SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
366178bb4007SShri Abhyankar   t  = a->solve_work;
366278bb4007SShri Abhyankar 
366378bb4007SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
366478bb4007SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
366578bb4007SShri Abhyankar 
366678bb4007SShri Abhyankar   /* forward solve the lower triangular */
366778bb4007SShri Abhyankar   idx    = 4*r[0];
366878bb4007SShri Abhyankar   t[0] = b[idx];   t[1] = b[1+idx];
366978bb4007SShri Abhyankar   t[2] = b[2+idx]; t[3] = b[3+idx];
367078bb4007SShri Abhyankar   for (i=1; i<n; i++) {
367178bb4007SShri Abhyankar     v     = aa + 16*ai[i];
367278bb4007SShri Abhyankar     vi    = aj + ai[i];
367378bb4007SShri Abhyankar     nz    = ai[i+1] - ai[i];
367478bb4007SShri Abhyankar     idx   = 4*r[i];
367578bb4007SShri Abhyankar     s1  = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
367678bb4007SShri Abhyankar     for(m=0;m<nz;m++){
367778bb4007SShri Abhyankar       idx   = 4*vi[m];
367878bb4007SShri Abhyankar       x1    = t[idx];x2 = t[1+idx];x3 = t[2+idx];x4 = t[3+idx];
367978bb4007SShri Abhyankar       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
368078bb4007SShri Abhyankar       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
368178bb4007SShri Abhyankar       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
368278bb4007SShri Abhyankar       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
368378bb4007SShri Abhyankar       v    += 16;
368478bb4007SShri Abhyankar     }
368578bb4007SShri Abhyankar     idx        = 4*i;
368678bb4007SShri Abhyankar     t[idx]   = s1;t[1+idx] = s2;
368778bb4007SShri Abhyankar     t[2+idx] = s3;t[3+idx] = s4;
368878bb4007SShri Abhyankar   }
368978bb4007SShri Abhyankar   /* backward solve the upper triangular */
369078bb4007SShri Abhyankar   for (i=n-1; i>=0; i--){
369178bb4007SShri Abhyankar     v    = aa + 16*(adiag[i+1]+1);
369278bb4007SShri Abhyankar     vi   = aj + adiag[i+1]+1;
369378bb4007SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
369478bb4007SShri Abhyankar     idt  = 4*i;
369578bb4007SShri Abhyankar     s1 = t[idt];  s2 = t[1+idt];
369678bb4007SShri Abhyankar     s3 = t[2+idt];s4 = t[3+idt];
369778bb4007SShri Abhyankar     for(m=0;m<nz;m++){
369878bb4007SShri Abhyankar       idx   = 4*vi[m];
369978bb4007SShri Abhyankar       x1    = t[idx];   x2 = t[1+idx];
370078bb4007SShri Abhyankar       x3    = t[2+idx]; x4 = t[3+idx];
370178bb4007SShri Abhyankar       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3   + v[12]*x4;
370278bb4007SShri Abhyankar       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3   + v[13]*x4;
370378bb4007SShri Abhyankar       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3  + v[14]*x4;
370478bb4007SShri Abhyankar       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3  + v[15]*x4;
370578bb4007SShri Abhyankar       v += 16;
370678bb4007SShri Abhyankar     }
370778bb4007SShri Abhyankar     idc      = 4*c[i];
370878bb4007SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4;
370978bb4007SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4;
371078bb4007SShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4;
371178bb4007SShri Abhyankar     x[3+idc] = t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4;
371278bb4007SShri Abhyankar   }
371378bb4007SShri Abhyankar 
371478bb4007SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
371578bb4007SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
371678bb4007SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
371778bb4007SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
371878bb4007SShri Abhyankar   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
371978bb4007SShri Abhyankar   PetscFunctionReturn(0);
372078bb4007SShri Abhyankar }
372178bb4007SShri Abhyankar 
372278bb4007SShri Abhyankar #undef __FUNCT__
3723f26ec98cSKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_Demotion"
3724dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_Demotion(Mat A,Vec bb,Vec xx)
3725f26ec98cSKris Buschelman {
3726f26ec98cSKris Buschelman   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
3727f26ec98cSKris Buschelman   IS                iscol=a->col,isrow=a->row;
37286849ba73SBarry Smith   PetscErrorCode    ierr;
3729b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
3730b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
37315d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
3732d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
3733d9fead3dSBarry Smith   MatScalar         s1,s2,s3,s4,x1,x2,x3,x4,*t;
3734d9fead3dSBarry Smith   PetscScalar       *x;
3735d9fead3dSBarry Smith   const PetscScalar *b;
3736f26ec98cSKris Buschelman 
3737f26ec98cSKris Buschelman   PetscFunctionBegin;
3738d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
37391ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
3740f26ec98cSKris Buschelman   t  = (MatScalar *)a->solve_work;
3741f26ec98cSKris Buschelman 
3742f26ec98cSKris Buschelman   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
3743f26ec98cSKris Buschelman   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
3744f26ec98cSKris Buschelman 
3745f26ec98cSKris Buschelman   /* forward solve the lower triangular */
3746f26ec98cSKris Buschelman   idx    = 4*(*r++);
3747f26ec98cSKris Buschelman   t[0] = (MatScalar)b[idx];
3748f26ec98cSKris Buschelman   t[1] = (MatScalar)b[1+idx];
3749f26ec98cSKris Buschelman   t[2] = (MatScalar)b[2+idx];
3750f26ec98cSKris Buschelman   t[3] = (MatScalar)b[3+idx];
3751f26ec98cSKris Buschelman   for (i=1; i<n; i++) {
3752f26ec98cSKris Buschelman     v     = aa + 16*ai[i];
3753f26ec98cSKris Buschelman     vi    = aj + ai[i];
3754f26ec98cSKris Buschelman     nz    = diag[i] - ai[i];
3755f26ec98cSKris Buschelman     idx   = 4*(*r++);
3756f26ec98cSKris Buschelman     s1 = (MatScalar)b[idx];
3757f26ec98cSKris Buschelman     s2 = (MatScalar)b[1+idx];
3758f26ec98cSKris Buschelman     s3 = (MatScalar)b[2+idx];
3759f26ec98cSKris Buschelman     s4 = (MatScalar)b[3+idx];
3760f26ec98cSKris Buschelman     while (nz--) {
3761f26ec98cSKris Buschelman       idx   = 4*(*vi++);
3762f26ec98cSKris Buschelman       x1  = t[idx];
3763f26ec98cSKris Buschelman       x2  = t[1+idx];
3764f26ec98cSKris Buschelman       x3  = t[2+idx];
3765f26ec98cSKris Buschelman       x4  = t[3+idx];
3766f26ec98cSKris Buschelman       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
3767f26ec98cSKris Buschelman       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
3768f26ec98cSKris Buschelman       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
3769f26ec98cSKris Buschelman       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
3770f26ec98cSKris Buschelman       v    += 16;
3771f26ec98cSKris Buschelman     }
3772f26ec98cSKris Buschelman     idx        = 4*i;
3773f26ec98cSKris Buschelman     t[idx]   = s1;
3774f26ec98cSKris Buschelman     t[1+idx] = s2;
3775f26ec98cSKris Buschelman     t[2+idx] = s3;
3776f26ec98cSKris Buschelman     t[3+idx] = s4;
3777f26ec98cSKris Buschelman   }
3778f26ec98cSKris Buschelman   /* backward solve the upper triangular */
3779f26ec98cSKris Buschelman   for (i=n-1; i>=0; i--){
3780f26ec98cSKris Buschelman     v    = aa + 16*diag[i] + 16;
3781f26ec98cSKris Buschelman     vi   = aj + diag[i] + 1;
3782f26ec98cSKris Buschelman     nz   = ai[i+1] - diag[i] - 1;
3783f26ec98cSKris Buschelman     idt  = 4*i;
3784f26ec98cSKris Buschelman     s1 = t[idt];
3785f26ec98cSKris Buschelman     s2 = t[1+idt];
3786f26ec98cSKris Buschelman     s3 = t[2+idt];
3787f26ec98cSKris Buschelman     s4 = t[3+idt];
3788f26ec98cSKris Buschelman     while (nz--) {
3789f26ec98cSKris Buschelman       idx   = 4*(*vi++);
3790f26ec98cSKris Buschelman       x1  = t[idx];
3791f26ec98cSKris Buschelman       x2  = t[1+idx];
3792f26ec98cSKris Buschelman       x3  = t[2+idx];
3793f26ec98cSKris Buschelman       x4  = t[3+idx];
3794f26ec98cSKris Buschelman       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3   + v[12]*x4;
3795f26ec98cSKris Buschelman       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3   + v[13]*x4;
3796f26ec98cSKris Buschelman       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3  + v[14]*x4;
3797f26ec98cSKris Buschelman       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3  + v[15]*x4;
3798f26ec98cSKris Buschelman       v += 16;
3799f26ec98cSKris Buschelman     }
3800f26ec98cSKris Buschelman     idc      = 4*(*c--);
3801f26ec98cSKris Buschelman     v        = aa + 16*diag[i];
3802f26ec98cSKris Buschelman     t[idt]   = v[0]*s1+v[4]*s2+v[8]*s3+v[12]*s4;
3803f26ec98cSKris Buschelman     t[1+idt] = v[1]*s1+v[5]*s2+v[9]*s3+v[13]*s4;
3804f26ec98cSKris Buschelman     t[2+idt] = v[2]*s1+v[6]*s2+v[10]*s3+v[14]*s4;
3805f26ec98cSKris Buschelman     t[3+idt] = v[3]*s1+v[7]*s2+v[11]*s3+v[15]*s4;
3806f26ec98cSKris Buschelman     x[idc]   = (PetscScalar)t[idt];
3807f26ec98cSKris Buschelman     x[1+idc] = (PetscScalar)t[1+idt];
3808f26ec98cSKris Buschelman     x[2+idc] = (PetscScalar)t[2+idt];
3809f26ec98cSKris Buschelman     x[3+idc] = (PetscScalar)t[3+idt];
3810f26ec98cSKris Buschelman  }
3811f26ec98cSKris Buschelman 
3812f26ec98cSKris Buschelman   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
3813f26ec98cSKris Buschelman   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
3814d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
38151ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
3816dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
3817f26ec98cSKris Buschelman   PetscFunctionReturn(0);
3818f26ec98cSKris Buschelman }
3819f26ec98cSKris Buschelman 
382024c233c2SKris Buschelman #if defined (PETSC_HAVE_SSE)
382124c233c2SKris Buschelman 
382224c233c2SKris Buschelman #include PETSC_HAVE_SSE
382324c233c2SKris Buschelman 
382424c233c2SKris Buschelman #undef __FUNCT__
382524c233c2SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_SSE_Demotion"
3826dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_SSE_Demotion(Mat A,Vec bb,Vec xx)
382724c233c2SKris Buschelman {
382824c233c2SKris Buschelman   /*
382924c233c2SKris Buschelman      Note: This code uses demotion of double
383024c233c2SKris Buschelman      to float when performing the mixed-mode computation.
383124c233c2SKris Buschelman      This may not be numerically reasonable for all applications.
383224c233c2SKris Buschelman   */
383324c233c2SKris Buschelman   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ *)A->data;
383424c233c2SKris Buschelman   IS             iscol=a->col,isrow=a->row;
38356849ba73SBarry Smith   PetscErrorCode ierr;
38365d0c19d7SBarry Smith   PetscInt       i,n=a->mbs,*vi,*ai=a->i,*aj=a->j,nz,idx,idt,idc,ai16;
38375d0c19d7SBarry Smith   const PetscInt *r,*c,*diag = a->diag,*rout,*cout;
383824c233c2SKris Buschelman   MatScalar      *aa=a->a,*v;
383987828ca2SBarry Smith   PetscScalar    *x,*b,*t;
384024c233c2SKris Buschelman 
384124c233c2SKris Buschelman   /* Make space in temp stack for 16 Byte Aligned arrays */
384224c233c2SKris Buschelman   float           ssealignedspace[11],*tmps,*tmpx;
384324c233c2SKris Buschelman   unsigned long   offset;
384424c233c2SKris Buschelman 
384524c233c2SKris Buschelman   PetscFunctionBegin;
384624c233c2SKris Buschelman   SSE_SCOPE_BEGIN;
384724c233c2SKris Buschelman 
384824c233c2SKris Buschelman     offset = (unsigned long)ssealignedspace % 16;
384924c233c2SKris Buschelman     if (offset) offset = (16 - offset)/4;
385024c233c2SKris Buschelman     tmps = &ssealignedspace[offset];
385124c233c2SKris Buschelman     tmpx = &ssealignedspace[offset+4];
385224c233c2SKris Buschelman     PREFETCH_NTA(aa+16*ai[1]);
385324c233c2SKris Buschelman 
38541ebc52fbSHong Zhang     ierr = VecGetArray(bb,&b);CHKERRQ(ierr);
38551ebc52fbSHong Zhang     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
385624c233c2SKris Buschelman     t  = a->solve_work;
385724c233c2SKris Buschelman 
385824c233c2SKris Buschelman     ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
385924c233c2SKris Buschelman     ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
386024c233c2SKris Buschelman 
386124c233c2SKris Buschelman     /* forward solve the lower triangular */
386224c233c2SKris Buschelman     idx  = 4*(*r++);
386324c233c2SKris Buschelman     t[0] = b[idx];   t[1] = b[1+idx];
386424c233c2SKris Buschelman     t[2] = b[2+idx]; t[3] = b[3+idx];
386524c233c2SKris Buschelman     v    =  aa + 16*ai[1];
386624c233c2SKris Buschelman 
386724c233c2SKris Buschelman     for (i=1; i<n;) {
386824c233c2SKris Buschelman       PREFETCH_NTA(&v[8]);
386924c233c2SKris Buschelman       vi   =  aj      + ai[i];
387024c233c2SKris Buschelman       nz   =  diag[i] - ai[i];
387124c233c2SKris Buschelman       idx  =  4*(*r++);
387224c233c2SKris Buschelman 
387324c233c2SKris Buschelman       /* Demote sum from double to float */
387424c233c2SKris Buschelman       CONVERT_DOUBLE4_FLOAT4(tmps,&b[idx]);
387524c233c2SKris Buschelman       LOAD_PS(tmps,XMM7);
387624c233c2SKris Buschelman 
387724c233c2SKris Buschelman       while (nz--) {
387824c233c2SKris Buschelman         PREFETCH_NTA(&v[16]);
387924c233c2SKris Buschelman         idx = 4*(*vi++);
388024c233c2SKris Buschelman 
388124c233c2SKris Buschelman         /* Demote solution (so far) from double to float */
388224c233c2SKris Buschelman         CONVERT_DOUBLE4_FLOAT4(tmpx,&x[idx]);
388324c233c2SKris Buschelman 
388424c233c2SKris Buschelman         /* 4x4 Matrix-Vector product with negative accumulation: */
388524c233c2SKris Buschelman         SSE_INLINE_BEGIN_2(tmpx,v)
388624c233c2SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
388724c233c2SKris Buschelman 
388824c233c2SKris Buschelman           /* First Column */
388924c233c2SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
389024c233c2SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
389124c233c2SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
389224c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
389324c233c2SKris Buschelman 
389424c233c2SKris Buschelman           /* Second Column */
389524c233c2SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
389624c233c2SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
389724c233c2SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
389824c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
389924c233c2SKris Buschelman 
390024c233c2SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
390124c233c2SKris Buschelman 
390224c233c2SKris Buschelman           /* Third Column */
390324c233c2SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
390424c233c2SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
390524c233c2SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
390624c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
390724c233c2SKris Buschelman 
390824c233c2SKris Buschelman           /* Fourth Column */
390924c233c2SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
391024c233c2SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
391124c233c2SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
391224c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
391324c233c2SKris Buschelman         SSE_INLINE_END_2
391424c233c2SKris Buschelman 
391524c233c2SKris Buschelman         v  += 16;
391624c233c2SKris Buschelman       }
391724c233c2SKris Buschelman       idx = 4*i;
391824c233c2SKris Buschelman       v   = aa + 16*ai[++i];
391924c233c2SKris Buschelman       PREFETCH_NTA(v);
392024c233c2SKris Buschelman       STORE_PS(tmps,XMM7);
392124c233c2SKris Buschelman 
392224c233c2SKris Buschelman       /* Promote result from float to double */
392324c233c2SKris Buschelman       CONVERT_FLOAT4_DOUBLE4(&t[idx],tmps);
392424c233c2SKris Buschelman     }
392524c233c2SKris Buschelman     /* backward solve the upper triangular */
392624c233c2SKris Buschelman     idt  = 4*(n-1);
392724c233c2SKris Buschelman     ai16 = 16*diag[n-1];
392824c233c2SKris Buschelman     v    = aa + ai16 + 16;
392924c233c2SKris Buschelman     for (i=n-1; i>=0;){
393024c233c2SKris Buschelman       PREFETCH_NTA(&v[8]);
393124c233c2SKris Buschelman       vi = aj + diag[i] + 1;
393224c233c2SKris Buschelman       nz = ai[i+1] - diag[i] - 1;
393324c233c2SKris Buschelman 
393424c233c2SKris Buschelman       /* Demote accumulator from double to float */
393524c233c2SKris Buschelman       CONVERT_DOUBLE4_FLOAT4(tmps,&t[idt]);
393624c233c2SKris Buschelman       LOAD_PS(tmps,XMM7);
393724c233c2SKris Buschelman 
393824c233c2SKris Buschelman       while (nz--) {
393924c233c2SKris Buschelman         PREFETCH_NTA(&v[16]);
394024c233c2SKris Buschelman         idx = 4*(*vi++);
394124c233c2SKris Buschelman 
394224c233c2SKris Buschelman         /* Demote solution (so far) from double to float */
394324c233c2SKris Buschelman         CONVERT_DOUBLE4_FLOAT4(tmpx,&t[idx]);
394424c233c2SKris Buschelman 
394524c233c2SKris Buschelman         /* 4x4 Matrix-Vector Product with negative accumulation: */
394624c233c2SKris Buschelman         SSE_INLINE_BEGIN_2(tmpx,v)
394724c233c2SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
394824c233c2SKris Buschelman 
394924c233c2SKris Buschelman           /* First Column */
395024c233c2SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
395124c233c2SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
395224c233c2SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
395324c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
395424c233c2SKris Buschelman 
395524c233c2SKris Buschelman           /* Second Column */
395624c233c2SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
395724c233c2SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
395824c233c2SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
395924c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
396024c233c2SKris Buschelman 
396124c233c2SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
396224c233c2SKris Buschelman 
396324c233c2SKris Buschelman           /* Third Column */
396424c233c2SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
396524c233c2SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
396624c233c2SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
396724c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
396824c233c2SKris Buschelman 
396924c233c2SKris Buschelman           /* Fourth Column */
397024c233c2SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
397124c233c2SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
397224c233c2SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
397324c233c2SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
397424c233c2SKris Buschelman         SSE_INLINE_END_2
397524c233c2SKris Buschelman         v  += 16;
397624c233c2SKris Buschelman       }
397724c233c2SKris Buschelman       v    = aa + ai16;
397824c233c2SKris Buschelman       ai16 = 16*diag[--i];
397924c233c2SKris Buschelman       PREFETCH_NTA(aa+ai16+16);
398024c233c2SKris Buschelman       /*
398124c233c2SKris Buschelman          Scale the result by the diagonal 4x4 block,
398224c233c2SKris Buschelman          which was inverted as part of the factorization
398324c233c2SKris Buschelman       */
398424c233c2SKris Buschelman       SSE_INLINE_BEGIN_3(v,tmps,aa+ai16)
398524c233c2SKris Buschelman         /* First Column */
398624c233c2SKris Buschelman         SSE_COPY_PS(XMM0,XMM7)
398724c233c2SKris Buschelman         SSE_SHUFFLE(XMM0,XMM0,0x00)
398824c233c2SKris Buschelman         SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0)
398924c233c2SKris Buschelman 
399024c233c2SKris Buschelman         /* Second Column */
399124c233c2SKris Buschelman         SSE_COPY_PS(XMM1,XMM7)
399224c233c2SKris Buschelman         SSE_SHUFFLE(XMM1,XMM1,0x55)
399324c233c2SKris Buschelman         SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4)
399424c233c2SKris Buschelman         SSE_ADD_PS(XMM0,XMM1)
399524c233c2SKris Buschelman 
399624c233c2SKris Buschelman         SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24)
399724c233c2SKris Buschelman 
399824c233c2SKris Buschelman         /* Third Column */
399924c233c2SKris Buschelman         SSE_COPY_PS(XMM2,XMM7)
400024c233c2SKris Buschelman         SSE_SHUFFLE(XMM2,XMM2,0xAA)
400124c233c2SKris Buschelman         SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8)
400224c233c2SKris Buschelman         SSE_ADD_PS(XMM0,XMM2)
400324c233c2SKris Buschelman 
400424c233c2SKris Buschelman         /* Fourth Column */
400524c233c2SKris Buschelman         SSE_COPY_PS(XMM3,XMM7)
400624c233c2SKris Buschelman         SSE_SHUFFLE(XMM3,XMM3,0xFF)
400724c233c2SKris Buschelman         SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12)
400824c233c2SKris Buschelman         SSE_ADD_PS(XMM0,XMM3)
400924c233c2SKris Buschelman 
401024c233c2SKris Buschelman         SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0)
401124c233c2SKris Buschelman       SSE_INLINE_END_3
401224c233c2SKris Buschelman 
401324c233c2SKris Buschelman       /* Promote solution from float to double */
401424c233c2SKris Buschelman       CONVERT_FLOAT4_DOUBLE4(&t[idt],tmps);
401524c233c2SKris Buschelman 
401624c233c2SKris Buschelman       /* Apply reordering to t and stream into x.    */
401724c233c2SKris Buschelman       /* This way, x doesn't pollute the cache.      */
401824c233c2SKris Buschelman       /* Be careful with size: 2 doubles = 4 floats! */
401924c233c2SKris Buschelman       idc  = 4*(*c--);
402024c233c2SKris Buschelman       SSE_INLINE_BEGIN_2((float *)&t[idt],(float *)&x[idc])
402124c233c2SKris Buschelman         /*  x[idc]   = t[idt];   x[1+idc] = t[1+idc]; */
402224c233c2SKris Buschelman         SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM0)
402324c233c2SKris Buschelman         SSE_STREAM_PS(SSE_ARG_2,FLOAT_0,XMM0)
402424c233c2SKris Buschelman         /*  x[idc+2] = t[idt+2]; x[3+idc] = t[3+idc]; */
402524c233c2SKris Buschelman         SSE_LOAD_PS(SSE_ARG_1,FLOAT_4,XMM1)
402624c233c2SKris Buschelman         SSE_STREAM_PS(SSE_ARG_2,FLOAT_4,XMM1)
402724c233c2SKris Buschelman       SSE_INLINE_END_2
402824c233c2SKris Buschelman       v    = aa + ai16 + 16;
402924c233c2SKris Buschelman       idt -= 4;
403024c233c2SKris Buschelman     }
403124c233c2SKris Buschelman 
403224c233c2SKris Buschelman     ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
403324c233c2SKris Buschelman     ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
40341ebc52fbSHong Zhang     ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr);
40351ebc52fbSHong Zhang     ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4036dc0b31edSSatish Balay     ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
403724c233c2SKris Buschelman   SSE_SCOPE_END;
403824c233c2SKris Buschelman   PetscFunctionReturn(0);
403924c233c2SKris Buschelman }
404024c233c2SKris Buschelman 
404124c233c2SKris Buschelman #endif
40420ef38995SBarry Smith 
40430ef38995SBarry Smith 
40444e2b4712SSatish Balay /*
40454e2b4712SSatish Balay       Special case where the matrix was ILU(0) factored in the natural
40464e2b4712SSatish Balay    ordering. This eliminates the need for the column and row permutation.
40474e2b4712SSatish Balay */
40484a2ae208SSatish Balay #undef __FUNCT__
404906e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_inplace"
405006e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
40514e2b4712SSatish Balay {
40524e2b4712SSatish Balay   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
4053356650c2SBarry Smith   PetscInt          n=a->mbs;
4054356650c2SBarry Smith   const PetscInt    *ai=a->i,*aj=a->j;
4055dfbe8321SBarry Smith   PetscErrorCode    ierr;
4056356650c2SBarry Smith   const PetscInt    *diag = a->diag;
4057d9fead3dSBarry Smith   const MatScalar   *aa=a->a;
4058d9fead3dSBarry Smith   PetscScalar       *x;
4059d9fead3dSBarry Smith   const PetscScalar *b;
40604e2b4712SSatish Balay 
40614e2b4712SSatish Balay   PetscFunctionBegin;
4062d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
40631ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
40644e2b4712SSatish Balay 
4065aa482453SBarry Smith #if defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJBLAS)
40662853dc0eSBarry Smith   {
406787828ca2SBarry Smith     static PetscScalar w[2000]; /* very BAD need to fix */
40682853dc0eSBarry Smith     fortransolvebaij4blas_(&n,x,ai,aj,diag,aa,b,w);
40692853dc0eSBarry Smith   }
4070aa482453SBarry Smith #elif defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
40712853dc0eSBarry Smith   {
407287828ca2SBarry Smith     static PetscScalar w[2000]; /* very BAD need to fix */
40732853dc0eSBarry Smith     fortransolvebaij4_(&n,x,ai,aj,diag,aa,b,w);
40742853dc0eSBarry Smith   }
4075aa482453SBarry Smith #elif defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJUNROLL)
40762853dc0eSBarry Smith   fortransolvebaij4unroll_(&n,x,ai,aj,diag,aa,b);
4077e1293385SBarry Smith #else
407830d4dcafSBarry Smith   {
407987828ca2SBarry Smith     PetscScalar     s1,s2,s3,s4,x1,x2,x3,x4;
4080d9fead3dSBarry Smith     const MatScalar *v;
4081356650c2SBarry Smith     PetscInt        jdx,idt,idx,nz,i,ai16;
4082356650c2SBarry Smith     const PetscInt  *vi;
4083e1293385SBarry Smith 
40844e2b4712SSatish Balay   /* forward solve the lower triangular */
40854e2b4712SSatish Balay   idx    = 0;
4086e1293385SBarry Smith   x[0]   = b[0]; x[1] = b[1]; x[2] = b[2]; x[3] = b[3];
40874e2b4712SSatish Balay   for (i=1; i<n; i++) {
40884e2b4712SSatish Balay     v     =  aa      + 16*ai[i];
40894e2b4712SSatish Balay     vi    =  aj      + ai[i];
40904e2b4712SSatish Balay     nz    =  diag[i] - ai[i];
4091e1293385SBarry Smith     idx   +=  4;
4092f1af5d2fSBarry Smith     s1  =  b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
40934e2b4712SSatish Balay     while (nz--) {
40944e2b4712SSatish Balay       jdx   = 4*(*vi++);
40954e2b4712SSatish Balay       x1    = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];x4 = x[3+jdx];
4096f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
4097f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
4098f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4099f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
41004e2b4712SSatish Balay       v    += 16;
41014e2b4712SSatish Balay     }
4102f1af5d2fSBarry Smith     x[idx]   = s1;
4103f1af5d2fSBarry Smith     x[1+idx] = s2;
4104f1af5d2fSBarry Smith     x[2+idx] = s3;
4105f1af5d2fSBarry Smith     x[3+idx] = s4;
41064e2b4712SSatish Balay   }
41074e2b4712SSatish Balay   /* backward solve the upper triangular */
41084e555682SBarry Smith   idt = 4*(n-1);
41094e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
41104e555682SBarry Smith     ai16 = 16*diag[i];
41114e555682SBarry Smith     v    = aa + ai16 + 16;
41124e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
41134e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
4114f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt];
4115f1af5d2fSBarry Smith     s3 = x[2+idt];s4 = x[3+idt];
41164e2b4712SSatish Balay     while (nz--) {
41174e2b4712SSatish Balay       idx   = 4*(*vi++);
41184e2b4712SSatish Balay       x1    = x[idx];   x2 = x[1+idx];x3    = x[2+idx]; x4 = x[3+idx];
4119f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3   + v[12]*x4;
4120f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3   + v[13]*x4;
4121f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3  + v[14]*x4;
4122f1af5d2fSBarry Smith       s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3  + v[15]*x4;
41234e2b4712SSatish Balay       v    += 16;
41244e2b4712SSatish Balay     }
41254e555682SBarry Smith     v        = aa + ai16;
4126f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[4]*s2 + v[8]*s3  + v[12]*s4;
4127f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[5]*s2 + v[9]*s3  + v[13]*s4;
4128f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4;
4129f1af5d2fSBarry Smith     x[3+idt] = v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4;
4130329f5518SBarry Smith     idt -= 4;
41314e2b4712SSatish Balay   }
413230d4dcafSBarry Smith   }
4133e1293385SBarry Smith #endif
41344e2b4712SSatish Balay 
4135d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
41361ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4137dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
41384e2b4712SSatish Balay   PetscFunctionReturn(0);
41394e2b4712SSatish Balay }
41404e2b4712SSatish Balay 
4141b2b2dd24SShri Abhyankar #undef __FUNCT__
41424dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering"
41434dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering(Mat A,Vec bb,Vec xx)
4144b2b2dd24SShri Abhyankar {
4145b2b2dd24SShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
4146b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
4147b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,jdx,idt;
4148b2b2dd24SShri Abhyankar     PetscErrorCode    ierr;
4149b3260449SShri Abhyankar     const PetscInt    bs = A->rmap->bs,bs2 = a->bs2;
4150b2b2dd24SShri Abhyankar     const MatScalar   *aa=a->a,*v;
4151b2b2dd24SShri Abhyankar     PetscScalar       *x;
4152b2b2dd24SShri Abhyankar     const PetscScalar *b;
4153b2b2dd24SShri Abhyankar     PetscScalar       s1,s2,s3,s4,x1,x2,x3,x4;
4154cee9d6f2SShri Abhyankar 
4155b2b2dd24SShri Abhyankar     PetscFunctionBegin;
4156b2b2dd24SShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4157b2b2dd24SShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4158b2b2dd24SShri Abhyankar     /* forward solve the lower triangular */
4159b2b2dd24SShri Abhyankar     idx    = 0;
4160b2b2dd24SShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];x[3] = b[3+idx];
4161b2b2dd24SShri Abhyankar     for (i=1; i<n; i++) {
4162b2b2dd24SShri Abhyankar        v    = aa + bs2*ai[i];
4163b2b2dd24SShri Abhyankar        vi   = aj + ai[i];
4164b2b2dd24SShri Abhyankar        nz   = ai[i+1] - ai[i];
4165b2b2dd24SShri Abhyankar       idx   = bs*i;
4166b2b2dd24SShri Abhyankar        s1   = b[idx];s2 = b[1+idx];s3 = b[2+idx];s4 = b[3+idx];
4167b2b2dd24SShri Abhyankar       for(k=0;k<nz;k++) {
4168b2b2dd24SShri Abhyankar           jdx   = bs*vi[k];
4169b2b2dd24SShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];x4 =x[3+jdx];
4170b2b2dd24SShri Abhyankar           s1   -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4;
4171b2b2dd24SShri Abhyankar           s2   -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4;
4172b2b2dd24SShri Abhyankar           s3   -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4173b2b2dd24SShri Abhyankar 	  s4   -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
4174b2b2dd24SShri Abhyankar 
4175b2b2dd24SShri Abhyankar           v   +=  bs2;
4176b2b2dd24SShri Abhyankar         }
4177b2b2dd24SShri Abhyankar 
4178b2b2dd24SShri Abhyankar        x[idx]   = s1;
4179b2b2dd24SShri Abhyankar        x[1+idx] = s2;
4180b2b2dd24SShri Abhyankar        x[2+idx] = s3;
4181b2b2dd24SShri Abhyankar        x[3+idx] = s4;
4182b2b2dd24SShri Abhyankar     }
4183b2b2dd24SShri Abhyankar 
4184b2b2dd24SShri Abhyankar    /* backward solve the upper triangular */
4185b2b2dd24SShri Abhyankar   for (i=n-1; i>=0; i--){
4186b2b2dd24SShri Abhyankar     v   = aa + bs2*(adiag[i+1]+1);
4187b2b2dd24SShri Abhyankar      vi  = aj + adiag[i+1]+1;
4188b2b2dd24SShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
4189b2b2dd24SShri Abhyankar      idt = bs*i;
4190b2b2dd24SShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];s3 = x[2+idt];s4 = x[3+idt];
4191b2b2dd24SShri Abhyankar 
4192b2b2dd24SShri Abhyankar     for(k=0;k<nz;k++){
4193b2b2dd24SShri Abhyankar       idx   = bs*vi[k];
4194b2b2dd24SShri Abhyankar        x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];x4 = x[3+idx];
4195b2b2dd24SShri Abhyankar        s1   -= v[0]*x1 + v[4]*x2 + v[8]*x3 + v[12]*x4;
4196b2b2dd24SShri Abhyankar        s2   -= v[1]*x1 + v[5]*x2 + v[9]*x3 + v[13]*x4;
4197b2b2dd24SShri Abhyankar        s3   -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4198b2b2dd24SShri Abhyankar        s4   -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
4199b2b2dd24SShri Abhyankar 
4200b2b2dd24SShri Abhyankar         v   +=  bs2;
4201b2b2dd24SShri Abhyankar     }
4202b2b2dd24SShri Abhyankar     /* x = inv_diagonal*x */
4203b2b2dd24SShri Abhyankar    x[idt]   = v[0]*s1 + v[4]*s2 + v[8]*s3 + v[12]*s4;
4204b2b2dd24SShri Abhyankar    x[1+idt] = v[1]*s1 + v[5]*s2 + v[9]*s3 + v[13]*s4;;
4205b2b2dd24SShri Abhyankar    x[2+idt] = v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4;
4206b2b2dd24SShri Abhyankar    x[3+idt] = v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4;
4207b2b2dd24SShri Abhyankar 
4208b2b2dd24SShri Abhyankar   }
4209b2b2dd24SShri Abhyankar 
4210b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4211b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4212b2b2dd24SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
4213b2b2dd24SShri Abhyankar   PetscFunctionReturn(0);
4214b2b2dd24SShri Abhyankar }
4215cee9d6f2SShri Abhyankar 
4216cee9d6f2SShri Abhyankar #undef __FUNCT__
4217f26ec98cSKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_Demotion"
4218dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_Demotion(Mat A,Vec bb,Vec xx)
4219f26ec98cSKris Buschelman {
4220f26ec98cSKris Buschelman   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
4221b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*diag=a->diag;
4222dfbe8321SBarry Smith   PetscErrorCode    ierr;
4223b3260449SShri Abhyankar   const MatScalar   *aa=a->a;
4224b3260449SShri Abhyankar   const PetscScalar *b;
4225b3260449SShri Abhyankar   PetscScalar       *x;
4226f26ec98cSKris Buschelman 
4227f26ec98cSKris Buschelman   PetscFunctionBegin;
4228b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
42291ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4230f26ec98cSKris Buschelman 
4231f26ec98cSKris Buschelman   {
4232f26ec98cSKris Buschelman     MatScalar        s1,s2,s3,s4,x1,x2,x3,x4;
4233b3260449SShri Abhyankar     const MatScalar  *v;
4234b3260449SShri Abhyankar     MatScalar        *t=(MatScalar *)x;
4235b3260449SShri Abhyankar     PetscInt         jdx,idt,idx,nz,i,ai16;
4236b3260449SShri Abhyankar     const PetscInt   *vi;
4237f26ec98cSKris Buschelman 
4238f26ec98cSKris Buschelman     /* forward solve the lower triangular */
4239f26ec98cSKris Buschelman     idx  = 0;
4240f26ec98cSKris Buschelman     t[0] = (MatScalar)b[0];
4241f26ec98cSKris Buschelman     t[1] = (MatScalar)b[1];
4242f26ec98cSKris Buschelman     t[2] = (MatScalar)b[2];
4243f26ec98cSKris Buschelman     t[3] = (MatScalar)b[3];
4244f26ec98cSKris Buschelman     for (i=1; i<n; i++) {
4245f26ec98cSKris Buschelman       v     =  aa      + 16*ai[i];
4246f26ec98cSKris Buschelman       vi    =  aj      + ai[i];
4247f26ec98cSKris Buschelman       nz    =  diag[i] - ai[i];
4248f26ec98cSKris Buschelman       idx   +=  4;
4249f26ec98cSKris Buschelman       s1 = (MatScalar)b[idx];
4250f26ec98cSKris Buschelman       s2 = (MatScalar)b[1+idx];
4251f26ec98cSKris Buschelman       s3 = (MatScalar)b[2+idx];
4252f26ec98cSKris Buschelman       s4 = (MatScalar)b[3+idx];
4253f26ec98cSKris Buschelman       while (nz--) {
4254f26ec98cSKris Buschelman         jdx = 4*(*vi++);
4255f26ec98cSKris Buschelman         x1  = t[jdx];
4256f26ec98cSKris Buschelman         x2  = t[1+jdx];
4257f26ec98cSKris Buschelman         x3  = t[2+jdx];
4258f26ec98cSKris Buschelman         x4  = t[3+jdx];
4259f26ec98cSKris Buschelman         s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
4260f26ec98cSKris Buschelman         s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
4261f26ec98cSKris Buschelman         s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4262f26ec98cSKris Buschelman         s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
4263f26ec98cSKris Buschelman         v    += 16;
4264f26ec98cSKris Buschelman       }
4265f26ec98cSKris Buschelman       t[idx]   = s1;
4266f26ec98cSKris Buschelman       t[1+idx] = s2;
4267f26ec98cSKris Buschelman       t[2+idx] = s3;
4268f26ec98cSKris Buschelman       t[3+idx] = s4;
4269f26ec98cSKris Buschelman     }
4270f26ec98cSKris Buschelman     /* backward solve the upper triangular */
4271f26ec98cSKris Buschelman     idt = 4*(n-1);
4272f26ec98cSKris Buschelman     for (i=n-1; i>=0; i--){
4273f26ec98cSKris Buschelman       ai16 = 16*diag[i];
4274f26ec98cSKris Buschelman       v    = aa + ai16 + 16;
4275f26ec98cSKris Buschelman       vi   = aj + diag[i] + 1;
4276f26ec98cSKris Buschelman       nz   = ai[i+1] - diag[i] - 1;
4277f26ec98cSKris Buschelman       s1   = t[idt];
4278f26ec98cSKris Buschelman       s2   = t[1+idt];
4279f26ec98cSKris Buschelman       s3   = t[2+idt];
4280f26ec98cSKris Buschelman       s4   = t[3+idt];
4281f26ec98cSKris Buschelman       while (nz--) {
4282f26ec98cSKris Buschelman         idx = 4*(*vi++);
4283f26ec98cSKris Buschelman         x1  = (MatScalar)x[idx];
4284f26ec98cSKris Buschelman         x2  = (MatScalar)x[1+idx];
4285f26ec98cSKris Buschelman         x3  = (MatScalar)x[2+idx];
4286f26ec98cSKris Buschelman         x4  = (MatScalar)x[3+idx];
4287f26ec98cSKris Buschelman         s1 -= v[0]*x1 + v[4]*x2 + v[8]*x3  + v[12]*x4;
4288f26ec98cSKris Buschelman         s2 -= v[1]*x1 + v[5]*x2 + v[9]*x3  + v[13]*x4;
4289f26ec98cSKris Buschelman         s3 -= v[2]*x1 + v[6]*x2 + v[10]*x3 + v[14]*x4;
4290f26ec98cSKris Buschelman         s4 -= v[3]*x1 + v[7]*x2 + v[11]*x3 + v[15]*x4;
4291f26ec98cSKris Buschelman         v    += 16;
4292f26ec98cSKris Buschelman       }
4293f26ec98cSKris Buschelman       v        = aa + ai16;
4294f26ec98cSKris Buschelman       x[idt]   = (PetscScalar)(v[0]*s1 + v[4]*s2 + v[8]*s3  + v[12]*s4);
4295f26ec98cSKris Buschelman       x[1+idt] = (PetscScalar)(v[1]*s1 + v[5]*s2 + v[9]*s3  + v[13]*s4);
4296f26ec98cSKris Buschelman       x[2+idt] = (PetscScalar)(v[2]*s1 + v[6]*s2 + v[10]*s3 + v[14]*s4);
4297f26ec98cSKris Buschelman       x[3+idt] = (PetscScalar)(v[3]*s1 + v[7]*s2 + v[11]*s3 + v[15]*s4);
4298f26ec98cSKris Buschelman       idt -= 4;
4299f26ec98cSKris Buschelman     }
4300f26ec98cSKris Buschelman   }
4301f26ec98cSKris Buschelman 
4302b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
43031ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4304dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
4305f26ec98cSKris Buschelman   PetscFunctionReturn(0);
4306f26ec98cSKris Buschelman }
4307f26ec98cSKris Buschelman 
43083660e330SKris Buschelman #if defined (PETSC_HAVE_SSE)
43093660e330SKris Buschelman 
43103660e330SKris Buschelman #include PETSC_HAVE_SSE
43113660e330SKris Buschelman #undef __FUNCT__
43127cf1b8d3SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion_usj"
4313dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion_usj(Mat A,Vec bb,Vec xx)
43143660e330SKris Buschelman {
43153660e330SKris Buschelman   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ *)A->data;
43162aa5897fSKris Buschelman   unsigned short *aj=(unsigned short *)a->j;
4317dfbe8321SBarry Smith   PetscErrorCode ierr;
4318dfbe8321SBarry Smith   int            *ai=a->i,n=a->mbs,*diag = a->diag;
43193660e330SKris Buschelman   MatScalar      *aa=a->a;
432087828ca2SBarry Smith   PetscScalar    *x,*b;
43213660e330SKris Buschelman 
43223660e330SKris Buschelman   PetscFunctionBegin;
43233660e330SKris Buschelman   SSE_SCOPE_BEGIN;
43243660e330SKris Buschelman   /*
43253660e330SKris Buschelman      Note: This code currently uses demotion of double
43263660e330SKris Buschelman      to float when performing the mixed-mode computation.
43273660e330SKris Buschelman      This may not be numerically reasonable for all applications.
43283660e330SKris Buschelman   */
43293660e330SKris Buschelman   PREFETCH_NTA(aa+16*ai[1]);
43303660e330SKris Buschelman 
43311ebc52fbSHong Zhang   ierr = VecGetArray(bb,&b);CHKERRQ(ierr);
43321ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
43333660e330SKris Buschelman   {
4334eb05f457SKris Buschelman     /* x will first be computed in single precision then promoted inplace to double */
4335eb05f457SKris Buschelman     MatScalar      *v,*t=(MatScalar *)x;
43362aa5897fSKris Buschelman     int            nz,i,idt,ai16;
43372aa5897fSKris Buschelman     unsigned int   jdx,idx;
43382aa5897fSKris Buschelman     unsigned short *vi;
4339eb05f457SKris Buschelman     /* Forward solve the lower triangular factor. */
43403660e330SKris Buschelman 
4341eb05f457SKris Buschelman     /* First block is the identity. */
43423660e330SKris Buschelman     idx  = 0;
4343eb05f457SKris Buschelman     CONVERT_DOUBLE4_FLOAT4(t,b);
43442aa5897fSKris Buschelman     v    =  aa + 16*((unsigned int)ai[1]);
43453660e330SKris Buschelman 
43463660e330SKris Buschelman     for (i=1; i<n;) {
43473660e330SKris Buschelman       PREFETCH_NTA(&v[8]);
43483660e330SKris Buschelman       vi   =  aj      + ai[i];
43493660e330SKris Buschelman       nz   =  diag[i] - ai[i];
43503660e330SKris Buschelman       idx +=  4;
43513660e330SKris Buschelman 
4352eb05f457SKris Buschelman       /* Demote RHS from double to float. */
4353eb05f457SKris Buschelman       CONVERT_DOUBLE4_FLOAT4(&t[idx],&b[idx]);
4354eb05f457SKris Buschelman       LOAD_PS(&t[idx],XMM7);
43553660e330SKris Buschelman 
43563660e330SKris Buschelman       while (nz--) {
43573660e330SKris Buschelman         PREFETCH_NTA(&v[16]);
43582aa5897fSKris Buschelman         jdx = 4*((unsigned int)(*vi++));
43593660e330SKris Buschelman 
43603660e330SKris Buschelman         /* 4x4 Matrix-Vector product with negative accumulation: */
4361eb05f457SKris Buschelman         SSE_INLINE_BEGIN_2(&t[jdx],v)
43623660e330SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
43633660e330SKris Buschelman 
43643660e330SKris Buschelman           /* First Column */
43653660e330SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
43663660e330SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
43673660e330SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
43683660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
43693660e330SKris Buschelman 
43703660e330SKris Buschelman           /* Second Column */
43713660e330SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
43723660e330SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
43733660e330SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
43743660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
43753660e330SKris Buschelman 
43763660e330SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
43773660e330SKris Buschelman 
43783660e330SKris Buschelman           /* Third Column */
43793660e330SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
43803660e330SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
43813660e330SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
43823660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
43833660e330SKris Buschelman 
43843660e330SKris Buschelman           /* Fourth Column */
43853660e330SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
43863660e330SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
43873660e330SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
43883660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
43893660e330SKris Buschelman         SSE_INLINE_END_2
43903660e330SKris Buschelman 
43913660e330SKris Buschelman         v  += 16;
43923660e330SKris Buschelman       }
43933660e330SKris Buschelman       v    =  aa + 16*ai[++i];
43943660e330SKris Buschelman       PREFETCH_NTA(v);
4395eb05f457SKris Buschelman       STORE_PS(&t[idx],XMM7);
43963660e330SKris Buschelman     }
4397eb05f457SKris Buschelman 
4398eb05f457SKris Buschelman     /* Backward solve the upper triangular factor.*/
4399eb05f457SKris Buschelman 
44003660e330SKris Buschelman     idt  = 4*(n-1);
44013660e330SKris Buschelman     ai16 = 16*diag[n-1];
44023660e330SKris Buschelman     v    = aa + ai16 + 16;
44033660e330SKris Buschelman     for (i=n-1; i>=0;){
44043660e330SKris Buschelman       PREFETCH_NTA(&v[8]);
44053660e330SKris Buschelman       vi = aj + diag[i] + 1;
44063660e330SKris Buschelman       nz = ai[i+1] - diag[i] - 1;
44073660e330SKris Buschelman 
4408eb05f457SKris Buschelman       LOAD_PS(&t[idt],XMM7);
44093660e330SKris Buschelman 
44103660e330SKris Buschelman       while (nz--) {
44113660e330SKris Buschelman         PREFETCH_NTA(&v[16]);
44122aa5897fSKris Buschelman         idx = 4*((unsigned int)(*vi++));
44133660e330SKris Buschelman 
44143660e330SKris Buschelman         /* 4x4 Matrix-Vector Product with negative accumulation: */
4415eb05f457SKris Buschelman         SSE_INLINE_BEGIN_2(&t[idx],v)
44163660e330SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
44173660e330SKris Buschelman 
44183660e330SKris Buschelman           /* First Column */
44193660e330SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
44203660e330SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
44213660e330SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
44223660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
44233660e330SKris Buschelman 
44243660e330SKris Buschelman           /* Second Column */
44253660e330SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
44263660e330SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
44273660e330SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
44283660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
44293660e330SKris Buschelman 
44303660e330SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
44313660e330SKris Buschelman 
44323660e330SKris Buschelman           /* Third Column */
44333660e330SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
44343660e330SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
44353660e330SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
44363660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
44373660e330SKris Buschelman 
44383660e330SKris Buschelman           /* Fourth Column */
44393660e330SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
44403660e330SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
44413660e330SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
44423660e330SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
44433660e330SKris Buschelman         SSE_INLINE_END_2
44443660e330SKris Buschelman         v  += 16;
44453660e330SKris Buschelman       }
44463660e330SKris Buschelman       v    = aa + ai16;
44473660e330SKris Buschelman       ai16 = 16*diag[--i];
44483660e330SKris Buschelman       PREFETCH_NTA(aa+ai16+16);
44493660e330SKris Buschelman       /*
44503660e330SKris Buschelman          Scale the result by the diagonal 4x4 block,
44513660e330SKris Buschelman          which was inverted as part of the factorization
44523660e330SKris Buschelman       */
4453eb05f457SKris Buschelman       SSE_INLINE_BEGIN_3(v,&t[idt],aa+ai16)
44543660e330SKris Buschelman         /* First Column */
44553660e330SKris Buschelman         SSE_COPY_PS(XMM0,XMM7)
44563660e330SKris Buschelman         SSE_SHUFFLE(XMM0,XMM0,0x00)
44573660e330SKris Buschelman         SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0)
44583660e330SKris Buschelman 
44593660e330SKris Buschelman         /* Second Column */
44603660e330SKris Buschelman         SSE_COPY_PS(XMM1,XMM7)
44613660e330SKris Buschelman         SSE_SHUFFLE(XMM1,XMM1,0x55)
44623660e330SKris Buschelman         SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4)
44633660e330SKris Buschelman         SSE_ADD_PS(XMM0,XMM1)
44643660e330SKris Buschelman 
44653660e330SKris Buschelman         SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24)
44663660e330SKris Buschelman 
44673660e330SKris Buschelman         /* Third Column */
44683660e330SKris Buschelman         SSE_COPY_PS(XMM2,XMM7)
44693660e330SKris Buschelman         SSE_SHUFFLE(XMM2,XMM2,0xAA)
44703660e330SKris Buschelman         SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8)
44713660e330SKris Buschelman         SSE_ADD_PS(XMM0,XMM2)
44723660e330SKris Buschelman 
44733660e330SKris Buschelman         /* Fourth Column */
44743660e330SKris Buschelman         SSE_COPY_PS(XMM3,XMM7)
44753660e330SKris Buschelman         SSE_SHUFFLE(XMM3,XMM3,0xFF)
44763660e330SKris Buschelman         SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12)
44773660e330SKris Buschelman         SSE_ADD_PS(XMM0,XMM3)
44783660e330SKris Buschelman 
44793660e330SKris Buschelman         SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0)
44803660e330SKris Buschelman       SSE_INLINE_END_3
44813660e330SKris Buschelman 
44823660e330SKris Buschelman       v    = aa + ai16 + 16;
44833660e330SKris Buschelman       idt -= 4;
44843660e330SKris Buschelman     }
4485eb05f457SKris Buschelman 
4486eb05f457SKris Buschelman     /* Convert t from single precision back to double precision (inplace)*/
4487eb05f457SKris Buschelman     idt = 4*(n-1);
4488eb05f457SKris Buschelman     for (i=n-1;i>=0;i--) {
4489eb05f457SKris Buschelman       /*     CONVERT_FLOAT4_DOUBLE4(&x[idt],&t[idt]); */
4490eb05f457SKris Buschelman       /* Unfortunately, CONVERT_ will count from 0 to 3 which doesn't work here. */
4491eb05f457SKris Buschelman       PetscScalar *xtemp=&x[idt];
4492eb05f457SKris Buschelman       MatScalar   *ttemp=&t[idt];
4493eb05f457SKris Buschelman       xtemp[3] = (PetscScalar)ttemp[3];
4494eb05f457SKris Buschelman       xtemp[2] = (PetscScalar)ttemp[2];
4495eb05f457SKris Buschelman       xtemp[1] = (PetscScalar)ttemp[1];
4496eb05f457SKris Buschelman       xtemp[0] = (PetscScalar)ttemp[0];
449754693613SKris Buschelman       idt -= 4;
44983660e330SKris Buschelman     }
4499eb05f457SKris Buschelman 
4500eb05f457SKris Buschelman   } /* End of artificial scope. */
45011ebc52fbSHong Zhang   ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr);
45021ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4503dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
45043660e330SKris Buschelman   SSE_SCOPE_END;
45053660e330SKris Buschelman   PetscFunctionReturn(0);
45063660e330SKris Buschelman }
45073660e330SKris Buschelman 
45087cf1b8d3SKris Buschelman #undef __FUNCT__
45097cf1b8d3SKris Buschelman #define __FUNCT__ "MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion"
4510dfbe8321SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_4_NaturalOrdering_SSE_Demotion(Mat A,Vec bb,Vec xx)
45117cf1b8d3SKris Buschelman {
45127cf1b8d3SKris Buschelman   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ *)A->data;
45137cf1b8d3SKris Buschelman   int            *aj=a->j;
4514dfbe8321SBarry Smith   PetscErrorCode ierr;
4515dfbe8321SBarry Smith   int            *ai=a->i,n=a->mbs,*diag = a->diag;
45167cf1b8d3SKris Buschelman   MatScalar      *aa=a->a;
45177cf1b8d3SKris Buschelman   PetscScalar    *x,*b;
45187cf1b8d3SKris Buschelman 
45197cf1b8d3SKris Buschelman   PetscFunctionBegin;
45207cf1b8d3SKris Buschelman   SSE_SCOPE_BEGIN;
45217cf1b8d3SKris Buschelman   /*
45227cf1b8d3SKris Buschelman      Note: This code currently uses demotion of double
45237cf1b8d3SKris Buschelman      to float when performing the mixed-mode computation.
45247cf1b8d3SKris Buschelman      This may not be numerically reasonable for all applications.
45257cf1b8d3SKris Buschelman   */
45267cf1b8d3SKris Buschelman   PREFETCH_NTA(aa+16*ai[1]);
45277cf1b8d3SKris Buschelman 
45281ebc52fbSHong Zhang   ierr = VecGetArray(bb,&b);CHKERRQ(ierr);
45291ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
45307cf1b8d3SKris Buschelman   {
45317cf1b8d3SKris Buschelman     /* x will first be computed in single precision then promoted inplace to double */
45327cf1b8d3SKris Buschelman     MatScalar *v,*t=(MatScalar *)x;
45337cf1b8d3SKris Buschelman     int       nz,i,idt,ai16;
45347cf1b8d3SKris Buschelman     int       jdx,idx;
45357cf1b8d3SKris Buschelman     int       *vi;
45367cf1b8d3SKris Buschelman     /* Forward solve the lower triangular factor. */
45377cf1b8d3SKris Buschelman 
45387cf1b8d3SKris Buschelman     /* First block is the identity. */
45397cf1b8d3SKris Buschelman     idx  = 0;
45407cf1b8d3SKris Buschelman     CONVERT_DOUBLE4_FLOAT4(t,b);
45417cf1b8d3SKris Buschelman     v    =  aa + 16*ai[1];
45427cf1b8d3SKris Buschelman 
45437cf1b8d3SKris Buschelman     for (i=1; i<n;) {
45447cf1b8d3SKris Buschelman       PREFETCH_NTA(&v[8]);
45457cf1b8d3SKris Buschelman       vi   =  aj      + ai[i];
45467cf1b8d3SKris Buschelman       nz   =  diag[i] - ai[i];
45477cf1b8d3SKris Buschelman       idx +=  4;
45487cf1b8d3SKris Buschelman 
45497cf1b8d3SKris Buschelman       /* Demote RHS from double to float. */
45507cf1b8d3SKris Buschelman       CONVERT_DOUBLE4_FLOAT4(&t[idx],&b[idx]);
45517cf1b8d3SKris Buschelman       LOAD_PS(&t[idx],XMM7);
45527cf1b8d3SKris Buschelman 
45537cf1b8d3SKris Buschelman       while (nz--) {
45547cf1b8d3SKris Buschelman         PREFETCH_NTA(&v[16]);
45557cf1b8d3SKris Buschelman         jdx = 4*(*vi++);
45567cf1b8d3SKris Buschelman /*          jdx = *vi++; */
45577cf1b8d3SKris Buschelman 
45587cf1b8d3SKris Buschelman         /* 4x4 Matrix-Vector product with negative accumulation: */
45597cf1b8d3SKris Buschelman         SSE_INLINE_BEGIN_2(&t[jdx],v)
45607cf1b8d3SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
45617cf1b8d3SKris Buschelman 
45627cf1b8d3SKris Buschelman           /* First Column */
45637cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
45647cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
45657cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
45667cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
45677cf1b8d3SKris Buschelman 
45687cf1b8d3SKris Buschelman           /* Second Column */
45697cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
45707cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
45717cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
45727cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
45737cf1b8d3SKris Buschelman 
45747cf1b8d3SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
45757cf1b8d3SKris Buschelman 
45767cf1b8d3SKris Buschelman           /* Third Column */
45777cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
45787cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
45797cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
45807cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
45817cf1b8d3SKris Buschelman 
45827cf1b8d3SKris Buschelman           /* Fourth Column */
45837cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
45847cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
45857cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
45867cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
45877cf1b8d3SKris Buschelman         SSE_INLINE_END_2
45887cf1b8d3SKris Buschelman 
45897cf1b8d3SKris Buschelman         v  += 16;
45907cf1b8d3SKris Buschelman       }
45917cf1b8d3SKris Buschelman       v    =  aa + 16*ai[++i];
45927cf1b8d3SKris Buschelman       PREFETCH_NTA(v);
45937cf1b8d3SKris Buschelman       STORE_PS(&t[idx],XMM7);
45947cf1b8d3SKris Buschelman     }
45957cf1b8d3SKris Buschelman 
45967cf1b8d3SKris Buschelman     /* Backward solve the upper triangular factor.*/
45977cf1b8d3SKris Buschelman 
45987cf1b8d3SKris Buschelman     idt  = 4*(n-1);
45997cf1b8d3SKris Buschelman     ai16 = 16*diag[n-1];
46007cf1b8d3SKris Buschelman     v    = aa + ai16 + 16;
46017cf1b8d3SKris Buschelman     for (i=n-1; i>=0;){
46027cf1b8d3SKris Buschelman       PREFETCH_NTA(&v[8]);
46037cf1b8d3SKris Buschelman       vi = aj + diag[i] + 1;
46047cf1b8d3SKris Buschelman       nz = ai[i+1] - diag[i] - 1;
46057cf1b8d3SKris Buschelman 
46067cf1b8d3SKris Buschelman       LOAD_PS(&t[idt],XMM7);
46077cf1b8d3SKris Buschelman 
46087cf1b8d3SKris Buschelman       while (nz--) {
46097cf1b8d3SKris Buschelman         PREFETCH_NTA(&v[16]);
46107cf1b8d3SKris Buschelman         idx = 4*(*vi++);
46117cf1b8d3SKris Buschelman /*          idx = *vi++; */
46127cf1b8d3SKris Buschelman 
46137cf1b8d3SKris Buschelman         /* 4x4 Matrix-Vector Product with negative accumulation: */
46147cf1b8d3SKris Buschelman         SSE_INLINE_BEGIN_2(&t[idx],v)
46157cf1b8d3SKris Buschelman           SSE_LOAD_PS(SSE_ARG_1,FLOAT_0,XMM6)
46167cf1b8d3SKris Buschelman 
46177cf1b8d3SKris Buschelman           /* First Column */
46187cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM0,XMM6)
46197cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM0,XMM0,0x00)
46207cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM0,SSE_ARG_2,FLOAT_0)
46217cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM0)
46227cf1b8d3SKris Buschelman 
46237cf1b8d3SKris Buschelman           /* Second Column */
46247cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM1,XMM6)
46257cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM1,XMM1,0x55)
46267cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM1,SSE_ARG_2,FLOAT_4)
46277cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM1)
46287cf1b8d3SKris Buschelman 
46297cf1b8d3SKris Buschelman           SSE_PREFETCH_NTA(SSE_ARG_2,FLOAT_24)
46307cf1b8d3SKris Buschelman 
46317cf1b8d3SKris Buschelman           /* Third Column */
46327cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM2,XMM6)
46337cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM2,XMM2,0xAA)
46347cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM2,SSE_ARG_2,FLOAT_8)
46357cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM2)
46367cf1b8d3SKris Buschelman 
46377cf1b8d3SKris Buschelman           /* Fourth Column */
46387cf1b8d3SKris Buschelman           SSE_COPY_PS(XMM3,XMM6)
46397cf1b8d3SKris Buschelman           SSE_SHUFFLE(XMM3,XMM3,0xFF)
46407cf1b8d3SKris Buschelman           SSE_MULT_PS_M(XMM3,SSE_ARG_2,FLOAT_12)
46417cf1b8d3SKris Buschelman           SSE_SUB_PS(XMM7,XMM3)
46427cf1b8d3SKris Buschelman         SSE_INLINE_END_2
46437cf1b8d3SKris Buschelman         v  += 16;
46447cf1b8d3SKris Buschelman       }
46457cf1b8d3SKris Buschelman       v    = aa + ai16;
46467cf1b8d3SKris Buschelman       ai16 = 16*diag[--i];
46477cf1b8d3SKris Buschelman       PREFETCH_NTA(aa+ai16+16);
46487cf1b8d3SKris Buschelman       /*
46497cf1b8d3SKris Buschelman          Scale the result by the diagonal 4x4 block,
46507cf1b8d3SKris Buschelman          which was inverted as part of the factorization
46517cf1b8d3SKris Buschelman       */
46527cf1b8d3SKris Buschelman       SSE_INLINE_BEGIN_3(v,&t[idt],aa+ai16)
46537cf1b8d3SKris Buschelman         /* First Column */
46547cf1b8d3SKris Buschelman         SSE_COPY_PS(XMM0,XMM7)
46557cf1b8d3SKris Buschelman         SSE_SHUFFLE(XMM0,XMM0,0x00)
46567cf1b8d3SKris Buschelman         SSE_MULT_PS_M(XMM0,SSE_ARG_1,FLOAT_0)
46577cf1b8d3SKris Buschelman 
46587cf1b8d3SKris Buschelman         /* Second Column */
46597cf1b8d3SKris Buschelman         SSE_COPY_PS(XMM1,XMM7)
46607cf1b8d3SKris Buschelman         SSE_SHUFFLE(XMM1,XMM1,0x55)
46617cf1b8d3SKris Buschelman         SSE_MULT_PS_M(XMM1,SSE_ARG_1,FLOAT_4)
46627cf1b8d3SKris Buschelman         SSE_ADD_PS(XMM0,XMM1)
46637cf1b8d3SKris Buschelman 
46647cf1b8d3SKris Buschelman         SSE_PREFETCH_NTA(SSE_ARG_3,FLOAT_24)
46657cf1b8d3SKris Buschelman 
46667cf1b8d3SKris Buschelman         /* Third Column */
46677cf1b8d3SKris Buschelman         SSE_COPY_PS(XMM2,XMM7)
46687cf1b8d3SKris Buschelman         SSE_SHUFFLE(XMM2,XMM2,0xAA)
46697cf1b8d3SKris Buschelman         SSE_MULT_PS_M(XMM2,SSE_ARG_1,FLOAT_8)
46707cf1b8d3SKris Buschelman         SSE_ADD_PS(XMM0,XMM2)
46717cf1b8d3SKris Buschelman 
46727cf1b8d3SKris Buschelman         /* Fourth Column */
46737cf1b8d3SKris Buschelman         SSE_COPY_PS(XMM3,XMM7)
46747cf1b8d3SKris Buschelman         SSE_SHUFFLE(XMM3,XMM3,0xFF)
46757cf1b8d3SKris Buschelman         SSE_MULT_PS_M(XMM3,SSE_ARG_1,FLOAT_12)
46767cf1b8d3SKris Buschelman         SSE_ADD_PS(XMM0,XMM3)
46777cf1b8d3SKris Buschelman 
46787cf1b8d3SKris Buschelman         SSE_STORE_PS(SSE_ARG_2,FLOAT_0,XMM0)
46797cf1b8d3SKris Buschelman       SSE_INLINE_END_3
46807cf1b8d3SKris Buschelman 
46817cf1b8d3SKris Buschelman       v    = aa + ai16 + 16;
46827cf1b8d3SKris Buschelman       idt -= 4;
46837cf1b8d3SKris Buschelman     }
46847cf1b8d3SKris Buschelman 
46857cf1b8d3SKris Buschelman     /* Convert t from single precision back to double precision (inplace)*/
46867cf1b8d3SKris Buschelman     idt = 4*(n-1);
46877cf1b8d3SKris Buschelman     for (i=n-1;i>=0;i--) {
46887cf1b8d3SKris Buschelman       /*     CONVERT_FLOAT4_DOUBLE4(&x[idt],&t[idt]); */
46897cf1b8d3SKris Buschelman       /* Unfortunately, CONVERT_ will count from 0 to 3 which doesn't work here. */
46907cf1b8d3SKris Buschelman       PetscScalar *xtemp=&x[idt];
46917cf1b8d3SKris Buschelman       MatScalar   *ttemp=&t[idt];
46927cf1b8d3SKris Buschelman       xtemp[3] = (PetscScalar)ttemp[3];
46937cf1b8d3SKris Buschelman       xtemp[2] = (PetscScalar)ttemp[2];
46947cf1b8d3SKris Buschelman       xtemp[1] = (PetscScalar)ttemp[1];
46957cf1b8d3SKris Buschelman       xtemp[0] = (PetscScalar)ttemp[0];
46967cf1b8d3SKris Buschelman       idt -= 4;
46977cf1b8d3SKris Buschelman     }
46987cf1b8d3SKris Buschelman 
46997cf1b8d3SKris Buschelman   } /* End of artificial scope. */
47001ebc52fbSHong Zhang   ierr = VecRestoreArray(bb,&b);CHKERRQ(ierr);
47011ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4702dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*16*(a->nz) - 4.0*A->cmap->n);CHKERRQ(ierr);
47037cf1b8d3SKris Buschelman   SSE_SCOPE_END;
47047cf1b8d3SKris Buschelman   PetscFunctionReturn(0);
47057cf1b8d3SKris Buschelman }
47067cf1b8d3SKris Buschelman 
47073660e330SKris Buschelman #endif
47088f690400SShri Abhyankar 
47094a2ae208SSatish Balay #undef __FUNCT__
471006e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_3_inplace"
471106e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_3_inplace(Mat A,Vec bb,Vec xx)
47124e2b4712SSatish Balay {
47134e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
47144e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
47156849ba73SBarry Smith   PetscErrorCode    ierr;
4716b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
4717b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
47185d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
4719d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
4720d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,x1,x2,x3,*t;
4721d9fead3dSBarry Smith   const PetscScalar *b;
47224e2b4712SSatish Balay 
47234e2b4712SSatish Balay   PetscFunctionBegin;
4724d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
47251ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4726f1af5d2fSBarry Smith   t  = a->solve_work;
47274e2b4712SSatish Balay 
47284e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
47294e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
47304e2b4712SSatish Balay 
47314e2b4712SSatish Balay   /* forward solve the lower triangular */
47324e2b4712SSatish Balay   idx    = 3*(*r++);
4733f1af5d2fSBarry Smith   t[0] = b[idx]; t[1] = b[1+idx]; t[2] = b[2+idx];
47344e2b4712SSatish Balay   for (i=1; i<n; i++) {
47354e2b4712SSatish Balay     v     = aa + 9*ai[i];
47364e2b4712SSatish Balay     vi    = aj + ai[i];
47374e2b4712SSatish Balay     nz    = diag[i] - ai[i];
47384e2b4712SSatish Balay     idx   = 3*(*r++);
4739f1af5d2fSBarry Smith     s1  = b[idx]; s2 = b[1+idx]; s3 = b[2+idx];
47404e2b4712SSatish Balay     while (nz--) {
47414e2b4712SSatish Balay       idx   = 3*(*vi++);
4742f1af5d2fSBarry Smith       x1    = t[idx]; x2 = t[1+idx]; x3 = t[2+idx];
4743f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4744f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4745f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
47464e2b4712SSatish Balay       v += 9;
47474e2b4712SSatish Balay     }
47484e2b4712SSatish Balay     idx = 3*i;
4749f1af5d2fSBarry Smith     t[idx] = s1; t[1+idx] = s2; t[2+idx] = s3;
47504e2b4712SSatish Balay   }
47514e2b4712SSatish Balay   /* backward solve the upper triangular */
47524e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
47534e2b4712SSatish Balay     v    = aa + 9*diag[i] + 9;
47544e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
47554e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
47564e2b4712SSatish Balay     idt  = 3*i;
4757f1af5d2fSBarry Smith     s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt];
47584e2b4712SSatish Balay     while (nz--) {
47594e2b4712SSatish Balay       idx   = 3*(*vi++);
4760f1af5d2fSBarry Smith       x1    = t[idx]; x2 = t[1+idx]; x3 = t[2+idx];
4761f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4762f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4763f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
47644e2b4712SSatish Balay       v += 9;
47654e2b4712SSatish Balay     }
47664e2b4712SSatish Balay     idc = 3*(*c--);
47674e2b4712SSatish Balay     v   = aa + 9*diag[i];
4768f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1 + v[3]*s2 + v[6]*s3;
4769f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3;
4770f1af5d2fSBarry Smith     x[2+idc] = t[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3;
47714e2b4712SSatish Balay   }
47724e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
47734e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
4774d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
47751ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4776dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr);
47774e2b4712SSatish Balay   PetscFunctionReturn(0);
47784e2b4712SSatish Balay }
47794e2b4712SSatish Balay 
47800c4413a7SShri Abhyankar #undef __FUNCT__
47814dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_3"
47824dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_3(Mat A,Vec bb,Vec xx)
47830c4413a7SShri Abhyankar {
47840c4413a7SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
47850c4413a7SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
47860c4413a7SShri Abhyankar   PetscErrorCode    ierr;
4787b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
4788b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc,m;
47890c4413a7SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
47900c4413a7SShri Abhyankar   const MatScalar   *aa=a->a,*v;
47910c4413a7SShri Abhyankar   PetscScalar       *x,s1,s2,s3,x1,x2,x3,*t;
47920c4413a7SShri Abhyankar   const PetscScalar *b;
47930c4413a7SShri Abhyankar 
47940c4413a7SShri Abhyankar   PetscFunctionBegin;
47950c4413a7SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
47960c4413a7SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
47970c4413a7SShri Abhyankar   t  = a->solve_work;
47980c4413a7SShri Abhyankar 
47990c4413a7SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
48000c4413a7SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
48010c4413a7SShri Abhyankar 
48020c4413a7SShri Abhyankar   /* forward solve the lower triangular */
48030c4413a7SShri Abhyankar   idx    = 3*r[0];
48040c4413a7SShri Abhyankar   t[0] = b[idx]; t[1] = b[1+idx]; t[2] = b[2+idx];
48050c4413a7SShri Abhyankar   for (i=1; i<n; i++) {
48060c4413a7SShri Abhyankar     v     = aa + 9*ai[i];
48070c4413a7SShri Abhyankar     vi    = aj + ai[i];
48080c4413a7SShri Abhyankar     nz    = ai[i+1] - ai[i];
48090c4413a7SShri Abhyankar     idx   = 3*r[i];
48100c4413a7SShri Abhyankar     s1  = b[idx]; s2 = b[1+idx]; s3 = b[2+idx];
48110c4413a7SShri Abhyankar     for(m=0;m<nz;m++){
48120c4413a7SShri Abhyankar       idx   = 3*vi[m];
48130c4413a7SShri Abhyankar       x1    = t[idx]; x2 = t[1+idx]; x3 = t[2+idx];
48140c4413a7SShri Abhyankar       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
48150c4413a7SShri Abhyankar       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
48160c4413a7SShri Abhyankar       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
48170c4413a7SShri Abhyankar       v += 9;
48180c4413a7SShri Abhyankar     }
48190c4413a7SShri Abhyankar     idx = 3*i;
48200c4413a7SShri Abhyankar     t[idx] = s1; t[1+idx] = s2; t[2+idx] = s3;
48210c4413a7SShri Abhyankar   }
48220c4413a7SShri Abhyankar   /* backward solve the upper triangular */
48230c4413a7SShri Abhyankar   for (i=n-1; i>=0; i--){
48240c4413a7SShri Abhyankar     v    = aa + 9*(adiag[i+1]+1);
48250c4413a7SShri Abhyankar     vi   = aj + adiag[i+1]+1;
48260c4413a7SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
48270c4413a7SShri Abhyankar     idt  = 3*i;
48280c4413a7SShri Abhyankar     s1 = t[idt]; s2 = t[1+idt]; s3 = t[2+idt];
48290c4413a7SShri Abhyankar     for(m=0;m<nz;m++){
48300c4413a7SShri Abhyankar       idx   = 3*vi[m];
48310c4413a7SShri Abhyankar       x1    = t[idx]; x2 = t[1+idx]; x3 = t[2+idx];
48320c4413a7SShri Abhyankar       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
48330c4413a7SShri Abhyankar       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
48340c4413a7SShri Abhyankar       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
48350c4413a7SShri Abhyankar       v += 9;
48360c4413a7SShri Abhyankar     }
48370c4413a7SShri Abhyankar     idc = 3*c[i];
48380c4413a7SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1 + v[3]*s2 + v[6]*s3;
48390c4413a7SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3;
48400c4413a7SShri Abhyankar     x[2+idc] = t[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3;
48410c4413a7SShri Abhyankar   }
48420c4413a7SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
48430c4413a7SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
48440c4413a7SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
48450c4413a7SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
48460c4413a7SShri Abhyankar   ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr);
48470c4413a7SShri Abhyankar   PetscFunctionReturn(0);
48480c4413a7SShri Abhyankar }
48490c4413a7SShri Abhyankar 
485015091d37SBarry Smith /*
485115091d37SBarry Smith       Special case where the matrix was ILU(0) factored in the natural
485215091d37SBarry Smith    ordering. This eliminates the need for the column and row permutation.
485315091d37SBarry Smith */
48544a2ae208SSatish Balay #undef __FUNCT__
485506e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_3_NaturalOrdering_inplace"
485606e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_3_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
485715091d37SBarry Smith {
485815091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
48590b68f018SBarry Smith   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j;
4860dfbe8321SBarry Smith   PetscErrorCode    ierr;
48610b68f018SBarry Smith   const PetscInt    *diag = a->diag,*vi;
4862d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
4863d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,s3,x1,x2,x3;
4864d9fead3dSBarry Smith   const PetscScalar *b;
48650b68f018SBarry Smith   PetscInt          jdx,idt,idx,nz,i;
486615091d37SBarry Smith 
486715091d37SBarry Smith   PetscFunctionBegin;
4868d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
48691ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
487015091d37SBarry Smith 
487115091d37SBarry Smith   /* forward solve the lower triangular */
487215091d37SBarry Smith   idx    = 0;
487315091d37SBarry Smith   x[0]   = b[0]; x[1] = b[1]; x[2] = b[2];
487415091d37SBarry Smith   for (i=1; i<n; i++) {
487515091d37SBarry Smith     v     =  aa      + 9*ai[i];
487615091d37SBarry Smith     vi    =  aj      + ai[i];
487715091d37SBarry Smith     nz    =  diag[i] - ai[i];
487815091d37SBarry Smith     idx   +=  3;
4879f1af5d2fSBarry Smith     s1  =  b[idx];s2 = b[1+idx];s3 = b[2+idx];
488015091d37SBarry Smith     while (nz--) {
488115091d37SBarry Smith       jdx   = 3*(*vi++);
488215091d37SBarry Smith       x1    = x[jdx];x2 = x[1+jdx];x3 = x[2+jdx];
4883f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4884f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4885f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
488615091d37SBarry Smith       v    += 9;
488715091d37SBarry Smith     }
4888f1af5d2fSBarry Smith     x[idx]   = s1;
4889f1af5d2fSBarry Smith     x[1+idx] = s2;
4890f1af5d2fSBarry Smith     x[2+idx] = s3;
489115091d37SBarry Smith   }
489215091d37SBarry Smith   /* backward solve the upper triangular */
489315091d37SBarry Smith   for (i=n-1; i>=0; i--){
489415091d37SBarry Smith     v    = aa + 9*diag[i] + 9;
489515091d37SBarry Smith     vi   = aj + diag[i] + 1;
489615091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
489715091d37SBarry Smith     idt  = 3*i;
4898f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt];
4899f1af5d2fSBarry Smith     s3 = x[2+idt];
490015091d37SBarry Smith     while (nz--) {
490115091d37SBarry Smith       idx   = 3*(*vi++);
490215091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx];x3    = x[2+idx];
4903f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4904f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4905f1af5d2fSBarry Smith       s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
490615091d37SBarry Smith       v    += 9;
490715091d37SBarry Smith     }
490815091d37SBarry Smith     v        = aa +  9*diag[i];
4909f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[3]*s2 + v[6]*s3;
4910f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3;
4911f1af5d2fSBarry Smith     x[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3;
491215091d37SBarry Smith   }
491315091d37SBarry Smith 
4914d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
49151ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4916dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*9*(a->nz) - 3.0*A->cmap->n);CHKERRQ(ierr);
491715091d37SBarry Smith   PetscFunctionReturn(0);
491815091d37SBarry Smith }
491915091d37SBarry Smith 
4920cee9d6f2SShri Abhyankar #undef __FUNCT__
49214dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_3_NaturalOrdering"
49224dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_3_NaturalOrdering(Mat A,Vec bb,Vec xx)
4923b2b2dd24SShri Abhyankar {
4924b2b2dd24SShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
4925b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
4926b2b2dd24SShri Abhyankar     PetscErrorCode    ierr;
4927b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,jdx,idt;
4928b3260449SShri Abhyankar     const PetscInt    bs = A->rmap->bs,bs2 = a->bs2;
4929b2b2dd24SShri Abhyankar     const MatScalar   *aa=a->a,*v;
4930b2b2dd24SShri Abhyankar     PetscScalar       *x;
4931b2b2dd24SShri Abhyankar     const PetscScalar *b;
4932b2b2dd24SShri Abhyankar     PetscScalar        s1,s2,s3,x1,x2,x3;
4933b2b2dd24SShri Abhyankar 
4934b2b2dd24SShri Abhyankar     PetscFunctionBegin;
4935b2b2dd24SShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4936b2b2dd24SShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
4937b2b2dd24SShri Abhyankar     /* forward solve the lower triangular */
4938b2b2dd24SShri Abhyankar     idx    = 0;
4939b2b2dd24SShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];x[2] = b[2+idx];
4940b2b2dd24SShri Abhyankar     for (i=1; i<n; i++) {
4941b2b2dd24SShri Abhyankar        v    = aa + bs2*ai[i];
4942b2b2dd24SShri Abhyankar        vi   = aj + ai[i];
4943b2b2dd24SShri Abhyankar        nz   = ai[i+1] - ai[i];
4944b2b2dd24SShri Abhyankar       idx   = bs*i;
4945b2b2dd24SShri Abhyankar        s1   = b[idx];s2 = b[1+idx];s3 = b[2+idx];
4946b2b2dd24SShri Abhyankar       for(k=0;k<nz;k++){
4947b2b2dd24SShri Abhyankar          jdx   = bs*vi[k];
4948b2b2dd24SShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx]; x3 =x[2+jdx];
4949b2b2dd24SShri Abhyankar           s1   -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4950b2b2dd24SShri Abhyankar           s2   -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4951b2b2dd24SShri Abhyankar           s3   -= v[2]*x1 + v[5]*x2 + v[8]*x3;
4952b2b2dd24SShri Abhyankar 
4953b2b2dd24SShri Abhyankar           v   +=  bs2;
4954b2b2dd24SShri Abhyankar         }
4955b2b2dd24SShri Abhyankar 
4956b2b2dd24SShri Abhyankar        x[idx]   = s1;
4957b2b2dd24SShri Abhyankar        x[1+idx] = s2;
4958b2b2dd24SShri Abhyankar        x[2+idx] = s3;
4959b2b2dd24SShri Abhyankar     }
4960b2b2dd24SShri Abhyankar 
4961b2b2dd24SShri Abhyankar    /* backward solve the upper triangular */
4962b2b2dd24SShri Abhyankar   for (i=n-1; i>=0; i--){
4963b2b2dd24SShri Abhyankar     v   = aa + bs2*(adiag[i+1]+1);
4964b2b2dd24SShri Abhyankar      vi  = aj + adiag[i+1]+1;
4965b2b2dd24SShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
4966b2b2dd24SShri Abhyankar      idt = bs*i;
4967b2b2dd24SShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];s3 = x[2+idt];
4968b2b2dd24SShri Abhyankar 
4969b2b2dd24SShri Abhyankar      for(k=0;k<nz;k++){
4970b2b2dd24SShri Abhyankar        idx   = bs*vi[k];
4971b2b2dd24SShri Abhyankar        x1    = x[idx];   x2 = x[1+idx]; x3 = x[2+idx];
4972b2b2dd24SShri Abhyankar        s1 -= v[0]*x1 + v[3]*x2 + v[6]*x3;
4973b2b2dd24SShri Abhyankar        s2 -= v[1]*x1 + v[4]*x2 + v[7]*x3;
4974b2b2dd24SShri Abhyankar        s3 -= v[2]*x1 + v[5]*x2 + v[8]*x3;
4975b2b2dd24SShri Abhyankar 
4976b2b2dd24SShri Abhyankar         v   +=  bs2;
4977b2b2dd24SShri Abhyankar     }
4978b2b2dd24SShri Abhyankar     /* x = inv_diagonal*x */
4979b2b2dd24SShri Abhyankar    x[idt]   = v[0]*s1 + v[3]*s2 + v[6]*s3;
4980b2b2dd24SShri Abhyankar    x[1+idt] = v[1]*s1 + v[4]*s2 + v[7]*s3;
4981b2b2dd24SShri Abhyankar    x[2+idt] = v[2]*s1 + v[5]*s2 + v[8]*s3;
4982b2b2dd24SShri Abhyankar 
4983b2b2dd24SShri Abhyankar   }
4984b2b2dd24SShri Abhyankar 
4985b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
4986b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
4987b2b2dd24SShri Abhyankar   ierr = PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);CHKERRQ(ierr);
4988b2b2dd24SShri Abhyankar   PetscFunctionReturn(0);
4989b2b2dd24SShri Abhyankar }
4990b2b2dd24SShri Abhyankar 
4991b2b2dd24SShri Abhyankar #undef __FUNCT__
499206e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_2_inplace"
499306e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_2_inplace(Mat A,Vec bb,Vec xx)
49944e2b4712SSatish Balay {
49954e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
49964e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
49976849ba73SBarry Smith   PetscErrorCode    ierr;
4998b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
4999b3260449SShri Abhyankar   PetscInt          i,nz,idx,idt,idc;
50005d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
5001d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
5002d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,x1,x2,*t;
5003d9fead3dSBarry Smith   const PetscScalar *b;
50044e2b4712SSatish Balay 
50054e2b4712SSatish Balay   PetscFunctionBegin;
5006d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
50071ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
5008f1af5d2fSBarry Smith   t  = a->solve_work;
50094e2b4712SSatish Balay 
50104e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
50114e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
50124e2b4712SSatish Balay 
50134e2b4712SSatish Balay   /* forward solve the lower triangular */
50144e2b4712SSatish Balay   idx    = 2*(*r++);
5015f1af5d2fSBarry Smith   t[0] = b[idx]; t[1] = b[1+idx];
50164e2b4712SSatish Balay   for (i=1; i<n; i++) {
50174e2b4712SSatish Balay     v     = aa + 4*ai[i];
50184e2b4712SSatish Balay     vi    = aj + ai[i];
50194e2b4712SSatish Balay     nz    = diag[i] - ai[i];
50204e2b4712SSatish Balay     idx   = 2*(*r++);
5021f1af5d2fSBarry Smith     s1  = b[idx]; s2 = b[1+idx];
50224e2b4712SSatish Balay     while (nz--) {
50234e2b4712SSatish Balay       idx   = 2*(*vi++);
5024f1af5d2fSBarry Smith       x1    = t[idx]; x2 = t[1+idx];
5025f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[2]*x2;
5026f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[3]*x2;
50274e2b4712SSatish Balay       v += 4;
50284e2b4712SSatish Balay     }
50294e2b4712SSatish Balay     idx = 2*i;
5030f1af5d2fSBarry Smith     t[idx] = s1; t[1+idx] = s2;
50314e2b4712SSatish Balay   }
50324e2b4712SSatish Balay   /* backward solve the upper triangular */
50334e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
50344e2b4712SSatish Balay     v    = aa + 4*diag[i] + 4;
50354e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
50364e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
50374e2b4712SSatish Balay     idt  = 2*i;
5038f1af5d2fSBarry Smith     s1 = t[idt]; s2 = t[1+idt];
50394e2b4712SSatish Balay     while (nz--) {
50404e2b4712SSatish Balay       idx   = 2*(*vi++);
5041f1af5d2fSBarry Smith       x1    = t[idx]; x2 = t[1+idx];
5042f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[2]*x2;
5043f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[3]*x2;
50444e2b4712SSatish Balay       v += 4;
50454e2b4712SSatish Balay     }
50464e2b4712SSatish Balay     idc = 2*(*c--);
50474e2b4712SSatish Balay     v   = aa + 4*diag[i];
5048f1af5d2fSBarry Smith     x[idc]   = t[idt]   = v[0]*s1 + v[2]*s2;
5049f1af5d2fSBarry Smith     x[1+idc] = t[1+idt] = v[1]*s1 + v[3]*s2;
50504e2b4712SSatish Balay   }
50514e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
50524e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
5053d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
50541ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5055dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
50564e2b4712SSatish Balay   PetscFunctionReturn(0);
50574e2b4712SSatish Balay }
50584e2b4712SSatish Balay 
50590c4413a7SShri Abhyankar #undef __FUNCT__
50604dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_2"
50614dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_2(Mat A,Vec bb,Vec xx)
50620c4413a7SShri Abhyankar {
50630c4413a7SShri Abhyankar   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
50640c4413a7SShri Abhyankar   IS                iscol=a->col,isrow=a->row;
50650c4413a7SShri Abhyankar   PetscErrorCode    ierr;
5066b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
5067b3260449SShri Abhyankar   PetscInt          i,nz,idx,jdx,idt,idc,m;
50680c4413a7SShri Abhyankar   const PetscInt    *r,*c,*rout,*cout;
50690c4413a7SShri Abhyankar   const MatScalar   *aa=a->a,*v;
50700c4413a7SShri Abhyankar   PetscScalar       *x,s1,s2,x1,x2,*t;
50710c4413a7SShri Abhyankar   const PetscScalar *b;
50720c4413a7SShri Abhyankar 
50730c4413a7SShri Abhyankar   PetscFunctionBegin;
50740c4413a7SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
50750c4413a7SShri Abhyankar   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
50760c4413a7SShri Abhyankar   t  = a->solve_work;
50770c4413a7SShri Abhyankar 
50780c4413a7SShri Abhyankar   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
50790c4413a7SShri Abhyankar   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout;
50800c4413a7SShri Abhyankar 
50810c4413a7SShri Abhyankar   /* forward solve the lower triangular */
50820c4413a7SShri Abhyankar   idx    = 2*r[0];
50830c4413a7SShri Abhyankar   t[0] = b[idx]; t[1] = b[1+idx];
50840c4413a7SShri Abhyankar   for (i=1; i<n; i++) {
50850c4413a7SShri Abhyankar     v     = aa + 4*ai[i];
50860c4413a7SShri Abhyankar     vi    = aj + ai[i];
50870c4413a7SShri Abhyankar     nz    = ai[i+1] - ai[i];
50880c4413a7SShri Abhyankar     idx   = 2*r[i];
50890c4413a7SShri Abhyankar     s1  = b[idx]; s2 = b[1+idx];
50900c4413a7SShri Abhyankar     for(m=0;m<nz;m++){
50910c4413a7SShri Abhyankar       jdx   = 2*vi[m];
50920c4413a7SShri Abhyankar       x1    = t[jdx]; x2 = t[1+jdx];
50930c4413a7SShri Abhyankar       s1 -= v[0]*x1 + v[2]*x2;
50940c4413a7SShri Abhyankar       s2 -= v[1]*x1 + v[3]*x2;
50950c4413a7SShri Abhyankar       v += 4;
50960c4413a7SShri Abhyankar     }
50970c4413a7SShri Abhyankar     idx = 2*i;
50980c4413a7SShri Abhyankar     t[idx] = s1; t[1+idx] = s2;
50990c4413a7SShri Abhyankar   }
51000c4413a7SShri Abhyankar   /* backward solve the upper triangular */
51010c4413a7SShri Abhyankar   for (i=n-1; i>=0; i--){
51020c4413a7SShri Abhyankar     v    = aa + 4*(adiag[i+1]+1);
51030c4413a7SShri Abhyankar     vi   = aj + adiag[i+1]+1;
51040c4413a7SShri Abhyankar     nz   = adiag[i] - adiag[i+1] - 1;
51050c4413a7SShri Abhyankar     idt  = 2*i;
51060c4413a7SShri Abhyankar     s1 = t[idt]; s2 = t[1+idt];
51070c4413a7SShri Abhyankar     for(m=0;m<nz;m++){
51080c4413a7SShri Abhyankar       idx   = 2*vi[m];
51090c4413a7SShri Abhyankar       x1    = t[idx]; x2 = t[1+idx];
51100c4413a7SShri Abhyankar       s1 -= v[0]*x1 + v[2]*x2;
51110c4413a7SShri Abhyankar       s2 -= v[1]*x1 + v[3]*x2;
51120c4413a7SShri Abhyankar       v += 4;
51130c4413a7SShri Abhyankar     }
51140c4413a7SShri Abhyankar     idc = 2*c[i];
51150c4413a7SShri Abhyankar     x[idc]   = t[idt]   = v[0]*s1 + v[2]*s2;
51160c4413a7SShri Abhyankar     x[1+idc] = t[1+idt] = v[1]*s1 + v[3]*s2;
51170c4413a7SShri Abhyankar   }
51180c4413a7SShri Abhyankar   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
51190c4413a7SShri Abhyankar   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
51200c4413a7SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
51210c4413a7SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
51220c4413a7SShri Abhyankar   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
51230c4413a7SShri Abhyankar   PetscFunctionReturn(0);
51240c4413a7SShri Abhyankar }
51258f690400SShri Abhyankar 
512615091d37SBarry Smith /*
512715091d37SBarry Smith       Special case where the matrix was ILU(0) factored in the natural
512815091d37SBarry Smith    ordering. This eliminates the need for the column and row permutation.
512915091d37SBarry Smith */
51304a2ae208SSatish Balay #undef __FUNCT__
513106e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_2_NaturalOrdering_inplace"
513206e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_2_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
513315091d37SBarry Smith {
513415091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
5135b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
5136dfbe8321SBarry Smith   PetscErrorCode    ierr;
5137d9fead3dSBarry Smith   const MatScalar   *aa=a->a,*v;
5138d9fead3dSBarry Smith   PetscScalar       *x,s1,s2,x1,x2;
5139d9fead3dSBarry Smith   const PetscScalar *b;
5140b3260449SShri Abhyankar   PetscInt          jdx,idt,idx,nz,i;
514115091d37SBarry Smith 
514215091d37SBarry Smith   PetscFunctionBegin;
5143d9fead3dSBarry Smith   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
51441ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
514515091d37SBarry Smith 
514615091d37SBarry Smith   /* forward solve the lower triangular */
514715091d37SBarry Smith   idx    = 0;
514815091d37SBarry Smith   x[0]   = b[0]; x[1] = b[1];
514915091d37SBarry Smith   for (i=1; i<n; i++) {
515015091d37SBarry Smith     v     =  aa      + 4*ai[i];
515115091d37SBarry Smith     vi    =  aj      + ai[i];
515215091d37SBarry Smith     nz    =  diag[i] - ai[i];
515315091d37SBarry Smith     idx   +=  2;
5154f1af5d2fSBarry Smith     s1  =  b[idx];s2 = b[1+idx];
515515091d37SBarry Smith     while (nz--) {
515615091d37SBarry Smith       jdx   = 2*(*vi++);
515715091d37SBarry Smith       x1    = x[jdx];x2 = x[1+jdx];
5158f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[2]*x2;
5159f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[3]*x2;
516015091d37SBarry Smith       v    += 4;
516115091d37SBarry Smith     }
5162f1af5d2fSBarry Smith     x[idx]   = s1;
5163f1af5d2fSBarry Smith     x[1+idx] = s2;
516415091d37SBarry Smith   }
516515091d37SBarry Smith   /* backward solve the upper triangular */
516615091d37SBarry Smith   for (i=n-1; i>=0; i--){
516715091d37SBarry Smith     v    = aa + 4*diag[i] + 4;
516815091d37SBarry Smith     vi   = aj + diag[i] + 1;
516915091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
517015091d37SBarry Smith     idt  = 2*i;
5171f1af5d2fSBarry Smith     s1 = x[idt];  s2 = x[1+idt];
517215091d37SBarry Smith     while (nz--) {
517315091d37SBarry Smith       idx   = 2*(*vi++);
517415091d37SBarry Smith       x1    = x[idx];   x2 = x[1+idx];
5175f1af5d2fSBarry Smith       s1 -= v[0]*x1 + v[2]*x2;
5176f1af5d2fSBarry Smith       s2 -= v[1]*x1 + v[3]*x2;
517715091d37SBarry Smith       v    += 4;
517815091d37SBarry Smith     }
517915091d37SBarry Smith     v        = aa +  4*diag[i];
5180f1af5d2fSBarry Smith     x[idt]   = v[0]*s1 + v[2]*s2;
5181f1af5d2fSBarry Smith     x[1+idt] = v[1]*s1 + v[3]*s2;
518215091d37SBarry Smith   }
518315091d37SBarry Smith 
5184d9fead3dSBarry Smith   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
51851ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5186dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
518715091d37SBarry Smith   PetscFunctionReturn(0);
518815091d37SBarry Smith }
518915091d37SBarry Smith 
5190cee9d6f2SShri Abhyankar #undef __FUNCT__
51914dd39f65SShri Abhyankar #define __FUNCT__ "MatSolve_SeqBAIJ_2_NaturalOrdering"
51924dd39f65SShri Abhyankar PetscErrorCode MatSolve_SeqBAIJ_2_NaturalOrdering(Mat A,Vec bb,Vec xx)
5193b2b2dd24SShri Abhyankar {
5194b2b2dd24SShri Abhyankar     Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
5195b3260449SShri Abhyankar     const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*adiag=a->diag;
5196b3260449SShri Abhyankar     PetscInt          i,k,nz,idx,idt,jdx;
5197b2b2dd24SShri Abhyankar     PetscErrorCode    ierr;
5198b2b2dd24SShri Abhyankar     const MatScalar   *aa=a->a,*v;
5199b2b2dd24SShri Abhyankar     PetscScalar       *x,s1,s2,x1,x2;
5200b2b2dd24SShri Abhyankar     const PetscScalar *b;
5201b2b2dd24SShri Abhyankar 
5202b2b2dd24SShri Abhyankar     PetscFunctionBegin;
5203b2b2dd24SShri Abhyankar     ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
5204b2b2dd24SShri Abhyankar     ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
5205b2b2dd24SShri Abhyankar     /* forward solve the lower triangular */
5206b2b2dd24SShri Abhyankar     idx    = 0;
5207b2b2dd24SShri Abhyankar     x[0] = b[idx]; x[1] = b[1+idx];
5208b2b2dd24SShri Abhyankar     for (i=1; i<n; i++) {
5209b2b2dd24SShri Abhyankar         v   = aa + 4*ai[i];
5210b2b2dd24SShri Abhyankar        vi   = aj + ai[i];
5211b2b2dd24SShri Abhyankar        nz   = ai[i+1] - ai[i];
5212b2b2dd24SShri Abhyankar        idx  = 2*i;
5213b2b2dd24SShri Abhyankar        s1   = b[idx];s2 = b[1+idx];
5214b2b2dd24SShri Abhyankar       for(k=0;k<nz;k++){
5215b2b2dd24SShri Abhyankar          jdx   = 2*vi[k];
5216b2b2dd24SShri Abhyankar           x1    = x[jdx];x2 = x[1+jdx];
5217b2b2dd24SShri Abhyankar           s1   -= v[0]*x1 + v[2]*x2;
5218b2b2dd24SShri Abhyankar           s2   -= v[1]*x1 + v[3]*x2;
5219b2b2dd24SShri Abhyankar            v   +=  4;
5220b2b2dd24SShri Abhyankar         }
5221b2b2dd24SShri Abhyankar        x[idx]   = s1;
5222b2b2dd24SShri Abhyankar        x[1+idx] = s2;
5223b2b2dd24SShri Abhyankar     }
5224b2b2dd24SShri Abhyankar 
5225b2b2dd24SShri Abhyankar    /* backward solve the upper triangular */
5226b2b2dd24SShri Abhyankar   for (i=n-1; i>=0; i--){
5227b2b2dd24SShri Abhyankar      v   = aa + 4*(adiag[i+1]+1);
5228b2b2dd24SShri Abhyankar      vi  = aj + adiag[i+1]+1;
5229b2b2dd24SShri Abhyankar      nz  = adiag[i] - adiag[i+1]-1;
5230b2b2dd24SShri Abhyankar      idt = 2*i;
5231b2b2dd24SShri Abhyankar      s1 = x[idt];  s2 = x[1+idt];
5232b2b2dd24SShri Abhyankar      for(k=0;k<nz;k++){
5233b2b2dd24SShri Abhyankar       idx   = 2*vi[k];
5234b2b2dd24SShri Abhyankar        x1    = x[idx];   x2 = x[1+idx];
5235b2b2dd24SShri Abhyankar        s1 -= v[0]*x1 + v[2]*x2;
5236b2b2dd24SShri Abhyankar        s2 -= v[1]*x1 + v[3]*x2;
5237b2b2dd24SShri Abhyankar          v    += 4;
5238b2b2dd24SShri Abhyankar     }
5239b2b2dd24SShri Abhyankar     /* x = inv_diagonal*x */
5240b2b2dd24SShri Abhyankar    x[idt]   = v[0]*s1 + v[2]*s2;
5241b2b2dd24SShri Abhyankar    x[1+idt] = v[1]*s1 + v[3]*s2;
5242b2b2dd24SShri Abhyankar   }
5243b2b2dd24SShri Abhyankar 
5244b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
5245b2b2dd24SShri Abhyankar   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5246b2b2dd24SShri Abhyankar   ierr = PetscLogFlops(2.0*4*(a->nz) - 2.0*A->cmap->n);CHKERRQ(ierr);
5247b2b2dd24SShri Abhyankar   PetscFunctionReturn(0);
5248b2b2dd24SShri Abhyankar }
5249b2b2dd24SShri Abhyankar 
5250b2b2dd24SShri Abhyankar #undef __FUNCT__
525106e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_1_inplace"
525206e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_1_inplace(Mat A,Vec bb,Vec xx)
52534e2b4712SSatish Balay {
52544e2b4712SSatish Balay   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ *)A->data;
52554e2b4712SSatish Balay   IS                iscol=a->col,isrow=a->row;
52566849ba73SBarry Smith   PetscErrorCode    ierr;
5257b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j;
5258b3260449SShri Abhyankar   PetscInt          i,nz;
52595d0c19d7SBarry Smith   const PetscInt    *r,*c,*diag = a->diag,*rout,*cout;
5260b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
5261b3260449SShri Abhyankar   PetscScalar       *x,s1,*t;
5262b3260449SShri Abhyankar   const PetscScalar *b;
52634e2b4712SSatish Balay 
52644e2b4712SSatish Balay   PetscFunctionBegin;
52654e2b4712SSatish Balay   if (!n) PetscFunctionReturn(0);
52664e2b4712SSatish Balay 
5267b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
52681ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
5269f1af5d2fSBarry Smith   t  = a->solve_work;
52704e2b4712SSatish Balay 
52714e2b4712SSatish Balay   ierr = ISGetIndices(isrow,&rout);CHKERRQ(ierr); r = rout;
52724e2b4712SSatish Balay   ierr = ISGetIndices(iscol,&cout);CHKERRQ(ierr); c = cout + (n-1);
52734e2b4712SSatish Balay 
52744e2b4712SSatish Balay   /* forward solve the lower triangular */
5275f1af5d2fSBarry Smith   t[0] = b[*r++];
52764e2b4712SSatish Balay   for (i=1; i<n; i++) {
52774e2b4712SSatish Balay     v     = aa + ai[i];
52784e2b4712SSatish Balay     vi    = aj + ai[i];
52794e2b4712SSatish Balay     nz    = diag[i] - ai[i];
5280f1af5d2fSBarry Smith     s1  = b[*r++];
52814e2b4712SSatish Balay     while (nz--) {
5282f1af5d2fSBarry Smith       s1 -= (*v++)*t[*vi++];
52834e2b4712SSatish Balay     }
5284f1af5d2fSBarry Smith     t[i] = s1;
52854e2b4712SSatish Balay   }
52864e2b4712SSatish Balay   /* backward solve the upper triangular */
52874e2b4712SSatish Balay   for (i=n-1; i>=0; i--){
52884e2b4712SSatish Balay     v    = aa + diag[i] + 1;
52894e2b4712SSatish Balay     vi   = aj + diag[i] + 1;
52904e2b4712SSatish Balay     nz   = ai[i+1] - diag[i] - 1;
5291f1af5d2fSBarry Smith     s1 = t[i];
52924e2b4712SSatish Balay     while (nz--) {
5293f1af5d2fSBarry Smith       s1 -= (*v++)*t[*vi++];
52944e2b4712SSatish Balay     }
5295f1af5d2fSBarry Smith     x[*c--] = t[i] = aa[diag[i]]*s1;
52964e2b4712SSatish Balay   }
52974e2b4712SSatish Balay 
52984e2b4712SSatish Balay   ierr = ISRestoreIndices(isrow,&rout);CHKERRQ(ierr);
52994e2b4712SSatish Balay   ierr = ISRestoreIndices(iscol,&cout);CHKERRQ(ierr);
5300b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
53011ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5302dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*1*(a->nz) - A->cmap->n);CHKERRQ(ierr);
53034e2b4712SSatish Balay   PetscFunctionReturn(0);
53044e2b4712SSatish Balay }
530515091d37SBarry Smith /*
530615091d37SBarry Smith       Special case where the matrix was ILU(0) factored in the natural
530715091d37SBarry Smith    ordering. This eliminates the need for the column and row permutation.
530815091d37SBarry Smith */
53094a2ae208SSatish Balay #undef __FUNCT__
531006e38f1dSHong Zhang #define __FUNCT__ "MatSolve_SeqBAIJ_1_NaturalOrdering_inplace"
531106e38f1dSHong Zhang PetscErrorCode MatSolve_SeqBAIJ_1_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
531215091d37SBarry Smith {
531315091d37SBarry Smith   Mat_SeqBAIJ       *a = (Mat_SeqBAIJ *)A->data;
5314b3260449SShri Abhyankar   const PetscInt    n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
5315dfbe8321SBarry Smith   PetscErrorCode    ierr;
5316b3260449SShri Abhyankar   const MatScalar   *aa=a->a,*v;
5317b3260449SShri Abhyankar   PetscScalar       *x;
5318b3260449SShri Abhyankar   const PetscScalar *b;
531987828ca2SBarry Smith   PetscScalar       s1,x1;
5320b3260449SShri Abhyankar   PetscInt          jdx,idt,idx,nz,i;
532115091d37SBarry Smith 
532215091d37SBarry Smith   PetscFunctionBegin;
5323b3260449SShri Abhyankar   ierr = VecGetArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
53241ebc52fbSHong Zhang   ierr = VecGetArray(xx,&x);CHKERRQ(ierr);
532515091d37SBarry Smith 
532615091d37SBarry Smith   /* forward solve the lower triangular */
532715091d37SBarry Smith   idx    = 0;
532815091d37SBarry Smith   x[0]   = b[0];
532915091d37SBarry Smith   for (i=1; i<n; i++) {
533015091d37SBarry Smith     v     =  aa      + ai[i];
533115091d37SBarry Smith     vi    =  aj      + ai[i];
533215091d37SBarry Smith     nz    =  diag[i] - ai[i];
533315091d37SBarry Smith     idx   +=  1;
5334f1af5d2fSBarry Smith     s1  =  b[idx];
533515091d37SBarry Smith     while (nz--) {
533615091d37SBarry Smith       jdx   = *vi++;
533715091d37SBarry Smith       x1    = x[jdx];
5338f1af5d2fSBarry Smith       s1 -= v[0]*x1;
533915091d37SBarry Smith       v    += 1;
534015091d37SBarry Smith     }
5341f1af5d2fSBarry Smith     x[idx]   = s1;
534215091d37SBarry Smith   }
534315091d37SBarry Smith   /* backward solve the upper triangular */
534415091d37SBarry Smith   for (i=n-1; i>=0; i--){
534515091d37SBarry Smith     v    = aa + diag[i] + 1;
534615091d37SBarry Smith     vi   = aj + diag[i] + 1;
534715091d37SBarry Smith     nz   = ai[i+1] - diag[i] - 1;
534815091d37SBarry Smith     idt  = i;
5349f1af5d2fSBarry Smith     s1 = x[idt];
535015091d37SBarry Smith     while (nz--) {
535115091d37SBarry Smith       idx   = *vi++;
535215091d37SBarry Smith       x1    = x[idx];
5353f1af5d2fSBarry Smith       s1 -= v[0]*x1;
535415091d37SBarry Smith       v    += 1;
535515091d37SBarry Smith     }
535615091d37SBarry Smith     v        = aa +  diag[i];
5357f1af5d2fSBarry Smith     x[idt]   = v[0]*s1;
535815091d37SBarry Smith   }
5359b3260449SShri Abhyankar   ierr = VecRestoreArray(bb,(PetscScalar**)&b);CHKERRQ(ierr);
53601ebc52fbSHong Zhang   ierr = VecRestoreArray(xx,&x);CHKERRQ(ierr);
5361dc0b31edSSatish Balay   ierr = PetscLogFlops(2.0*(a->nz) - A->cmap->n);CHKERRQ(ierr);
536215091d37SBarry Smith   PetscFunctionReturn(0);
536315091d37SBarry Smith }
53644e2b4712SSatish Balay 
53654e2b4712SSatish Balay /* ----------------------------------------------------------------*/
536616a2bf60SHong Zhang EXTERN PetscErrorCode MatDuplicateNoCreate_SeqBAIJ(Mat,Mat,MatDuplicateOption,PetscTruth);
53676bce7ff8SHong Zhang 
53682b0b2ea7SShri Abhyankar #undef __FUNCT__
536929a97285SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_15_NaturalOrdering"
5370766f9fbaSBarry Smith /*
5371766f9fbaSBarry Smith    This is not much faster than MatLUFactorNumeric_SeqBAIJ_N() but the solve is faster at least sometimes
5372766f9fbaSBarry Smith */
537329a97285SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_15_NaturalOrdering(Mat B,Mat A,const MatFactorInfo *info)
53742b0b2ea7SShri Abhyankar {
53752b0b2ea7SShri Abhyankar   Mat             C=B;
53762b0b2ea7SShri Abhyankar   Mat_SeqBAIJ     *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data;
53772b0b2ea7SShri Abhyankar   PetscErrorCode  ierr;
5378766f9fbaSBarry Smith   PetscInt        i,j,k,ipvt[15];
5379766f9fbaSBarry Smith   const PetscInt  n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j,*ajtmp,*bjtmp,*bdiag=b->diag,*pj;
5380766f9fbaSBarry Smith   PetscInt        nz,nzL,row;
5381766f9fbaSBarry Smith   MatScalar       *rtmp,*pc,*mwork,*pv,*vv,work[225];
5382766f9fbaSBarry Smith   const MatScalar *v,*aa=a->a;
53832b0b2ea7SShri Abhyankar   PetscInt        bs2 = a->bs2,bs=A->rmap->bs,flg;
5384*0fa040f9SShri Abhyankar   PetscInt        sol_ver;
53852b0b2ea7SShri Abhyankar 
53862b0b2ea7SShri Abhyankar   PetscFunctionBegin;
53872b0b2ea7SShri Abhyankar 
5388*0fa040f9SShri Abhyankar   ierr = PetscOptionsGetInt(PETSC_NULL,"-sol_ver",&sol_ver,PETSC_NULL);CHKERRQ(ierr);
5389*0fa040f9SShri Abhyankar 
53902b0b2ea7SShri Abhyankar   /* generate work space needed by the factorization */
53912b0b2ea7SShri Abhyankar   ierr = PetscMalloc2(bs2*n,MatScalar,&rtmp,bs2,MatScalar,&mwork);CHKERRQ(ierr);
53922b0b2ea7SShri Abhyankar   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
53932b0b2ea7SShri Abhyankar 
53942b0b2ea7SShri Abhyankar   for (i=0; i<n; i++){
53952b0b2ea7SShri Abhyankar     /* zero rtmp */
53962b0b2ea7SShri Abhyankar     /* L part */
53972b0b2ea7SShri Abhyankar     nz    = bi[i+1] - bi[i];
53982b0b2ea7SShri Abhyankar     bjtmp = bj + bi[i];
53992b0b2ea7SShri Abhyankar     for  (j=0; j<nz; j++){
54002b0b2ea7SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
54012b0b2ea7SShri Abhyankar     }
54022b0b2ea7SShri Abhyankar 
54032b0b2ea7SShri Abhyankar     /* U part */
54042b0b2ea7SShri Abhyankar     nz = bdiag[i] - bdiag[i+1];
54052b0b2ea7SShri Abhyankar     bjtmp = bj + bdiag[i+1]+1;
54062b0b2ea7SShri Abhyankar     for  (j=0; j<nz; j++){
54072b0b2ea7SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
54082b0b2ea7SShri Abhyankar     }
54092b0b2ea7SShri Abhyankar 
54102b0b2ea7SShri Abhyankar     /* load in initial (unfactored row) */
541129a97285SShri Abhyankar     nz    = ai[i+1] - ai[i];
541229a97285SShri Abhyankar     ajtmp = aj + ai[i];
541329a97285SShri Abhyankar     v     = aa + bs2*ai[i];
54142b0b2ea7SShri Abhyankar     for (j=0; j<nz; j++) {
541529a97285SShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ajtmp[j],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
54162b0b2ea7SShri Abhyankar     }
54172b0b2ea7SShri Abhyankar 
54182b0b2ea7SShri Abhyankar     /* elimination */
54192b0b2ea7SShri Abhyankar     bjtmp = bj + bi[i];
54202b0b2ea7SShri Abhyankar     nzL   = bi[i+1] - bi[i];
54212b0b2ea7SShri Abhyankar     for(k=0;k < nzL;k++) {
54222b0b2ea7SShri Abhyankar       row = bjtmp[k];
54232b0b2ea7SShri Abhyankar       pc = rtmp + bs2*row;
54242b0b2ea7SShri Abhyankar       for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }}
54252b0b2ea7SShri Abhyankar       if (flg) {
54262b0b2ea7SShri Abhyankar         pv = b->a + bs2*bdiag[row];
5427766f9fbaSBarry Smith 	Kernel_A_gets_A_times_B(bs,pc,pv,mwork);
5428766f9fbaSBarry Smith 	/*ierr = Kernel_A_gets_A_times_B_15(pc,pv,mwork);CHKERRQ(ierr);*/
54292b0b2ea7SShri Abhyankar 	pj = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
54302b0b2ea7SShri Abhyankar         pv = b->a + bs2*(bdiag[row+1]+1);
54312b0b2ea7SShri Abhyankar         nz = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
54322b0b2ea7SShri Abhyankar         for (j=0; j<nz; j++) {
5433766f9fbaSBarry Smith           vv   = rtmp + bs2*pj[j];
5434766f9fbaSBarry Smith           Kernel_A_gets_A_minus_B_times_C(bs,vv,pc,pv);
5435766f9fbaSBarry Smith 	  /* ierr = Kernel_A_gets_A_minus_B_times_C_15(vv,pc,pv);CHKERRQ(ierr); */
54362b0b2ea7SShri Abhyankar 	  pv  += bs2;
54372b0b2ea7SShri Abhyankar         }
5438766f9fbaSBarry Smith         ierr = PetscLogFlops(2*bs2*bs*(nz+1)-bs2);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
54392b0b2ea7SShri Abhyankar       }
54402b0b2ea7SShri Abhyankar     }
54412b0b2ea7SShri Abhyankar 
54422b0b2ea7SShri Abhyankar     /* finished row so stick it into b->a */
54432b0b2ea7SShri Abhyankar     /* L part */
54442b0b2ea7SShri Abhyankar     pv   = b->a + bs2*bi[i] ;
54452b0b2ea7SShri Abhyankar     pj   = b->j + bi[i] ;
54462b0b2ea7SShri Abhyankar     nz   = bi[i+1] - bi[i];
54472b0b2ea7SShri Abhyankar     for (j=0; j<nz; j++) {
54482b0b2ea7SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
54492b0b2ea7SShri Abhyankar     }
54502b0b2ea7SShri Abhyankar 
54512b0b2ea7SShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
54522b0b2ea7SShri Abhyankar     pv   = b->a + bs2*bdiag[i];
54532b0b2ea7SShri Abhyankar     pj   = b->j + bdiag[i];
54542b0b2ea7SShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
5455766f9fbaSBarry Smith     /* Kernel_A_gets_inverse_A(bs,pv,pivots,work); */
5456766f9fbaSBarry Smith     ierr = Kernel_A_gets_inverse_A_15(pv,ipvt,work,info->shiftinblocks);CHKERRQ(ierr);
54572b0b2ea7SShri Abhyankar 
54582b0b2ea7SShri Abhyankar     /* U part */
54592b0b2ea7SShri Abhyankar     pv = b->a + bs2*(bdiag[i+1]+1);
54602b0b2ea7SShri Abhyankar     pj = b->j + bdiag[i+1]+1;
54612b0b2ea7SShri Abhyankar     nz = bdiag[i] - bdiag[i+1] - 1;
54622b0b2ea7SShri Abhyankar     for (j=0; j<nz; j++){
54632b0b2ea7SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
54642b0b2ea7SShri Abhyankar     }
54652b0b2ea7SShri Abhyankar   }
54662b0b2ea7SShri Abhyankar 
54672b0b2ea7SShri Abhyankar   ierr = PetscFree2(rtmp,mwork);CHKERRQ(ierr);
5468*0fa040f9SShri Abhyankar   if(sol_ver == 1) C->ops->solve = MatSolve_SeqBAIJ_15_NaturalOrdering;
5469*0fa040f9SShri Abhyankar   else if (sol_ver == 2) C->ops->solve = MatSolve_SeqBAIJ_15_NaturalOrdering_ver2;
5470*0fa040f9SShri Abhyankar   else C->ops->solve = MatSolve_SeqBAIJ_N_NaturalOrdering;
5471766f9fbaSBarry Smith   C->ops->solvetranspose = MatSolve_SeqBAIJ_N_NaturalOrdering;
54722b0b2ea7SShri Abhyankar   C->assembled = PETSC_TRUE;
5473766f9fbaSBarry Smith   ierr = PetscLogFlops(1.333333333333*bs*bs2*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */
54742b0b2ea7SShri Abhyankar   PetscFunctionReturn(0);
54752b0b2ea7SShri Abhyankar }
54762b0b2ea7SShri Abhyankar 
54776bce7ff8SHong Zhang #undef __FUNCT__
54784dd39f65SShri Abhyankar #define __FUNCT__ "MatLUFactorNumeric_SeqBAIJ_N"
54794dd39f65SShri Abhyankar PetscErrorCode MatLUFactorNumeric_SeqBAIJ_N(Mat B,Mat A,const MatFactorInfo *info)
54806bce7ff8SHong Zhang {
54816bce7ff8SHong Zhang   Mat            C=B;
54826bce7ff8SHong Zhang   Mat_SeqBAIJ    *a=(Mat_SeqBAIJ*)A->data,*b=(Mat_SeqBAIJ *)C->data;
54836bce7ff8SHong Zhang   IS             isrow = b->row,isicol = b->icol;
54846bce7ff8SHong Zhang   PetscErrorCode ierr;
54856bce7ff8SHong Zhang   const PetscInt *r,*ic,*ics;
54866bce7ff8SHong Zhang   PetscInt       i,j,k,n=a->mbs,*ai=a->i,*aj=a->j,*bi=b->i,*bj=b->j;
54876bce7ff8SHong Zhang   PetscInt       *ajtmp,*bjtmp,nz,nzL,row,*bdiag=b->diag,*pj;
5488b588c5a2SHong Zhang   MatScalar      *rtmp,*pc,*mwork,*v,*pv,*aa=a->a;
5489914a18a2SHong Zhang   PetscInt       bs=A->rmap->bs,bs2 = a->bs2,*v_pivots,flg;
5490914a18a2SHong Zhang   MatScalar      *v_work;
5491ae3d28f0SHong Zhang   PetscTruth     col_identity,row_identity,both_identity;
54926bce7ff8SHong Zhang 
54936bce7ff8SHong Zhang   PetscFunctionBegin;
54946bce7ff8SHong Zhang   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
54956bce7ff8SHong Zhang   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
5496ae3d28f0SHong Zhang 
5497fca92195SBarry Smith   ierr = PetscMalloc(bs2*n*sizeof(MatScalar),&rtmp);CHKERRQ(ierr);
5498fca92195SBarry Smith   ierr = PetscMemzero(rtmp,bs2*n*sizeof(MatScalar));CHKERRQ(ierr);
54996bce7ff8SHong Zhang   ics  = ic;
55006bce7ff8SHong Zhang 
5501914a18a2SHong Zhang   /* generate work space needed by dense LU factorization */
5502fca92195SBarry Smith   ierr  = PetscMalloc3(bs,MatScalar,&v_work,bs2,MatScalar,&mwork,bs,PetscInt,&v_pivots);CHKERRQ(ierr);
5503914a18a2SHong Zhang 
55046bce7ff8SHong Zhang   for (i=0; i<n; i++){
55056bce7ff8SHong Zhang     /* zero rtmp */
55066bce7ff8SHong Zhang     /* L part */
55076bce7ff8SHong Zhang     nz    = bi[i+1] - bi[i];
55086bce7ff8SHong Zhang     bjtmp = bj + bi[i];
5509914a18a2SHong Zhang     for  (j=0; j<nz; j++){
5510914a18a2SHong Zhang       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
5511914a18a2SHong Zhang     }
55126bce7ff8SHong Zhang 
55136bce7ff8SHong Zhang     /* U part */
55141a83e813SShri Abhyankar     nz = bdiag[i] - bdiag[i+1];
55151a83e813SShri Abhyankar     bjtmp = bj + bdiag[i+1]+1;
55161a83e813SShri Abhyankar     for  (j=0; j<nz; j++){
55171a83e813SShri Abhyankar       ierr = PetscMemzero(rtmp+bs2*bjtmp[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
55181a83e813SShri Abhyankar     }
55191a83e813SShri Abhyankar 
55201a83e813SShri Abhyankar     /* load in initial (unfactored row) */
55211a83e813SShri Abhyankar     nz    = ai[r[i]+1] - ai[r[i]];
55221a83e813SShri Abhyankar     ajtmp = aj + ai[r[i]];
55231a83e813SShri Abhyankar     v     = aa + bs2*ai[r[i]];
55241a83e813SShri Abhyankar     for (j=0; j<nz; j++) {
55251a83e813SShri Abhyankar       ierr = PetscMemcpy(rtmp+bs2*ic[ajtmp[j]],v+bs2*j,bs2*sizeof(MatScalar));CHKERRQ(ierr);
55261a83e813SShri Abhyankar     }
55271a83e813SShri Abhyankar 
55281a83e813SShri Abhyankar     /* elimination */
55291a83e813SShri Abhyankar     bjtmp = bj + bi[i];
55301a83e813SShri Abhyankar     nzL   = bi[i+1] - bi[i];
55311a83e813SShri Abhyankar     for(k=0;k < nzL;k++) {
55321a83e813SShri Abhyankar       row = bjtmp[k];
55331a83e813SShri Abhyankar       pc = rtmp + bs2*row;
55341a83e813SShri Abhyankar       for (flg=0,j=0; j<bs2; j++) { if (pc[j]!=0.0) { flg = 1; break; }}
55351a83e813SShri Abhyankar       if (flg) {
55361a83e813SShri Abhyankar         pv         = b->a + bs2*bdiag[row];
55371a83e813SShri Abhyankar         Kernel_A_gets_A_times_B(bs,pc,pv,mwork); /* *pc = *pc * (*pv); */
55381a83e813SShri Abhyankar         pj         = b->j + bdiag[row+1]+1; /* begining of U(row,:) */
55391a83e813SShri Abhyankar         pv         = b->a + bs2*(bdiag[row+1]+1);
55401a83e813SShri Abhyankar         nz         = bdiag[row] - bdiag[row+1] - 1; /* num of entries inU(row,:), excluding diag */
55411a83e813SShri Abhyankar         for (j=0; j<nz; j++) {
55421a83e813SShri Abhyankar           Kernel_A_gets_A_minus_B_times_C(bs,rtmp+bs2*pj[j],pc,pv+bs2*j);
55431a83e813SShri Abhyankar         }
55441a83e813SShri Abhyankar         ierr = PetscLogFlops(2*bs2*bs*(nz+1)-bs2);CHKERRQ(ierr); /* flops = 2*bs^3*nz + 2*bs^3 - bs2) */
55451a83e813SShri Abhyankar       }
55461a83e813SShri Abhyankar     }
55471a83e813SShri Abhyankar 
55481a83e813SShri Abhyankar     /* finished row so stick it into b->a */
55491a83e813SShri Abhyankar     /* L part */
55501a83e813SShri Abhyankar     pv   = b->a + bs2*bi[i] ;
55511a83e813SShri Abhyankar     pj   = b->j + bi[i] ;
55521a83e813SShri Abhyankar     nz   = bi[i+1] - bi[i];
55531a83e813SShri Abhyankar     for (j=0; j<nz; j++) {
55541a83e813SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
55551a83e813SShri Abhyankar     }
55561a83e813SShri Abhyankar 
55571a83e813SShri Abhyankar     /* Mark diagonal and invert diagonal for simplier triangular solves */
55581a83e813SShri Abhyankar     pv  = b->a + bs2*bdiag[i];
55591a83e813SShri Abhyankar     pj  = b->j + bdiag[i];
55601a83e813SShri Abhyankar     /* if (*pj != i)SETERRQ2(PETSC_ERR_SUP,"row %d != *pj %d",i,*pj); */
55611a83e813SShri Abhyankar     ierr = PetscMemcpy(pv,rtmp+bs2*pj[0],bs2*sizeof(MatScalar));CHKERRQ(ierr);
55621a83e813SShri Abhyankar     ierr = Kernel_A_gets_inverse_A(bs,pv,v_pivots,v_work);CHKERRQ(ierr);
55631a83e813SShri Abhyankar 
55641a83e813SShri Abhyankar     /* U part */
55651a83e813SShri Abhyankar     pv = b->a + bs2*(bdiag[i+1]+1);
55661a83e813SShri Abhyankar     pj = b->j + bdiag[i+1]+1;
55671a83e813SShri Abhyankar     nz = bdiag[i] - bdiag[i+1] - 1;
55681a83e813SShri Abhyankar     for (j=0; j<nz; j++){
55691a83e813SShri Abhyankar       ierr = PetscMemcpy(pv+bs2*j,rtmp+bs2*pj[j],bs2*sizeof(MatScalar));CHKERRQ(ierr);
55701a83e813SShri Abhyankar     }
55711a83e813SShri Abhyankar   }
55721a83e813SShri Abhyankar 
55731a83e813SShri Abhyankar   ierr = PetscFree(rtmp);CHKERRQ(ierr);
5574fca92195SBarry Smith   ierr = PetscFree3(v_work,mwork,v_pivots);CHKERRQ(ierr);
55751a83e813SShri Abhyankar   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
55761a83e813SShri Abhyankar   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
55771a83e813SShri Abhyankar 
5578ae3d28f0SHong Zhang   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
5579ae3d28f0SHong Zhang   ierr = ISIdentity(isicol,&col_identity);CHKERRQ(ierr);
5580ae3d28f0SHong Zhang   both_identity = (PetscTruth) (row_identity && col_identity);
5581ae3d28f0SHong Zhang   if (both_identity){
55824dd39f65SShri Abhyankar     C->ops->solve = MatSolve_SeqBAIJ_N_NaturalOrdering;
5583ae3d28f0SHong Zhang   } else {
55844dd39f65SShri Abhyankar     C->ops->solve = MatSolve_SeqBAIJ_N;
5585ae3d28f0SHong Zhang   }
55864dd39f65SShri Abhyankar   C->ops->solvetranspose = MatSolveTranspose_SeqBAIJ_N;
5587ae3d28f0SHong Zhang 
55881a83e813SShri Abhyankar   C->assembled = PETSC_TRUE;
5589766f9fbaSBarry Smith   ierr = PetscLogFlops(1.333333333333*bs*bs2*b->mbs);CHKERRQ(ierr); /* from inverting diagonal blocks */
55901a83e813SShri Abhyankar   PetscFunctionReturn(0);
55911a83e813SShri Abhyankar }
55921a83e813SShri Abhyankar 
55936bce7ff8SHong Zhang /*
55946bce7ff8SHong Zhang    ilu(0) with natural ordering under new data structure.
55954dd39f65SShri Abhyankar    See MatILUFactorSymbolic_SeqAIJ_ilu0() for detailed description
55964dd39f65SShri Abhyankar    because this code is almost identical to MatILUFactorSymbolic_SeqAIJ_ilu0_inplace().
55976bce7ff8SHong Zhang */
5598c0c7eb62SShri Abhyankar 
55996bce7ff8SHong Zhang #undef __FUNCT__
56004dd39f65SShri Abhyankar #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ_ilu0"
56014dd39f65SShri Abhyankar PetscErrorCode MatILUFactorSymbolic_SeqBAIJ_ilu0(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
56026bce7ff8SHong Zhang {
56036bce7ff8SHong Zhang 
56046bce7ff8SHong Zhang   Mat_SeqBAIJ        *a = (Mat_SeqBAIJ*)A->data,*b;
56056bce7ff8SHong Zhang   PetscErrorCode     ierr;
560616a2bf60SHong Zhang   PetscInt           n=a->mbs,*ai=a->i,*aj,*adiag=a->diag,bs2 = a->bs2;
560735aa4fcfSShri Abhyankar   PetscInt           i,j,nz,*bi,*bj,*bdiag,bi_temp;
560835aa4fcfSShri Abhyankar 
560935aa4fcfSShri Abhyankar   PetscFunctionBegin;
561035aa4fcfSShri Abhyankar   ierr = MatDuplicateNoCreate_SeqBAIJ(fact,A,MAT_DO_NOT_COPY_VALUES,PETSC_FALSE);CHKERRQ(ierr);
561135aa4fcfSShri Abhyankar   b    = (Mat_SeqBAIJ*)(fact)->data;
561235aa4fcfSShri Abhyankar 
561335aa4fcfSShri Abhyankar   /* allocate matrix arrays for new data structure */
561435aa4fcfSShri Abhyankar   ierr = PetscMalloc3(bs2*ai[n]+1,PetscScalar,&b->a,ai[n]+1,PetscInt,&b->j,n+1,PetscInt,&b->i);CHKERRQ(ierr);
561535aa4fcfSShri Abhyankar   ierr = PetscLogObjectMemory(fact,ai[n]*(bs2*sizeof(PetscScalar)+sizeof(PetscInt))+(n+1)*sizeof(PetscInt));CHKERRQ(ierr);
561635aa4fcfSShri Abhyankar   b->singlemalloc = PETSC_TRUE;
561735aa4fcfSShri Abhyankar   if (!b->diag){
561835aa4fcfSShri Abhyankar     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&b->diag);CHKERRQ(ierr);
561935aa4fcfSShri Abhyankar     ierr = PetscLogObjectMemory(fact,(n+1)*sizeof(PetscInt));CHKERRQ(ierr);
562035aa4fcfSShri Abhyankar   }
562135aa4fcfSShri Abhyankar   bdiag = b->diag;
562235aa4fcfSShri Abhyankar 
562335aa4fcfSShri Abhyankar   if (n > 0) {
562435aa4fcfSShri Abhyankar     ierr = PetscMemzero(b->a,bs2*ai[n]*sizeof(MatScalar));CHKERRQ(ierr);
562535aa4fcfSShri Abhyankar   }
562635aa4fcfSShri Abhyankar 
562735aa4fcfSShri Abhyankar   /* set bi and bj with new data structure */
562835aa4fcfSShri Abhyankar   bi = b->i;
562935aa4fcfSShri Abhyankar   bj = b->j;
563035aa4fcfSShri Abhyankar 
563135aa4fcfSShri Abhyankar   /* L part */
563235aa4fcfSShri Abhyankar   bi[0] = 0;
563335aa4fcfSShri Abhyankar   for (i=0; i<n; i++){
563435aa4fcfSShri Abhyankar     nz = adiag[i] - ai[i];
563535aa4fcfSShri Abhyankar     bi[i+1] = bi[i] + nz;
563635aa4fcfSShri Abhyankar     aj = a->j + ai[i];
563735aa4fcfSShri Abhyankar     for (j=0; j<nz; j++){
563835aa4fcfSShri Abhyankar       *bj = aj[j]; bj++;
563935aa4fcfSShri Abhyankar     }
564035aa4fcfSShri Abhyankar   }
564135aa4fcfSShri Abhyankar 
564235aa4fcfSShri Abhyankar   /* U part */
564335aa4fcfSShri Abhyankar   bi_temp = bi[n];
564435aa4fcfSShri Abhyankar   bdiag[n] = bi[n]-1;
564535aa4fcfSShri Abhyankar   for (i=n-1; i>=0; i--){
564635aa4fcfSShri Abhyankar     nz = ai[i+1] - adiag[i] - 1;
564735aa4fcfSShri Abhyankar     bi_temp = bi_temp + nz + 1;
564835aa4fcfSShri Abhyankar     aj = a->j + adiag[i] + 1;
564935aa4fcfSShri Abhyankar     for (j=0; j<nz; j++){
565035aa4fcfSShri Abhyankar       *bj = aj[j]; bj++;
565135aa4fcfSShri Abhyankar     }
565235aa4fcfSShri Abhyankar     /* diag[i] */
565335aa4fcfSShri Abhyankar     *bj = i; bj++;
565435aa4fcfSShri Abhyankar     bdiag[i] = bi_temp - 1;
565535aa4fcfSShri Abhyankar   }
565635aa4fcfSShri Abhyankar   PetscFunctionReturn(0);
565735aa4fcfSShri Abhyankar }
565835aa4fcfSShri Abhyankar 
565935aa4fcfSShri Abhyankar #undef __FUNCT__
56604dd39f65SShri Abhyankar #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ"
56614dd39f65SShri Abhyankar PetscErrorCode MatILUFactorSymbolic_SeqBAIJ(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
566216a2bf60SHong Zhang {
566316a2bf60SHong Zhang   Mat_SeqBAIJ        *a = (Mat_SeqBAIJ*)A->data,*b;
566416a2bf60SHong Zhang   IS                 isicol;
566516a2bf60SHong Zhang   PetscErrorCode     ierr;
566616a2bf60SHong Zhang   const PetscInt     *r,*ic;
56677fa3a6a0SHong Zhang   PetscInt           n=a->mbs,*ai=a->i,*aj=a->j,d;
566816a2bf60SHong Zhang   PetscInt           *bi,*cols,nnz,*cols_lvl;
566916a2bf60SHong Zhang   PetscInt           *bdiag,prow,fm,nzbd,reallocs=0,dcount=0;
567016a2bf60SHong Zhang   PetscInt           i,levels,diagonal_fill;
56717fa3a6a0SHong Zhang   PetscTruth         col_identity,row_identity,both_identity;
567216a2bf60SHong Zhang   PetscReal          f;
567316a2bf60SHong Zhang   PetscInt           nlnk,*lnk,*lnk_lvl=PETSC_NULL;
567416a2bf60SHong Zhang   PetscBT            lnkbt;
567516a2bf60SHong Zhang   PetscInt           nzi,*bj,**bj_ptr,**bjlvl_ptr;
567616a2bf60SHong Zhang   PetscFreeSpaceList free_space=PETSC_NULL,current_space=PETSC_NULL;
567716a2bf60SHong Zhang   PetscFreeSpaceList free_space_lvl=PETSC_NULL,current_space_lvl=PETSC_NULL;
567816a2bf60SHong Zhang   PetscTruth         missing;
56797fa3a6a0SHong Zhang   PetscInt           bs=A->rmap->bs,bs2=a->bs2;
568016a2bf60SHong Zhang 
568116a2bf60SHong Zhang   PetscFunctionBegin;
568216a2bf60SHong 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);
568316a2bf60SHong Zhang   ierr = MatMissingDiagonal(A,&missing,&d);CHKERRQ(ierr);
568416a2bf60SHong Zhang   if (missing) SETERRQ1(PETSC_ERR_ARG_WRONGSTATE,"Matrix is missing diagonal entry %D",d);
568516a2bf60SHong Zhang 
568616a2bf60SHong Zhang   f             = info->fill;
568716a2bf60SHong Zhang   levels        = (PetscInt)info->levels;
568816a2bf60SHong Zhang   diagonal_fill = (PetscInt)info->diagonal_fill;
568916a2bf60SHong Zhang   ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr);
569016a2bf60SHong Zhang 
569116a2bf60SHong Zhang   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
569216a2bf60SHong Zhang   ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr);
56937fa3a6a0SHong Zhang   both_identity = (PetscTruth) (row_identity && col_identity);
569416a2bf60SHong Zhang 
56957fa3a6a0SHong Zhang   if (!levels && both_identity) {
569616a2bf60SHong Zhang     /* special case: ilu(0) with natural ordering */
56974dd39f65SShri Abhyankar     ierr = MatILUFactorSymbolic_SeqBAIJ_ilu0(fact,A,isrow,iscol,info);CHKERRQ(ierr);
56984dd39f65SShri Abhyankar     ierr = MatSeqBAIJSetNumericFactorization(fact,both_identity);CHKERRQ(ierr);
569935aa4fcfSShri Abhyankar 
570035aa4fcfSShri Abhyankar     fact->factor = MAT_FACTOR_ILU;
570135aa4fcfSShri Abhyankar     (fact)->info.factor_mallocs    = 0;
570235aa4fcfSShri Abhyankar     (fact)->info.fill_ratio_given  = info->fill;
570335aa4fcfSShri Abhyankar     (fact)->info.fill_ratio_needed = 1.0;
570435aa4fcfSShri Abhyankar     b                = (Mat_SeqBAIJ*)(fact)->data;
570535aa4fcfSShri Abhyankar     b->row           = isrow;
570635aa4fcfSShri Abhyankar     b->col           = iscol;
570735aa4fcfSShri Abhyankar     b->icol          = isicol;
570835aa4fcfSShri Abhyankar     ierr             = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
570935aa4fcfSShri Abhyankar     ierr             = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
571035aa4fcfSShri Abhyankar     b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
571135aa4fcfSShri Abhyankar     ierr = PetscMalloc((n+1)*bs*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
571235aa4fcfSShri Abhyankar     PetscFunctionReturn(0);
571335aa4fcfSShri Abhyankar   }
571435aa4fcfSShri Abhyankar 
571535aa4fcfSShri Abhyankar   ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
571635aa4fcfSShri Abhyankar   ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
571735aa4fcfSShri Abhyankar 
571835aa4fcfSShri Abhyankar   /* get new row pointers */
571935aa4fcfSShri Abhyankar   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bi);CHKERRQ(ierr);
572035aa4fcfSShri Abhyankar   bi[0] = 0;
572135aa4fcfSShri Abhyankar   /* bdiag is location of diagonal in factor */
572235aa4fcfSShri Abhyankar   ierr = PetscMalloc((n+1)*sizeof(PetscInt),&bdiag);CHKERRQ(ierr);
572335aa4fcfSShri Abhyankar   bdiag[0]  = 0;
572435aa4fcfSShri Abhyankar 
5725fca92195SBarry Smith   ierr = PetscMalloc2(n,PetscInt*,&bj_ptr,n,PetscInt*,&bjlvl_ptr);CHKERRQ(ierr);
572635aa4fcfSShri Abhyankar 
572735aa4fcfSShri Abhyankar   /* create a linked list for storing column indices of the active row */
572835aa4fcfSShri Abhyankar   nlnk = n + 1;
572935aa4fcfSShri Abhyankar   ierr = PetscIncompleteLLCreate(n,n,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr);
573035aa4fcfSShri Abhyankar 
573135aa4fcfSShri Abhyankar   /* initial FreeSpace size is f*(ai[n]+1) */
573235aa4fcfSShri Abhyankar   ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space);CHKERRQ(ierr);
573335aa4fcfSShri Abhyankar   current_space = free_space;
573435aa4fcfSShri Abhyankar   ierr = PetscFreeSpaceGet((PetscInt)(f*(ai[n]+1)),&free_space_lvl);CHKERRQ(ierr);
573535aa4fcfSShri Abhyankar   current_space_lvl = free_space_lvl;
573635aa4fcfSShri Abhyankar 
573735aa4fcfSShri Abhyankar   for (i=0; i<n; i++) {
573835aa4fcfSShri Abhyankar     nzi = 0;
573935aa4fcfSShri Abhyankar     /* copy current row into linked list */
574035aa4fcfSShri Abhyankar     nnz  = ai[r[i]+1] - ai[r[i]];
574135aa4fcfSShri 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);
574235aa4fcfSShri Abhyankar     cols = aj + ai[r[i]];
574335aa4fcfSShri Abhyankar     lnk[i] = -1; /* marker to indicate if diagonal exists */
574435aa4fcfSShri Abhyankar     ierr = PetscIncompleteLLInit(nnz,cols,n,ic,nlnk,lnk,lnk_lvl,lnkbt);CHKERRQ(ierr);
574535aa4fcfSShri Abhyankar     nzi += nlnk;
574635aa4fcfSShri Abhyankar 
574735aa4fcfSShri Abhyankar     /* make sure diagonal entry is included */
574835aa4fcfSShri Abhyankar     if (diagonal_fill && lnk[i] == -1) {
574935aa4fcfSShri Abhyankar       fm = n;
575035aa4fcfSShri Abhyankar       while (lnk[fm] < i) fm = lnk[fm];
575135aa4fcfSShri Abhyankar       lnk[i]     = lnk[fm]; /* insert diagonal into linked list */
575235aa4fcfSShri Abhyankar       lnk[fm]    = i;
575335aa4fcfSShri Abhyankar       lnk_lvl[i] = 0;
575435aa4fcfSShri Abhyankar       nzi++; dcount++;
575535aa4fcfSShri Abhyankar     }
575635aa4fcfSShri Abhyankar 
575735aa4fcfSShri Abhyankar     /* add pivot rows into the active row */
575835aa4fcfSShri Abhyankar     nzbd = 0;
575935aa4fcfSShri Abhyankar     prow = lnk[n];
576035aa4fcfSShri Abhyankar     while (prow < i) {
576135aa4fcfSShri Abhyankar       nnz      = bdiag[prow];
576235aa4fcfSShri Abhyankar       cols     = bj_ptr[prow] + nnz + 1;
576335aa4fcfSShri Abhyankar       cols_lvl = bjlvl_ptr[prow] + nnz + 1;
576435aa4fcfSShri Abhyankar       nnz      = bi[prow+1] - bi[prow] - nnz - 1;
576535aa4fcfSShri Abhyankar       ierr = PetscILULLAddSorted(nnz,cols,levels,cols_lvl,prow,nlnk,lnk,lnk_lvl,lnkbt,prow);CHKERRQ(ierr);
576635aa4fcfSShri Abhyankar       nzi += nlnk;
576735aa4fcfSShri Abhyankar       prow = lnk[prow];
576835aa4fcfSShri Abhyankar       nzbd++;
576935aa4fcfSShri Abhyankar     }
577035aa4fcfSShri Abhyankar     bdiag[i] = nzbd;
577135aa4fcfSShri Abhyankar     bi[i+1]  = bi[i] + nzi;
577235aa4fcfSShri Abhyankar 
577335aa4fcfSShri Abhyankar     /* if free space is not available, make more free space */
577435aa4fcfSShri Abhyankar     if (current_space->local_remaining<nzi) {
577535aa4fcfSShri Abhyankar       nnz = 2*nzi*(n - i); /* estimated and max additional space needed */
577635aa4fcfSShri Abhyankar       ierr = PetscFreeSpaceGet(nnz,&current_space);CHKERRQ(ierr);
577735aa4fcfSShri Abhyankar       ierr = PetscFreeSpaceGet(nnz,&current_space_lvl);CHKERRQ(ierr);
577835aa4fcfSShri Abhyankar       reallocs++;
577935aa4fcfSShri Abhyankar     }
578035aa4fcfSShri Abhyankar 
578135aa4fcfSShri Abhyankar     /* copy data into free_space and free_space_lvl, then initialize lnk */
578235aa4fcfSShri Abhyankar     ierr = PetscIncompleteLLClean(n,n,nzi,lnk,lnk_lvl,current_space->array,current_space_lvl->array,lnkbt);CHKERRQ(ierr);
578335aa4fcfSShri Abhyankar     bj_ptr[i]    = current_space->array;
578435aa4fcfSShri Abhyankar     bjlvl_ptr[i] = current_space_lvl->array;
578535aa4fcfSShri Abhyankar 
578635aa4fcfSShri Abhyankar     /* make sure the active row i has diagonal entry */
578735aa4fcfSShri Abhyankar     if (*(bj_ptr[i]+bdiag[i]) != i) {
578835aa4fcfSShri Abhyankar       SETERRQ1(PETSC_ERR_MAT_LU_ZRPVT,"Row %D has missing diagonal in factored matrix\n\
578935aa4fcfSShri Abhyankar     try running with -pc_factor_nonzeros_along_diagonal or -pc_factor_diagonal_fill",i);
579035aa4fcfSShri Abhyankar     }
579135aa4fcfSShri Abhyankar 
579235aa4fcfSShri Abhyankar     current_space->array           += nzi;
579335aa4fcfSShri Abhyankar     current_space->local_used      += nzi;
579435aa4fcfSShri Abhyankar     current_space->local_remaining -= nzi;
579535aa4fcfSShri Abhyankar     current_space_lvl->array           += nzi;
579635aa4fcfSShri Abhyankar     current_space_lvl->local_used      += nzi;
579735aa4fcfSShri Abhyankar     current_space_lvl->local_remaining -= nzi;
579835aa4fcfSShri Abhyankar   }
579935aa4fcfSShri Abhyankar 
580035aa4fcfSShri Abhyankar   ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
580135aa4fcfSShri Abhyankar   ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
580235aa4fcfSShri Abhyankar 
580335aa4fcfSShri Abhyankar   /* destroy list of free space and other temporary arrays */
580435aa4fcfSShri Abhyankar   ierr = PetscMalloc((bi[n]+1)*sizeof(PetscInt),&bj);CHKERRQ(ierr);
580535aa4fcfSShri Abhyankar 
580635aa4fcfSShri Abhyankar   /* copy free_space into bj and free free_space; set bi, bj, bdiag in new datastructure; */
58072ce24eb6SHong Zhang   ierr = PetscFreeSpaceContiguous_LU(&free_space,bj,n,bi,bdiag);CHKERRQ(ierr);
580835aa4fcfSShri Abhyankar 
580935aa4fcfSShri Abhyankar   ierr = PetscIncompleteLLDestroy(lnk,lnkbt);CHKERRQ(ierr);
581035aa4fcfSShri Abhyankar   ierr = PetscFreeSpaceDestroy(free_space_lvl);CHKERRQ(ierr);
5811fca92195SBarry Smith   ierr = PetscFree2(bj_ptr,bjlvl_ptr);CHKERRQ(ierr);
581235aa4fcfSShri Abhyankar 
581335aa4fcfSShri Abhyankar #if defined(PETSC_USE_INFO)
581435aa4fcfSShri Abhyankar   {
581535aa4fcfSShri Abhyankar     PetscReal af = ((PetscReal)bi[n])/((PetscReal)ai[n]);
581635aa4fcfSShri Abhyankar     ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocs,f,af);CHKERRQ(ierr);
581735aa4fcfSShri Abhyankar     ierr = PetscInfo1(A,"Run with -[sub_]pc_factor_fill %G or use \n",af);CHKERRQ(ierr);
581835aa4fcfSShri Abhyankar     ierr = PetscInfo1(A,"PCFactorSetFill([sub]pc,%G);\n",af);CHKERRQ(ierr);
581935aa4fcfSShri Abhyankar     ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr);
582035aa4fcfSShri Abhyankar     if (diagonal_fill) {
582135aa4fcfSShri Abhyankar       ierr = PetscInfo1(A,"Detected and replaced %D missing diagonals",dcount);CHKERRQ(ierr);
582235aa4fcfSShri Abhyankar     }
582335aa4fcfSShri Abhyankar   }
582435aa4fcfSShri Abhyankar #endif
582535aa4fcfSShri Abhyankar 
582635aa4fcfSShri Abhyankar   /* put together the new matrix */
582735aa4fcfSShri Abhyankar   ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(fact,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr);
582835aa4fcfSShri Abhyankar   ierr = PetscLogObjectParent(fact,isicol);CHKERRQ(ierr);
582935aa4fcfSShri Abhyankar   b = (Mat_SeqBAIJ*)(fact)->data;
583035aa4fcfSShri Abhyankar   b->free_a       = PETSC_TRUE;
583135aa4fcfSShri Abhyankar   b->free_ij      = PETSC_TRUE;
583235aa4fcfSShri Abhyankar   b->singlemalloc = PETSC_FALSE;
583335aa4fcfSShri Abhyankar   ierr = PetscMalloc( (bs2*(bdiag[0]+1) )*sizeof(MatScalar),&b->a);CHKERRQ(ierr);
583435aa4fcfSShri Abhyankar   b->j          = bj;
583535aa4fcfSShri Abhyankar   b->i          = bi;
583635aa4fcfSShri Abhyankar   b->diag       = bdiag;
583735aa4fcfSShri Abhyankar   b->free_diag  = PETSC_TRUE;
583835aa4fcfSShri Abhyankar   b->ilen       = 0;
583935aa4fcfSShri Abhyankar   b->imax       = 0;
584035aa4fcfSShri Abhyankar   b->row        = isrow;
584135aa4fcfSShri Abhyankar   b->col        = iscol;
584235aa4fcfSShri Abhyankar   ierr          = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
584335aa4fcfSShri Abhyankar   ierr          = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
584435aa4fcfSShri Abhyankar   b->icol       = isicol;
584535aa4fcfSShri Abhyankar   ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
584635aa4fcfSShri Abhyankar   /* In b structure:  Free imax, ilen, old a, old j.
584735aa4fcfSShri Abhyankar      Allocate bdiag, solve_work, new a, new j */
584835aa4fcfSShri Abhyankar   ierr = PetscLogObjectMemory(fact,(bdiag[0]+1) * (sizeof(PetscInt)+bs2*sizeof(PetscScalar)));CHKERRQ(ierr);
584935aa4fcfSShri Abhyankar   b->maxnz = b->nz = bdiag[0]+1;
5850ae3d28f0SHong Zhang   fact->info.factor_mallocs    = reallocs;
5851ae3d28f0SHong Zhang   fact->info.fill_ratio_given  = f;
5852ae3d28f0SHong Zhang   fact->info.fill_ratio_needed = ((PetscReal)(bdiag[0]+1))/((PetscReal)ai[n]);
58534dd39f65SShri Abhyankar   ierr = MatSeqBAIJSetNumericFactorization(fact,both_identity);CHKERRQ(ierr);
585435aa4fcfSShri Abhyankar   PetscFunctionReturn(0);
585535aa4fcfSShri Abhyankar }
585635aa4fcfSShri Abhyankar 
585735aa4fcfSShri Abhyankar 
58584e2b4712SSatish Balay /*
58594e2b4712SSatish Balay      This code is virtually identical to MatILUFactorSymbolic_SeqAIJ
58604e2b4712SSatish Balay    except that the data structure of Mat_SeqAIJ is slightly different.
58614e2b4712SSatish Balay    Not a good example of code reuse.
58624e2b4712SSatish Balay */
58634a2ae208SSatish Balay #undef __FUNCT__
586406e38f1dSHong Zhang #define __FUNCT__ "MatILUFactorSymbolic_SeqBAIJ_inplace"
586506e38f1dSHong Zhang PetscErrorCode MatILUFactorSymbolic_SeqBAIJ_inplace(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info)
58664e2b4712SSatish Balay {
58674e2b4712SSatish Balay   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ*)A->data,*b;
58684e2b4712SSatish Balay   IS             isicol;
58696849ba73SBarry Smith   PetscErrorCode ierr;
58705d0c19d7SBarry Smith   const PetscInt *r,*ic,*ai = a->i,*aj = a->j,*xi;
58715d0c19d7SBarry Smith   PetscInt       prow,n = a->mbs,*ainew,*ajnew,jmax,*fill,nz,*im,*ajfill,*flev,*xitmp;
5872a96a251dSBarry Smith   PetscInt       *dloc,idx,row,m,fm,nzf,nzi,reallocate = 0,dcount = 0;
5873d0f46423SBarry Smith   PetscInt       incrlev,nnz,i,bs = A->rmap->bs,bs2 = a->bs2,levels,diagonal_fill,dd;
587441df41f0SMatthew Knepley   PetscTruth     col_identity,row_identity,both_identity,flg;
5875329f5518SBarry Smith   PetscReal      f;
58764e2b4712SSatish Balay 
58774e2b4712SSatish Balay   PetscFunctionBegin;
58786bce7ff8SHong Zhang   ierr = MatMissingDiagonal_SeqBAIJ(A,&flg,&dd);CHKERRQ(ierr);
58796bce7ff8SHong Zhang   if (flg) SETERRQ1(PETSC_ERR_ARG_WRONGSTATE,"Matrix A is missing diagonal entry in row %D",dd);
58806bce7ff8SHong Zhang 
5881435faa5fSBarry Smith   f             = info->fill;
5882690b6cddSBarry Smith   levels        = (PetscInt)info->levels;
5883690b6cddSBarry Smith   diagonal_fill = (PetscInt)info->diagonal_fill;
58844c49b128SBarry Smith   ierr = ISInvertPermutation(iscol,PETSC_DECIDE,&isicol);CHKERRQ(ierr);
588516a2bf60SHong Zhang 
5886667159a5SBarry Smith   ierr = ISIdentity(isrow,&row_identity);CHKERRQ(ierr);
5887667159a5SBarry Smith   ierr = ISIdentity(iscol,&col_identity);CHKERRQ(ierr);
58887d18ce8fSMatthew Knepley   both_identity = (PetscTruth) (row_identity && col_identity);
5889309c388cSBarry Smith 
589041df41f0SMatthew Knepley   if (!levels && both_identity) {  /* special case copy the nonzero structure */
589116a2bf60SHong Zhang     ierr = MatDuplicateNoCreate_SeqBAIJ(fact,A,MAT_DO_NOT_COPY_VALUES,PETSC_TRUE);CHKERRQ(ierr);
58928b1456e3SHong Zhang     ierr = MatSeqBAIJSetNumericFactorization_inplace(fact,both_identity);CHKERRQ(ierr);
58936bce7ff8SHong Zhang 
5894719d5645SBarry Smith     fact->factor = MAT_FACTOR_ILU;
5895ae3d28f0SHong Zhang     b            = (Mat_SeqBAIJ*)fact->data;
5896bb3d539aSBarry Smith     b->row       = isrow;
5897bb3d539aSBarry Smith     b->col       = iscol;
5898bb3d539aSBarry Smith     ierr         = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
5899bb3d539aSBarry Smith     ierr         = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
5900bb3d539aSBarry Smith     b->icol      = isicol;
5901bcd9e38bSBarry Smith     b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
5902b588c5a2SHong Zhang     ierr         = PetscMalloc((n+1)*bs*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
59036bce7ff8SHong Zhang     PetscFunctionReturn(0);
59046bce7ff8SHong Zhang   }
59056bce7ff8SHong Zhang 
59066bce7ff8SHong Zhang   /* general case perform the symbolic factorization */
59074e2b4712SSatish Balay     ierr = ISGetIndices(isrow,&r);CHKERRQ(ierr);
59084e2b4712SSatish Balay     ierr = ISGetIndices(isicol,&ic);CHKERRQ(ierr);
59094e2b4712SSatish Balay 
59104e2b4712SSatish Balay     /* get new row pointers */
5911690b6cddSBarry Smith     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&ainew);CHKERRQ(ierr);
59124e2b4712SSatish Balay     ainew[0] = 0;
59134e2b4712SSatish Balay     /* don't know how many column pointers are needed so estimate */
5914690b6cddSBarry Smith     jmax = (PetscInt)(f*ai[n] + 1);
5915690b6cddSBarry Smith     ierr = PetscMalloc((jmax)*sizeof(PetscInt),&ajnew);CHKERRQ(ierr);
59164e2b4712SSatish Balay     /* ajfill is level of fill for each fill entry */
5917690b6cddSBarry Smith     ierr = PetscMalloc((jmax)*sizeof(PetscInt),&ajfill);CHKERRQ(ierr);
59184e2b4712SSatish Balay     /* fill is a linked list of nonzeros in active row */
5919690b6cddSBarry Smith     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&fill);CHKERRQ(ierr);
59204e2b4712SSatish Balay     /* im is level for each filled value */
5921690b6cddSBarry Smith     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&im);CHKERRQ(ierr);
59224e2b4712SSatish Balay     /* dloc is location of diagonal in factor */
5923690b6cddSBarry Smith     ierr = PetscMalloc((n+1)*sizeof(PetscInt),&dloc);CHKERRQ(ierr);
59244e2b4712SSatish Balay     dloc[0]  = 0;
59254e2b4712SSatish Balay     for (prow=0; prow<n; prow++) {
5926435faa5fSBarry Smith 
5927435faa5fSBarry Smith       /* copy prow into linked list */
59284e2b4712SSatish Balay       nzf        = nz  = ai[r[prow]+1] - ai[r[prow]];
59293b4a8b6dSBarry 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);
59304e2b4712SSatish Balay       xi         = aj + ai[r[prow]];
59314e2b4712SSatish Balay       fill[n]    = n;
5932435faa5fSBarry Smith       fill[prow] = -1; /* marker for diagonal entry */
59334e2b4712SSatish Balay       while (nz--) {
59344e2b4712SSatish Balay 	fm  = n;
59354e2b4712SSatish Balay 	idx = ic[*xi++];
59364e2b4712SSatish Balay 	do {
59374e2b4712SSatish Balay 	  m  = fm;
59384e2b4712SSatish Balay 	  fm = fill[m];
59394e2b4712SSatish Balay 	} while (fm < idx);
59404e2b4712SSatish Balay 	fill[m]   = idx;
59414e2b4712SSatish Balay 	fill[idx] = fm;
59424e2b4712SSatish Balay 	im[idx]   = 0;
59434e2b4712SSatish Balay       }
5944435faa5fSBarry Smith 
5945435faa5fSBarry Smith       /* make sure diagonal entry is included */
5946435faa5fSBarry Smith       if (diagonal_fill && fill[prow] == -1) {
5947435faa5fSBarry Smith 	fm = n;
5948435faa5fSBarry Smith 	while (fill[fm] < prow) fm = fill[fm];
5949435faa5fSBarry Smith 	fill[prow] = fill[fm];  /* insert diagonal into linked list */
5950435faa5fSBarry Smith 	fill[fm]   = prow;
5951435faa5fSBarry Smith 	im[prow]   = 0;
5952435faa5fSBarry Smith 	nzf++;
5953335d9088SBarry Smith 	dcount++;
5954435faa5fSBarry Smith       }
5955435faa5fSBarry Smith 
59564e2b4712SSatish Balay       nzi = 0;
59574e2b4712SSatish Balay       row = fill[n];
59584e2b4712SSatish Balay       while (row < prow) {
59594e2b4712SSatish Balay 	incrlev = im[row] + 1;
59604e2b4712SSatish Balay 	nz      = dloc[row];
5961435faa5fSBarry Smith 	xi      = ajnew  + ainew[row] + nz + 1;
59624e2b4712SSatish Balay 	flev    = ajfill + ainew[row] + nz + 1;
59634e2b4712SSatish Balay 	nnz     = ainew[row+1] - ainew[row] - nz - 1;
59644e2b4712SSatish Balay 	fm      = row;
59654e2b4712SSatish Balay 	while (nnz-- > 0) {
59664e2b4712SSatish Balay 	  idx = *xi++;
59674e2b4712SSatish Balay 	  if (*flev + incrlev > levels) {
59684e2b4712SSatish Balay 	    flev++;
59694e2b4712SSatish Balay 	    continue;
59704e2b4712SSatish Balay 	  }
59714e2b4712SSatish Balay 	  do {
59724e2b4712SSatish Balay 	    m  = fm;
59734e2b4712SSatish Balay 	    fm = fill[m];
59744e2b4712SSatish Balay 	  } while (fm < idx);
59754e2b4712SSatish Balay 	  if (fm != idx) {
59764e2b4712SSatish Balay 	    im[idx]   = *flev + incrlev;
59774e2b4712SSatish Balay 	    fill[m]   = idx;
59784e2b4712SSatish Balay 	    fill[idx] = fm;
59794e2b4712SSatish Balay 	    fm        = idx;
59804e2b4712SSatish Balay 	    nzf++;
5981ecf371e4SBarry Smith 	  } else {
59824e2b4712SSatish Balay 	    if (im[idx] > *flev + incrlev) im[idx] = *flev+incrlev;
59834e2b4712SSatish Balay 	  }
59844e2b4712SSatish Balay 	  flev++;
59854e2b4712SSatish Balay 	}
59864e2b4712SSatish Balay 	row = fill[row];
59874e2b4712SSatish Balay 	nzi++;
59884e2b4712SSatish Balay       }
59894e2b4712SSatish Balay       /* copy new filled row into permanent storage */
59904e2b4712SSatish Balay       ainew[prow+1] = ainew[prow] + nzf;
59914e2b4712SSatish Balay       if (ainew[prow+1] > jmax) {
5992ecf371e4SBarry Smith 
5993ecf371e4SBarry Smith 	/* estimate how much additional space we will need */
5994ecf371e4SBarry Smith 	/* use the strategy suggested by David Hysom <hysom@perch-t.icase.edu> */
5995ecf371e4SBarry Smith 	/* just double the memory each time */
5996690b6cddSBarry Smith 	PetscInt maxadd = jmax;
5997ecf371e4SBarry Smith 	/* maxadd = (int)(((f*ai[n]+1)*(n-prow+5))/n); */
59984e2b4712SSatish Balay 	if (maxadd < nzf) maxadd = (n-prow)*(nzf+1);
59994e2b4712SSatish Balay 	jmax += maxadd;
6000ecf371e4SBarry Smith 
6001ecf371e4SBarry Smith 	/* allocate a longer ajnew and ajfill */
60025d0c19d7SBarry Smith 	ierr = PetscMalloc(jmax*sizeof(PetscInt),&xitmp);CHKERRQ(ierr);
60035d0c19d7SBarry Smith 	ierr = PetscMemcpy(xitmp,ajnew,ainew[prow]*sizeof(PetscInt));CHKERRQ(ierr);
6004606d414cSSatish Balay 	ierr = PetscFree(ajnew);CHKERRQ(ierr);
60055d0c19d7SBarry Smith 	ajnew = xitmp;
60065d0c19d7SBarry Smith 	ierr = PetscMalloc(jmax*sizeof(PetscInt),&xitmp);CHKERRQ(ierr);
60075d0c19d7SBarry Smith 	ierr = PetscMemcpy(xitmp,ajfill,ainew[prow]*sizeof(PetscInt));CHKERRQ(ierr);
6008606d414cSSatish Balay 	ierr = PetscFree(ajfill);CHKERRQ(ierr);
60095d0c19d7SBarry Smith 	ajfill = xitmp;
6010eb150c5cSKris Buschelman 	reallocate++; /* count how many reallocations are needed */
60114e2b4712SSatish Balay       }
60125d0c19d7SBarry Smith       xitmp       = ajnew + ainew[prow];
60134e2b4712SSatish Balay       flev        = ajfill + ainew[prow];
60144e2b4712SSatish Balay       dloc[prow]  = nzi;
60154e2b4712SSatish Balay       fm          = fill[n];
60164e2b4712SSatish Balay       while (nzf--) {
60175d0c19d7SBarry Smith 	*xitmp++ = fm;
60184e2b4712SSatish Balay 	*flev++ = im[fm];
60194e2b4712SSatish Balay 	fm      = fill[fm];
60204e2b4712SSatish Balay       }
6021435faa5fSBarry Smith       /* make sure row has diagonal entry */
6022435faa5fSBarry Smith       if (ajnew[ainew[prow]+dloc[prow]] != prow) {
602377431f27SBarry Smith 	SETERRQ1(PETSC_ERR_MAT_LU_ZRPVT,"Row %D has missing diagonal in factored matrix\n\
60242401956bSBarry Smith     try running with -pc_factor_nonzeros_along_diagonal or -pc_factor_diagonal_fill",prow);
6025435faa5fSBarry Smith       }
60264e2b4712SSatish Balay     }
6027606d414cSSatish Balay     ierr = PetscFree(ajfill);CHKERRQ(ierr);
60284e2b4712SSatish Balay     ierr = ISRestoreIndices(isrow,&r);CHKERRQ(ierr);
60294e2b4712SSatish Balay     ierr = ISRestoreIndices(isicol,&ic);CHKERRQ(ierr);
6030606d414cSSatish Balay     ierr = PetscFree(fill);CHKERRQ(ierr);
6031606d414cSSatish Balay     ierr = PetscFree(im);CHKERRQ(ierr);
60324e2b4712SSatish Balay 
60336cf91177SBarry Smith #if defined(PETSC_USE_INFO)
60344e2b4712SSatish Balay     {
6035329f5518SBarry Smith       PetscReal af = ((PetscReal)ainew[n])/((PetscReal)ai[n]);
6036ae15b995SBarry Smith       ierr = PetscInfo3(A,"Reallocs %D Fill ratio:given %G needed %G\n",reallocate,f,af);CHKERRQ(ierr);
6037ae15b995SBarry Smith       ierr = PetscInfo1(A,"Run with -pc_factor_fill %G or use \n",af);CHKERRQ(ierr);
6038ae15b995SBarry Smith       ierr = PetscInfo1(A,"PCFactorSetFill(pc,%G);\n",af);CHKERRQ(ierr);
6039ae15b995SBarry Smith       ierr = PetscInfo(A,"for best performance.\n");CHKERRQ(ierr);
6040335d9088SBarry Smith       if (diagonal_fill) {
6041ae15b995SBarry Smith 	ierr = PetscInfo1(A,"Detected and replaced %D missing diagonals\n",dcount);CHKERRQ(ierr);
6042335d9088SBarry Smith       }
60434e2b4712SSatish Balay     }
604463ba0a88SBarry Smith #endif
60454e2b4712SSatish Balay 
60464e2b4712SSatish Balay     /* put together the new matrix */
6047719d5645SBarry Smith     ierr = MatSeqBAIJSetPreallocation_SeqBAIJ(fact,bs,MAT_SKIP_ALLOCATION,PETSC_NULL);CHKERRQ(ierr);
6048719d5645SBarry Smith     ierr = PetscLogObjectParent(fact,isicol);CHKERRQ(ierr);
6049ae3d28f0SHong Zhang     b    = (Mat_SeqBAIJ*)fact->data;
6050e6b907acSBarry Smith     b->free_a       = PETSC_TRUE;
6051e6b907acSBarry Smith     b->free_ij      = PETSC_TRUE;
60527c922b88SBarry Smith     b->singlemalloc = PETSC_FALSE;
6053a96a251dSBarry Smith     ierr = PetscMalloc(bs2*ainew[n]*sizeof(MatScalar),&b->a);CHKERRQ(ierr);
60544e2b4712SSatish Balay     b->j          = ajnew;
60554e2b4712SSatish Balay     b->i          = ainew;
60564e2b4712SSatish Balay     for (i=0; i<n; i++) dloc[i] += ainew[i];
60574e2b4712SSatish Balay     b->diag       = dloc;
60587f53bb6cSHong Zhang     b->free_diag  = PETSC_TRUE;
60594e2b4712SSatish Balay     b->ilen       = 0;
60604e2b4712SSatish Balay     b->imax       = 0;
60614e2b4712SSatish Balay     b->row        = isrow;
60624e2b4712SSatish Balay     b->col        = iscol;
6063bcd9e38bSBarry Smith     b->pivotinblocks = (info->pivotinblocks) ? PETSC_TRUE : PETSC_FALSE;
6064c38d4ed2SBarry Smith     ierr          = PetscObjectReference((PetscObject)isrow);CHKERRQ(ierr);
6065c38d4ed2SBarry Smith     ierr          = PetscObjectReference((PetscObject)iscol);CHKERRQ(ierr);
6066e51c0b9cSSatish Balay     b->icol       = isicol;
606787828ca2SBarry Smith     ierr = PetscMalloc((bs*n+bs)*sizeof(PetscScalar),&b->solve_work);CHKERRQ(ierr);
60684e2b4712SSatish Balay     /* In b structure:  Free imax, ilen, old a, old j.
60694e2b4712SSatish Balay        Allocate dloc, solve_work, new a, new j */
6070719d5645SBarry Smith     ierr = PetscLogObjectMemory(fact,(ainew[n]-n)*(sizeof(PetscInt))+bs2*ainew[n]*sizeof(PetscScalar));CHKERRQ(ierr);
60714e2b4712SSatish Balay     b->maxnz          = b->nz = ainew[n];
60724e2b4712SSatish Balay 
6073ae3d28f0SHong Zhang     fact->info.factor_mallocs    = reallocate;
6074ae3d28f0SHong Zhang     fact->info.fill_ratio_given  = f;
6075ae3d28f0SHong Zhang     fact->info.fill_ratio_needed = ((PetscReal)ainew[n])/((PetscReal)ai[prow]);
60766bce7ff8SHong Zhang 
60778b1456e3SHong Zhang   ierr = MatSeqBAIJSetNumericFactorization_inplace(fact,both_identity);CHKERRQ(ierr);
60788661488fSKris Buschelman   PetscFunctionReturn(0);
60798661488fSKris Buschelman }
60808661488fSKris Buschelman 
6081732ee342SKris Buschelman #undef __FUNCT__
60827e7071cdSKris Buschelman #define __FUNCT__ "MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE"
6083dfbe8321SBarry Smith PetscErrorCode MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE(Mat A)
60847e7071cdSKris Buschelman {
608512272027SHong Zhang   /* Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data; */
608612272027SHong Zhang   /* int i,*AJ=a->j,nz=a->nz; */
60875a9542e3SKris Buschelman   PetscFunctionBegin;
60887cf1b8d3SKris Buschelman   /* Undo Column scaling */
60897cf1b8d3SKris Buschelman /*    while (nz--) { */
60907cf1b8d3SKris Buschelman /*      AJ[i] = AJ[i]/4; */
60917cf1b8d3SKris Buschelman /*    } */
6092c115a38dSKris Buschelman   /* This should really invoke a push/pop logic, but we don't have that yet. */
6093c115a38dSKris Buschelman   A->ops->setunfactored = PETSC_NULL;
60947cf1b8d3SKris Buschelman   PetscFunctionReturn(0);
60957cf1b8d3SKris Buschelman }
60967cf1b8d3SKris Buschelman 
60977cf1b8d3SKris Buschelman #undef __FUNCT__
60987cf1b8d3SKris Buschelman #define __FUNCT__ "MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE_usj"
6099dfbe8321SBarry Smith PetscErrorCode MatSetUnfactored_SeqBAIJ_4_NaturalOrdering_SSE_usj(Mat A)
61007cf1b8d3SKris Buschelman {
61017cf1b8d3SKris Buschelman   Mat_SeqBAIJ    *a = (Mat_SeqBAIJ *)A->data;
6102b24ad042SBarry Smith   PetscInt       *AJ=a->j,nz=a->nz;
61032aa5897fSKris Buschelman   unsigned short *aj=(unsigned short *)AJ;
61045a9542e3SKris Buschelman   PetscFunctionBegin;
61050b9da03eSKris Buschelman   /* Is this really necessary? */
610620235379SKris Buschelman   while (nz--) {
61070b9da03eSKris Buschelman     AJ[nz] = (int)((unsigned int)aj[nz]); /* First extend, then convert to signed. */
61087e7071cdSKris Buschelman   }
6109c115a38dSKris Buschelman   A->ops->setunfactored = PETSC_NULL;
61107e7071cdSKris Buschelman   PetscFunctionReturn(0);
61117e7071cdSKris Buschelman }
61127e7071cdSKris Buschelman 
6113732ee342SKris Buschelman 
6114