Skip to content
Snippets Groups Projects
RunTime.h 1.18 KiB
Newer Older
  • Learn to ignore specific revisions
  • Lars Bilke's avatar
    Lars Bilke committed
    /**
    
    Lars Bilke's avatar
    Lars Bilke committed
     * \file
     * \author Thomas Fischer
    
     * \author Wenqing Wang
     * \date   2012-05-10, 2014-10.10
    
    Lars Bilke's avatar
    Lars Bilke committed
     * \brief  Definition of the RunTime class.
     *
     * \copyright
    
     * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
    
    Lars Bilke's avatar
    Lars Bilke committed
     *            Distributed under a Modified BSD License.
     *              See accompanying file LICENSE.txt or
    
    Lars Bilke's avatar
    Lars Bilke committed
     *              http://www.opengeosys.org/project/license
    
    #ifdef USE_PETSC
    
    #include <mpi.h>
    #else
    
    namespace BaseLib
    {
    
    /// Count the running time.
    
    class RunTime
    
    public:
        /// Start the timer.
        void start()
        {
    #ifdef USE_PETSC
            _start_time = MPI_Wtime();
    
            _start_time = std::chrono::system_clock::now();
    
        /// Get the elapsed time in seconds.
        double elapsed() const
        {
    #ifdef USE_PETSC
            return MPI_Wtime() - _start_time;
    
            using namespace std::chrono;
            return duration<double>(system_clock::now() - _start_time).count();
    
    private:
    #ifdef USE_PETSC
        double _start_time = std::numeric_limits<double>::quiet_NaN();
    
        std::chrono::time_point<std::chrono::system_clock> _start_time;
    
    }  // end namespace BaseLib