Actual source code: baijsolvtrannat2.c

  1: #include <../src/mat/impls/baij/seq/baij.h>

  3: PetscErrorCode MatSolveTranspose_SeqBAIJ_2_NaturalOrdering_inplace(Mat A,Vec bb,Vec xx)
  4: {
  5:   Mat_SeqBAIJ     *a=(Mat_SeqBAIJ*)A->data;
  6:   PetscInt        i,nz,idx,idt,oidx;
  7:   const PetscInt  *diag = a->diag,*vi,n=a->mbs,*ai=a->i,*aj=a->j;
  8:   const MatScalar *aa   =a->a,*v;
  9:   PetscScalar     s1,s2,x1,x2,*x;

 11:   VecCopy(bb,xx);
 12:   VecGetArray(xx,&x);

 14:   /* forward solve the U^T */
 15:   idx = 0;
 16:   for (i=0; i<n; i++) {

 18:     v = aa + 4*diag[i];
 19:     /* multiply by the inverse of the block diagonal */
 20:     x1 = x[idx];   x2 = x[1+idx];
 21:     s1 = v[0]*x1  +  v[1]*x2;
 22:     s2 = v[2]*x1  +  v[3]*x2;
 23:     v += 4;

 25:     vi = aj + diag[i] + 1;
 26:     nz = ai[i+1] - diag[i] - 1;
 27:     while (nz--) {
 28:       oidx       = 2*(*vi++);
 29:       x[oidx]   -= v[0]*s1  +  v[1]*s2;
 30:       x[oidx+1] -= v[2]*s1  +  v[3]*s2;
 31:       v         += 4;
 32:     }
 33:     x[idx] = s1;x[1+idx] = s2;
 34:     idx   += 2;
 35:   }
 36:   /* backward solve the L^T */
 37:   for (i=n-1; i>=0; i--) {
 38:     v   = aa + 4*diag[i] - 4;
 39:     vi  = aj + diag[i] - 1;
 40:     nz  = diag[i] - ai[i];
 41:     idt = 2*i;
 42:     s1  = x[idt];  s2 = x[1+idt];
 43:     while (nz--) {
 44:       idx       = 2*(*vi--);
 45:       x[idx]   -=  v[0]*s1 +  v[1]*s2;
 46:       x[idx+1] -=  v[2]*s1 +  v[3]*s2;
 47:       v        -= 4;
 48:     }
 49:   }
 50:   VecRestoreArray(xx,&x);
 51:   PetscLogFlops(2.0*4.0*(a->nz) - 2.0*A->cmap->n);
 52:   return 0;
 53: }

 55: PetscErrorCode MatSolveTranspose_SeqBAIJ_2_NaturalOrdering(Mat A,Vec bb,Vec xx)
 56: {
 57:   Mat_SeqBAIJ     *a=(Mat_SeqBAIJ*)A->data;
 58:   const PetscInt  n=a->mbs,*vi,*ai=a->i,*aj=a->j,*diag=a->diag;
 59:   PetscInt        nz,idx,idt,j,i,oidx;
 60:   const PetscInt  bs =A->rmap->bs,bs2=a->bs2;
 61:   const MatScalar *aa=a->a,*v;
 62:   PetscScalar     s1,s2,x1,x2,*x;

 64:   VecCopy(bb,xx);
 65:   VecGetArray(xx,&x);

 67:   /* forward solve the U^T */
 68:   idx = 0;
 69:   for (i=0; i<n; i++) {
 70:     v = aa + bs2*diag[i];
 71:     /* multiply by the inverse of the block diagonal */
 72:     x1 = x[idx];   x2 = x[1+idx];
 73:     s1 = v[0]*x1  +  v[1]*x2;
 74:     s2 = v[2]*x1  +  v[3]*x2;
 75:     v -= bs2;

 77:     vi = aj + diag[i] - 1;
 78:     nz = diag[i] - diag[i+1] - 1;
 79:     for (j=0; j>-nz; j--) {
 80:       oidx       = bs*vi[j];
 81:       x[oidx]   -= v[0]*s1  +  v[1]*s2;
 82:       x[oidx+1] -= v[2]*s1  +  v[3]*s2;
 83:       v         -= bs2;
 84:     }
 85:     x[idx] = s1;x[1+idx] = s2;
 86:     idx   += bs;
 87:   }
 88:   /* backward solve the L^T */
 89:   for (i=n-1; i>=0; i--) {
 90:     v   = aa + bs2*ai[i];
 91:     vi  = aj + ai[i];
 92:     nz  = ai[i+1] - ai[i];
 93:     idt = bs*i;
 94:     s1  = x[idt];  s2 = x[1+idt];
 95:     for (j=0; j<nz; j++) {
 96:       idx       = bs*vi[j];
 97:       x[idx]   -=  v[0]*s1 +  v[1]*s2;
 98:       x[idx+1] -=  v[2]*s1 +  v[3]*s2;
 99:       v        += bs2;
100:     }
101:   }
102:   VecRestoreArray(xx,&x);
103:   PetscLogFlops(2.0*bs2*(a->nz) - bs*A->cmap->n);
104:   return 0;
105: }