Psi4
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables

Obtain user and system timings for blocks of codeTIMER.CC: These functions allow one to obtain user and system timings for arbitrary blocks of code. If a code block is called repeatedly during the course of program execution, the timer functions will report the block's cumulative execution time and the number of calls. In addition, one may time multiple code blocks simultaneously, and even ``overlap'' timers. Timing data is written to the file "timer.dat" at the end of timer execution, i.e., when timer_done() is called. More...

#include "psi4/libciomr/libciomr.h"
#include "psi4/libpsi4util/PsiOutStream.h"
#include "psi4/libpsi4util/exception.h"
#include "psi4/psi4-dec.h"
#include "psi4/psifiles.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <sys/time.h>
#include <sys/times.h>
#include <unistd.h>
#include <chrono>
#include <list>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

Classes

class  psi::Timer_thread
 
class  psi::Timer_Structure
 

Namespaces

 psi
 This is all defined in python.cc initialize.
 

Macros

#define omp_init_lock(lock_timer_p)
 
#define omp_set_lock(lock_timer_p)
 
#define omp_unset_lock(lock_timer_p)
 
#define omp_destroy_lock(lock_timer_p)
 
#define HZ   60
 

Typedefs

typedef int omp_lock_t
 
using psi::clock = std::chrono::high_resolution_clock
 

Enumerations

enum  psi::Timer_Status { psi::OFF, psi::ON, psi::PARALLEL }
 

Functions

void psi::print_timer (const Timer_Structure &timer, std::shared_ptr< PsiOutStream > printer, int align_key_width)
 
void psi::print_nested_timer (const Timer_Structure &timer, std::shared_ptr< PsiOutStream > printer, const std::string &indent)
 
bool psi::empty_parallel ()
 
void psi::timer_init (void)
 
void psi::timer_done (void)
 
void psi::start_skip_timers ()
 
void psi::stop_skip_timers ()
 
void psi::timer_on (const std::string &key)
 
void psi::timer_off (const std::string &key)
 
void psi::parallel_timer_on (const std::string &key, int thread_rank)
 
void psi::parallel_timer_off (const std::string &key, int thread_rank)
 

Variables

Timer_Structure psi::root_timer (nullptr,"")
 
Timer_Structure psi::parallel_timer (nullptr,"")
 
std::list< Timer_Structure * > psi::ser_on_timers
 
std::vector< std::list
< Timer_Structure * > > 
psi::par_on_timers
 
time_t psi::timer_start
 
time_t psi::timer_end
 
bool psi::skip_timers
 
static omp_lock_t psi::lock_timer
 

Detailed Description

Obtain user and system timings for blocks of code

TIMER.CC: These functions allow one to obtain user and system timings for arbitrary blocks of code. If a code block is called repeatedly during the course of program execution, the timer functions will report the block's cumulative execution time and the number of calls. In addition, one may time multiple code blocks simultaneously, and even ``overlap'' timers. Timing data is written to the file "timer.dat" at the end of timer execution, i.e., when timer_done() is called.

To use the timer functions defined here:

(1) Initialize the linked list of timers at the beginning of your program: timer_init();

(2) Start a timer at the start of the block of code: timer_on("My Timer");

(3) Stop the timer at the end of the block: timer_off("My Timer");

(4) When all timer calls are complete, dump the linked list of timing data to the output file, "timer.dat": timer_done();

NB this code uses system functions ctime(), time(), and times(), which may not quite be standard on all machines.

T. Daniel Crawford, August 1999.

Modified to use timeval structures for the module wall times, getting nanosecond precision on cumulated wall time instead of second. Useful to time integral computations where there can be millions to billion calls to functions.

J. F. Gonthier, February 2016

Modified to use std::chrono::high_resolution_clock for the module wall times. Modified implementation of timer to a Class of tree structured timers and a stack of timer to enable nested timer prints. Implemented timer for OpenMP parallism.

Tianyuan Zhang, June 2017

Macro Definition Documentation

#define HZ   60
#define omp_destroy_lock (   lock_timer_p)
Value:
do { \
} while (0)
#define omp_init_lock (   lock_timer_p)
Value:
do { \
} while (0)
#define omp_set_lock (   lock_timer_p)
Value:
do { \
} while (0)
#define omp_unset_lock (   lock_timer_p)
Value:
do { \
} while (0)

Typedef Documentation

typedef int omp_lock_t