Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Fixe Solver Statistics management regression. (#187) #188

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/ginkgo/src/ginkgo_linear_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class InternalLinearSolver
//! Etat du solveur
const SolverStatus& getStatus() const override;
const SolverStat& getSolverStat() const override { return m_stat; }
SolverStat& getSolverStat() override { return m_stat; }

std::shared_ptr<ILinearAlgebra> algebra() const override;

Expand Down
2 changes: 2 additions & 0 deletions plugins/hypre/src/hypre_linear_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class InternalLinearSolver : public IInternalLinearSolver<Matrix, Vector>

const SolverStat& getSolverStat() const final { return m_stat; }

SolverStat& getSolverStat() override { return m_stat; }

std::shared_ptr<ILinearAlgebra> algebra() const final;

private:
Expand Down
2 changes: 2 additions & 0 deletions plugins/petsc/src/petsc_linear_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class InternalLinearSolver

const SolverStat& getSolverStat() const override { return m_stat; }

SolverStat& getSolverStat() override { return m_stat; }

std::shared_ptr<ILinearAlgebra> algebra() const override;

private:
Expand Down
4 changes: 3 additions & 1 deletion plugins/trilinos/src/trilinos_linear_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class InternalLinearSolver : public IInternalLinearSolver<Matrix, Vector>

const SolverStat& getSolverStat() const { return m_stat; }

SolverStat& getSolverStat() override { return m_stat; }

std::shared_ptr<ILinearAlgebra> algebra() const;

private:
Expand All @@ -72,4 +74,4 @@ class InternalLinearSolver : public IInternalLinearSolver<Matrix, Vector>

void checkError(const Arccore::String& msg, int ierr, int skipError = 0) const;
};
} // namespace Alien::Trilinos
} // namespace Alien::Trilinos
10 changes: 10 additions & 0 deletions src/core/alien/core/backend/IInternalLinearSolverT.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ class IInternalLinearSolver
*/
virtual SolverStat const& getSolverStat() const = 0;

/*!
* \brief Get statistics on the solve phase
*
* Get statistics on the solver phase, such as iteration count, initialization time,
* solve time, etc.
*
* \return Solver statistics
*/
virtual SolverStat& getSolverStat() = 0;

/*!
* \brief Indicates if the kernel is parallel
* \returns Parallel support capability
Expand Down
4 changes: 4 additions & 0 deletions src/core/alien/core/backend/LinearSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <alien/expression/solver/ILinearSolver.h>

#include <alien/expression/solver/SolverStater.h>
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

Expand Down Expand Up @@ -77,6 +78,7 @@ class LinearSolver : public ILinearSolver
template <typename... T>
LinearSolver(T... args)
: m_solver(AlgebraTraits<Tag>::solver_factory(args...))
, m_stater(m_solver.get())
{}

//! Free resources
Expand All @@ -102,6 +104,7 @@ class LinearSolver : public ILinearSolver
* \param[in] pm : new parallel mng
*/
void updateParallelMng(Arccore::MessagePassing::IMessagePassingMng* pm);

/*!
* \brief Solve the linear system A * x = b
* \param[in] A The matrix to invert
Expand Down Expand Up @@ -162,6 +165,7 @@ class LinearSolver : public ILinearSolver
private:
//! The linear solver kernel
std::unique_ptr<KernelSolver> m_solver;
SolverStater<KernelSolver> m_stater;
};

/*---------------------------------------------------------------------------*/
Expand Down
8 changes: 6 additions & 2 deletions src/core/alien/core/backend/LinearSolverT.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ bool LinearSolver<Tag>::solve(const IMatrix& A, const IVector& b, IVector& x)
else {
m_solver->updateParallelMng(A.impl()->distribution().parallelMng());
}
// m_solver->getSolverStat().startPrepareMeasure();

SolverStatSentry<KernelSolver> sentry(m_stater, BaseSolverStater::ePrepare);
const auto& matrix = A.impl()->get<Tag>();
const auto& rhs = b.impl()->get<Tag>();
auto& sol = x.impl()->get<Tag>(true);
// m_solver->getSolverStat().stopPrepareMeasure();
sentry.release();

SolverStatSentry<KernelSolver> sentry2(m_stater, BaseSolverStater::eSolve);
return m_solver->solve(matrix, rhs, sol);
}

Expand All @@ -89,6 +92,7 @@ bool LinearSolver<Tag>::solve(const IMatrix& A, const IVector& b, IVector& x)
template <class Tag>
void LinearSolver<Tag>::init()
{
SolverStatSentry<KernelSolver> sentry(m_stater, BaseSolverStater::eInit);
m_solver->init();
}

Expand Down
12 changes: 12 additions & 0 deletions src/core/alien/expression/solver/SolverStat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Alien
{

using namespace Arccore;

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

Expand Down Expand Up @@ -81,6 +82,17 @@ SolverStat::SolverStat()
{}

/*---------------------------------------------------------------------------*/
void SolverStat::reset()
{
m_solve_count = 0;
m_iteration_count = 0;
m_last_iteration_count = 0;
m_initialization_time = m_initialization_cpu_time = 0;
m_prepare_time = m_prepare_cpu_time = 0;
m_last_prepare_time = m_last_prepare_cpu_time = 0;
m_solve_time = m_solve_cpu_time = 0;
m_last_solve_time = m_last_solve_cpu_time = 0;
}

Integer
SolverStat::solveCount() const
Expand Down
4 changes: 3 additions & 1 deletion src/core/alien/expression/solver/SolverStat.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Alien
class ALIEN_EXPORT SolverStat
{
public:
template <typename SolverT> friend class SolverStater;
/** Constructeur de la classe */
SolverStat();

Expand All @@ -57,6 +58,8 @@ class ALIEN_EXPORT SolverStat
Real lastSolveTime() const;
Real lastSolveCpuTime() const;

void reset();

public:
void print(
ITraceMng* traceMng, const SolverStatus& status, String title = String()) const;
Expand All @@ -78,7 +81,6 @@ class ALIEN_EXPORT SolverStat
};

/*---------------------------------------------------------------------------*/

} // namespace Alien

