ARGOBOTS  1227c643f7a7f974f1f1778a9ffebd29d7dafecf
 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  int abt_errno = ABT_SUCCESS;
45  ABTI_timer *p_newtimer;
46 
47  abt_errno = timer_alloc(&p_newtimer);
48  ABTI_CHECK_ERROR(abt_errno);
49 
50  *newtimer = ABTI_timer_get_handle(p_newtimer);
51 
52 fn_exit:
53  return abt_errno;
54 
55 fn_fail:
56  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
57  goto fn_exit;
58 }
59 
75 int ABT_timer_dup(ABT_timer timer, ABT_timer *newtimer)
76 {
77  int abt_errno = ABT_SUCCESS;
78  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
80 
81  ABTI_timer *p_newtimer;
82 
83  abt_errno = timer_alloc(&p_newtimer);
84  ABTI_CHECK_ERROR(abt_errno);
85 
86  memcpy(p_newtimer, p_timer, sizeof(ABTI_timer));
87 
88  *newtimer = ABTI_timer_get_handle(p_newtimer);
89 
90 fn_exit:
91  return abt_errno;
92 
93 fn_fail:
94  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
95  goto fn_exit;
96 }
97 
113 {
114  int abt_errno = ABT_SUCCESS;
115  ABTI_timer *p_timer = ABTI_timer_get_ptr(*timer);
116  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
117 
118  /* We use libc malloc/free for ABT_timer because ABTU_malloc/free might
119  * need the initialization of Argobots if they are not the same as libc
120  * malloc/free. This is to allow ABT_timer to be used irrespective of
121  * Argobots initialization. */
122  free(p_timer);
123  *timer = ABT_TIMER_NULL;
124 
125 fn_exit:
126  return abt_errno;
127 
128 fn_fail:
129  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
130  goto fn_exit;
131 }
132 
146 {
147  int abt_errno = ABT_SUCCESS;
148  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
149  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
150 
151  ABTD_time_get(&p_timer->start);
152 
153 fn_exit:
154  return abt_errno;
155 
156 fn_fail:
157  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
158  goto fn_exit;
159 }
160 
174 {
175  int abt_errno = ABT_SUCCESS;
176  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
177  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
178 
179  ABTD_time_get(&p_timer->end);
180 
181 fn_exit:
182  return abt_errno;
183 
184 fn_fail:
185  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
186  goto fn_exit;
187 }
188 
203 int ABT_timer_read(ABT_timer timer, double *secs)
204 {
205  int abt_errno = ABT_SUCCESS;
206  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
207  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
208 
209  double start, end;
210 
211  start = ABTD_time_read_sec(&p_timer->start);
212  end = ABTD_time_read_sec(&p_timer->end);
213 
214  *secs = end - start;
215 
216 fn_exit:
217  return abt_errno;
218 
219 fn_fail:
220  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
221  goto fn_exit;
222 }
223 
239 int ABT_timer_stop_and_read(ABT_timer timer, double *secs)
240 {
241  int abt_errno = ABT_SUCCESS;
242  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
243  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
244 
245  double start, end;
246 
247  ABTD_time_get(&p_timer->end);
248  start = ABTD_time_read_sec(&p_timer->start);
249  end = ABTD_time_read_sec(&p_timer->end);
250 
251  *secs = end - start;
252 
253 fn_exit:
254  return abt_errno;
255 
256 fn_fail:
257  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
258  goto fn_exit;
259 }
260 
276 int ABT_timer_stop_and_add(ABT_timer timer, double *secs)
277 {
278  int abt_errno = ABT_SUCCESS;
279  ABTI_timer *p_timer = ABTI_timer_get_ptr(timer);
280  ABTI_CHECK_NULL_TIMER_PTR(p_timer);
281 
282  double start, end;
283 
284  ABTD_time_get(&p_timer->end);
285  start = ABTD_time_read_sec(&p_timer->start);
286  end = ABTD_time_read_sec(&p_timer->end);
287 
288  *secs += (end - start);
289 
290 fn_exit:
291  return abt_errno;
292 
293 fn_fail:
294  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
295  goto fn_exit;
296 }
297 
311 int ABT_timer_get_overhead(double *overhead)
312 {
313  int abt_errno = ABT_SUCCESS;
314  ABT_timer h_timer;
315  int i;
316  const int iter = 5000;
317  double secs, sum = 0.0;
318 
319  abt_errno = ABT_timer_create(&h_timer);
320  ABTI_CHECK_ERROR(abt_errno);
321 
322  for (i = 0; i < iter; i++) {
323  ABT_timer_start(h_timer);
324  ABT_timer_stop(h_timer);
325  ABT_timer_read(h_timer, &secs);
326  sum += secs;
327  }
328 
329  abt_errno = ABT_timer_free(&h_timer);
330  ABTI_CHECK_ERROR(abt_errno);
331 
332  *overhead = sum / iter;
333 
334 fn_exit:
335  return abt_errno;
336 
337 fn_fail:
338  HANDLE_ERROR_FUNC_WITH_CODE(abt_errno);
339  goto fn_exit;
340 }
341 
342 /*****************************************************************************/
343 /* Internal static functions */
344 /*****************************************************************************/
345 
346 ABTU_ret_err static int timer_alloc(ABTI_timer **pp_newtimer)
347 {
348  /* We use libc malloc/free for ABT_timer because ABTU_malloc/free might
349  * need the initialization of Argobots if they are not the same as libc
350  * malloc/free. This is to allow ABT_timer to be used irrespective of
351  * Argobots initialization. */
352  ABTI_timer *p_newtimer = (ABTI_timer *)malloc(sizeof(ABTI_timer));
353  ABTI_CHECK_TRUE_RET(p_newtimer != NULL, ABT_ERR_MEM);
354 
355  *pp_newtimer = p_newtimer;
356 
357  return ABT_SUCCESS;
358 }
int ABT_timer_stop(ABT_timer timer) ABT_API_PUBLIC
Stop the timer.
Definition: timer.c:173
static ABTI_timer * ABTI_timer_get_ptr(ABT_timer timer)
Definition: abti_timer.h:18
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:276
double ABTD_time_read_sec(ABTD_time *p_time)
Definition: abtd_time.c:35
int ABT_timer_dup(ABT_timer timer, ABT_timer *newtimer) ABT_API_PUBLIC
Duplicate the timer.
Definition: timer.c:75
#define ABT_TIMER_NULL
Definition: abt.h:426
static ABTU_ret_err int timer_alloc(ABTI_timer **pp_newtimer)
Definition: timer.c:346
int ABT_timer_read(ABT_timer timer, double *secs) ABT_API_PUBLIC
Read the elapsed time of the timer.
Definition: timer.c:203
int ABT_timer_get_overhead(double *overhead) ABT_API_PUBLIC
Obtain the overhead time of using ABT_timer.
Definition: timer.c:311
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
Definition: abti_error.h:353
void ABTD_time_get(ABTD_time *p_time)
Definition: abtd_time.c:21
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:112
#define ABT_ERR_MEM
Definition: abt.h:66
#define ABT_SUCCESS
Definition: abt.h:64
static ABT_timer ABTI_timer_get_handle(ABTI_timer *p_timer)
Definition: abti_timer.h:33
#define ABTI_CHECK_TRUE_RET(cond, val)
Definition: abti_error.h:119
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:239
static double ABTI_get_wtime(void)
Definition: abti_timer.h:11
#define ABTI_CHECK_NULL_TIMER_PTR(p)
Definition: abti_error.h:308
int ABT_timer_start(ABT_timer timer) ABT_API_PUBLIC
Start the timer.
Definition: timer.c:145
#define ABTI_CHECK_ERROR(abt_errno)
Definition: abti_error.h:86
double ABT_get_wtime(void) ABT_API_PUBLIC
Get elapsed wall clock time.
Definition: timer.c:24
ABTD_time end
Definition: abti.h:425
ABTD_time start
Definition: abti.h:424
#define ABTU_ret_err
Definition: abtu.h:49
struct ABT_timer_opaque * ABT_timer
Definition: abt.h:371