ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
timer_wrapper.h
Go to the documentation of this file.
1#ifndef TIMER_WRAPPER_H
2#define TIMER_WRAPPER_H
3
4#include <chrono>
5
6#ifdef __MPI
7#include <mpi.h>
8#endif
9
10namespace ModuleBase {
11
15typedef double TimePoint;
16
23{
24#ifdef __MPI
25 int is_initialized = 0;
26 MPI_Initialized(&is_initialized);
27 if (is_initialized)
28 {
29 return MPI_Wtime();
30 }
31 else
32 {
33 return std::chrono::duration_cast<std::chrono::microseconds>(
34 std::chrono::system_clock::now().time_since_epoch()).count() / 1e6;
35 }
36#else
37 return std::chrono::duration_cast<std::chrono::microseconds>(
38 std::chrono::system_clock::now().time_since_epoch()).count() / 1e6;
39#endif
40}
41
49inline double get_duration(const TimePoint& start, const TimePoint& end)
50{
51 return end - start;
52}
53
54}
55
56#endif // TIMER_WRAPPER_H
Definition clebsch_gordan_coeff.cpp:8
double get_duration(const TimePoint &start, const TimePoint &end)
Calculate duration between two TimePoints in seconds.
Definition timer_wrapper.h:49
TimePoint get_time()
Get current time as a TimePoint.
Definition timer_wrapper.h:22
double TimePoint
Time point type that works in both MPI and non-MPI environments.
Definition timer_wrapper.h:15
iclock::time_point start
Definition test_partition.cpp:22