Commit 67168e9b authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Adding tnlTimer.

parent 93c4f802
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ endif()
set( CMAKE_CXX_FLAGS "-std=c++11" )
set( CMAKE_CXX_FLAGS_DEBUG "-g" )
set( CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG" )
#set( CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG -ftree-vectorizer-verbose=1 -ftree-vectorize -fopt-info-vec-missed -funroll-loops" )
# pass -rdynamic only in Debug mode
set( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" )
set( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS_DEBUG "-rdynamic" )

src/core/tnlTimer.cpp

0 → 100644
+152 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlTimer.cpp  -  description
                             -------------------
    begin                : Mar 14, 2016
    copyright            : (C) 2016 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <core/tnlTimer.h>

#include "tnlConfig.h"
#ifdef HAVE_SYS_RESOURCE_H
   #include <sys/resource.h>
#endif
#ifdef HAVE_SYS_TIME_H
   #include <stddef.h>
   #include <sys/time.h>
   #define HAVE_TIME
#endif


tnlTimer defaultTimer;

tnlTimer::tnlTimer()
{
   reset();
}

void tnlTimer::reset()
{
   this->initialCPUTime = 0;
   this->totalCPUTime = 0.0;
   this->initialRealTime = 0;
   this->totalRealTime = 0.0;
   this->initialCPUCycles = 0;
   this->totalCPUCycles = 0;
   this->stopState = true;
}

void tnlTimer::stop()
{

   if( ! this->stopState )
   {
      /****
       * Real time
       */
#ifdef HAVE_TIME      
      struct timeval tp;
      int rtn = gettimeofday( &tp, NULL );
      this->totalRealTime += ( double ) tp. tv_sec + 1.0e-6 * ( double ) tp. tv_usec - this->initialRealTime;
#endif
      
      /****
       * CPU time
       */
#ifdef HAVE_SYS_RESOURCE_H      
      rusage initUsage;
      getrusage(  RUSAGE_SELF, &initUsage );
      this->totalCPUTime += initUsage. ru_utime. tv_sec + 1.0e-6 * ( double ) initUsage. ru_utime. tv_usec - this->initialCPUTime;
#endif      
      
      /****
       * CPU cycles
       */
      this->totalCPUCycles += this->rdtsc() - this->initialCPUCycles;
      this->stopState = true;
   }
}

void tnlTimer::start()
{
   /****
    * Real time
    */
#ifdef HAVE_TIME
   struct timeval tp;
   int rtn = gettimeofday( &tp, NULL );
   this->initialRealTime = ( double ) tp. tv_sec + 1.0e-6 * ( double ) tp. tv_usec;
#endif

   /****
    * CPU Time
    */
#ifdef HAVE_SYS_RESOURCE_H
   rusage initUsage;
   getrusage( RUSAGE_SELF, &initUsage );
   this->initialCPUTime = initUsage. ru_utime. tv_sec + 1.0e-6 * ( double ) initUsage. ru_utime. tv_usec;
#endif
   
   /****
    * CPU cycles
    */
   this->initialCPUCycles = this->rdtsc();
   
   this->stopState = false;
}

double tnlTimer::getRealTime()
{
#ifdef HAVE_TIME
   if( ! this->stopState )
   {
      this->stop();
      this->start();
   }
   return this->totalRealTime;
#else
   return -1;
#endif
}

double tnlTimer::getCPUTime()
{
#ifdef HAVE_SYS_RESOURCE_H
   if( ! this->stopState )
   {
      this->stop();
      this->start();
   }
   return this->totalCPUTime;
#else
   return -1;
#endif
}

unsigned long long int tnlTimer::getCPUCycles()
{
   if( ! this->stopState )
   {
      this->stop();
      this->start();
   }
   return this->totalCPUCycles;
}

bool tnlTimer::writeLog( tnlLogger& logger, int logLevel )
{
   logger.writeParameter< double                 >( "Real time:",  this->getRealTime(),  logLevel );
   logger.writeParameter< double                 >( "CPU time:",   this->getCPUTime(),   logLevel );
   logger.writeParameter< unsigned long long int >( "CPU Cycles:", this->getCPUCycles(), logLevel );

}

src/core/tnlTimer.h

0 → 100644
+64 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlTimer.h  -  description
                             -------------------
    begin                : Mar 14, 2016
    copyright            : (C) 2016 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef TNLTIMER_H
#define	TNLTIMER_H

#include <core/tnlLogger.h>

class tnlTimer
{
   public:
   
      tnlTimer();

      void reset();

      void stop();

      void start();

      double getRealTime();

      double getCPUTime();

      unsigned long long int getCPUCycles();
      
      bool writeLog( tnlLogger& logger, int logLevel = 0 );
         
   protected:

   double initialRealTime, totalRealTime,
          initialCPUTime, totalCPUTime;
   
   unsigned long long int initialCPUCycles, totalCPUCycles;
   
   bool stopState;
   
   inline unsigned long long rdtsc()
   {
     unsigned hi, lo;
     __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
     return ( ( unsigned long long ) lo ) | ( ( ( unsigned long long ) hi ) << 32 );
   }
};

extern tnlTimer defaultTimer;

#endif	/* TNLTIMER_H */
+2 −2
Original line number Diff line number Diff line
@@ -112,8 +112,8 @@ class tnlGridTraverser< tnlGrid< 2, Real, tnlHost, Index > >
      static void
      processEntities(
         const GridType& grid,
         const CoordinatesType& begin,
         const CoordinatesType& end,
         const CoordinatesType begin,
         const CoordinatesType end,
         const CoordinatesType& entityOrientation,
         const CoordinatesType& entityBasis,         
         UserData& userData );
+5 −3
Original line number Diff line number Diff line
@@ -38,10 +38,11 @@ processEntities(
   const CoordinatesType& entityBasis,   
   UserData& userData )
{

   
   GridEntity entity( grid );
   entity.setOrientation( entityOrientation );
   entity.setBasis( entityBasis );
   
   if( processOnlyBoundaryEntities )
   {
      entity.getCoordinates() = begin;
@@ -172,8 +173,8 @@ void
tnlGridTraverser< tnlGrid< 2, Real, tnlHost, Index > >::
processEntities(
   const GridType& grid,
   const CoordinatesType& begin,
   const CoordinatesType& end,
   const CoordinatesType begin,
   const CoordinatesType end,
   const CoordinatesType& entityOrientation,
   const CoordinatesType& entityBasis,      
   UserData& userData )
@@ -211,6 +212,7 @@ processEntities(
   }
   else
   {
//#pragma omp parallel for firstprivate( entity, begin, end ) if( tnlHost::isOMPEnabled() )      
      for( entity.getCoordinates().y() = begin.y();
           entity.getCoordinates().y() <= end.y();
           entity.getCoordinates().y() ++ )
Loading