1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Programmer: Quincey Koziol <koziol@hdfgroup.org>
* March, 2013
*
* Purpose: Wrappers around existing HDF5 to support Exascale FastForward
* functionality.
*
*/
/****************/
/* Module Setup */
/****************/
/* Interface initialization */
#define H5_INTERFACE_INIT_FUNC H5EQ_init_interface
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5EQprivate.h" /* Event Queues */
#include "H5Iprivate.h" /* IDs */
#include "H5MMprivate.h" /* Memory management */
#include "H5VLprivate.h" /* VOL plugins */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/********************/
/* Local Prototypes */
/********************/
/*********************/
/* Package Variables */
/*********************/
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/* Declare a free list to manage the H5S_t struct */
H5FL_DEFINE(H5EQ_t);
/* Dataspace ID class */
static const H5I_class_t H5I_EQ_CLS[1] = {{
H5I_EQ, /* ID class value */
0, /* Class flags */
64, /* Minimum hash size for class */
2, /* # of reserved IDs for class */
NULL, /* Callback routine for closing objects of this class */
(H5I_free2_t)H5EQ_close /* Callback routine for closing auxilary objects of this class */
}};
/*-------------------------------------------------------------------------
* Function: H5EQ_init
*
* Purpose: Initialize the interface from some other package.
*
* Return: Success: non-negative
* Failure: negative
*
* Programmer: Mohamad Chaarawi
* April 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5EQ_init(void)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* FUNC_ENTER() does all the work */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5EQ_init() */
/*--------------------------------------------------------------------------
NAME
H5EQ_init_interface -- Initialize interface-specific information
USAGE
herr_t H5EQ_init_interface()
RETURNS
Non-negative on success/Negative on failure
DESCRIPTION
Initializes any interface-specific data or routines.
--------------------------------------------------------------------------*/
static herr_t
H5EQ_init_interface(void)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* Initialize the atom group for the file IDs */
if(H5I_register_type(H5I_EQ_CLS) < 0)
HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize interface")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5EQ_init_interface() */
/*--------------------------------------------------------------------------
NAME
H5EQ_term_interface
PURPOSE
Terminate various H5EQ objects
USAGE
void H5EQ_term_interface()
RETURNS
Non-negative on success/Negative on failure
DESCRIPTION
Release the atom group and any other resources allocated.
GLOBAL VARIABLES
COMMENTS, BUGS, ASSUMPTIONS
Can't report errors...
EXAMPLES
REVISION LOG
--------------------------------------------------------------------------*/
int
H5EQ_term_interface(void)
{
int n = 0;
FUNC_ENTER_NOAPI_NOINIT_NOERR
if(H5_interface_initialize_g) {
if((n = H5I_nmembers(H5I_EQ))) {
H5I_clear_type(H5I_EQ, FALSE, FALSE);
} /* end if */
else {
/* Free data types */
H5I_dec_type_ref(H5I_EQ);
/* Shut down interface */
H5_interface_initialize_g = 0;
n = 1; /*H5I*/
} /* end else */
} /* end if */
FUNC_LEAVE_NOAPI(n)
} /* end H5EQ_term_interface() */
/*-------------------------------------------------------------------------
* Function: H5EQcreate
*
* Purpose: Creates an Event Queue used to manage async requests
*
* Return: Success: The ID for a new event queue.
* Failure: FAIL
*
* Programmer: Mohamad Chaarawi
* March 2013
*
*-------------------------------------------------------------------------
*/
hid_t
H5EQcreate(hid_t fapl_id)
{
void *eq = NULL; /* event queue token */
H5VL_t *vol_plugin = NULL; /* VOL plugin information from fapl */
H5P_genplist_t *plist; /* Property list pointer */
hid_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE1("i", "i", fapl_id);
/* Check the file access property list */
if(H5P_DEFAULT == fapl_id)
fapl_id = H5P_FILE_ACCESS_DEFAULT;
else
if(TRUE != H5P_isa_class(fapl_id, H5P_FILE_ACCESS))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not file access property list")
/* Get the plist structure */
if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADATOM, FAIL, "can't find object for ID")
/* create a new event queue */
if(NULL == (eq = H5EQ_create(&vol_plugin, plist)))
HGOTO_ERROR(H5E_SYM, H5E_CANTCREATE, FAIL, "unable to create event queue")
/* Get an atom for the event queue with the VOL information as the auxilary struct*/
if((ret_value = H5I_register2(H5I_EQ, eq, vol_plugin, TRUE)) < 0)
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to atomize event queue handle")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5EQcreate() */
/*-------------------------------------------------------------------------
* Function: H5EQinsert
*
* Purpose: Inserts an async request into an Event Queue.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Programmer: Mohamad Chaarawi
* March 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5EQinsert(hid_t eq_id, H5_request_t req)
{
H5EQ_t *eq = NULL; /* event queue token */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments. */
if(H5I_EQ != H5I_get_type(eq_id))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an event queue ID")
/* get the eq object */
if(NULL == (eq = (H5EQ_t *)H5I_object(eq_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid event queue identifier")
/* Insert request in the event queue */
if(H5EQ_insert(eq, (H5_priv_request_t *)req) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINSERT, FAIL, "unable to insert request into event queue")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5EQinsert() */
/*-------------------------------------------------------------------------
* Function: H5EQpop
*
* Purpose: retrieves the top async request from an Event Queue.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Programmer: Mohamad Chaarawi
* March 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5EQpop(hid_t eq_id, H5_request_t *req/*OUT*/)
{
H5EQ_t *eq = NULL; /* event queue token */
H5_priv_request_t *priv_req = NULL; /* internal request struct */
H5_priv_request_t *head = NULL;
H5_priv_request_t *next = NULL;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments. */
if(H5I_EQ != H5I_get_type(eq_id))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an event queue ID")
/* get the eq object */
if(NULL == (eq = (H5EQ_t *)H5I_object(eq_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid event queue identifier");
priv_req = eq->head;
head = eq->head;
next = head->next;
eq->head = next;
if(NULL == eq->head)
eq->tail = eq->head;
eq->size --;
*req = (H5_request_t) priv_req;
done:
FUNC_LEAVE_API(ret_value)
} /* end H5EQpop() */
/*-------------------------------------------------------------------------
* Function: H5EQwait
*
* Purpose: Waits on all async requests in an Event Queue.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Programmer: Mohamad Chaarawi
* March 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5EQwait(hid_t eq_id, int *num_requests/*OUT*/, H5_status_t **status/*OUT*/)
{
void *eq = NULL; /* event queue token */
H5VL_t *vol_plugin = NULL; /* VOL plugin pointer this event queue should use */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments. */
if(H5I_EQ != H5I_get_type(eq_id))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an event queue ID")
/* get the eq object */
if(NULL == (eq = (void *)H5I_object(eq_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid event queue identifier")
/* get the plugin pointer */
if (NULL == (vol_plugin = (H5VL_t *)H5I_get_aux(eq_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "ID does not contain VOL information");
/* Wait request in the event queue */
if(H5EQ_wait((H5EQ_t *)eq, vol_plugin, num_requests, status) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, FAIL, "unable to wait request into event queue")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5EQwait() */
/*-------------------------------------------------------------------------
* Function: H5EQclose
*
* Purpose: Closes the specified event queue. The ID will no longer be
* valid for accessing the event queue.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Mohamad Chaarawi
* April 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5EQclose(hid_t eq_id)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE1("e", "i", eq_id);
/* Check args */
if(NULL == H5I_object_verify(eq_id,H5I_EQ))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an event queue")
if(H5I_dec_app_ref(eq_id) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTRELEASE, FAIL, "unable to close event queue")
done:
FUNC_LEAVE_API(ret_value)
} /* end H5EQclose() */
/*-------------------------------------------------------------------------
* Function: H5AOcancel
*
* Purpose: Cancel an asynchronous operation
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Programmer: Quincey Koziol
* May, 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5AOcancel(H5_request_t req, H5_status_t *status)
{
H5_priv_request_t *request = (H5_priv_request_t *)req;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
if(H5VL_request_cancel(&request->req, request->vol_plugin, status) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, FAIL, "unable to cancel request");
request->req = NULL;
request->vol_plugin = NULL;
request->next = NULL;
request = (H5_priv_request_t *)H5MM_xfree(request);
done:
FUNC_LEAVE_API(ret_value)
} /* end H5AOcancel() */
/*-------------------------------------------------------------------------
* Function: H5AOtest
*
* Purpose: Test for an asynchronous operation's completion
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Programmer: Quincey Koziol
* Wednesday, March 20, 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5AOtest(H5_request_t req, H5_status_t *status)
{
H5_priv_request_t *request = (H5_priv_request_t *)req;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
if(H5VL_request_test(&request->req, request->vol_plugin, status) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, FAIL, "unable to test request");
if(*status != H5AO_PENDING) {
request->req = NULL;
request->vol_plugin = NULL;
request->next = NULL;
request = (H5_priv_request_t *)H5MM_xfree(request);
}
done:
FUNC_LEAVE_API(ret_value)
} /* end H5AOtest() */
/*-------------------------------------------------------------------------
* Function: H5AOwait
*
* Purpose: Wait for an asynchronous operation to complete
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Programmer: Quincey Koziol
* Wednesday, March 20, 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5AOwait(H5_request_t req, H5_status_t *status)
{
H5_priv_request_t *request = (H5_priv_request_t *)req;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
if(H5VL_request_wait(&request->req, request->vol_plugin, status) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, FAIL, "unable to test request");
request->req = NULL;
request->vol_plugin = NULL;
request->next = NULL;
request = (H5_priv_request_t *)H5MM_xfree(request);
done:
FUNC_LEAVE_API(ret_value)
} /* end H5AOwait() */
/*-------------------------------------------------------------------------
* Function: H5EQcreate
*
* Purpose: Creates an Event Queue used to manage async requests
*
* Return: Success: The ID for a new event queue.
* Failure: FAIL
*
* Programmer: Mohamad Chaarawi
* March 2013
*
*-------------------------------------------------------------------------
*/
H5EQ_t *
H5EQ_create(H5VL_t **plugin, H5P_genplist_t *plist)
{
H5EQ_t *eq = NULL; /* Event Queue object */
H5VL_class_t *vol_cls; /* VOL class attached to fapl_id */
H5VL_t *vol_plugin = NULL; /* the public VOL struct */
H5EQ_t *ret_value = NULL; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
if(H5P_get(plist, H5F_ACS_VOL_NAME, &vol_cls) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get vol plugin ID")
/* Allocate the event queue structure */
if(NULL == (eq = H5FL_CALLOC(H5EQ_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate space for event queue");
eq->head = eq->tail = NULL;
eq->size = 0;
/* Build the vol plugin struct */
if(NULL == (*plugin = (H5VL_t *)H5MM_calloc(sizeof(H5VL_t))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
vol_plugin = *plugin;
vol_plugin->cls = vol_cls;
vol_plugin->nrefs = 1;
vol_plugin->container_name = NULL;
ret_value = eq;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5EQcreate() */
/*-------------------------------------------------------------------------
* Function: H5EQ_insert
*
* Purpose: Inserts an async request into an Event Queue.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Programmer: Mohamad Chaarawi
* March 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5EQ_insert(H5EQ_t *eq, H5_priv_request_t *req)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
if(NULL == req)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "bad request");
if(NULL == eq)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "event queue not intialized");
req->next = NULL;
req->prev = NULL;
if(NULL == eq->head && NULL == eq->tail) {
eq->head = eq->tail = req;
}
else {
eq->head->prev = req;
req->next = eq->head;
eq->head = req;
}
eq->size ++;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5EQ_insert() */
/*-------------------------------------------------------------------------
* Function: H5EQ_wait
*
* Purpose: Waits on all async requests in an Event Queue.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Programmer: Mohamad Chaarawi
* March 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5EQ_wait(H5EQ_t *eq, H5VL_t *vol_plugin, int *num_requests/*OUT*/, H5_status_t **_status/*OUT*/)
{
H5_priv_request_t *cur = NULL, *tail = NULL, *prev = NULL;
int i = 0;
H5_status_t *status = NULL;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
if(NULL == eq)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "event queue not intialized");
if(NULL == (status = (H5_status_t *)HDmalloc (sizeof(H5_status_t) * eq->size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate space for status array");
*num_requests = eq->size;
cur = eq->head;
while(eq->tail) {
/* Pop the last item and manage the queue accordingly */
tail = eq->tail;
prev = tail->prev;
eq->tail = prev;
if(NULL == eq->tail)
eq->head = eq->tail;
/* wait on and free the request */
if(tail->req && H5VL_request_wait(&tail->req, vol_plugin, &status[i++]) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, FAIL, "unable to test request");
tail->req = NULL;
tail->vol_plugin = NULL;
tail->next = NULL;
tail->prev = NULL;
tail = (H5_priv_request_t *)H5MM_xfree(tail);
eq->size --;
}
*_status = status;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5EQ_wait() */
/*-------------------------------------------------------------------------
* Function: H5EQ_close
*
* Purpose: Close an event queue object
*
* Return: Success: Non-negative
*
* Failure: Negative
*
* Programmer: Mohamad Chaarawi
* March 2013
*
*-------------------------------------------------------------------------
*/
herr_t
H5EQ_close(void *eq, H5VL_t *vol_plugin)
{
FUNC_ENTER_NOAPI_NOINIT_NOERR
eq = H5FL_FREE(H5EQ_t, eq);
/* decrement ref count on VOL plugin */
vol_plugin->nrefs --;
/* close if ref count is zero */
if (0 == vol_plugin->nrefs)
vol_plugin = (H5VL_t *)H5MM_xfree(vol_plugin);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5EQ_close_group() */
|