Skip to content

Commit 306db40

Browse files
authored
Avoid calling H5FD_subfiling_init from h5open_f. (#2149)
* Only call H5FD_SUBFILING if subfiling conditions are met * clang format
1 parent e80079f commit 306db40

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

fortran/src/H5_f.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,29 @@ h5init_flags_c(int_f *h5d_flags, size_t_f *h5d_size_flags, int_f *h5e_flags, hid
561561
h5fd_hid_flags[4] = (hid_t_f)H5FD_MULTI;
562562
h5fd_hid_flags[5] = (hid_t_f)H5FD_SEC2;
563563
h5fd_hid_flags[6] = (hid_t_f)H5FD_STDIO;
564-
h5fd_hid_flags[7] = (hid_t_f)H5FD_SUBFILING;
564+
565+
/* Calling H5FD_subfiling_init here requires the
566+
subfiling requirements to be met. Only set the
567+
subfiling if it meets the below conditions */
568+
569+
h5fd_hid_flags[7] = (hid_t_f)H5I_INVALID_HID;
570+
571+
#ifdef H5_HAVE_PARALLEL
572+
int mpi_initialized = 0;
573+
int provided = 0;
574+
int mpi_code;
575+
576+
if (MPI_SUCCESS == (mpi_code = MPI_Initialized(&mpi_initialized))) {
577+
if (mpi_initialized) {
578+
/* If MPI is initialized, validate that it was initialized with MPI_THREAD_MULTIPLE */
579+
if (MPI_SUCCESS == (mpi_code = MPI_Query_thread(&provided))) {
580+
if (provided == MPI_THREAD_MULTIPLE) {
581+
h5fd_hid_flags[7] = (hid_t_f)H5FD_SUBFILING;
582+
}
583+
}
584+
}
585+
}
586+
#endif
565587
#ifdef H5_HAVE_SUBFILING_VFD
566588
h5fd_hid_flags[8] = (hid_t_f)H5FD_SUBFILING_DEFAULT_STRIPE_SIZE;
567589
#else

0 commit comments

Comments
 (0)