Skip to content

Commit

Permalink
Provide memory info for iterative solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
ddemidov committed Jul 23, 2018
1 parent 10dad8a commit 8a4c96f
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 7 deletions.
10 changes: 10 additions & 0 deletions amgcl/detail/qr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ class QR {
solve(rows, cols, row_stride, col_stride, A, b, x, computed);
}

size_t bytes() {
return backend::bytes(tau) +
backend::bytes(f) +
backend::bytes(q);
}

private:
typedef typename math::scalar_of<value_type>::type scalar_type;

Expand Down Expand Up @@ -561,6 +567,10 @@ class QR<value_type, typename std::enable_if<math::is_static_matrix<value_type>:
solve(rows, cols, row_stride, col_stride, A, f, x, computed);
}

size_t bytes() const {
return base.bytes() + backend::bytes(buf);
}

private:
typedef typename amgcl::math::scalar_of<value_type>::type scalar_type;

Expand Down
27 changes: 26 additions & 1 deletion amgcl/solver/bicgstabl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,34 @@ class bicgstabl {
return (*this)(P.system_matrix(), P, rhs, x);
}

size_t bytes() const {
size_t b = 0;

b += backend::bytes(*Rt);
b += backend::bytes(*X);
b += backend::bytes(*B);
b += backend::bytes(*T);

for(const auto &v : R) b += backend::bytes(*v);
for(const auto &v : U) b += backend::bytes(*v);

b += MZa.size() * sizeof(coef_type);
b += MZb.size() * sizeof(coef_type);

b += backend::bytes(Y0);
b += backend::bytes(YL);

b += qr.bytes();

return b;
}

friend std::ostream& operator<<(std::ostream &os, const bicgstabl &s) {
return os << "bicgstab(" << s.prm.L << "): " << s.n << " unknowns";
return os
<< "Type: BiCGStab(" << s.prm.L << ")"
<< "\nUnknowns: " << s.n
<< "\nMemory footprint: " << human_readable_memory(s.bytes())
<< std::endl;
}
public:
params prm;
Expand Down
14 changes: 13 additions & 1 deletion amgcl/solver/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,20 @@ class cg {
return (*this)(P.system_matrix(), P, rhs, x);
}

size_t bytes() const {
return
backend::bytes(*r) +
backend::bytes(*s) +
backend::bytes(*p) +
backend::bytes(*q);
}

friend std::ostream& operator<<(std::ostream &os, const cg &s) {
return os << "cg: " << s.n << " unknowns";
return os
<< "Type: CG"
<< "\nUnknowns: " << s.n
<< "\nMemory footprint: " << human_readable_memory(s.bytes())
<< std::endl;
}
public:
params prm;
Expand Down
20 changes: 19 additions & 1 deletion amgcl/solver/fgmres.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,27 @@ class fgmres {
return (*this)(P.system_matrix(), P, rhs, x);
}

size_t bytes() const {
size_t b = 0;

b += H.size() * sizeof(coef_type);
b += backend::bytes(s);
b += backend::bytes(cs);
b += backend::bytes(sn);
b += backend::bytes(*r);

for(const auto &x : v) b += backend::bytes(*x);
for(const auto &x : z) b += backend::bytes(*x);

return b;
}

friend std::ostream& operator<<(std::ostream &os, const fgmres &s) {
return os << "fgmres(" << s.prm.M << "): " << s.n << " unknowns";
return os
<< "Type: FGMRES(" << s.prm.M << ")"
<< "\nUnknowns: " << s.n
<< "\nMemory footprint: " << human_readable_memory(s.bytes())
<< std::endl;
}
private:
size_t n;
Expand Down
20 changes: 18 additions & 2 deletions amgcl/solver/gmres.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,29 @@ class gmres {
return (*this)(P.system_matrix(), P, rhs, x);
}


friend std::ostream& operator<<(std::ostream &os, const gmres &s) {
return os << "gmres(" << s.prm.M << "): " << s.n << " unknowns";
return os
<< "Type: GMRES(" << s.prm.M << ")"
<< "\nUnknowns: " << s.n
<< "\nMemory footprint: " << human_readable_memory(s.bytes())
<< std::endl;
}
public:
params prm;

size_t bytes() const {
size_t b = 0;

b += H.size() * sizeof(coef_type);
b += backend::bytes(s);
b += backend::bytes(cs);
b += backend::bytes(sn);
b += backend::bytes(*r);

for(const auto &x : v) b += backend::bytes(*x);

return b;
}
private:
size_t n;

Expand Down
28 changes: 27 additions & 1 deletion amgcl/solver/idrs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,34 @@ class idrs {
return (*this)(P.system_matrix(), P, rhs, x);
}

size_t bytes() const {
size_t b = 0;

b += M.size() * sizeof(coef_type);

b += backend::bytes(f);
b += backend::bytes(c);

b += backend::bytes(*r);
b += backend::bytes(*v);
b += backend::bytes(*t);

if (x_s) b += backend::bytes(*x_s);
if (r_s) b += backend::bytes(*r_s);

for(const auto &v : P) b += backend::bytes(*v);
for(const auto &v : G) b += backend::bytes(*v);
for(const auto &v : U) b += backend::bytes(*v);

return b;
}

friend std::ostream& operator<<(std::ostream &os, const idrs &s) {
return os << "IDR(" << s.prm.s << "): " << s.n << " unknowns";
return os
<< "Type: IDR(" << s.prm.s << ")"
<< "\nUnknowns: " << s.n
<< "\nMemory footprint: " << human_readable_memory(s.bytes())
<< std::endl;
}

private:
Expand Down
26 changes: 25 additions & 1 deletion amgcl/solver/lgmres.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,33 @@ class lgmres {
return (*this)(P.system_matrix(), P, rhs, x);
}

size_t bytes() const {
size_t b = 0;

b += H.size() * sizeof(coef_type);
b += H0.size() * sizeof(coef_type);

b += backend::bytes(s);
b += backend::bytes(cs);
b += backend::bytes(sn);
b += backend::bytes(y);

b += backend::bytes(*r);

for(const auto &v : vs) b += backend::bytes(*v);

for(const auto &v : outer_v_data) b += backend::bytes(*v);
for(const auto &v : outer_Av_data) b += backend::bytes(*v);

return b;
}

friend std::ostream& operator<<(std::ostream &os, const lgmres &s) {
return os << "lgmres(" << s.prm.M << "," << s.prm.K << "): " << s.n << " unknowns";
return os
<< "Type: LGMRES(" << s.prm.M << "," << s.prm.K << ")"
<< "\nUnknowns: " << s.n
<< "\nMemory footprint: " << human_readable_memory(s.bytes())
<< std::endl;
}
private:
size_t n;
Expand Down

0 comments on commit 8a4c96f

Please sign in to comment.