Skip to content

Commit

Permalink
detail namespace, fix doxygen warning, update doc
Browse files Browse the repository at this point in the history
Co-authored-by: Pratik Nayak <pratikvn@protonmail.com>
Co-authored-by: Terry Cojean <terry.cojean@kit.edu>
  • Loading branch information
3 people committed Nov 7, 2022
1 parent 3279d1c commit ed2ea48
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
52 changes: 28 additions & 24 deletions core/solver/multigrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ GKO_ATTRIBUTES GKO_INLINE bool operator&(cycle_info a, cycle_info b)
}


namespace detail {


/**
* MultigridState is to store the necessary cache and run the operation of all
* levels.
* MultigridState is used to store the necessary cache and run the operation of
* all levels.
*
* @note it should only be used internally
*/
Expand Down Expand Up @@ -249,13 +252,13 @@ struct MultigridState {
* @param matrix the system matrix of current level
* @param b the right hand side
* @param x the input vectors
* @param info the info of cycle
* @param info the info of cycle (See cycle_info)
*/
void run_cycle(multigrid::cycle cycle, size_type level,
const std::shared_ptr<const LinOp>& matrix, const LinOp* b,
LinOp* x,
cycle_info info = cycle_info::first_of_cycle |
cycle_info::end_of_cycle);
void run_mg_cycle(multigrid::cycle cycle, size_type level,
const std::shared_ptr<const LinOp>& matrix,
const LinOp* b, LinOp* x,
cycle_info info = cycle_info::first_of_cycle |
cycle_info::end_of_cycle);

/**
* @copydoc run_cycle
Expand Down Expand Up @@ -354,9 +357,9 @@ void MultigridState::allocate_memory(int level, multigrid::cycle cycle,
}


void MultigridState::run_cycle(multigrid::cycle cycle, size_type level,
const std::shared_ptr<const LinOp>& matrix,
const LinOp* b, LinOp* x, cycle_info info)
void MultigridState::run_mg_cycle(multigrid::cycle cycle, size_type level,
const std::shared_ptr<const LinOp>& matrix,
const LinOp* b, LinOp* x, cycle_info info)
{
if (level == multigrid->get_mg_level_list().size()) {
multigrid->get_coarsest_solver()->apply(b, x);
Expand All @@ -374,9 +377,9 @@ void MultigridState::run_cycle(multigrid::cycle cycle, size_type level,


template <typename ValueType>
void MultigridState::run_cycle(multigrid::cycle cycle, size_type level,
const std::shared_ptr<const LinOp>& matrix,
const LinOp* b, LinOp* x, cycle_info info)
void MultigridState::run_mg_cycle(multigrid::cycle cycle, size_type level,
const std::shared_ptr<const LinOp>& matrix,
const LinOp* b, LinOp* x, cycle_info info)
{
auto total_level = multigrid->get_mg_level_list().size();

Expand Down Expand Up @@ -445,18 +448,19 @@ void MultigridState::run_cycle(multigrid::cycle cycle, size_type level,
// v cycle only contains one step
next_info = next_info | cycle_info::end_of_cycle;
}
this->run_cycle(cycle, level + 1, next_level_matrix, g.get(), e.get(),
next_info);
this->run_mg_cycle(cycle, level + 1, next_level_matrix, g.get(), e.get(),
next_info);
if (level < multigrid->get_mg_level_list().size() - 1) {
// additional work for non-v_cycle
// next level
if (cycle == multigrid::cycle::f) {
// f_cycle call v_cycle in the second cycle
this->run_cycle(multigrid::cycle::v, level + 1, next_level_matrix,
g.get(), e.get(), cycle_info::end_of_cycle);
this->run_mg_cycle(multigrid::cycle::v, level + 1,
next_level_matrix, g.get(), e.get(),
cycle_info::end_of_cycle);
} else if (cycle == multigrid::cycle::w) {
this->run_cycle(cycle, level + 1, next_level_matrix, g.get(),
e.get(), cycle_info::end_of_cycle);
this->run_mg_cycle(cycle, level + 1, next_level_matrix, g.get(),
e.get(), cycle_info::end_of_cycle);
}
}
// prolong
Expand All @@ -482,7 +486,7 @@ void MultigridState::run_cycle(multigrid::cycle cycle, size_type level,
}
}


} // namespace detail
} // namespace multigrid


Expand Down Expand Up @@ -690,8 +694,8 @@ void Multigrid::apply_dense_impl(const VectorType* b, VectorType* x,
if (iter == 0 && guess == initial_guess_mode::zero) {
info = info | multigrid::cycle_info::x_is_zero;
}
cache_.state->run_cycle(this->get_parameters().cycle, 0,
this->get_system_matrix(), b, x, info);
cache_.state->run_mg_cycle(this->get_parameters().cycle, 0,
this->get_system_matrix(), b, x, info);
}
};

Expand All @@ -706,7 +710,7 @@ void Multigrid::apply_dense_impl(const VectorType* b, VectorType* x,
void Multigrid::create_state() const
{
if (cache_.state == nullptr) {
cache_.state = std::make_unique<multigrid::MultigridState>();
cache_.state = std::make_unique<multigrid::detail::MultigridState>();
}
}

Expand Down
5 changes: 5 additions & 0 deletions include/ginkgo/core/solver/multigrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ enum class cycle { v, f, w };
enum class mid_smooth_type { both, post_smoother, pre_smoother, standalone };


namespace detail {


// It should only be used internally
class MultigridState;


} // namespace detail
} // namespace multigrid


Expand Down
10 changes: 5 additions & 5 deletions include/ginkgo/core/solver/solver_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ class MultigridState;
*/
class ApplyWithInitialGuess {
protected:
friend class multigrid::MultigridState;
friend class multigrid::detail::MultigridState;

/**
* Applies a linear operator to a vector (or a sequence of vectors) with
* initial guess statement.
*
* Performs the operation x = op(b) with a initial guess statement, where op
* is this linear operator and the initial guess parameter will modify the
* input vector to the requested the initial guess mode (See @enum
* initial_guess_mode) .
* input vector to the requested the initial guess mode (See
* initial_guess_mode).
*
* @param b the input vector(s) on which the operator is applied
* @param x the output vector(s) where the result is stored
Expand All @@ -108,7 +108,7 @@ class ApplyWithInitialGuess {
* Performs the operation x = alpha * op(b) + beta * x with a initial guess
* statement, where op is this linear operator and the initial guess
* parameter will modify the input vector to the requested the initial guess
* mode (See @enum initial_guess_mode) .
* mode (See initial_guess_mode) .
*
* @param alpha scaling of the result of op(b)
* @param b vector(s) on which the operator is applied
Expand Down Expand Up @@ -165,7 +165,7 @@ class ApplyWithInitialGuess {
template <typename DerivedType>
class EnableApplyWithInitialGuess : public ApplyWithInitialGuess {
protected:
friend class multigrid::MultigridState;
friend class multigrid::detail::MultigridState;

explicit EnableApplyWithInitialGuess(
initial_guess_mode guess = initial_guess_mode::provided)
Expand Down

0 comments on commit ed2ea48

Please sign in to comment.