timers.h 3.61 KB
Newer Older
Pedro Gonnet's avatar
Pedro Gonnet committed
1
2
/*******************************************************************************
 * This file is part of SWIFT.
3
 * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
4
5
6
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
 *               2016 John A. Regan (john.a.regan@durham.ac.uk)
 *                    Tom Theuns (tom.theuns@durham.ac.uk)
7
 *
Pedro Gonnet's avatar
Pedro Gonnet committed
8
9
10
11
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
12
 *
Pedro Gonnet's avatar
Pedro Gonnet committed
13
14
15
16
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
17
 *
Pedro Gonnet's avatar
Pedro Gonnet committed
18
19
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
Pedro Gonnet's avatar
Pedro Gonnet committed
21
 ******************************************************************************/
22
23
#ifndef SWIFT_TIMERS_H
#define SWIFT_TIMERS_H
Pedro Gonnet's avatar
Pedro Gonnet committed
24

25
26
27
28
/* Config parameters. */
#include "../config.h"

/* Local includes. */
29
#include "atomic.h"
30
#include "cycle.h"
31
#include "inline.h"
Pedro Gonnet's avatar
Pedro Gonnet committed
32

33
34
35
36
37
38
/**
 * @brief The timers themselves.
 *
 * If you modify this list, be sure to change timers_names in timers.c as
 * well!
 **/
Pedro Gonnet's avatar
Pedro Gonnet committed
39
enum {
40
41
  timer_none = 0,
  timer_prepare,
42
  timer_init,
43
  timer_init_grav,
44
45
  timer_drift_part,
  timer_drift_gpart,
46
47
  timer_kick1,
  timer_kick2,
48
  timer_timestep,
49
  timer_endforce,
50
51
  timer_dosort,
  timer_doself_density,
52
  timer_doself_gradient,
53
  timer_doself_force,
54
  timer_doself_grav_pp,
55
  timer_dopair_density,
56
  timer_dopair_gradient,
57
  timer_dopair_force,
58
  timer_dopair_grav_mm,
59
  timer_dopair_grav_pp,
60
  timer_dograv_external,
61
  timer_dograv_down,
62
  timer_dograv_mesh,
Matthieu Schaller's avatar
Matthieu Schaller committed
63
  timer_dograv_top_level,
64
  timer_dograv_long_range,
Tom Theuns's avatar
Tom Theuns committed
65
  timer_dosource,
66
  timer_dosub_self_density,
67
  timer_dosub_self_gradient,
68
69
70
  timer_dosub_self_force,
  timer_dosub_self_grav,
  timer_dosub_pair_density,
71
  timer_dosub_pair_gradient,
72
73
  timer_dosub_pair_force,
  timer_dosub_pair_grav,
74
  timer_doself_subset,
75
  timer_dopair_subset,
76
77
  timer_dopair_subset_naive,
  timer_dosub_subset,
Matthieu Schaller's avatar
Matthieu Schaller committed
78
  timer_do_ghost,
79
  timer_do_extra_ghost,
80
81
  timer_dorecv_part,
  timer_dorecv_gpart,
82
  timer_dorecv_spart,
83
  timer_do_cooling,
Matthieu Schaller's avatar
Matthieu Schaller committed
84
  timer_do_star_formation,
85
86
87
  timer_gettask,
  timer_qget,
  timer_qsteal,
88
  timer_locktree,
89
90
  timer_runners,
  timer_step,
91
92
93
94
95
96
97
  timer_doself_stars_density,
  timer_dopair_stars_density,
  timer_dostars_ghost,
  timer_doself_subset_stars_density,
  timer_dopair_subset_stars_density,
  timer_dosubpair_stars_density,
  timer_dosub_self_stars_density,
Loikki's avatar
Loikki committed
98
  timer_logger,
99
100
101
  timer_count,
};

Pedro Gonnet's avatar
Pedro Gonnet committed
102
/* The timers. */
103
extern ticks timers[timer_count];
Pedro Gonnet's avatar
Pedro Gonnet committed
104

105
/* The timer names. */
106
extern const char *timers_names[];
107

Pedro Gonnet's avatar
Pedro Gonnet committed
108
/* Mask for all timers. */
109
#define timers_mask_all ((1ull << timer_count) - 1)
Pedro Gonnet's avatar
Pedro Gonnet committed
110
111

/* Define the timer macros. */
112
113
#ifdef SWIFT_USE_TIMERS
#define TIMER_TIC const ticks tic = getticks();
114
#define TIMER_TOC(t) timers_toc(t, tic)
115
#define TIMER_TIC2 const ticks tic2 = getticks();
116
#define TIMER_TOC2(t) timers_toc(t, tic2)
117
INLINE static ticks timers_toc(unsigned int t, ticks tic) {
118
  const ticks d = (getticks() - tic);
119
  atomic_add(&timers[t], d);
120
121
  return d;
}
Pedro Gonnet's avatar
Pedro Gonnet committed
122
#else
123
#define TIMER_TIC
124
#define TIMER_TOC(t) (void)0
125
#define TIMER_TIC2
126
#define TIMER_TOC2(t) (void)0
Pedro Gonnet's avatar
Pedro Gonnet committed
127
128
129
#endif

/* Function prototypes. */
130
void timers_reset_all(void);
131
void timers_reset(unsigned long long mask);
132
void timers_open_file(int rank);
133
void timers_close_file(void);
134
void timers_print(int step);
135
136

#endif /* SWIFT_TIMERS_H */