/*---------------------------------------------------------------------------*/
122 changes: 5 additions & 117 deletions src/core/alien/expression/solver/SolverStater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,121 +45,9 @@ static clock_t current_clock_value = 0;
#endif

/*---------------------------------------------------------------------------*/

SolverStater::SolverStater()
: m_state(eNone)
, m_suspend_count(0)
{}

/*---------------------------------------------------------------------------*/

void SolverStater::reset()
{
m_solve_count = 0;
m_iteration_count = 0;
m_last_iteration_count = 0;
m_initialization_time = m_initialization_cpu_time = 0;
m_prepare_time = m_prepare_cpu_time = 0;
m_last_prepare_time = m_last_prepare_cpu_time = 0;
m_solve_time = m_solve_cpu_time = 0;
m_last_solve_time = m_last_solve_cpu_time = 0;

m_state = eNone;
m_suspend_count = 0;
}

/*---------------------------------------------------------------------------*/

void SolverStater::startInitializationMeasure()
{
ALIEN_ASSERT((m_state == eNone), ("Unexpected SolverStater state %d", m_state));
_startTimer();
m_state = eInit;
}

/*---------------------------------------------------------------------------*/

void SolverStater::stopInitializationMeasure()
{
ALIEN_ASSERT((m_state == eInit), ("Unexpected SolverStater state %d", m_state));
_stopTimer();
m_state = eNone;
m_initialization_time += m_real_time;
m_initialization_cpu_time += m_cpu_time;
}

/*---------------------------------------------------------------------------*/

void SolverStater::startPrepareMeasure()
{
ALIEN_ASSERT((m_state == eNone), ("Unexpected SolverStater state %d", m_state));
_startTimer();
m_state = ePrepare;
}

/*---------------------------------------------------------------------------*/

void SolverStater::suspendPrepareMeasure()
{
ALIEN_ASSERT((m_state == ePrepare), ("Unexpected SolverStater state %d", m_state));
_stopTimer();
if (m_suspend_count == 0) {
m_last_prepare_time = m_real_time;
m_last_prepare_cpu_time = m_cpu_time;
}
else {
m_last_prepare_time += m_real_time;
m_last_prepare_cpu_time += m_cpu_time;
}
m_state = eNone;
++m_suspend_count;
}

/*---------------------------------------------------------------------------*/

void SolverStater::stopPrepareMeasure()
{
if (m_state == ePrepare)
suspendPrepareMeasure();
ALIEN_ASSERT((m_suspend_count > 0), ("Unexpected suspend count"));

m_last_prepare_time += m_real_time;
m_last_prepare_cpu_time += m_cpu_time;

m_suspend_count = 0;
m_state = eNone;
m_prepare_time += m_last_prepare_time;
m_prepare_cpu_time += m_last_prepare_cpu_time;
}

/*---------------------------------------------------------------------------*/

void SolverStater::startSolveMeasure()
{
ALIEN_ASSERT((m_state == eNone), ("Unexpected SolverStater state %d", m_state));
_startTimer();
m_state = eSolve;
}

/*---------------------------------------------------------------------------*/

void SolverStater::stopSolveMeasure(const Alien::SolverStatus& status)
{
ALIEN_ASSERT((m_state == eSolve), ("Unexpected SolverStater state %d", m_state));
_stopTimer();
m_state = eNone;
m_last_solve_time = m_real_time;
m_last_solve_cpu_time = m_cpu_time;
m_solve_time += m_last_solve_time;
m_solve_cpu_time += m_last_solve_cpu_time;
++m_solve_count;
m_last_iteration_count = status.iteration_count;
m_iteration_count += m_last_iteration_count;
}

/*---------------------------------------------------------------------------*/

Real SolverStater::_getVirtualTime()
Real BaseSolverStater::_getVirtualTime()
{
// From Arcane 1.16.3 to work with historical timers and Windows
#ifdef ARCANE_TIMER_USE_CLOCK
Expand All @@ -178,7 +66,7 @@ Real SolverStater::_getVirtualTime()

/*---------------------------------------------------------------------------*/

Real SolverStater::_getRealTime()
Real BaseSolverStater::_getRealTime()
{
// From Arcane 1.16.3 to work with old timers and Windows.
#ifdef WIN32
Expand All @@ -202,15 +90,15 @@ Real SolverStater::_getRealTime()

/*---------------------------------------------------------------------------*/

void SolverStater::_errorInTimer(const String& msg, int retcode)
void BaseSolverStater::_errorInTimer(const String& msg, int retcode)
{
throw FatalErrorException(
A_FUNCINFO, String::format("{0} return code: {1} errno: {2}", msg, retcode, errno));
}

/*---------------------------------------------------------------------------*/

void SolverStater::_startTimer()
void BaseSolverStater::_startTimer()
{
ALIEN_ASSERT((m_state == eNone), ("Unexpected SolverStater state %d", m_state));
m_real_time = _getRealTime();
Expand All @@ -219,7 +107,7 @@ void SolverStater::_startTimer()

/*---------------------------------------------------------------------------*/

void SolverStater::_stopTimer()
void BaseSolverStater::_stopTimer()
{
ALIEN_ASSERT((m_state != eNone), ("Unexpected SolverStater state %d", m_state));
m_real_time = _getRealTime() - m_real_time;
Expand Down
Loading
Loading