Skip to content

Commit a8e6154

Browse files
committedJul 23, 2012
Implement gettime function as a separate module.
1 parent e0a4f58 commit a8e6154

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
 

‎gettime.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/***********************************************************************
2+
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Carsten Urbach
3+
* Copyright (C) 2012 Bartosz Kostrzewa (gettime.[c,h])
4+
*
5+
* This file is part of tmLQCD.
6+
*
7+
* tmLQCD is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* tmLQCD is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with tmLQCD. If not, see <http://www.gnu.org/licenses/>.
19+
***********************************************************************/
20+
21+
22+
#ifdef HAVE_CONFIG_H
23+
# include<config.h>
24+
#endif
25+
#include <time.h>
26+
#if (defined BGL && !defined BGP)
27+
# include <rts.h>
28+
#endif
29+
#ifdef MPI
30+
# include <mpi.h>
31+
#endif
32+
33+
#include "gettime.h"
34+
35+
double gettime(void) {
36+
double t;
37+
#if (defined BGL && !defined BGP)
38+
const double clockspeed=1.0e-6/700.0;
39+
t = rts_get_timebase() * clockspeed;
40+
#elif defined MPI
41+
t = MPI_Wtime();
42+
/* clock_gettime is detected on BGL/BGP but it is an unsupported system call so we can't use it! */
43+
#elif (defined HAVE_CLOCK_GETTIME && !defined BGL)
44+
struct timespec ts;
45+
clock_gettime(CLOCK_MONOTONIC,&ts);
46+
t = ts.tv_sec + 1.0e-9*ts.tv_nsec;
47+
#else
48+
t = (double)clock()/(CLOCKS_PER_SEC);
49+
#endif
50+
return t;
51+
}
52+

‎gettime.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/***********************************************************************
2+
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008 Carsten Urbach
3+
* Copyright (C) 2012 Bartosz Kostrzewa (gettime.[c,h])
4+
*
5+
* This file is part of tmLQCD.
6+
*
7+
* tmLQCD is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* tmLQCD is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with tmLQCD. If not, see <http://www.gnu.org/licenses/>.
19+
***********************************************************************/
20+
21+
#ifndef _GETTIME_H
22+
#define _GETTIME_H
23+
24+
/* gettime provides a time measurement with the BGL real time ticker,
25+
MPI_Wtime, clock_gettime and clock in decreasing order of preference
26+
depending on availability. Except for clock(), all these measurements
27+
are good representations of walltime */
28+
29+
double gettime(void);
30+
31+
#endif /* _GETTIME_H */
32+

0 commit comments

Comments
 (0)
Please sign in to comment.