Commit 56f0c672 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Jakub Klinkovský
Browse files

Added computation minimal time, config setup and setup to Benchmark.

parent 3a2432a3
Loading
Loading
Loading
Loading
+36 −6
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <TNL/Devices/Host.h>
#include <TNL/Devices/SystemInfo.h>
#include <TNL/Devices/CudaDeviceInfo.h>
#include <TNL/Config/ConfigDescription.h>
#include <TNL/Communicators/MpiCommunicator.h>

namespace TNL {
@@ -40,6 +41,7 @@ double
timeFunction( ComputeFunction compute,
              ResetFunction reset,
              int loops,
              int minTime, 
              Monitor && monitor = Monitor() )
{
   // the timer is constructed zero-initialized and stopped
@@ -52,7 +54,11 @@ timeFunction( ComputeFunction compute,
   reset();
   compute();

   for(int i = 0; i < loops; ++i) {
   int i;
   for( i = 0;
        i < loops && ( ! minTime || timer.getRealTime() < ( double ) minTime );
        ++i) 
   {
      // abuse the monitor's "time" for loops
      monitor.setTime( i + 1 );

@@ -71,7 +77,7 @@ timeFunction( ComputeFunction compute,
      timer.stop();
   }

   return timer.getRealTime() / loops;
   return timer.getRealTime() / ( double ) i;
}


@@ -89,6 +95,12 @@ public:
   : verbose(verbose)
   {}

   void
   setVerbose( bool verbose)
   {
      this->verbose = verbose;
   }

   void
   writeTitle( const String & title )
   {
@@ -315,6 +327,19 @@ public:
   : Logging(verbose), loops(loops)
   {}
   
   static void configSetup( Config::ConfigDescription& config )
   {
      config.addEntry< int >( "loops", "Number of iterations for every computation.", 10 );
      config.addEntry< int >( "min-time", "Minimal real time in seconds for every computation.", 1 );
   }

   void setup( const Config::ParameterContainer& parameters )
   {
      this->loops = parameters.getParameter< unsigned >( "loops" );
      this->minTime = parameters.getParameter< unsigned >( "min-time" );
      const unsigned verbose = parameters.getParameter< unsigned >( "verbose" );
      Logging::setVerbose( verbose );
   }
   // TODO: ensure that this is not called in the middle of the benchmark
   // (or just remove it completely?)
   void
@@ -323,6 +348,11 @@ public:
      this->loops = loops;
   }
   
   void setMinTime( int minTime )
   {
      this->minTime = minTime;
   }

   // Marks the start of a new benchmark
   void
   newBenchmark( const String & title )
@@ -424,10 +454,10 @@ public:
         if( verbose ) {
            // run the monitor main loop
            Solvers::SolverMonitorThread monitor_thread( monitor );
            result.time = timeFunction( compute, reset, loops, monitor );
            result.time = timeFunction( compute, reset, loops, minTime, monitor );
         }
         else {
            result.time = timeFunction( compute, reset, loops, monitor );
            result.time = timeFunction( compute, reset, minTime, loops, monitor );
         }
      }
      catch ( const std::exception& e ) {
@@ -477,7 +507,7 @@ public:
   }

protected:
   int loops;
   int loops, minTime = 1;
   double datasetSize = 0.0;
   double baseTime = 0.0;
   Solvers::IterativeSolverMonitor< double, int > monitor;