LevelS C support library  3.50
walltime_c.c
1 /*
2  * This file is part of libc_utils.
3  *
4  * libc_utils is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * libc_utils is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with libc_utils; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  * libc_utils is being developed at the Max-Planck-Institut fuer Astrophysik
21  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
22  * (DLR).
23  */
24 
25 /*
26  * Functionality for reading wall clock time
27  *
28  * Copyright (C) 2010-2016 Max-Planck-Society
29  * Author: Martin Reinecke
30  */
31 
32 #if defined (_OPENMP)
33 #include <omp.h>
34 #elif defined (USE_MPI)
35 #include "mpi.h"
36 #elif defined (_WIN32)
37 #include <Windows.h>
38 #else
39 #include <sys/time.h>
40 #include <stdlib.h>
41 #endif
42 
43 #include "walltime_c.h"
44 
45 double wallTime(void)
46  {
47 #if defined (_OPENMP)
48  return omp_get_wtime();
49 #elif defined (USE_MPI)
50  return MPI_Wtime();
51 #elif defined (_WIN32)
52  static double inv_freq = -1.;
53  if (inv_freq<0)
54  {
55  LARGE_INTEGER freq;
56  QueryPerformanceFrequency(&freq);
57  inv_freq = 1. / double(freq.QuadPart);
58  }
59  LARGE_INTEGER count;
60  QueryPerformanceCounter(&count);
61  return count.QuadPart*inv_freq;
62 #else
63  struct timeval t;
64  gettimeofday(&t, NULL);
65  return t.tv_sec + 1e-6*t.tv_usec;
66 #endif
67  }
double wallTime(void)
Definition: walltime_c.c:45

Generated on Mon Dec 10 2018 10:24:19 for LevelS C support library