FrontISTR  5.8.0
Large-scale structural analysis program with finit element method
hecmw_time.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 #include "hecmw_time.h"
7 
8 double HECMW_Wtime(void) {
9 #ifndef HECMW_SERIAL
10  return MPI_Wtime();
11 #else
12  #if defined(CLOCK_MONOTONIC)
13  struct timespec ts;
14  if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
15  return (double)ts.tv_sec + (double)ts.tv_nsec * 1e-9;
16  }
17  #endif
18  /* Fallback for systems without CLOCK_MONOTONIC */
19  struct timeval tv;
20  gettimeofday(&tv, NULL);
21  return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
22 #endif
23 }
24 
25 double HECMW_Wtick(void) {
26 #ifndef HECMW_SERIAL
27  return MPI_Wtick();
28 #else
29  #if defined(CLOCK_MONOTONIC)
30  struct timespec res;
31  if (clock_getres(CLOCK_MONOTONIC, &res) == 0) {
32  return (double)res.tv_sec + (double)res.tv_nsec * 1e-9;
33  }
34  #endif
35  return 1e-6; /* gettimeofday microsecond resolution */
36 #endif
37 }
38 
39 /* interface for fortran */
40 
41 double hecmw_wtime_fi(void) { return HECMW_Wtime(); }
42 double hecmw_wtime_fi_(void) { return HECMW_Wtime(); }
43 double hecmw_wtime_fi__(void) { return HECMW_Wtime(); }
44 double HECMW_WTIME_FI(void) { return HECMW_Wtime(); }
45 double HECMW_WTIME_FI_(void) { return HECMW_Wtime(); }
46 double HECMW_WTIME_FI__(void) { return HECMW_Wtime(); }
47 
48 double hecmw_wtick_fi(void) { return HECMW_Wtick(); }
49 double hecmw_wtick_fi_(void) { return HECMW_Wtick(); }
50 double hecmw_wtick_fi__(void) { return HECMW_Wtick(); }
51 double HECMW_WTICK_FI(void) { return HECMW_Wtick(); }
52 double HECMW_WTICK_FI_(void) { return HECMW_Wtick(); }
53 double HECMW_WTICK_FI__(void) { return HECMW_Wtick(); }
#define NULL
double HECMW_WTICK_FI__(void)
Definition: hecmw_time.c:53
double hecmw_wtime_fi__(void)
Definition: hecmw_time.c:43
double HECMW_WTIME_FI_(void)
Definition: hecmw_time.c:45
double hecmw_wtime_fi_(void)
Definition: hecmw_time.c:42
double HECMW_WTICK_FI_(void)
Definition: hecmw_time.c:52
double hecmw_wtick_fi_(void)
Definition: hecmw_time.c:49
double HECMW_WTIME_FI__(void)
Definition: hecmw_time.c:46
double HECMW_Wtime(void)
Definition: hecmw_time.c:8
double HECMW_WTIME_FI(void)
Definition: hecmw_time.c:44
double hecmw_wtime_fi(void)
Definition: hecmw_time.c:41
double HECMW_WTICK_FI(void)
Definition: hecmw_time.c:51
double HECMW_Wtick(void)
Definition: hecmw_time.c:25
double hecmw_wtick_fi__(void)
Definition: hecmw_time.c:50
double hecmw_wtick_fi(void)
Definition: hecmw_time.c:48