Actual source code: baijsolvtran1.c
1: #include <../src/mat/impls/baij/seq/baij.h>
2: #include <petsc/private/kernels/blockinvert.h>
4: PetscErrorCode MatSolveTranspose_SeqBAIJ_1(Mat A, Vec bb, Vec xx)
5: {
6: Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data;
7: IS iscol = a->col, isrow = a->row;
8: const PetscInt *rout, *cout, *r, *c, *adiag = a->diag, *ai = a->i, *aj = a->j, *vi;
9: PetscInt i, n = a->mbs, j;
10: PetscInt nz;
11: PetscScalar *x, *tmp, s1;
12: const MatScalar *aa = a->a, *v;
13: const PetscScalar *b;
15: VecGetArrayRead(bb, &b);
16: VecGetArray(xx, &x);
17: tmp = a->solve_work;
19: ISGetIndices(isrow, &rout);
20: r = rout;
21: ISGetIndices(iscol, &cout);
22: c = cout;
24: /* copy the b into temp work space according to permutation */
25: for (i = 0; i < n; i++) tmp[i] = b[c[i]];
27: /* forward solve the U^T */
28: for (i = 0; i < n; i++) {
29: v = aa + adiag[i + 1] + 1;
30: vi = aj + adiag[i + 1] + 1;
31: nz = adiag[i] - adiag[i + 1] - 1;
32: s1 = tmp[i];
33: s1 *= v[nz]; /* multiply by inverse of diagonal entry */
34: for (j = 0; j < nz; j++) tmp[vi[j]] -= s1 * v[j];
35: tmp[i] = s1;
36: }
38: /* backward solve the L^T */
39: for (i = n - 1; i >= 0; i--) {
40: v = aa + ai[i];
41: vi = aj + ai[i];
42: nz = ai[i + 1] - ai[i];
43: s1 = tmp[i];
44: for (j = 0; j < nz; j++) tmp[vi[j]] -= s1 * v[j];
45: }
47: /* copy tmp into x according to permutation */
48: for (i = 0; i < n; i++) x[r[i]] = tmp[i];
50: ISRestoreIndices(isrow, &rout);
51: ISRestoreIndices(iscol, &cout);
52: VecRestoreArrayRead(bb, &b);
53: VecRestoreArray(xx, &x);
55: PetscLogFlops(2.0 * a->nz - A->cmap->n);
56: return 0;
57: }
59: PetscErrorCode MatSolveTranspose_SeqBAIJ_1_inplace(Mat A, Vec bb, Vec xx)
60: {
61: Mat_SeqBAIJ *a = (Mat_SeqBAIJ *)A->data;
62: IS iscol = a->col, isrow = a->row;
63: const PetscInt *r, *c, *rout, *cout;
64: const PetscInt *diag = a->diag, n = a->mbs, *vi, *ai = a->i, *aj = a->j;
65: PetscInt i, nz;
66: const MatScalar *aa = a->a, *v;
67: PetscScalar s1, *x, *t;
68: const PetscScalar *b;
70: VecGetArrayRead(bb, &b);
71: VecGetArray(xx, &x);
72: t = a->solve_work;
74: ISGetIndices(isrow, &rout);
75: r = rout;
76: ISGetIndices(iscol, &cout);
77: c = cout;
79: /* copy the b into temp work space according to permutation */
80: for (i = 0; i < n; i++) t[i] = b[c[i]];
82: /* forward solve the U^T */
83: for (i = 0; i < n; i++) {
84: v = aa + diag[i];
85: /* multiply by the inverse of the block diagonal */
86: s1 = (*v++) * t[i];
87: vi = aj + diag[i] + 1;
88: nz = ai[i + 1] - diag[i] - 1;
89: while (nz--) t[*vi++] -= (*v++) * s1;
90: t[i] = s1;
91: }
92: /* backward solve the L^T */
93: for (i = n - 1; i >= 0; i--) {
94: v = aa + diag[i] - 1;
95: vi = aj + diag[i] - 1;
96: nz = diag[i] - ai[i];
97: s1 = t[i];
98: while (nz--) t[*vi--] -= (*v--) * s1;
99: }
101: /* copy t into x according to permutation */
102: for (i = 0; i < n; i++) x[r[i]] = t[i];
104: ISRestoreIndices(isrow, &rout);
105: ISRestoreIndices(iscol, &cout);
106: VecRestoreArrayRead(bb, &b);
107: VecRestoreArray(xx, &x);
108: PetscLogFlops(2.0 * (a->nz) - A->cmap->n);
109: return 0;
110: }