1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
void Blas::MPI_CG(SparseMatrix& A, VecDbl_t& x, VecDbl_t& b, size_t iter_max) {
double TOLERANCE = 1.0e-10;
const double NEARZERO = 1.0e-10;
int n = A.Size_;
x.resize(n);
VecDbl_t Ap(n);
VecDbl_t r = b;
VecDbl_t p = r;
int k = 0;
while (k < 1000)
{
VecDbl_t rold = r;
MxV(A, p, Ap);
double alpha = dotproduct(r,r) / dotproduct(p, Ap);
x = vectorCombination(1.0, x, alpha, p);
r = vectorCombination(1.0, r, -alpha, Ap);
if (vectorNorm(r) < TOLERANCE) break;
double beta = dotproduct(r, r) / dotproduct(rold, rold);
p = vectorCombination(1.0, r, beta, p);
k++;
}
}
|