xref: /petsc/src/mat/impls/baij/seq/baijsolvnat11.c (revision 9566063d113dddea24716c546802770db7481bc0)
12c733ed4SBarry Smith #include <../src/mat/impls/baij/seq/baij.h>
22c733ed4SBarry Smith #include <petsc/private/kernels/blockinvert.h>
32c733ed4SBarry Smith 
42c733ed4SBarry Smith /* Block operations are done by accessing one column at at time */
52c733ed4SBarry Smith /* Default MatSolve for block size 11 */
62c733ed4SBarry Smith 
72c733ed4SBarry Smith PetscErrorCode MatSolve_SeqBAIJ_11_NaturalOrdering(Mat A,Vec bb,Vec xx)
82c733ed4SBarry Smith {
92c733ed4SBarry Smith   Mat_SeqBAIJ       *a=(Mat_SeqBAIJ*)A->data;
102c733ed4SBarry Smith   const PetscInt    n=a->mbs,*ai=a->i,*aj=a->j,*adiag=a->diag,*vi,bs=A->rmap->bs,bs2=a->bs2;
112c733ed4SBarry Smith   PetscInt          i,k,nz,idx,idt,m;
122c733ed4SBarry Smith   const MatScalar   *aa=a->a,*v;
132c733ed4SBarry Smith   PetscScalar       s[11];
142c733ed4SBarry Smith   PetscScalar       *x,xv;
152c733ed4SBarry Smith   const PetscScalar *b;
162c733ed4SBarry Smith 
172c733ed4SBarry Smith   PetscFunctionBegin;
18*9566063dSJacob Faibussowitsch   PetscCall(VecGetArrayRead(bb,&b));
19*9566063dSJacob Faibussowitsch   PetscCall(VecGetArray(xx,&x));
202c733ed4SBarry Smith 
212c733ed4SBarry Smith   /* forward solve the lower triangular */
222c733ed4SBarry Smith   for (i=0; i<n; i++) {
232c733ed4SBarry Smith     v         = aa + bs2*ai[i];
242c733ed4SBarry Smith     vi        = aj + ai[i];
252c733ed4SBarry Smith     nz        = ai[i+1] - ai[i];
262c733ed4SBarry Smith     idt       = bs*i;
272c733ed4SBarry Smith     x[idt]    = b[idt];    x[1+idt]  = b[1+idt];  x[2+idt]  = b[2+idt];  x[3+idt]  = b[3+idt];  x[4+idt]  = b[4+idt];
282c733ed4SBarry Smith     x[5+idt]  = b[5+idt];  x[6+idt]  = b[6+idt];  x[7+idt]  = b[7+idt];  x[8+idt]  = b[8+idt];  x[9+idt] = b[9+idt];
292c733ed4SBarry Smith     x[10+idt] = b[10+idt];
302c733ed4SBarry Smith     for (m=0; m<nz; m++) {
312c733ed4SBarry Smith       idx = bs*vi[m];
322c733ed4SBarry Smith       for (k=0; k<11; k++) {
332c733ed4SBarry Smith         xv         = x[k + idx];
342c733ed4SBarry Smith         x[idt]    -= v[0]*xv;
352c733ed4SBarry Smith         x[1+idt]  -= v[1]*xv;
362c733ed4SBarry Smith         x[2+idt]  -= v[2]*xv;
372c733ed4SBarry Smith         x[3+idt]  -= v[3]*xv;
382c733ed4SBarry Smith         x[4+idt]  -= v[4]*xv;
392c733ed4SBarry Smith         x[5+idt]  -= v[5]*xv;
402c733ed4SBarry Smith         x[6+idt]  -= v[6]*xv;
412c733ed4SBarry Smith         x[7+idt]  -= v[7]*xv;
422c733ed4SBarry Smith         x[8+idt]  -= v[8]*xv;
432c733ed4SBarry Smith         x[9+idt]  -= v[9]*xv;
442c733ed4SBarry Smith         x[10+idt] -= v[10]*xv;
452c733ed4SBarry Smith         v         += 11;
462c733ed4SBarry Smith       }
472c733ed4SBarry Smith     }
482c733ed4SBarry Smith   }
492c733ed4SBarry Smith   /* backward solve the upper triangular */
502c733ed4SBarry Smith   for (i=n-1; i>=0; i--) {
512c733ed4SBarry Smith     v     = aa + bs2*(adiag[i+1]+1);
522c733ed4SBarry Smith     vi    = aj + adiag[i+1]+1;
532c733ed4SBarry Smith     nz    = adiag[i] - adiag[i+1] - 1;
542c733ed4SBarry Smith     idt   = bs*i;
552c733ed4SBarry Smith     s[0]  = x[idt];    s[1]  = x[1+idt];  s[2]  = x[2+idt];  s[3]  = x[3+idt];  s[4]  = x[4+idt];
562c733ed4SBarry Smith     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];
572c733ed4SBarry Smith     s[10] = x[10+idt];
582c733ed4SBarry Smith 
592c733ed4SBarry Smith     for (m=0; m<nz; m++) {
602c733ed4SBarry Smith       idx = bs*vi[m];
612c733ed4SBarry Smith       for (k=0; k<11; k++) {
622c733ed4SBarry Smith         xv     = x[k + idx];
632c733ed4SBarry Smith         s[0]  -= v[0]*xv;
642c733ed4SBarry Smith         s[1]  -= v[1]*xv;
652c733ed4SBarry Smith         s[2]  -= v[2]*xv;
662c733ed4SBarry Smith         s[3]  -= v[3]*xv;
672c733ed4SBarry Smith         s[4]  -= v[4]*xv;
682c733ed4SBarry Smith         s[5]  -= v[5]*xv;
692c733ed4SBarry Smith         s[6]  -= v[6]*xv;
702c733ed4SBarry Smith         s[7]  -= v[7]*xv;
712c733ed4SBarry Smith         s[8]  -= v[8]*xv;
722c733ed4SBarry Smith         s[9]  -= v[9]*xv;
732c733ed4SBarry Smith         s[10] -= v[10]*xv;
742c733ed4SBarry Smith         v     += 11;
752c733ed4SBarry Smith       }
762c733ed4SBarry Smith     }
77*9566063dSJacob Faibussowitsch     PetscCall(PetscArrayzero(x+idt,bs));
782c733ed4SBarry Smith     for (k=0; k<11; k++) {
792c733ed4SBarry Smith       x[idt]    += v[0]*s[k];
802c733ed4SBarry Smith       x[1+idt]  += v[1]*s[k];
812c733ed4SBarry Smith       x[2+idt]  += v[2]*s[k];
822c733ed4SBarry Smith       x[3+idt]  += v[3]*s[k];
832c733ed4SBarry Smith       x[4+idt]  += v[4]*s[k];
842c733ed4SBarry Smith       x[5+idt]  += v[5]*s[k];
852c733ed4SBarry Smith       x[6+idt]  += v[6]*s[k];
862c733ed4SBarry Smith       x[7+idt]  += v[7]*s[k];
872c733ed4SBarry Smith       x[8+idt]  += v[8]*s[k];
882c733ed4SBarry Smith       x[9+idt]  += v[9]*s[k];
892c733ed4SBarry Smith       x[10+idt] += v[10]*s[k];
902c733ed4SBarry Smith       v         += 11;
912c733ed4SBarry Smith     }
922c733ed4SBarry Smith   }
93*9566063dSJacob Faibussowitsch   PetscCall(VecRestoreArrayRead(bb,&b));
94*9566063dSJacob Faibussowitsch   PetscCall(VecRestoreArray(xx,&x));
95*9566063dSJacob Faibussowitsch   PetscCall(PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n));
962c733ed4SBarry Smith   PetscFunctionReturn(0);
972c733ed4SBarry Smith }
98