Commit 93c4f802 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Improving timers, adding CPU cycles.

parent f2b684c6
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -22,13 +22,13 @@ set (headers tnlAssert.h
             tnlList.h
             tnlList_impl.h
             tnlLogger.h
             tnlOmp.h
             tnlObject.h 
             tnlStack.h
             tnlStaticFor.h
             tnlStatistics.h 
             tnlString.h 
             tnlReal.h
             tnlTimer.h
             tnlTimerCPU.h  
             tnlTimerRT.h    
             mfilename.h 
@@ -48,12 +48,12 @@ set( common_SOURCES
     ${CURRENT_DIR}/tnlObject.cpp
     ${CURRENT_DIR}/tnlStatistics.cpp
     ${CURRENT_DIR}/tnlString.cpp 
     ${CURRENT_DIR}/tnlTimer.cpp 
     ${CURRENT_DIR}/tnlTimerCPU.cpp      
     ${CURRENT_DIR}/mfilename.cpp 
     ${CURRENT_DIR}/mpi-supp.cpp 
     ${CURRENT_DIR}/tnlCuda.cpp
     ${CURRENT_DIR}/tnlHost.cpp
     ${CURRENT_DIR}/tnlOmp.cpp )
     ${CURRENT_DIR}/tnlHost.cpp )

IF( BUILD_CUDA )
   set( tnl_core_CUDA__SOURCES
+7 −6
Original line number Diff line number Diff line
@@ -18,12 +18,13 @@
#ifndef TERMINAL_COLORS_H
#define	TERMINAL_COLORS_H

const std::string red( "\033[0;31m" );
const std::string green( "\033[1;32m" );
const std::string yellow( "\033[1;33m" );
const std::string cyan( "\033[0;36m" );
const std::string magenta( "\033[0;35m" );
const std::string reset( "\033[0m" );
const tnlString red( "\033[0;31m" );
const tnlString green( "\033[1;32m" );
const tnlString yellow( "\033[1;33m" );
const tnlString cyan( "\033[0;36m" );
const tnlString magenta( "\033[0;35m" );
const tnlString bold(); 
const tnlString reset( "\033[0m" );


#endif	/* TERMINAL_COLORS_H */
+68 −0
Original line number Diff line number Diff line
@@ -19,6 +19,15 @@
#define TNLHOSTL_H_

#include <core/tnlHost.h>
#ifdef HAVE_OPENMP
#include <omp.h>
#endif
#include <config/tnlConfigDescription.h>
#include <config/tnlParameterContainer.h>


bool tnlHost::ompEnabled( true );
int tnlHost::maxThreadsCount( -1 );

tnlString tnlHost::getDeviceType()
{
@@ -32,4 +41,63 @@ size_t tnlHost::getFreeMemory()
   return pages * page_size;
};

void tnlHost::enableOMP()
{
   ompEnabled = true;
}

void tnlHost::disableOMP()
{
   ompEnabled = false;
}

void tnlHost::setMaxThreadsCount( int maxThreadsCount_ )
{
   maxThreadsCount = maxThreadsCount_;
#ifdef HAVE_OPENMP   
   omp_set_num_threads( maxThreadsCount );
#endif   
}

int tnlHost::getMaxThreadsCount()
{
#ifdef HAVE_OPENMP
   if( maxThreadsCount == -1 )
      return omp_get_max_threads();
   return maxThreadsCount;
#else
   return 0;
#endif
}
      
int tnlHost::getThreadIdx()
{
#ifdef HAVE_OPENMP
   return omp_get_thread_num();
#else
   return 0;
#endif  
}

void tnlHost::configSetup( tnlConfigDescription& config, const tnlString& prefix )
{
#ifdef HAVE_OPENMP
   config.addEntry< bool >( prefix + "omp-enabled", "Enable support of OpenMP.", true );
   config.addEntry<  int >( prefix + "omp-max-threads", "Set maximum number of OpenMP threads.", omp_get_max_threads() );
#else
   config.addEntry< bool >( prefix + "omp-enabled", "Enable support of OpenMP (not supported on this system).", false );
   config.addEntry<  int >( prefix + "omp-max-threads", "Set maximum number of OpenMP threads (not supported on this system).", 0 );
#endif
   
}
      
bool tnlHost::setup( const tnlParameterContainer& parameters,
                    const tnlString& prefix )
{
   ompEnabled = parameters.getParameter< bool >( prefix + "omp-enabled" );
   maxThreadsCount = parameters.getParameter< int >( prefix + "omp-max-threads" );
   return true;
}


#endif /* TNLHOST_H_ */
+35 −7
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@
#include <core/tnlDevice.h>
#include <core/tnlString.h>

class tnlConfigDescription;
class tnlParameterContainer;

class tnlHost
{
   public:
@@ -36,6 +39,31 @@ class tnlHost
      static inline tnlDeviceEnum getDevice() { return tnlHostDevice; };

      static size_t getFreeMemory();
   
      static void disableOMP();
      
      static void enableOMP();
      
      static inline bool isOMPEnabled() { return ompEnabled; };
      
      static void setMaxThreadsCount( int maxThreadsCount );
      
      static int getMaxThreadsCount();
      
      static int getThreadIdx();
      
      static void configSetup( tnlConfigDescription& config, const tnlString& prefix = "" );
      
      static bool setup( const tnlParameterContainer& parameters,
                         const tnlString& prefix = "" );

   protected:
      
      static bool ompEnabled;
      
      static int maxThreadsCount;


};

#endif /* TNLHOST_H_ */

src/core/tnlOmp.cpp

deleted100644 → 0
+0 −83
Original line number Diff line number Diff line
/***************************************************************************
                          tnlOmp.cpp  -  description
                             -------------------
    begin                : Mar 4, 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/tnlOmp.h>
#ifdef HAVE_OPENMP
#include <omp.h>
#endif

bool tnlOmp::enabled( true );
int tnlOmp::maxThreadsCount( -1 );

void tnlOmp::enable()
{
   enabled = true;
}

void tnlOmp::disable()
{
   enabled = false;
}

void tnlOmp::setMaxThreadsCount( int maxThreadsCount_ )
{
   maxThreadsCount = maxThreadsCount_;
#ifdef HAVE_OPENMP   
   omp_set_num_threads( maxThreadsCount );
#endif   
}

int tnlOmp::getMaxThreadsCount()
{
#ifdef HAVE_OPENMP
   if( maxThreadsCount == -1 )
      return omp_get_max_threads();
   return maxThreadsCount;
#else
   return 0;
#endif
}
      
int tnlOmp::getThreadIdx()
{
#ifdef HAVE_OPENMP
   return omp_get_thread_num();
#else
   return 0;
#endif  
}

void tnlOmp::configSetup( tnlConfigDescription& config, const tnlString& prefix )
{
#ifdef HAVE_OPENMP
   config.addEntry< bool >( prefix + "omp-enabled", "Enable support of OpenMP.", true );
   config.addEntry<  int >( prefix + "omp-max-threads", "Set maximum number of OpenMP threads.", omp_get_max_threads() );
#else
   config.addEntry< bool >( prefix + "omp-enabled", "Enable support of OpenMP (not supported on this system).", false );
   config.addEntry<  int >( prefix + "omp-max-threads", "Set maximum number of OpenMP threads (not supported on this system).", 0 );
#endif
   
}
      
bool tnlOmp::setup( const tnlParameterContainer& parameters,
                    const tnlString& prefix )
{
   enabled = parameters.getParameter< bool >( prefix + "omp-enabled" );
   maxThreadsCount = parameters.getParameter< int >( prefix + "omp-max-threads" );
   return true;
}
Loading