9.2
general documentation
cs_timer.h
Go to the documentation of this file.
1#ifndef CS_TIMER_H
2#define CS_TIMER_H
3
4/*============================================================================
5 * Program timing information
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_defs.h"
35
36/*============================================================================
37 * Public types
38 *============================================================================*/
39
40/* Information structure for precise timings */
41
42typedef struct {
43
44 long long sec; /* seconds */
45 long long nsec; /* nanoseconds */
46
48
49/* Information structure for timing counters */
50
51typedef struct {
52
53 long long nsec; /* wall-time nanoseconds */
54
56
57/*============================================================================
58 * Public macros
59 *============================================================================*/
60
61/*----------------------------------------------------------------------------
62 * Initialize timer counter.
63 *
64 * parameters:
65 * _t --> resulting counter.
66 *----------------------------------------------------------------------------*/
67
68#define CS_TIMER_COUNTER_INIT(_t) \
69 (_t.nsec = 0)
70
71/*----------------------------------------------------------------------------
72 * Add timer counter.
73 *
74 * The result may be identical to one of the 2 counters to add.
75 *
76 * parameters:
77 * _res --> resulting counter.
78 * _c0 <-- counter to add.
79 * _c1 <-- counter to add.
80 *----------------------------------------------------------------------------*/
81
82#define CS_TIMER_COUNTER_ADD(_res, _c0, _c1) \
83 (_res.nsec = _c0.nsec + _c1.nsec)
84
85/*=============================================================================
86 * Global variable definitions
87 *=============================================================================*/
88
89/* Activate timings for low-level operators (useful to globally activate
90 various timings in low-level operators) */
91
93
94/*============================================================================
95 * Public function prototypes
96 *============================================================================*/
97
98/*----------------------------------------------------------------------------
99 * Return Wall clock time
100 *
101 * returns:
102 * elapsed time from first call of a function of the cs_timer_...()
103 * series, or -1 if unable to compute.
104 *----------------------------------------------------------------------------*/
105
106double
107cs_timer_wtime(void);
108
109/*----------------------------------------------------------------------------
110 * Return CPU time.
111 *
112 * Note that in the rare case that only the minimal C library clock()
113 * method is available (see cs_timer_cpu_time_method()), at least one of
114 * the cs_timer_...() functions (possibly this one) must be called
115 * upon program start for this function to be used. In addition,
116 * in this case, time may "loop" back to 0 every multiple of
117 * 2^size_t / CLOCKS_PER_SEC seconds.
118 *
119 * returns:
120 * current CPU time usage, or -1 if unable to compute.
121 *----------------------------------------------------------------------------*/
122
123double
125
126/*----------------------------------------------------------------------------
127 * Return separate user and system CPU times.
128 *
129 * parameters:
130 * user_time --> current user CPU usage.
131 * system_time --> current system CPU usage.
132 *----------------------------------------------------------------------------*/
133
134void
135cs_timer_cpu_times(double *user_time,
136 double *system_time);
137
138/*----------------------------------------------------------------------------
139 * Return a timer's value
140 *
141 * returns:
142 * timer structure.
143 *----------------------------------------------------------------------------*/
144
146cs_timer_time(void);
147
148/*----------------------------------------------------------------------------
149 * Compute the difference between 2 timers.
150 *
151 * parameters:
152 * t0 <-- oldest timer value
153 * t1 <-- most recent timer value
154 *
155 * returns:
156 * last - first timer value.
157 *----------------------------------------------------------------------------*/
158
161 const cs_timer_t *t1);
162
163/*----------------------------------------------------------------------------
164 * Add the the difference between 2 timers to a counter.
165 *
166 * parameters:
167 * tc <-> pointer to timer counter
168 * t0 <-- oldest timer value
169 * t1 <-- most recent timer value
170 *
171 * returns:
172 * last - first timer value.
173 *----------------------------------------------------------------------------*/
174
175static inline void
177 const cs_timer_t *t0,
178 const cs_timer_t *t1)
179{
180 tc->nsec += (t1->sec - t0->sec) * (long long)1000000000
181 + t1->nsec - t0->nsec;
182}
183
184/*----------------------------------------------------------------------------
185 * Return method used to return wall clock time.
186 *
187 * Note that in the rare case that only the minimal C library clock()
188 * method is available, this function will return -1 values.
189 *
190 * returns:
191 * short description of method used to return wall clock time.
192 *----------------------------------------------------------------------------*/
193
194const char *
196
197/*----------------------------------------------------------------------------
198 * Return method used to return CPU time.
199 *
200 * returns:
201 * short description of method used to return CPU time.
202 *----------------------------------------------------------------------------*/
203
204const char *
206
207/*----------------------------------------------------------------------------*/
208
209#endif /* CS_TIMER_H */
double cs_timer_wtime(void)
Return Wall clock time.
Definition: cs_timer.cpp:458
static void cs_timer_counter_add_diff(cs_timer_counter_t *tc, const cs_timer_t *t0, const cs_timer_t *t1)
Definition: cs_timer.h:176
const char * cs_timer_wtime_method(void)
Return method used to return wall clock time.
Definition: cs_timer.cpp:624
int cs_glob_timer_kernels_flag
const char * cs_timer_cpu_time_method(void)
Return method used to return CPU time.
Definition: cs_timer.cpp:652
void cs_timer_cpu_times(double *user_time, double *system_time)
Return separate user and system CPU times.
Definition: cs_timer.cpp:527
cs_timer_t cs_timer_time(void)
Return a timer's value.
Definition: cs_timer.cpp:576
double cs_timer_cpu_time(void)
Return CPU time.
Definition: cs_timer.cpp:494
cs_timer_counter_t cs_timer_diff(const cs_timer_t *t0, const cs_timer_t *t1)
Compute the difference between 2 timers.
Definition: cs_timer.cpp:604
real(c_double), pointer, save t0
reference temperature.
Definition: cstphy.f90:68
Definition: cs_timer.h:51
long long nsec
Definition: cs_timer.h:53
Definition: cs_timer.h:42
long long sec
Definition: cs_timer.h:44
long long nsec
Definition: cs_timer.h:45