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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by the Board of Trustees of the University of Illinois. *
* 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define H5S_PACKAGE /*suppress error about including H5Spkg */
#define H5G_PACKAGE /*suppress error about including H5Gpkg */
#include "H5private.h" /* Generic Functions */
#include "H5ACprivate.h" /* Metadata Cache */
#include "H5Dprivate.h" /* Dataset Functions */
#include "H5Eprivate.h" /* Error Handling */
#include "H5Fprivate.h" /* Files */
#include "H5FDprivate.h" /* File Drivers */
#include "H5Gpkg.h" /* Group Functions */
#include "H5Iprivate.h" /* ID Functions */
#include "H5MMprivate.h" /* Memory Allocation */
#include "H5Oprivate.h" /* Object Headers */
#include "H5Rprivate.h" /* References */
#include "H5Spkg.h" /* Dataspace Functions */
#include "H5TBprivate.h" /* Threaded, Balanced, Binary Trees */
#ifdef H5_HAVE_FPHDF5
#include "H5FDfphdf5.h" /* File Driver for FPHDF5 */
#include "H5FPprivate.h" /* Flexible Parallel Functions */
/* Pablo mask */
#define PABLO_MASK H5FPclient_mask
/* Is the interface initialized? */
static int interface_initialize_g = 0;
#define INTERFACE_INIT NULL
/* local functions */
static unsigned H5FP_gen_request_id(void);
static herr_t H5FP_dump_to_file(H5FD_t *file, hid_t dxpl_id);
/*
*===----------------------------------------------------------------------===
* Public Library (non-API) Functions
*===----------------------------------------------------------------------===
*/
/*
* Function: H5FP_request_open
* Purpose: Request an open of a file from the SAP. You pass in the
* metadata string (MDATA) (the filename), it's length in
* (MD_LEN), and the type of the object you're trying to
* open (OBJ_TYPE). The request ID is returned in a pointer
* supplied by the user.
*
* The so-called "captain" process is in charge of telling
* the SAP that the processes opened a file. All processes
* opening the file, though, should call this function so
* that they can get the file ID that the SAP assigns to it.
*
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 28. August, 2002
* Modifications:
*/
herr_t
H5FP_request_open(H5FP_obj_t obj_type, haddr_t maxaddr,
unsigned long feature_flags, hsize_t meta_block_size,
hsize_t sdata_block_size, hsize_t threshold,
hsize_t alignment, unsigned *file_id, unsigned *req_id)
{
H5FP_request_t req;
MPI_Status mpi_status;
int mrc, my_rank;
int ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_open, FAIL);
/* check args */
assert(file_id);
assert(req_id);
HDmemset(&mpi_status, 0, sizeof(MPI_Status));
if ((mrc = MPI_Comm_rank(H5FP_SAP_COMM, &my_rank)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Comm_rank failed", mrc);
if ((unsigned)my_rank == H5FP_capt_rank) {
/*
* The captain process sends the information about the file to
* the SAP.
*/
HDmemset(&req, 0, sizeof(req));
req.req_type = H5FP_REQ_OPEN;
req.req_id = H5FP_gen_request_id();
req.proc_rank = my_rank;
req.md_size = 0;
req.obj_type = obj_type;
req.addr = maxaddr;
req.feature_flags = feature_flags;
req.meta_block_size = meta_block_size;
req.sdata_block_size = sdata_block_size;
req.threshold = threshold;
req.alignment = alignment;
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
if ((mrc = MPI_Recv(file_id, 1, MPI_UNSIGNED, (int)H5FP_sap_rank,
H5FP_TAG_FILE_ID, H5FP_SAP_COMM,
&mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
}
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_lock
* Purpose: Request a lock on an object in a file from the SAP. The
* request ID is returned in a pointer supplied by the user.
* The status of the SAP is returned to the user in the
* supplied STATUS pointer.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 30. July, 2002
* Modifications:
*/
herr_t
H5FP_request_lock(unsigned file_id, hobj_ref_t obj_oid,
H5FP_lock_t rw_lock, int last, unsigned *req_id,
H5FP_status_t *status)
{
H5FP_request_t req;
int mrc, my_rank;
int ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_lock, FAIL);
/* check args */
assert(obj_oid);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
if ((mrc = MPI_Comm_rank(H5FP_SAP_COMM, &my_rank)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Comm_rank failed", mrc);
*status = H5FP_STATUS_OK;
req.req_type = last ? H5FP_REQ_LOCK_END : H5FP_REQ_LOCK;
req.req_id = H5FP_gen_request_id();
req.file_id = file_id;
req.rw_lock = rw_lock;
req.md_size = 0;
req.proc_rank = my_rank;
req.oid = obj_oid;
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS) {
*status = H5FP_STATUS_LOCK_FAILED;
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
}
if (last) {
/*
* On the last lock in the lock-group to be acquired, we expect a
* reply from the SAP
*/
H5FP_reply_t sap_reply;
MPI_Status mpi_status;
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_reply, 1, H5FP_reply, (int)H5FP_sap_rank,
H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
*status = sap_reply.status;
if (sap_reply.status != H5FP_STATUS_LOCK_ACQUIRED)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTLOCK, FAIL, "can't lock object on server");
}
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_release_lock
* Purpose: Release a lock on the file from the SAP. Request a lock
* on an object in a file from the SAP. The request ID is
* returned in a pointer supplied by the user. The status
* of the SAP is returned to the user in the supplied STATUS
* pointer.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 30. July, 2002
* Modifications:
*/
herr_t
H5FP_request_release_lock(unsigned file_id, hobj_ref_t obj_oid,
int last, unsigned *req_id, H5FP_status_t *status)
{
H5FP_request_t req;
int mrc, my_rank;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_release_lock, FAIL);
/* check args */
assert(obj_oid);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
if ((mrc = MPI_Comm_rank(H5FP_SAP_COMM, &my_rank)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Comm_rank failed", mrc);
*status = H5FP_STATUS_OK;
req.oid = obj_oid;
req.req_type = last ? H5FP_REQ_RELEASE_END : H5FP_REQ_RELEASE;
req.req_id = H5FP_gen_request_id();
req.file_id = file_id;
req.md_size = 0;
req.proc_rank = my_rank;
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS) {
*status = H5FP_STATUS_LOCK_RELEASE_FAILED;
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
}
if (last) {
/*
* On the last lock released in this lock-group, we expect a
* reply from the SAP
*/
H5FP_reply_t sap_reply;
MPI_Status mpi_status;
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_reply, 1, H5FP_reply, (int)H5FP_sap_rank,
H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
*status = sap_reply.status;
if (sap_reply.status != H5FP_STATUS_LOCK_RELEASED)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTUNLOCK, FAIL,
"can't unlock object on server");
}
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_read_metadata
* Purpose: Read a piece of metadata from the SAP. That is, if the
* SAP has access to that metadata. If not, then we'll need
* to read it from disk.
*
* This function has the potential of causing the process to
* act as a dumper for the SAP's metadata. Places which call
* this function and check the STATUS variable should take
* this into account.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 02. August, 2002
* Modifications:
*/
herr_t
H5FP_request_read_metadata(H5FD_t *file, unsigned file_id, hid_t dxpl_id,
H5FD_mem_t UNUSED mem_type, haddr_t addr,
size_t size, uint8_t **buf, int *bytes_read,
unsigned *req_id, H5FP_status_t *status)
{
H5FP_request_t req;
H5FP_read_t sap_read;
MPI_Status mpi_status;
int mrc, my_rank;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_read_metadata, FAIL);
/* check args */
assert(file);
assert(buf);
assert(bytes_read);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
if ((mrc = MPI_Comm_rank(H5FP_SAP_COMM, &my_rank)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Comm_rank failed", mrc);
*status = H5FP_STATUS_OK;
req.req_type = H5FP_REQ_READ;
req.req_id = H5FP_gen_request_id();
req.file_id = file_id;
req.proc_rank = my_rank;
req.addr = addr;
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_read, 1, H5FP_read, (int)H5FP_sap_rank, H5FP_TAG_READ,
H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
switch (sap_read.status) {
case H5FP_STATUS_OK:
/* use the info in the H5FP_read_t structure to update the metadata */
*status = H5FP_STATUS_OK;
HDmemset(*buf, '\0', size);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if (size < sap_read.md_size) {
char *mdata;
if (H5FP_read_metadata(&mdata, (int)sap_read.md_size, (int)H5FP_sap_rank) == FAIL) {
HDfprintf(stderr, "Metadata Read Failed!!!!\n");
}
HDmemcpy(*buf, mdata, size);
HDfree(mdata);
} else if (size == sap_read.md_size) {
if ((mrc = MPI_Recv(*buf, (int)sap_read.md_size, MPI_BYTE,
(int)H5FP_sap_rank, H5FP_TAG_METADATA,
H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
} else {
HDfprintf(stderr, "Buffer not big enough to hold metadata!!!!\n");
assert(0);
}
*bytes_read = size;
break;
case H5FP_STATUS_DUMPING:
/*
* Collect the metadata updates from the SAP and write them to
* the file. We fall through because at this point the metadata
* won't be cached on the server anymore.
*/
if (H5FP_dump_to_file(file, dxpl_id) == FAIL)
HGOTO_ERROR(H5E_FPHDF5, H5E_WRITEERROR, FAIL,
"can't write metadata update to file");
/* FALLTHROUGH */
case H5FP_STATUS_MDATA_NOT_CACHED:
/*
* The metadata wasn't in the SAP's cache. Should read from disk
* now.
*/
*status = H5FP_STATUS_MDATA_NOT_CACHED;
break;
default:
*status = sap_read.status;
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't write metadata to server");
}
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_write_metadata
* Purpose: Tell the SAP that we want to change a piece of metadata
* associated with the file. The request ID is returned in a
* pointer supplied by the user.
*
* This function has the potential of causing the process to
* act as a dumper for the SAP's metadata. Places which call
* this function and check the STATUS variable should take
* this into account.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 02. August, 2002
* Modifications:
*/
herr_t
H5FP_request_write_metadata(H5FD_t *file, unsigned file_id, hid_t dxpl_id,
H5FD_mem_t mem_type, haddr_t addr,
int mdata_size, const char *mdata,
unsigned *req_id, H5FP_status_t *status)
{
H5FP_reply_t sap_reply;
MPI_Status mpi_status;
H5FP_request_t req;
int mrc, my_rank;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_write_metadata, FAIL);
/* check args */
assert(file);
assert(mdata);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
if ((mrc = MPI_Comm_rank(H5FP_SAP_COMM, &my_rank)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Comm_rank failed", mrc);
req.req_type = H5FP_REQ_WRITE;
req.req_id = H5FP_gen_request_id();
req.proc_rank = my_rank;
req.file_id = file_id;
req.mem_type = mem_type;
req.addr = addr;
req.md_size = mdata_size;
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
/* The first MPI_Send will have been sent before this one will be read. */
if (H5FP_send_metadata(mdata, mdata_size, (int)H5FP_sap_rank) != SUCCEED)
HGOTO_ERROR(H5E_FPHDF5, H5E_CANTSENDMDATA, FAIL, "can't send metadata to server");
HDmemset(&mpi_status, 0, sizeof(mpi_status));
HDmemset(&sap_reply, 0, sizeof(sap_reply));
if ((mrc = MPI_Recv(&sap_reply, 1, H5FP_reply, (int)H5FP_sap_rank,
H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
switch (sap_reply.status) {
case H5FP_STATUS_OK:
/* Nothing to do... */
break;
case H5FP_STATUS_DUMPING:
/*
* Collect the metadata updates from the SAP and write them to
* the file. The function which sends us the dumping data sends
* it to us as an H5FP_read object instead of the H5FP_reply
* object we got above. So we need this "extra" read.
*
* FIXME: This is probably too much of a hack and could be fixed
* for read/write/closing instances...
*/
if (H5FP_dump_to_file(file, dxpl_id) == FAIL) {
*status = H5FP_STATUS_DUMPING_FAILED;
HGOTO_ERROR(H5E_FPHDF5, H5E_WRITEERROR, FAIL,
"can't write metadata update to file");
}
if ((mrc = MPI_Recv(&sap_reply, 1, H5FP_reply, (int)H5FP_sap_rank,
H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_reply.status != H5FP_STATUS_OK)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't write metadata to server");
break;
default:
*status = sap_reply.status;
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't write metadata to server");
}
*status = H5FP_STATUS_OK;
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_flush_metadata
* Purpose: Tell the SAP that we want to change a piece of metadata
* associated with the file. The request ID is returned in a
* pointer supplied by the user.
*
* This function has the potential of causing the process to
* act as a dumper for the SAP's metadata. Places which call
* this function and check the STATUS variable should take
* this into account.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 02. August, 2002
* Modifications:
*/
herr_t
H5FP_request_flush_metadata(H5FD_t *file, unsigned file_id, hid_t dxpl_id,
unsigned *req_id, H5FP_status_t *status)
{
H5FP_reply_t sap_reply;
H5FP_request_t req;
MPI_Status mpi_status;
int mrc, ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_flush_metadata, FAIL);
/* check args */
assert(file);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
if ((mrc = MPI_Comm_rank(H5FP_SAP_COMM, (int *)&req.proc_rank)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Comm_rank failed", mrc);
req.req_type = H5FP_REQ_FLUSH;
req.req_id = H5FP_gen_request_id();
req.file_id = file_id;
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_reply, 1, H5FP_reply, (int)H5FP_sap_rank,
H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
switch (sap_reply.status) {
case H5FP_STATUS_OK:
/* Nothing to do... */
break;
case H5FP_STATUS_DUMPING:
/*
* Collect the metadata updates from the SAP and write them to
* the file. The function which sends us the dumping data sends
* it to us as an H5FP_read object instead of the H5FP_reply
* object we got above.
*/
if (H5FP_dump_to_file(file, dxpl_id) == FAIL) {
*status = H5FP_STATUS_DUMPING_FAILED;
HGOTO_ERROR(H5E_FPHDF5, H5E_WRITEERROR, FAIL,
"can't write metadata update to file");
}
if ((mrc = MPI_Recv(&sap_reply, 1, H5FP_reply, (int)H5FP_sap_rank,
H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_reply.status != H5FP_STATUS_OK)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't write metadata to server");
break;
default:
*status = sap_reply.status;
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't write metadata to server");
}
*status = H5FP_STATUS_OK;
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_close
* Purpose: Tell the SAP that we want all of the structural changes
* made on the file and then close the file. The request ID
* is returned in a pointer passed to the function by the
* user.
*
* This function has the potential of causing the process to
* act as a dumper for the SAP's metadata. Places which call
* this function and check the STATUS variable should take
* this into account.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 02. August, 2002
* Modifications:
*/
herr_t
H5FP_request_close(H5FD_t *file, unsigned file_id, unsigned *req_id,
H5FP_status_t *status)
{
H5FP_reply_t sap_reply;
H5FP_request_t req;
MPI_Status mpi_status;
int mrc;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_close, FAIL);
/* check args */
assert(file);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
req.req_type = H5FP_REQ_CLOSE;
req.req_id = H5FP_gen_request_id();
req.file_id = file_id;
req.proc_rank = H5FD_fphdf5_mpi_rank(file);
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_reply, 1, H5FP_reply, (int)H5FP_sap_rank,
H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_reply.status != H5FP_STATUS_OK)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't close file on server");
*status = H5FP_STATUS_OK;
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_allocate
* Purpose: Request an allocation of space from the SAP.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 19. February 2003
* Modifications:
*/
herr_t
H5FP_request_allocate(H5FD_t *file, H5FD_mem_t mem_type, hsize_t size,
haddr_t *addr, haddr_t *eoa, unsigned *req_id,
H5FP_status_t *status)
{
H5FP_alloc_t sap_alloc;
H5FP_request_t req;
MPI_Status mpi_status;
int mrc;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_allocate, FAIL);
/* check args */
assert(file);
assert(addr);
assert(eoa);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
req.req_type = H5FP_REQ_ALLOC;
req.req_id = H5FP_gen_request_id();
req.file_id = H5FD_fphdf5_file_id(file);
req.proc_rank = H5FD_fphdf5_mpi_rank(file);
req.mem_type = mem_type;
req.meta_block_size = size; /* use this field as the size to allocate */
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_alloc, 1, H5FP_alloc, (int)H5FP_sap_rank,
H5FP_TAG_ALLOC, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_alloc.status != H5FP_STATUS_OK)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't allocate space on server");
*status = H5FP_STATUS_OK;
*addr = sap_alloc.addr;
*eoa = sap_alloc.eoa;
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_free
* Purpose: Request freeing of space from the SAP.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 20. February 2003
* Modifications:
*/
herr_t
H5FP_request_free(H5FD_t *file, H5FD_mem_t mem_type, haddr_t addr, hsize_t size,
unsigned *req_id, H5FP_status_t *status)
{
H5FP_alloc_t sap_alloc;
H5FP_request_t req;
MPI_Status mpi_status;
int mrc;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_free, FAIL);
/* check args */
assert(file);
assert(req_id);
assert(status);
/* Allow zero-sized frees to occur without penalty */
if (size == 0)
HGOTO_DONE(SUCCEED);
HDmemset(&req, 0, sizeof(req));
req.req_type = H5FP_REQ_FREE;
req.req_id = H5FP_gen_request_id();
req.file_id = H5FD_fphdf5_file_id(file);
req.proc_rank = H5FD_fphdf5_mpi_rank(file);
req.mem_type = mem_type;
req.addr = addr;
req.meta_block_size = size;
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_alloc, 1, H5FP_alloc, (int)H5FP_sap_rank,
H5FP_TAG_ALLOC, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_alloc.status != H5FP_STATUS_OK)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't free space on server");
/* Set the EOA for all processes. This call doesn't fail. */
file->cls->set_eoa(file, sap_alloc.eoa);
*status = H5FP_STATUS_OK;
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_get_eoa
* Purpose: Request the SAP send the EOA of the file.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 30. October 2003
* Modifications:
*/
herr_t
H5FP_request_get_eoa(H5FD_t *file, haddr_t *eoa, unsigned *req_id, H5FP_status_t *status)
{
H5FP_eoa_t sap_eoa;
H5FP_request_t req;
MPI_Status mpi_status;
int mrc;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_get_eoa, FAIL);
/* check args */
assert(file);
assert(eoa);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
req.req_type = H5FP_REQ_GET_EOA;
req.req_id = H5FP_gen_request_id();
req.file_id = H5FD_fphdf5_file_id(file);
req.proc_rank = H5FD_fphdf5_mpi_rank(file);
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_eoa, 1, H5FP_eoa, (int)H5FP_sap_rank,
H5FP_TAG_EOA, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_eoa.status != H5FP_STATUS_OK)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't free space on server");
/* Set the EOA for all processes. This doesn't fail. */
*eoa = sap_eoa.eoa;
*status = H5FP_STATUS_OK;
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_set_eoa
* Purpose: Request the SAP set the EOA of the file.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 31. October 2003
* Modifications:
*/
herr_t
H5FP_request_set_eoa(H5FD_t *file, haddr_t eoa, unsigned *req_id, H5FP_status_t *status)
{
H5FP_reply_t sap_reply;
H5FP_request_t req;
MPI_Status mpi_status;
int mrc;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_set_eoa, FAIL);
/* check args */
assert(file);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
req.req_type = H5FP_REQ_SET_EOA;
req.req_id = H5FP_gen_request_id();
req.file_id = H5FD_fphdf5_file_id(file);
req.proc_rank = H5FD_fphdf5_mpi_rank(file);
req.addr = eoa;
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_reply, 1, H5FP_reply, (int)H5FP_sap_rank,
H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_reply.status != H5FP_STATUS_OK)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't close file on server");
*status = H5FP_STATUS_OK;
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
* Function: H5FP_request_update_eoma_eosda
* Purpose: Request the SAP updates the EOMA and EOSDA information
* for the file.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 02. April 2003
* Modifications:
*/
herr_t
H5FP_request_update_eoma_eosda(H5FD_t *file, unsigned *req_id, H5FP_status_t *status)
{
H5FP_eoa_t sap_eoa;
H5FP_request_t req;
MPI_Status mpi_status;
int mrc;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5FP_request_update_eoma_eosda, FAIL);
/* check args */
assert(file);
assert(req_id);
assert(status);
HDmemset(&req, 0, sizeof(req));
req.req_type = H5FP_REQ_UPDATE_EOMA_EOSDA;
req.req_id = H5FP_gen_request_id();
req.file_id = H5FD_fphdf5_file_id(file);
req.proc_rank = H5FD_fphdf5_mpi_rank(file);
if ((mrc = MPI_Send(&req, 1, H5FP_request, (int)H5FP_sap_rank,
H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);
HDmemset(&mpi_status, 0, sizeof(mpi_status));
if ((mrc = MPI_Recv(&sap_eoa, 1, H5FP_eoa, (int)H5FP_sap_rank,
H5FP_TAG_EOA, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_eoa.status != H5FP_STATUS_OK)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTCHANGE, FAIL, "can't free space on server");
if ((mrc = MPI_Bcast(&sap_eoa, 1, H5FP_eoa, (int)H5FP_capt_barrier_rank,
H5FP_SAP_BARRIER_COMM)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Bcast failed!", mrc);
/* Set the EOA for all processes. This doesn't fail. */
file->cls->set_eoa(file, sap_eoa.eoa);
*status = H5FP_STATUS_OK;
done:
*req_id = req.req_id;
FUNC_LEAVE_NOAPI(ret_value);
}
/*
*===----------------------------------------------------------------------===
* Functions Private to Client Module
*===----------------------------------------------------------------------===
*/
/*
* Function: H5FP_gen_request_id
* Purpose: Generate a unique request ID to send along with a
* message.
* Return: Integer >= 0 - Doesn't fail.
* Programmer: Bill Wendling, 30. July, 2002
* Modifications:
*/
static unsigned
H5FP_gen_request_id()
{
static unsigned int i = 0;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FP_gen_request_id);
FUNC_LEAVE_NOAPI(i++);
}
/*
* Function: H5FP_dump_to_file
* Purpose: Dump the updated metadata to the file.
* Return: Success: SUCCEED
* Failure: FAIL
* Programmer: Bill Wendling, 03. February 2003
* Modifications:
*/
static herr_t
H5FP_dump_to_file(H5FD_t *file, hid_t dxpl_id)
{
H5FP_read_t sap_read;
hid_t new_dxpl_id = FAIL;
H5P_genplist_t *plist = NULL, *old_plist;
unsigned dumping = 1;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI_NOINIT(H5FP_dump_to_file);
/* check args */
assert(file);
if ((old_plist = H5I_object(dxpl_id)) == NULL)
HGOTO_ERROR(H5E_PLIST, H5E_NOTFOUND, FAIL, "property object doesn't exist");
/* Compare property lists */
if ((new_dxpl_id = H5P_copy_plist(old_plist)) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "can't copy property list");
if ((plist = H5P_object_verify(new_dxpl_id, H5P_DATASET_XFER)) == NULL)
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a dataset transfer list");
/* Set the fact that we're dumping metadata to the file */
if (H5P_insert(plist, H5FD_FPHDF5_XFER_DUMPING_METADATA,
H5FD_FPHDF5_XFER_DUMPING_SIZE, &dumping,
NULL, NULL, NULL, NULL, NULL) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't insert MPI-I/O property");
/*
* At this point, we've received a message saying that the SAP is
* dumping info to us. There's a metadata read waiting for us right
* now...
*/
for (;;) {
MPI_Status mpi_status;
int mrc;
char *mdata;
HDmemset(&mpi_status, 0, sizeof(mpi_status));
HDmemset(&sap_read, 0, sizeof(sap_read));
if ((mrc = MPI_Recv(&sap_read, 1, H5FP_read, (int)H5FP_sap_rank,
H5FP_TAG_DUMP, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
if (sap_read.status != H5FP_STATUS_DUMPING) {
if (sap_read.status == H5FP_STATUS_DUMPING_FINISHED)
break;
/* FIXME: ERROR */
}
if (H5FP_read_metadata(&mdata, (int)sap_read.md_size,
(int)H5FP_sap_rank) != FAIL) {
if (H5FD_fphdf5_write_real(file, H5FD_MEM_DEFAULT, plist,
sap_read.addr, (int)sap_read.md_size, mdata) == FAIL) {
HDfree(mdata);
HGOTO_ERROR(H5E_FPHDF5, H5E_WRITEERROR, FAIL, "can't write metadata to file");
}
HDfree(mdata);
} else {
/* FIXME: Error */
}
}
done:
if (new_dxpl_id > 0)
H5I_dec_ref(new_dxpl_id);
FUNC_LEAVE_NOAPI(ret_value);
}
#endif /* H5_HAVE_FPHDF5 */
|