Astaroth  3.1
Scalable Multi-GPU Stencil Computations
Loading...
Searching...
No Matches
timer_hires.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2014-2026, Johannes Pekkila, Touko Puro, Miikka Vaisala.
3
4 This file is part of Astaroth.
5
6 Astaroth is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Astaroth is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Astaroth. If not, see <http://www.gnu.org/licenses/>.
18*/
19
31#pragma once
32
33#include <stdio.h> // perror
34#include <time.h>
35
36#include "func_define.h"
37
39
40typedef struct timespec Timer;
41// Contains at least the following members:
42// time_t tv_sec;
43// long tv_nsec;
44
45static inline int
46timer_reset(Timer* t)
47{
48 const int retval = clock_gettime(CLOCK_REALTIME, t);
49 if (retval == -1)
50 perror("clock_gettime failure");
51
52 return retval;
53}
54
55static inline long
56timer_diff_nsec(const Timer start)
57{
58 Timer end;
59 timer_reset(&end);
60 const long diff = (end.tv_sec - start.tv_sec) * 1000000000l + (end.tv_nsec - start.tv_nsec);
61 return diff;
62}
63
64static inline void
65timer_diff_print(const Timer t)
66{
67 printf("Time elapsed: %g ms\n", timer_diff_nsec(t) / 1e6);
68}
69
#define AC_BEGIN_C_DECLARATIONS
Definition func_define.h:14
#define AC_END_C_DECLARATIONS
Definition func_define.h:15
struct timespec Timer
Definition timer_hires.h:40