timers.h 2.43 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
/* Includes. */
#include "cycle.h"
27
#include "inline.h"
Pedro Gonnet's avatar
Pedro Gonnet committed
28
29
30

/* The timers themselves. */
enum {
31
32
  timer_none = 0,
  timer_prepare,
33
  timer_init,
Matthieu Schaller's avatar
Matthieu Schaller committed
34
35
  timer_drift,
  timer_kick,
36
37
38
39
40
41
42
  timer_dosort,
  timer_doself_density,
  timer_doself_force,
  timer_doself_grav,
  timer_dopair_density,
  timer_dopair_force,
  timer_dopair_grav,
43
  timer_dograv_external,
44
45
46
47
48
  timer_dosub_density,
  timer_dosub_force,
  timer_dosub_grav,
  timer_dopair_subset,
  timer_doghost,
49
  timer_dorecv_cell,
50
51
52
53
54
55
56
57
  timer_gettask,
  timer_qget,
  timer_qsteal,
  timer_runners,
  timer_step,
  timer_count,
};

Pedro Gonnet's avatar
Pedro Gonnet committed
58
/* The timers. */
59
extern ticks timers[timer_count];
Pedro Gonnet's avatar
Pedro Gonnet committed
60
61

/* Mask for all timers. */
62
#define timers_mask_all ((1 << timer_count) - 1)
Pedro Gonnet's avatar
Pedro Gonnet committed
63
64
65

/* Define the timer macros. */
#ifdef TIMER
66
67
68
69
70
71
72
73
74
75
76
#define TIMER_TIC_ND tic = getticks();
#define TIMER_TIC2_ND ticks tic2 = getticks();
#define TIMER_TIC ticks tic = getticks();
#define TIMER_TOC(t) timers_toc(t, tic)
#define TIMER_TIC2 ticks tic2 = getticks();
#define TIMER_TOC2(t) timers_toc(t, tic2)
INLINE static ticks timers_toc(int t, ticks tic) {
  ticks d = (getticks() - tic);
  __sync_add_and_fetch(&timers[t], d);
  return d;
}
Pedro Gonnet's avatar
Pedro Gonnet committed
77
#else
78
79
80
81
#define TIMER_TIC
#define TIMER_TOC(t)
#define TIMER_TIC2
#define TIMER_TOC2(t)
Pedro Gonnet's avatar
Pedro Gonnet committed
82
83
84
#endif

/* Function prototypes. */
85
86
87
void timers_reset(unsigned int mask);

#endif /* SWIFT_TIMERS_H */