Loading src/TNL/Solvers/IterativeSolverMonitor.h +7 −9 Original line number Diff line number Diff line Loading @@ -24,32 +24,30 @@ public: IterativeSolverMonitor(); void setStage( const std::string& stage ); void setTime( const RealType& time ); void setTimeStep( const RealType& timeStep ); void setStage( const std::string& stage ); void setIterations( const IndexType& iterations ); void setResidue( const RealType& residue ); void setVerbose( const Index& verbose ); virtual void refresh( bool force = false ); virtual void refresh(); protected: int getLineWidth(); RealType time; RealType timeStep; std::string stage, saved_stage; std::string stage; std::atomic_bool saved; IndexType iterations; RealType time, saved_time, timeStep, saved_timeStep, residue, saved_residue; RealType residue; IndexType iterations, saved_iterations; IndexType verbose; }; Loading src/TNL/Solvers/IterativeSolverMonitor_impl.h +52 −28 Original line number Diff line number Diff line Loading @@ -28,34 +28,51 @@ namespace Solvers { template< typename Real, typename Index> IterativeSolverMonitor< Real, Index > :: IterativeSolverMonitor() : SolverMonitor(), stage( "" ), saved_stage( "" ), saved( false ), time( 0.0 ), saved_time( 0.0 ), timeStep( 0.0 ), stage( "" ), saved_timeStep( 0.0 ), residue( 0.0 ), saved_residue( 0.0 ), iterations( 0 ), residue( 0 ), saved_iterations( 0 ), verbose( 1 ) { } template< typename Real, typename Index> void IterativeSolverMonitor< Real, Index > :: setTime( const RealType& time ) void IterativeSolverMonitor< Real, Index > :: setStage( const std::string& stage ) { this->time = time; // save the items after a complete stage if( iterations > 0 ) { saved_stage = this->stage; saved_time = time; saved_timeStep = timeStep; saved_iterations = iterations; saved_residue = residue; } // reset the current items iterations = 0; residue = 0.0; this->stage = stage; saved = true; } template< typename Real, typename Index> void IterativeSolverMonitor< Real, Index > :: setTimeStep( const RealType& timeStep ) void IterativeSolverMonitor< Real, Index > :: setTime( const RealType& time ) { this->timeStep = timeStep; this->time = time; } template< typename Real, typename Index> void IterativeSolverMonitor< Real, Index > :: setStage( const std::string& stage ) void IterativeSolverMonitor< Real, Index > :: setTimeStep( const RealType& timeStep ) { this->stage = stage; // reset numerical items displayed after stage this->iterations = 0; this->residue = 0.0; this->timeStep = timeStep; } template< typename Real, typename Index> Loading @@ -77,12 +94,18 @@ void IterativeSolverMonitor< Real, Index > :: setVerbose( const Index& verbose ) } template< typename Real, typename Index> void IterativeSolverMonitor< Real, Index > :: refresh( bool force ) void IterativeSolverMonitor< Real, Index > :: refresh() { // if( this->verbose > 0 && ( force || this->getIterations() % this->refreshRate == 0 ) ) if( this->verbose > 0 || force ) if( this->verbose > 0 ) { const int line_width = this->getLineWidth(); // Check if we should display the current values or the values saved after // the previous stage. If the iterations cycle much faster than the solver // monitor refreshes, we display only the values saved after the whole // cycle to hide the irrelevant partial progress. const bool saved = this->saved; this->saved = false; const int line_width = getLineWidth(); int free = line_width ? line_width : std::numeric_limits<int>::max(); auto real_to_string = []( Real value, int precision = 6 ) { Loading @@ -103,36 +126,37 @@ void IterativeSolverMonitor< Real, Index > :: refresh( bool force ) // FIXME: nvcc 8.0 ignores default parameter values for lambda functions in template functions, so we have to pass the defaults // print_item( " ELA:" ); print_item( " ELA:", 0 ); print_item( real_to_string( this->getElapsedTime(), 5 ), 8 ); print_item( real_to_string( getElapsedTime(), 5 ), 8 ); // print_item( " T:" ); print_item( " T:", 0 ); print_item( real_to_string( this->time, 5 ), 8 ); if( this->timeStep > 0 ) { print_item( real_to_string( (saved) ? saved_time : time, 5 ), 8 ); if( (saved) ? saved_timeStep : timeStep > 0 ) { // print_item( " TAU:" ); print_item( " TAU:", 0 ); print_item( real_to_string( this->timeStep, 5 ), 8 ); print_item( real_to_string( (saved) ? saved_timeStep : timeStep, 5 ), 8 ); } if( this->stage.length() && free > 5 ) { if( (int) this->stage.length() <= free - 2 ) { std::cout << " " << this->stage; free -= ( 2 + this->stage.length() ); const std::string displayed_stage = (saved) ? saved_stage : stage; if( displayed_stage.length() && free > 5 ) { if( (int) displayed_stage.length() <= free - 2 ) { std::cout << " " << displayed_stage; free -= ( 2 + displayed_stage.length() ); } else { std::cout << " " << this->stage.substr( 0, free - 5 ) << "..."; std::cout << " " << displayed_stage.substr( 0, free - 5 ) << "..."; free = 0; } } if( this->iterations > 0 && free >= 14 ) { if( (saved) ? saved_iterations : iterations > 0 && free >= 14 ) { // print_item( " ITER:" ); print_item( " ITER:", 0 ); print_item( std::to_string( this->iterations ), 8 ); print_item( std::to_string( (saved) ? saved_iterations : iterations ), 8 ); } if( this->residue && free >= 17 ) { if( (saved) ? saved_residue : residue && free >= 17 ) { // print_item( " RES:" ); print_item( " RES:", 0 ); print_item( real_to_string( this->residue, 5 ), 12 ); print_item( real_to_string( (saved) ? saved_residue : residue, 5 ), 12 ); } // return to the beginning of the line Loading src/TNL/Solvers/IterativeSolver_impl.h +0 −1 Original line number Diff line number Diff line Loading @@ -212,7 +212,6 @@ void IterativeSolver< Real, Index> :: refreshSolverMonitor( bool force ) this->solverMonitor->setIterations( this->getIterations() ); this->solverMonitor->setResidue( this->getResidue() ); this->solverMonitor->setRefreshRate( this-> refreshRate ); // this->solverMonitor -> refresh( force ); } } Loading src/TNL/Solvers/ODE/ExplicitSolver_impl.h +0 −1 Original line number Diff line number Diff line Loading @@ -159,7 +159,6 @@ refreshSolverMonitor( bool force ) this->solverMonitor->setTimeStep( this->getTau() ); this->solverMonitor->setTime( this->getTime() ); this->solverMonitor->setRefreshRate( this->refreshRate ); this->solverMonitor->refresh( force ); } } Loading src/TNL/Solvers/SolverMonitor.h +4 −5 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ public: timer( nullptr ) {} virtual void refresh( bool force = false ) = 0; virtual void refresh() = 0; void setRefreshRate( const int& refreshRate ) { Loading @@ -52,7 +52,7 @@ public: const std::chrono::milliseconds timeout( timeout_base ); while( ! stopped ) { refresh( true ); refresh(); // make sure to detect changes to refresh rate int steps = timeout_milliseconds / timeout_base; Loading Loading @@ -90,8 +90,7 @@ protected: std::atomic_int timeout_milliseconds; std::atomic_bool started; std::atomic_bool stopped; std::atomic_bool started, stopped; Timer* timer; }; Loading Loading
src/TNL/Solvers/IterativeSolverMonitor.h +7 −9 Original line number Diff line number Diff line Loading @@ -24,32 +24,30 @@ public: IterativeSolverMonitor(); void setStage( const std::string& stage ); void setTime( const RealType& time ); void setTimeStep( const RealType& timeStep ); void setStage( const std::string& stage ); void setIterations( const IndexType& iterations ); void setResidue( const RealType& residue ); void setVerbose( const Index& verbose ); virtual void refresh( bool force = false ); virtual void refresh(); protected: int getLineWidth(); RealType time; RealType timeStep; std::string stage, saved_stage; std::string stage; std::atomic_bool saved; IndexType iterations; RealType time, saved_time, timeStep, saved_timeStep, residue, saved_residue; RealType residue; IndexType iterations, saved_iterations; IndexType verbose; }; Loading
src/TNL/Solvers/IterativeSolverMonitor_impl.h +52 −28 Original line number Diff line number Diff line Loading @@ -28,34 +28,51 @@ namespace Solvers { template< typename Real, typename Index> IterativeSolverMonitor< Real, Index > :: IterativeSolverMonitor() : SolverMonitor(), stage( "" ), saved_stage( "" ), saved( false ), time( 0.0 ), saved_time( 0.0 ), timeStep( 0.0 ), stage( "" ), saved_timeStep( 0.0 ), residue( 0.0 ), saved_residue( 0.0 ), iterations( 0 ), residue( 0 ), saved_iterations( 0 ), verbose( 1 ) { } template< typename Real, typename Index> void IterativeSolverMonitor< Real, Index > :: setTime( const RealType& time ) void IterativeSolverMonitor< Real, Index > :: setStage( const std::string& stage ) { this->time = time; // save the items after a complete stage if( iterations > 0 ) { saved_stage = this->stage; saved_time = time; saved_timeStep = timeStep; saved_iterations = iterations; saved_residue = residue; } // reset the current items iterations = 0; residue = 0.0; this->stage = stage; saved = true; } template< typename Real, typename Index> void IterativeSolverMonitor< Real, Index > :: setTimeStep( const RealType& timeStep ) void IterativeSolverMonitor< Real, Index > :: setTime( const RealType& time ) { this->timeStep = timeStep; this->time = time; } template< typename Real, typename Index> void IterativeSolverMonitor< Real, Index > :: setStage( const std::string& stage ) void IterativeSolverMonitor< Real, Index > :: setTimeStep( const RealType& timeStep ) { this->stage = stage; // reset numerical items displayed after stage this->iterations = 0; this->residue = 0.0; this->timeStep = timeStep; } template< typename Real, typename Index> Loading @@ -77,12 +94,18 @@ void IterativeSolverMonitor< Real, Index > :: setVerbose( const Index& verbose ) } template< typename Real, typename Index> void IterativeSolverMonitor< Real, Index > :: refresh( bool force ) void IterativeSolverMonitor< Real, Index > :: refresh() { // if( this->verbose > 0 && ( force || this->getIterations() % this->refreshRate == 0 ) ) if( this->verbose > 0 || force ) if( this->verbose > 0 ) { const int line_width = this->getLineWidth(); // Check if we should display the current values or the values saved after // the previous stage. If the iterations cycle much faster than the solver // monitor refreshes, we display only the values saved after the whole // cycle to hide the irrelevant partial progress. const bool saved = this->saved; this->saved = false; const int line_width = getLineWidth(); int free = line_width ? line_width : std::numeric_limits<int>::max(); auto real_to_string = []( Real value, int precision = 6 ) { Loading @@ -103,36 +126,37 @@ void IterativeSolverMonitor< Real, Index > :: refresh( bool force ) // FIXME: nvcc 8.0 ignores default parameter values for lambda functions in template functions, so we have to pass the defaults // print_item( " ELA:" ); print_item( " ELA:", 0 ); print_item( real_to_string( this->getElapsedTime(), 5 ), 8 ); print_item( real_to_string( getElapsedTime(), 5 ), 8 ); // print_item( " T:" ); print_item( " T:", 0 ); print_item( real_to_string( this->time, 5 ), 8 ); if( this->timeStep > 0 ) { print_item( real_to_string( (saved) ? saved_time : time, 5 ), 8 ); if( (saved) ? saved_timeStep : timeStep > 0 ) { // print_item( " TAU:" ); print_item( " TAU:", 0 ); print_item( real_to_string( this->timeStep, 5 ), 8 ); print_item( real_to_string( (saved) ? saved_timeStep : timeStep, 5 ), 8 ); } if( this->stage.length() && free > 5 ) { if( (int) this->stage.length() <= free - 2 ) { std::cout << " " << this->stage; free -= ( 2 + this->stage.length() ); const std::string displayed_stage = (saved) ? saved_stage : stage; if( displayed_stage.length() && free > 5 ) { if( (int) displayed_stage.length() <= free - 2 ) { std::cout << " " << displayed_stage; free -= ( 2 + displayed_stage.length() ); } else { std::cout << " " << this->stage.substr( 0, free - 5 ) << "..."; std::cout << " " << displayed_stage.substr( 0, free - 5 ) << "..."; free = 0; } } if( this->iterations > 0 && free >= 14 ) { if( (saved) ? saved_iterations : iterations > 0 && free >= 14 ) { // print_item( " ITER:" ); print_item( " ITER:", 0 ); print_item( std::to_string( this->iterations ), 8 ); print_item( std::to_string( (saved) ? saved_iterations : iterations ), 8 ); } if( this->residue && free >= 17 ) { if( (saved) ? saved_residue : residue && free >= 17 ) { // print_item( " RES:" ); print_item( " RES:", 0 ); print_item( real_to_string( this->residue, 5 ), 12 ); print_item( real_to_string( (saved) ? saved_residue : residue, 5 ), 12 ); } // return to the beginning of the line Loading
src/TNL/Solvers/IterativeSolver_impl.h +0 −1 Original line number Diff line number Diff line Loading @@ -212,7 +212,6 @@ void IterativeSolver< Real, Index> :: refreshSolverMonitor( bool force ) this->solverMonitor->setIterations( this->getIterations() ); this->solverMonitor->setResidue( this->getResidue() ); this->solverMonitor->setRefreshRate( this-> refreshRate ); // this->solverMonitor -> refresh( force ); } } Loading
src/TNL/Solvers/ODE/ExplicitSolver_impl.h +0 −1 Original line number Diff line number Diff line Loading @@ -159,7 +159,6 @@ refreshSolverMonitor( bool force ) this->solverMonitor->setTimeStep( this->getTau() ); this->solverMonitor->setTime( this->getTime() ); this->solverMonitor->setRefreshRate( this->refreshRate ); this->solverMonitor->refresh( force ); } } Loading
src/TNL/Solvers/SolverMonitor.h +4 −5 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ public: timer( nullptr ) {} virtual void refresh( bool force = false ) = 0; virtual void refresh() = 0; void setRefreshRate( const int& refreshRate ) { Loading @@ -52,7 +52,7 @@ public: const std::chrono::milliseconds timeout( timeout_base ); while( ! stopped ) { refresh( true ); refresh(); // make sure to detect changes to refresh rate int steps = timeout_milliseconds / timeout_base; Loading Loading @@ -90,8 +90,7 @@ protected: std::atomic_int timeout_milliseconds; std::atomic_bool started; std::atomic_bool stopped; std::atomic_bool started, stopped; Timer* timer; }; Loading