ARGOBOTS  66b1c39742507d8df30e8d28c54839b961a14814
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
timer.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include "abti.h"
7 
8 ABTU_ret_err static int timer_alloc(ABTI_timer **pp_newtimer);
9 
24 double ABT_get_wtime(void)
25 {
26  return ABTI_get_wtime();
27 }
28 
43 {
44  ABTI_timer *p_newtimer;
45  int abt_errno = timer_alloc(&p_newtimer);
46  ABTI_CHECK_ERROR(abt_errno);
47 
48  *newtimer = ABTI_timer_get_handle(p_newtimer);
49  return ABT_SUCCESS;
50 }
51 
67 int ABT_timer_dup(ABT_timer timer, ABT_timer *newtimer)
68 {
69  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
70  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
71 
72  ABTI_timer *p_newtimer;
73  int abt_errno = timer_alloc(&p_newtimer);
74  ABTI_CHECK_ERROR(abt_errno);
75 
76  memcpy(p_newtimer, p_timer, sizeof(ABTI_timer));
77  *newtimer = ABTI_timer_get_handle(p_newtimer);
78  return ABT_SUCCESS;
79 }
80 
96 {
97  ABTI_timer *p_timer = ABTI_timer_get_ptr(*timer);
98  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
99 
100  /* We use libc malloc/free for ABT_timer because ABTU_malloc/free might
101  * need the initialization of Argobots if they are not the same as libc
102  * malloc/free. This is to allow ABT_timer to be used irrespective of
103  * Argobots initialization. */
104  free(p_timer);
105  *timer = ABT_TIMER_NULL;
106  return ABT_SUCCESS;
107 }
108 
122 {
123  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
124  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
125 
126  ABTD_time_get(&p_timer->start);
127  return ABT_SUCCESS;
128 }
129 
143 {
144  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
145  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
146 
147  ABTD_time_get(&p_timer->end);
148  return ABT_SUCCESS;
149 }
150 
165 int ABT_timer_read(ABT_timer timer, double *secs)
166 {
167  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
168  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
169 
170  double start = ABTD_time_read_sec(&p_timer->start);
171  double end = ABTD_time_read_sec(&p_timer->end);
172 
173  *secs = end - start;
174  return ABT_SUCCESS;
175 }
176 
192 int ABT_timer_stop_and_read(ABT_timer timer, double *secs)
193 {
194  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
195  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
196 
197  ABTD_time_get(&p_timer->end);
198  double start = ABTD_time_read_sec(&p_timer->start);
199  double end = ABTD_time_read_sec(&p_timer->end);
200 
201  *secs = end - start;
202  return ABT_SUCCESS;
203 }
204 
220 int ABT_timer_stop_and_add(ABT_timer timer, double *secs)
221 {
222  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
223  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
224 
225  ABTD_time_get(&p_timer->end);
226  double start = ABTD_time_read_sec(&p_timer->start);
227  double end = ABTD_time_read_sec(&p_timer->end);
228 
229  *secs += (end - start);
230  return ABT_SUCCESS;
231 }
232 
246 int ABT_timer_get_overhead(double *overhead)
247 {
248  int abt_errno;
249  ABT_timer h_timer;
250  int i;
251  const int iter = 5000;
252  double secs, sum = 0.0;
253 
254  abt_errno = ABT_timer_create(&h_timer);
255  ABTI_CHECK_ERROR(abt_errno);
256 
257  for (i = 0; i < iter; i++) {
258  ABT_timer_start(h_timer);
259  ABT_timer_stop(h_timer);
260  ABT_timer_read(h_timer, &secs);
261  sum += secs;
262  }
263 
264  abt_errno = ABT_timer_free(&h_timer);
265  ABTI_CHECK_ERROR(abt_errno);
266 
267  *overhead = sum / iter;
268  return ABT_SUCCESS;
269 }
270 
271 /*****************************************************************************/
272 /* Internal static functions */
273 /*****************************************************************************/
274 
275 ABTU_ret_err static int timer_alloc(ABTI_timer **pp_newtimer)
276 {
277  /* We use libc malloc/free for ABT_timer because ABTU_malloc/free might
278  * need the initialization of Argobots if they are not the same as libc
279  * malloc/free. This is to allow ABT_timer to be used irrespective of
280  * Argobots initialization. */
281  ABTI_timer *p_newtimer = (ABTI_timer *)malloc(sizeof(ABTI_timer));
282  ABTI_CHECK_TRUE(p_newtimer != NULL, ABT_ERR_MEM);
283 
284  *pp_newtimer = p_newtimer;
285  return ABT_SUCCESS;
286 }
int ABT_timer_stop(ABT_timer timer) ABT_API_PUBLIC
Stop the timer.
Definition: timer.c:142
int ABT_timer_stop_and_add(ABT_timer timer, double *secs) ABT_API_PUBLIC
Stop the timer and add the elapsed time of the timer.
Definition: timer.c:220
int ABT_timer_dup(ABT_timer timer, ABT_timer *newtimer) ABT_API_PUBLIC
Duplicate the timer.
Definition: timer.c:67
#define ABT_TIMER_NULL
Definition: abt.h:426
static ABTU_ret_err int timer_alloc(ABTI_timer **pp_newtimer)
Definition: timer.c:275
int ABT_timer_read(ABT_timer timer, double *secs) ABT_API_PUBLIC
Read the elapsed time of the timer.
Definition: timer.c:165
int ABT_timer_get_overhead(double *overhead) ABT_API_PUBLIC
Obtain the overhead time of using ABT_timer.
Definition: timer.c:246
int ABT_timer_create(ABT_timer *newtimer) ABT_API_PUBLIC
Create a new timer.
Definition: timer.c:42
int ABT_timer_free(ABT_timer *timer) ABT_API_PUBLIC
Free the timer object.
Definition: timer.c:95
#define ABT_ERR_MEM
Definition: abt.h:66
#define ABT_SUCCESS
Definition: abt.h:64
int ABT_timer_stop_and_read(ABT_timer timer, double *secs) ABT_API_PUBLIC
Stop the timer and read the elapsed time of the timer.
Definition: timer.c:192
int ABT_timer_start(ABT_timer timer) ABT_API_PUBLIC
Start the timer.
Definition: timer.c:121
double ABT_get_wtime(void) ABT_API_PUBLIC
Get elapsed wall clock time.
Definition: timer.c:24
#define ABTU_ret_err
Definition: abtu.h:49
struct ABT_timer_opaque * ABT_timer
Definition: abt.h:371