From 7984e453ecb77aa7829f6da9f59c3c029d1a44e7 Mon Sep 17 00:00:00 2001
From: Lisa Julia Nebel <lisa_julia.nebel@tu-dresden.de>
Date: Mon, 30 Mar 2020 15:48:42 +0200
Subject: [PATCH] Print total time, total assembly time and total time needed
 for solving at the end of the trust-region solver run

---
 dune/gfe/riemanniantrsolver.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/dune/gfe/riemanniantrsolver.cc b/dune/gfe/riemanniantrsolver.cc
index d290d704..0ccc1306 100644
--- a/dune/gfe/riemanniantrsolver.cc
+++ b/dune/gfe/riemanniantrsolver.cc
@@ -374,6 +374,8 @@ void RiemannianTrustRegionSolver<Basis,TargetSpace>::solve()
                                                0);
 #endif
     auto& i = statistics_.finalIteration;
+    double totalAssemblyTime = 0.0;
+    double totalSolverTime = 0.0;
     for (i=0; i<maxTrustRegionSteps_; i++) {
 
 /*        std::cout << "current iterate:\n";
@@ -421,6 +423,7 @@ void RiemannianTrustRegionSolver<Basis,TargetSpace>::solve()
 
             if (this->verbosity_ == Solver::FULL)
               std::cout << "Assembly took " << gradientTimer.elapsed() << " sec." << std::endl;
+            totalAssemblyTime += gradientTimer.elapsed();
 
             // Transfer matrix data
 #if HAVE_MPI
@@ -460,6 +463,7 @@ void RiemannianTrustRegionSolver<Basis,TargetSpace>::solve()
                 corr_global = 0;
             }
             std::cout << "Solving the quadratic problem took " << solutionTimer.elapsed() << " seconds." << std::endl;
+            totalSolverTime += solutionTimer.elapsed();
 
             if (mgStep && solved)
                 corr_global = mgStep->getSol();
@@ -551,6 +555,9 @@ void RiemannianTrustRegionSolver<Basis,TargetSpace>::solve()
         double energy = 0;
         double modelDecrease = 0;
         SolutionType newIterate = x_;
+        if (i == maxTrustRegionSteps_ - 1)
+            std::cout << i+1 << " trust-region steps were taken, the maximum was reached." << std::endl << "Total solver time: " << totalSolverTime << " sec., total assembly time: " << totalAssemblyTime << " sec." << std::endl;
+
         if (solved) {
             if (this->verbosity_ == NumProc::FULL)
                 std::cout << "Infinity norm of the correction: " << corr.infinity_norm() << std::endl;
@@ -560,7 +567,7 @@ void RiemannianTrustRegionSolver<Basis,TargetSpace>::solve()
                     std::cout << "CORRECTION IS SMALL ENOUGH" << std::endl;
 
                 if (this->verbosity_ != NumProc::QUIET and rank==0)
-                    std::cout << i+1 << " trust-region steps were taken." << std::endl;
+                    std::cout << i+1 << " trust-region steps were taken" << std::endl << "Total solver time: " << totalSolverTime << " sec., total assembly time: " << totalAssemblyTime << " sec." << std::endl;
                 break;
             }
 
-- 
GitLab