Timer.cc 1.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
Naumann, Andreas's avatar
Naumann, Andreas committed
20
21
22
23
24
#include "Timer.h"
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#include <mpi.h>
#endif

25
26
using namespace boost::posix_time;

Naumann, Andreas's avatar
Naumann, Andreas committed
27
namespace AMDiS {
28
29
30
  
  Timer::Timer() : 
     first_seq(microsec_clock::local_time())
Naumann, Andreas's avatar
Naumann, Andreas committed
31
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
32
    ,first_mpi(MPI::Wtime())
Naumann, Andreas's avatar
Naumann, Andreas committed
33
#endif
34
  {}
Naumann, Andreas's avatar
Naumann, Andreas committed
35

36
37
  void Timer::reset()
  {
Naumann, Andreas's avatar
Naumann, Andreas committed
38
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
39
    first_mpi = MPI::Wtime();
Naumann, Andreas's avatar
Naumann, Andreas committed
40
#else
41
    first_seq = microsec_clock::local_time();
Naumann, Andreas's avatar
Naumann, Andreas committed
42
#endif
43
  }
Naumann, Andreas's avatar
Naumann, Andreas committed
44

45
46
  double Timer::elapsed()
  {
Naumann, Andreas's avatar
Naumann, Andreas committed
47
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
48
    return MPI::Wtime() - first_mpi;
Naumann, Andreas's avatar
Naumann, Andreas committed
49
#else
50
    time_duration td = microsec_clock::local_time()-first_seq;
51
    return static_cast<double>(td.total_microseconds())*1.e-6;
Naumann, Andreas's avatar
Naumann, Andreas committed
52
#endif
53
54
55
  }
  
} // end namespace AMDiS