8.3
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-2024 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 "cs_defs.h"
35
36/*----------------------------------------------------------------------------*/
37
39
40/*============================================================================
41 * Public types
42 *============================================================================*/
43
44/* Information structure for precise timings */
45
46typedef struct {
47
48 long long sec; /* seconds */
49 long long nsec; /* nanoseconds */
50
52
53/* Information structure for timing counters */
54
55typedef struct {
56
57 long long nsec; /* wall-time nanoseconds */
58
60
61/*============================================================================
62 * Public macros
63 *============================================================================*/
64
65/*----------------------------------------------------------------------------
66 * Initialize timer counter.
67 *
68 * parameters:
69 * _t --> resulting counter.
70 *----------------------------------------------------------------------------*/
71
72#define CS_TIMER_COUNTER_INIT(_t) \
73 (_t.nsec = 0)
74
75/*----------------------------------------------------------------------------
76 * Add timer counter.
77 *
78 * The result may be identical to one of the 2 counters to add.
79 *
80 * parameters:
81 * _res --> resulting counter.
82 * _c0 <-- counter to add.
83 * _c1 <-- counter to add.
84 *----------------------------------------------------------------------------*/
85
86#define CS_TIMER_COUNTER_ADD(_res, _c0, _c1) \
87 (_res.nsec = _c0.nsec + _c1.nsec)
88
89/*=============================================================================
90 * Global variable definitions
91 *=============================================================================*/
92
93/* Activate timings for low-level operators (useful to globally activate
94 various timings in low-level operators) */
95
97
98/*============================================================================
99 * Public function prototypes
100 *============================================================================*/
101
102/*----------------------------------------------------------------------------
103 * Return Wall clock time
104 *
105 * returns:
106 * elapsed time from first call of a function of the cs_timer_...()
107 * series, or -1 if unable to compute.
108 *----------------------------------------------------------------------------*/
109
110double
111cs_timer_wtime(void);
112
113/*----------------------------------------------------------------------------
114 * Return CPU time.
115 *
116 * Note that in the rare case that only the minimal C library clock()
117 * method is available (see cs_timer_cpu_time_method()), at least one of
118 * the cs_timer_...() functions (possibly this one) must be called
119 * upon program start for this function to be used. In addition,
120 * in this case, time may "loop" back to 0 every multiple of
121 * 2^size_t / CLOCKS_PER_SEC seconds.
122 *
123 * returns:
124 * current CPU time usage, or -1 if unable to compute.
125 *----------------------------------------------------------------------------*/
126
127double
129
130/*----------------------------------------------------------------------------
131 * Return separate user and system CPU times.
132 *
133 * parameters:
134 * user_time --> current user CPU usage.
135 * system_time --> current system CPU usage.
136 *----------------------------------------------------------------------------*/
137
138void
139cs_timer_cpu_times(double *user_time,
140 double *system_time);
141
142/*----------------------------------------------------------------------------
143 * Return a timer's value
144 *
145 * returns:
146 * timer structure.
147 *----------------------------------------------------------------------------*/
148
150cs_timer_time(void);
151
152/*----------------------------------------------------------------------------
153 * Compute the difference between 2 timers.
154 *
155 * parameters:
156 * t0 <-- oldest timer value
157 * t1 <-- most recent timer value
158 *
159 * returns:
160 * last - first timer value.
161 *----------------------------------------------------------------------------*/
162
165 const cs_timer_t *t1);
166
167/*----------------------------------------------------------------------------
168 * Add the the difference between 2 timers to a counter.
169 *
170 * parameters:
171 * tc <-> pointer to timer counter
172 * t0 <-- oldest timer value
173 * t1 <-- most recent timer value
174 *
175 * returns:
176 * last - first timer value.
177 *----------------------------------------------------------------------------*/
178
179static inline void
181 const cs_timer_t *t0,
182 const cs_timer_t *t1)
183{
184 tc->nsec += (t1->sec - t0->sec) * (long long)1000000000
185 + t1->nsec - t0->nsec;
186}
187
188/*----------------------------------------------------------------------------
189 * Return method used to return wall clock time.
190 *
191 * Note that in the rare case that only the minimal C library clock()
192 * method is available, this function will return -1 values.
193 *
194 * returns:
195 * short description of method used to return wall clock time.
196 *----------------------------------------------------------------------------*/
197
198const char *
200
201/*----------------------------------------------------------------------------
202 * Return method used to return CPU time.
203 *
204 * returns:
205 * short description of method used to return CPU time.
206 *----------------------------------------------------------------------------*/
207
208const char *
210
211/*----------------------------------------------------------------------------*/
212
214
215#endif /* __CS_TIMER_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
#define END_C_DECLS
Definition: cs_defs.h:543
double cs_timer_wtime(void)
Return Wall clock time.
Definition: cs_timer.cpp:460
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:180
const char * cs_timer_wtime_method(void)
Return method used to return wall clock time.
Definition: cs_timer.cpp:626
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:654
void cs_timer_cpu_times(double *user_time, double *system_time)
Return separate user and system CPU times.
Definition: cs_timer.cpp:529
cs_timer_t cs_timer_time(void)
Return a timer's value.
Definition: cs_timer.cpp:578
double cs_timer_cpu_time(void)
Return CPU time.
Definition: cs_timer.cpp:496
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:606
real(c_double), pointer, save t0
reference temperature.
Definition: cstphy.f90:217
Definition: cs_timer.h:55
long long nsec
Definition: cs_timer.h:57
Definition: cs_timer.h:46
long long sec
Definition: cs_timer.h:48
long long nsec
Definition: cs_timer.h:49