-
-
Notifications
You must be signed in to change notification settings - Fork 265
/
H5FDmpio.c
3958 lines (3383 loc) · 161 KB
/
H5FDmpio.c
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 LICENSE file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Purpose: This is the MPI I/O driver.
*/
#include "H5FDmodule.h" /* This source code file is part of the H5FD module */
#include "H5private.h" /* Generic Functions */
#ifdef H5_HAVE_PARALLEL
#include "H5CXprivate.h" /* API Contexts */
#include "H5Dprivate.h" /* Dataset functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Fprivate.h" /* File access */
#include "H5FDmpi.h" /* MPI-based file drivers */
#include "H5FDpkg.h" /* File drivers */
#include "H5Iprivate.h" /* IDs */
#include "H5MMprivate.h" /* Memory management */
#include "H5Pprivate.h" /* Property lists */
/*
* The driver identification number, initialized at runtime if H5_HAVE_PARALLEL
* is defined. This allows applications to still have the H5FD_MPIO
* "constants" in their source code.
*/
hid_t H5FD_MPIO_id_g = H5I_INVALID_HID;
/* Flag to indicate whether global driver resources & settings have been
* initialized.
*/
static bool H5FD_mpio_init_s = false;
/* Whether to allow collective I/O operations */
/* (Can be changed by setting "HDF5_MPI_OPT_TYPES" environment variable to '0' or '1') */
bool H5FD_mpi_opt_types_g = true;
/* Whether the driver initialized MPI on its own */
static bool H5FD_mpi_self_initialized_s = false;
/*
* The view is set to this value
*/
static char H5FD_mpi_native_g[] = "native";
/*
* The description of a file belonging to this driver.
* The EOF value is only used just after the file is opened in order for the
* library to determine whether the file is empty, truncated, or okay. The MPIO
* driver doesn't bother to keep it updated since it's an expensive operation.
*/
typedef struct H5FD_mpio_t {
H5FD_t pub; /* Public stuff, must be first */
MPI_File f; /* MPIO file handle */
MPI_Comm comm; /* MPI Communicator */
MPI_Info info; /* MPI info object */
int mpi_rank; /* This process's rank */
int mpi_size; /* Total number of processes */
haddr_t eof; /* End-of-file marker */
haddr_t eoa; /* End-of-address marker */
haddr_t last_eoa; /* Last known end-of-address marker */
haddr_t local_eof; /* Local end-of-file address for each process */
bool mpi_file_sync_required; /* Whether the ROMIO driver requires MPI_File_sync after write */
} H5FD_mpio_t;
/* Private Prototypes */
/* Callbacks */
static herr_t H5FD__mpio_term(void);
static H5FD_t *H5FD__mpio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr);
static herr_t H5FD__mpio_close(H5FD_t *_file);
static herr_t H5FD__mpio_query(const H5FD_t *_f1, unsigned long *flags);
static haddr_t H5FD__mpio_get_eoa(const H5FD_t *_file, H5FD_mem_t type);
static herr_t H5FD__mpio_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr);
static haddr_t H5FD__mpio_get_eof(const H5FD_t *_file, H5FD_mem_t type);
static herr_t H5FD__mpio_get_handle(H5FD_t *_file, hid_t fapl, void **file_handle);
static herr_t H5FD__mpio_read(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size,
void *buf);
static herr_t H5FD__mpio_write(H5FD_t *_file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size,
const void *buf);
static herr_t H5FD__mpio_read_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t count,
H5FD_mem_t types[], haddr_t addrs[], size_t sizes[], void *bufs[]);
static herr_t H5FD__mpio_write_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t count,
H5FD_mem_t types[], haddr_t addrs[], size_t sizes[],
const void *bufs[]);
static herr_t H5FD__mpio_read_selection(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
size_t count, hid_t mem_space_ids[], hid_t file_space_ids[],
haddr_t offsets[], size_t element_sizes[], void *bufs[]);
static herr_t H5FD__mpio_write_selection(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
size_t count, hid_t mem_space_ids[], hid_t file_space_ids[],
haddr_t offsets[], size_t element_sizes[], const void *bufs[]);
static herr_t H5FD__mpio_flush(H5FD_t *_file, hid_t dxpl_id, bool closing);
static herr_t H5FD__mpio_truncate(H5FD_t *_file, hid_t dxpl_id, bool closing);
static herr_t H5FD__mpio_delete(const char *filename, hid_t fapl_id);
static herr_t H5FD__mpio_ctl(H5FD_t *_file, uint64_t op_code, uint64_t flags, const void *input,
void **output);
/* Other functions */
static herr_t H5FD__mpio_vector_build_types(uint32_t count, H5FD_mem_t types[], haddr_t addrs[],
size_t sizes[], H5_flexible_const_ptr_t bufs[],
haddr_t *s_addrs[], size_t *s_sizes[], uint32_t *s_sizes_len,
H5_flexible_const_ptr_t *s_bufs[], bool *vector_was_sorted,
MPI_Offset *mpi_off, H5_flexible_const_ptr_t *mpi_bufs_base,
int *size_i, MPI_Datatype *buf_type, bool *buf_type_created,
MPI_Datatype *file_type, bool *file_type_created, char *unused);
static herr_t H5FD__selection_build_types(bool io_op_write, size_t num_pieces, H5_flexible_const_ptr_t mbb,
H5S_t **file_spaces, H5S_t **mem_spaces, haddr_t offsets[],
H5_flexible_const_ptr_t bufs[], size_t src_element_sizes[],
size_t dst_element_sizes[], MPI_Datatype *final_ftype,
bool *final_ftype_is_derived, MPI_Datatype *final_mtype,
bool *final_mtype_is_derived);
/* The MPIO file driver information */
static const H5FD_class_t H5FD_mpio_g = {
H5FD_CLASS_VERSION, /* struct version */
H5_VFD_MPIO, /* value */
"mpio", /* name */
HADDR_MAX, /* maxaddr */
H5F_CLOSE_SEMI, /* fc_degree */
H5FD__mpio_term, /* terminate */
NULL, /* sb_size */
NULL, /* sb_encode */
NULL, /* sb_decode */
0, /* fapl_size */
NULL, /* fapl_get */
NULL, /* fapl_copy */
NULL, /* fapl_free */
0, /* dxpl_size */
NULL, /* dxpl_copy */
NULL, /* dxpl_free */
H5FD__mpio_open, /* open */
H5FD__mpio_close, /* close */
NULL, /* cmp */
H5FD__mpio_query, /* query */
NULL, /* get_type_map */
NULL, /* alloc */
NULL, /* free */
H5FD__mpio_get_eoa, /* get_eoa */
H5FD__mpio_set_eoa, /* set_eoa */
H5FD__mpio_get_eof, /* get_eof */
H5FD__mpio_get_handle, /* get_handle */
H5FD__mpio_read, /* read */
H5FD__mpio_write, /* write */
H5FD__mpio_read_vector, /* read_vector */
H5FD__mpio_write_vector, /* write_vector */
H5FD__mpio_read_selection, /* read_selection */
H5FD__mpio_write_selection, /* write_selection */
H5FD__mpio_flush, /* flush */
H5FD__mpio_truncate, /* truncate */
NULL, /* lock */
NULL, /* unlock */
H5FD__mpio_delete, /* del */
H5FD__mpio_ctl, /* ctl */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};
#ifdef H5FDmpio_DEBUG
/* Flags to control debug actions in the MPI-IO VFD.
* (Meant to be indexed by characters)
*
* These flags can be set with either (or both) the environment variable
* "H5FD_mpio_Debug" set to a string containing one or more characters
* (flags) or by setting them as a string value for the
* "H5F_mpio_debug_key" MPI Info key.
*
* Supported characters in 'H5FD_mpio_Debug' string:
* 't' trace function entry and exit
* 'r' show read offset and size
* 'w' show write offset and size
* '0'-'9' only show output from a single MPI rank (ranks 0-9 supported)
*/
static int H5FD_mpio_debug_flags_s[256];
static int H5FD_mpio_debug_rank_s = -1;
/* Indicate if this rank should output tracing info */
#define H5FD_MPIO_TRACE_THIS_RANK(file) \
(H5FD_mpio_debug_rank_s < 0 || H5FD_mpio_debug_rank_s == (file)->mpi_rank)
#endif
#ifdef H5FDmpio_DEBUG
/*---------------------------------------------------------------------------
* Function: H5FD__mpio_parse_debug_str
*
* Purpose: Parse a string for debugging flags
*
* Returns: N/A
*
*---------------------------------------------------------------------------
*/
static void
H5FD__mpio_parse_debug_str(const char *s)
{
FUNC_ENTER_PACKAGE_NOERR
/* Sanity check */
assert(s);
/* Set debug mask */
while (*s) {
if ((int)(*s) >= (int)'0' && (int)(*s) <= (int)'9')
H5FD_mpio_debug_rank_s = ((int)*s) - (int)'0';
else
H5FD_mpio_debug_flags_s[(int)*s]++;
s++;
} /* end while */
FUNC_LEAVE_NOAPI_VOID
} /* end H5FD__mpio_parse_debug_str() */
/*---------------------------------------------------------------------------
* Function: H5FD__mem_t_to_str
*
* Purpose: Returns a string representing the enum value in an H5FD_mem_t
* enum
*
* Returns: H5FD_mem_t enum value string
*
*---------------------------------------------------------------------------
*/
static const char *
H5FD__mem_t_to_str(H5FD_mem_t mem_type)
{
switch (mem_type) {
case H5FD_MEM_NOLIST:
return "H5FD_MEM_NOLIST";
case H5FD_MEM_DEFAULT:
return "H5FD_MEM_DEFAULT";
case H5FD_MEM_SUPER:
return "H5FD_MEM_SUPER";
case H5FD_MEM_BTREE:
return "H5FD_MEM_BTREE";
case H5FD_MEM_DRAW:
return "H5FD_MEM_DRAW";
case H5FD_MEM_GHEAP:
return "H5FD_MEM_GHEAP";
case H5FD_MEM_LHEAP:
return "H5FD_MEM_LHEAP";
case H5FD_MEM_OHDR:
return "H5FD_MEM_OHDR";
case H5FD_MEM_NTYPES:
return "H5FD_MEM_NTYPES";
default:
return "(Unknown)";
}
}
#endif /* H5FDmpio_DEBUG */
/*-------------------------------------------------------------------------
* Function: H5FD__mpio_register
*
* Purpose: Register the driver with the library.
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5FD__mpio_register(void)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Register the MPI-IO VFD, if it isn't already */
if (H5I_VFL != H5I_get_type(H5FD_MPIO_id_g))
if ((H5FD_MPIO_id_g = H5FD_register(&H5FD_mpio_g, sizeof(H5FD_class_t), false)) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTREGISTER, FAIL, "unable to register mpio driver");
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__mpio_register() */
/*---------------------------------------------------------------------------
* Function: H5FD__mpio_unregister
*
* Purpose: Reset library driver info.
*
* Returns: SUCCEED (Can't fail)
*
*---------------------------------------------------------------------------
*/
herr_t
H5FD__mpio_unregister(void)
{
FUNC_ENTER_PACKAGE_NOERR
/* Reset VFL ID */
H5FD_MPIO_id_g = H5I_INVALID_HID;
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5FD__mpio_unregister() */
/*-------------------------------------------------------------------------
* Function: H5FD__mpio_init
*
* Purpose: Singleton to initialize global driver settings & resources.
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
static herr_t
H5FD__mpio_init(void)
{
char *env = NULL;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check if MPI driver has been loaded dynamically */
env = getenv(HDF5_DRIVER);
if (env && !strcmp(env, "mpio")) {
int mpi_initialized = 0;
/* Initialize MPI if not already initialized */
if (MPI_SUCCESS != MPI_Initialized(&mpi_initialized))
HGOTO_ERROR(H5E_VFL, H5E_UNINITIALIZED, FAIL, "can't check if MPI is initialized");
if (!mpi_initialized) {
if (MPI_SUCCESS != MPI_Init(NULL, NULL))
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize MPI");
H5FD_mpi_self_initialized_s = true;
}
}
/* Allow MPI buf-and-file-type optimizations? */
env = getenv("HDF5_MPI_OPT_TYPES");
if (env && isdigit(*env))
H5FD_mpi_opt_types_g = (0 == strtol(env, NULL, 0)) ? false : true;
#ifdef H5FDmpio_DEBUG
/* Clear the flag buffer */
memset(H5FD_mpio_debug_flags_s, 0, sizeof(H5FD_mpio_debug_flags_s));
/* Retrieve MPI-IO debugging environment variable */
env = getenv("H5FD_mpio_Debug");
if (env)
H5FD__mpio_parse_debug_str(env);
#endif /* H5FDmpio_DEBUG */
/* Indicate that driver is set up */
H5FD_mpio_init_s = true;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__mpio_init() */
/*---------------------------------------------------------------------------
* Function: H5FD__mpio_term
*
* Purpose: Shut down the VFD
*
* Returns: SUCCEED (Can't fail)
*
*---------------------------------------------------------------------------
*/
static herr_t
H5FD__mpio_term(void)
{
FUNC_ENTER_PACKAGE_NOERR
/* Terminate MPI if the driver initialized it */
if (H5FD_mpi_self_initialized_s) {
int mpi_finalized = 0;
MPI_Finalized(&mpi_finalized);
if (!mpi_finalized)
MPI_Finalize();
H5FD_mpi_self_initialized_s = false;
}
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5FD__mpio_term() */
/*-------------------------------------------------------------------------
* Function: H5Pset_fapl_mpio
*
* Purpose: Store the user supplied MPIO communicator comm and info in
* the file access property list FAPL_ID which can then be used
* to create and/or open the file. This function is available
* only in the parallel HDF5 library and is not collective.
*
* comm is the MPI communicator to be used for file open as
* defined in MPI_FILE_OPEN of MPI. This function makes a
* duplicate of comm. Any modification to comm after this function
* call returns has no effect on the access property list.
*
* info is the MPI Info object to be used for file open as
* defined in MPI_FILE_OPEN of MPI. This function makes a
* duplicate of info. Any modification to info after this
* function call returns has no effect on the access property
* list.
*
* If fapl_id has previously set comm and info values, they
* will be replaced and the old communicator and Info object
* are freed.
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5Pset_fapl_mpio(hid_t fapl_id, MPI_Comm comm, MPI_Info info)
{
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value;
FUNC_ENTER_API(FAIL)
/* Check arguments */
if (fapl_id == H5P_DEFAULT)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't set values in default property list");
if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS, false)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a file access list");
if (MPI_COMM_NULL == comm)
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "MPI_COMM_NULL is not a valid communicator");
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver");
/* Set the MPI communicator and info object */
if (H5P_set(plist, H5F_ACS_MPI_PARAMS_COMM_NAME, &comm) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set MPI communicator");
if (H5P_set(plist, H5F_ACS_MPI_PARAMS_INFO_NAME, &info) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set MPI info object");
/* duplication is done during driver setting. */
ret_value = H5P_set_driver(plist, H5FD_MPIO, NULL, NULL);
done:
FUNC_LEAVE_API(ret_value)
} /* H5Pset_fapl_mpio() */
/*-------------------------------------------------------------------------
* Function: H5Pget_fapl_mpio
*
* Purpose: If the file access property list is set to the H5FD_MPIO
* driver then this function returns duplicates of the MPI
* communicator and Info object stored through the comm and
* info pointers. It is the responsibility of the application
* to free the returned communicator and Info object.
*
* Return: Success: Non-negative with the communicator and
* Info object returned through the comm and
* info arguments if non-null. Since they are
* duplicates of the stored objects, future
* modifications to the access property list do
* not affect them and it is the responsibility
* of the application to free them.
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5Pget_fapl_mpio(hid_t fapl_id, MPI_Comm *comm /*out*/, MPI_Info *info /*out*/)
{
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Set comm and info in case we have problems */
if (comm)
*comm = MPI_COMM_NULL;
if (info)
*info = MPI_INFO_NULL;
/* Check arguments */
if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS, true)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a file access list");
if (H5FD_MPIO != H5P_peek_driver(plist))
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "VFL driver is not MPI-I/O");
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver");
/* Get the MPI communicator and info object */
if (comm)
if (H5P_get(plist, H5F_ACS_MPI_PARAMS_COMM_NAME, comm) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get MPI communicator");
if (info)
if (H5P_get(plist, H5F_ACS_MPI_PARAMS_INFO_NAME, info) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get MPI info object");
done:
/* Clean up anything duplicated on errors. The free calls will set
* the output values to MPI_COMM|INFO_NULL.
*/
if (ret_value != SUCCEED) {
if (comm)
if (H5_mpi_comm_free(comm) < 0)
HDONE_ERROR(H5E_PLIST, H5E_CANTFREE, FAIL, "unable to free MPI communicator");
if (info)
if (H5_mpi_info_free(info) < 0)
HDONE_ERROR(H5E_PLIST, H5E_CANTFREE, FAIL, "unable to free MPI info object");
}
FUNC_LEAVE_API(ret_value)
} /* end H5Pget_fapl_mpio() */
/*-------------------------------------------------------------------------
* Function: H5Pset_dxpl_mpio
*
* Purpose: Set the data transfer property list DXPL_ID to use transfer
* mode XFER_MODE. The property list can then be used to control
* the I/O transfer mode during data I/O operations. The valid
* transfer modes are:
*
* H5FD_MPIO_INDEPENDENT:
* Use independent I/O access (the default).
*
* H5FD_MPIO_COLLECTIVE:
* Use collective I/O access.
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5Pset_dxpl_mpio(hid_t dxpl_id, H5FD_mpio_xfer_t xfer_mode)
{
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments */
if (dxpl_id == H5P_DEFAULT)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't set values in default property list");
if (NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER, false)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a dxpl");
if (H5FD_MPIO_INDEPENDENT != xfer_mode && H5FD_MPIO_COLLECTIVE != xfer_mode)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "incorrect xfer_mode");
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver");
/* Set the transfer mode */
if (H5P_set(plist, H5D_XFER_IO_XFER_MODE_NAME, &xfer_mode) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set value");
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Pset_dxpl_mpio() */
/*-------------------------------------------------------------------------
* Function: H5Pget_dxpl_mpio
*
* Purpose: Queries the transfer mode current set in the data transfer
* property list DXPL_ID. This is not collective.
*
* Return: Success: Non-negative, with the transfer mode returned
* through the XFER_MODE argument if it is
* non-null.
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5Pget_dxpl_mpio(hid_t dxpl_id, H5FD_mpio_xfer_t *xfer_mode /*out*/)
{
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments */
if (NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER, true)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a dxpl");
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver");
/* Get the transfer mode */
if (xfer_mode)
if (H5P_get(plist, H5D_XFER_IO_XFER_MODE_NAME, xfer_mode) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to get value");
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Pget_dxpl_mpio() */
/*-------------------------------------------------------------------------
* Function: H5Pset_dxpl_mpio_collective_opt
*
* Purpose: Set the data transfer property list DXPL_ID to use transfer
* mode OPT_MODE during I/O. This allows the application to
* specify collective I/O at the HDF5 interface level (with
* the H5Pset_dxpl_mpio routine), while controlling whether
* the actual I/O is performed collectively (e.g., via
* MPI_File_write_at_all) or independently (e.g., via
* MPI_File_write_at).
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5Pset_dxpl_mpio_collective_opt(hid_t dxpl_id, H5FD_mpio_collective_opt_t opt_mode)
{
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments */
if (dxpl_id == H5P_DEFAULT)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't set values in default property list");
if (NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER, false)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a dxpl");
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver");
/* Set the transfer mode */
if (H5P_set(plist, H5D_XFER_MPIO_COLLECTIVE_OPT_NAME, &opt_mode) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set value");
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Pset_dxpl_mpio_collective_opt() */
/*-------------------------------------------------------------------------
* Function: H5Pset_dxpl_mpio_chunk_opt
*
* Purpose: To set a flag to choose linked chunk I/O or multi-chunk I/O
* without involving decision-making inside HDF5
*
* Note: The library will do linked chunk I/O or multi-chunk I/O without
* involving communications for decision-making process.
* The library won't behave as it asks for only when we find
* that the low-level MPI-IO package doesn't support this.
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5Pset_dxpl_mpio_chunk_opt(hid_t dxpl_id, H5FD_mpio_chunk_opt_t opt_mode)
{
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments */
if (dxpl_id == H5P_DEFAULT)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't set values in default property list");
if (NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER, false)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a dxpl");
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver");
/* Set the transfer mode */
if (H5P_set(plist, H5D_XFER_MPIO_CHUNK_OPT_HARD_NAME, &opt_mode) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set value");
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Pset_dxpl_mpio_chunk_opt() */
/*-------------------------------------------------------------------------
* Function: H5Pset_dxpl_mpio_chunk_opt_num
*
* Purpose: To set a threshold for doing linked chunk IO
*
* Note: If the number is greater than the threshold set by the user,
* the library will do linked chunk I/O; otherwise, I/O will be
* done for every chunk.
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5Pset_dxpl_mpio_chunk_opt_num(hid_t dxpl_id, unsigned num_chunk_per_proc)
{
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments */
if (dxpl_id == H5P_DEFAULT)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't set values in default property list");
if (NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER, false)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a dxpl");
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver");
/* Set the transfer mode */
if (H5P_set(plist, H5D_XFER_MPIO_CHUNK_OPT_NUM_NAME, &num_chunk_per_proc) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set value");
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Pset_dxpl_mpio_chunk_opt_num() */
/*-------------------------------------------------------------------------
* Function: H5Pset_dxpl_mpio_chunk_opt_ratio
*
* Purpose: To set a threshold for doing collective I/O for each chunk
*
* Note: The library will calculate the percentage of the number of
* process holding selections at each chunk. If that percentage
* of number of process in the individual chunk is greater than
* the threshold set by the user, the library will do collective
* chunk I/O for this chunk; otherwise, independent I/O will be
* done for this chunk.
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5Pset_dxpl_mpio_chunk_opt_ratio(hid_t dxpl_id, unsigned percent_num_proc_per_chunk)
{
H5P_genplist_t *plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
/* Check arguments */
if (dxpl_id == H5P_DEFAULT)
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "can't set values in default property list");
if (NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER, false)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a dxpl");
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize driver");
/* Set the transfer mode */
if (H5P_set(plist, H5D_XFER_MPIO_CHUNK_OPT_RATIO_NAME, &percent_num_proc_per_chunk) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "unable to set value");
done:
FUNC_LEAVE_API(ret_value)
} /* end H5Pset_dxpl_mpio_chunk_opt_ratio() */
/*-------------------------------------------------------------------------
* Function: H5FD_set_mpio_atomicity
*
* Purpose: Sets the atomicity mode
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5FD_set_mpio_atomicity(H5FD_t *_file, bool flag)
{
H5FD_mpio_t *file = (H5FD_mpio_t *)_file;
#ifdef H5FDmpio_DEBUG
bool H5FD_mpio_debug_t_flag = (H5FD_mpio_debug_flags_s[(int)'t'] && H5FD_MPIO_TRACE_THIS_RANK(file));
#endif
int mpi_code; /* MPI return code */
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI_NOINIT
#ifdef H5FDmpio_DEBUG
if (H5FD_mpio_debug_t_flag)
fprintf(stderr, "%s: (%d) Entering\n", __func__, file->mpi_rank);
#endif
/* set atomicity value */
if (MPI_SUCCESS != (mpi_code = MPI_File_set_atomicity(file->f, (int)(flag != false))))
HMPI_GOTO_ERROR(FAIL, "MPI_File_set_atomicity", mpi_code)
done:
#ifdef H5FDmpio_DEBUG
if (H5FD_mpio_debug_t_flag)
fprintf(stderr, "%s: (%d) Leaving\n", __func__, file->mpi_rank);
#endif
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_set_mpio_atomicity() */
/*-------------------------------------------------------------------------
* Function: H5FD_get_mpio_atomicity
*
* Purpose: Returns the atomicity mode
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5FD_get_mpio_atomicity(H5FD_t *_file, bool *flag)
{
H5FD_mpio_t *file = (H5FD_mpio_t *)_file;
int temp_flag;
#ifdef H5FDmpio_DEBUG
bool H5FD_mpio_debug_t_flag = (H5FD_mpio_debug_flags_s[(int)'t'] && H5FD_MPIO_TRACE_THIS_RANK(file));
#endif
int mpi_code; /* MPI return code */
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI_NOINIT
#ifdef H5FDmpio_DEBUG
if (H5FD_mpio_debug_t_flag)
fprintf(stderr, "%s: (%d) Entering\n", __func__, file->mpi_rank);
#endif
/* Get atomicity value */
if (MPI_SUCCESS != (mpi_code = MPI_File_get_atomicity(file->f, &temp_flag)))
HMPI_GOTO_ERROR(FAIL, "MPI_File_get_atomicity", mpi_code)
if (0 != temp_flag)
*flag = true;
else
*flag = false;
done:
#ifdef H5FDmpio_DEBUG
if (H5FD_mpio_debug_t_flag)
fprintf(stderr, "%s: (%d) Leaving\n", __func__, file->mpi_rank);
#endif
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_get_mpio_atomicity() */
/*-------------------------------------------------------------------------
* Function: H5FD__mpio_open
*
* Purpose: Opens a file with name NAME. The FLAGS are a bit field with
* purpose similar to the second argument of open(2) and which
* are defined in H5Fpublic.h. The file access property list
* FAPL_ID contains the properties driver properties and MAXADDR
* is the largest address which this file will be expected to
* access. This is collective.
*
* Return: Success: A new file pointer
* Failure: NULL
*
*-------------------------------------------------------------------------
*/
static H5FD_t *
H5FD__mpio_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t H5_ATTR_UNUSED maxaddr)
{
H5FD_mpio_t *file = NULL; /* VFD File struct for new file */
H5P_genplist_t *plist; /* Property list pointer */
MPI_Comm comm = MPI_COMM_NULL; /* MPI Communicator, from plist */
MPI_Info info = MPI_INFO_NULL; /* MPI Info, from plist */
MPI_Info info_used; /* MPI Info returned from MPI_File_open */
MPI_File fh; /* MPI file handle */
bool file_opened = false; /* Flag to indicate that the file was successfully opened */
int mpi_amode; /* MPI file access flags */
int mpi_rank = INT_MAX; /* MPI rank of this process */
int mpi_size; /* Total number of MPI processes */
MPI_Offset file_size; /* File size (of existing files) */
#ifdef H5FDmpio_DEBUG
bool H5FD_mpio_debug_t_flag = false;
#endif
int mpi_code; /* MPI return code */
H5FD_t *ret_value = NULL; /* Return value */
FUNC_ENTER_PACKAGE
/* Initialize driver, if it's not yet */
if (!H5FD_mpio_init_s)
if (H5FD__mpio_init() < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, NULL, "can't initialize driver");
/* Get a pointer to the fapl */
if (NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS, true)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list");
if (H5FD_mpi_self_initialized_s) {
comm = MPI_COMM_WORLD;
}
else {
/* Get the MPI communicator and info object from the property list */
if (H5P_get(plist, H5F_ACS_MPI_PARAMS_COMM_NAME, &comm) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't get MPI communicator");
if (H5P_get(plist, H5F_ACS_MPI_PARAMS_INFO_NAME, &info) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't get MPI info object");
}
/* Get the MPI rank of this process and the total number of processes */
if (MPI_SUCCESS != (mpi_code = MPI_Comm_rank(comm, &mpi_rank)))
HMPI_GOTO_ERROR(NULL, "MPI_Comm_rank failed", mpi_code)
if (MPI_SUCCESS != (mpi_code = MPI_Comm_size(comm, &mpi_size)))
HMPI_GOTO_ERROR(NULL, "MPI_Comm_size failed", mpi_code)
#ifdef H5FDmpio_DEBUG
H5FD_mpio_debug_t_flag = (H5FD_mpio_debug_flags_s[(int)'t'] &&
(H5FD_mpio_debug_rank_s < 0 || H5FD_mpio_debug_rank_s == mpi_rank));
if (H5FD_mpio_debug_t_flag)
fprintf(stderr, "%s: (%d) Entering - name = \"%s\", flags = 0x%x, fapl_id = %d, maxaddr = %lu\n",
__func__, mpi_rank, name, flags, (int)fapl_id, (unsigned long)maxaddr);
#endif
/* Convert HDF5 flags to MPI-IO flags */
/* Some combinations are illegal; let MPI-IO figure it out */
mpi_amode = (flags & H5F_ACC_RDWR) ? MPI_MODE_RDWR : MPI_MODE_RDONLY;
if (flags & H5F_ACC_CREAT)
mpi_amode |= MPI_MODE_CREATE;
if (flags & H5F_ACC_EXCL)
mpi_amode |= MPI_MODE_EXCL;
#ifdef H5FDmpio_DEBUG
/* Check for debug commands in the info parameter */
if (MPI_INFO_NULL != info) {
char debug_str[128];
int flag;
MPI_Info_get(info, H5F_MPIO_DEBUG_KEY, sizeof(debug_str) - 1, debug_str, &flag);
if (flag)
H5FD__mpio_parse_debug_str(debug_str);
} /* end if */
#endif
if (MPI_SUCCESS != (mpi_code = MPI_File_open(comm, name, mpi_amode, info, &fh)))
HMPI_GOTO_ERROR(NULL, "MPI_File_open failed", mpi_code)
file_opened = true;
/* Get the MPI-IO hints that actually used by MPI-IO underneath. */
if (MPI_SUCCESS != (mpi_code = MPI_File_get_info(fh, &info_used)))
HMPI_GOTO_ERROR(NULL, "MPI_File_get_info failed", mpi_code)
/* Copy hints in info_used into info. Note hints in info_used supersede
* info. There may be some hints set and used by HDF5 only, but not
* recognizable by MPI-IO. We need to keep them, as MPI_File_get_info()
* will remove any hints unrecognized by MPI-IO library underneath.
*/
if (info_used != MPI_INFO_NULL) {
int i, nkeys;
if (info == MPI_INFO_NULL) /* reuse info created from MPI_File_get_info() */
info = info_used;
else {
/* retrieve the number of hints */
if (MPI_SUCCESS != (mpi_code = MPI_Info_get_nkeys(info_used, &nkeys)))
HMPI_GOTO_ERROR(NULL, "MPI_Info_get_nkeys failed", mpi_code)
/* copy over each hint */
for (i = 0; i < nkeys; i++) {
char key[MPI_MAX_INFO_KEY], value[MPI_MAX_INFO_VAL + 1];
int valuelen, flag;
/* retrieve the nth hint */
if (MPI_SUCCESS != (mpi_code = MPI_Info_get_nthkey(info_used, i, key)))
HMPI_GOTO_ERROR(NULL, "MPI_Info_get_nkeys failed", mpi_code)
/* retrieve the key of nth hint */
if (MPI_SUCCESS != (mpi_code = MPI_Info_get_valuelen(info_used, key, &valuelen, &flag)))
HMPI_GOTO_ERROR(NULL, "MPI_Info_get_valuelen failed", mpi_code)
/* retrieve the value of nth hint */
if (MPI_SUCCESS != (mpi_code = MPI_Info_get(info_used, key, valuelen, value, &flag)))
HMPI_GOTO_ERROR(NULL, "MPI_Info_get failed", mpi_code)
/* copy the hint into info */
if (MPI_SUCCESS != (mpi_code = MPI_Info_set(info, key, value)))
HMPI_GOTO_ERROR(NULL, "MPI_Info_set failed", mpi_code)
}
/* Free info_used allocated in the call to MPI_File_get_info() */
if (MPI_SUCCESS != (mpi_code = MPI_Info_free(&info_used)))
HMPI_GOTO_ERROR(NULL, "MPI_Info_free failed", mpi_code)