|
| 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 | + |
0 commit comments