Skip to content

Commit 73e46e6

Browse files
HDF5: Correctly choose datatype of plotfile based on RD numBytes (#4006)
## Summary If numBytes is 4, use H5T_NATIVE_FLOAT instead of H5T_NATIVE_DOUBLE. This fixes writing real values, as in ExaEpi. ## Additional background As far as I can tell, whichRD (and therefore whichRDBytes) does not change between levels, so I perform this check outside of the level loop, but if it is indeed possible for these values to change, I can move it inside. ## Checklist The proposed changes: - [x] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate
1 parent 2f93525 commit 73e46e6

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

Src/Extern/HDF5/AMReX_PlotFileUtilHDF5.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,15 @@ void WriteMultiLevelPlotfileHDF5SingleDset (const std::string& plotfilename,
524524
bool doConvert(*whichRD != FPC::NativeRealDescriptor());
525525
int whichRDBytes(whichRD->numBytes());
526526

527+
// Pick data type of dataset
528+
hid_t data_type;
529+
if (whichRDBytes == 4) {
530+
data_type = H5T_NATIVE_FLOAT;
531+
}
532+
else {
533+
data_type = H5T_NATIVE_DOUBLE;
534+
}
535+
527536
// Write data for each level
528537
char level_name[32];
529538
for (int level = 0; level <= finest_level; ++level) {
@@ -712,10 +721,11 @@ void WriteMultiLevelPlotfileHDF5SingleDset (const std::string& plotfilename,
712721
#endif
713722

714723
#ifdef AMREX_USE_HDF5_ASYNC
715-
hid_t dataset = H5Dcreate_async(grp, dataname.c_str(), H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT, es_id_g);
724+
hid_t dataset = H5Dcreate_async(grp, dataname.c_str(), data_type, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT, es_id_g);
716725
#else
717-
hid_t dataset = H5Dcreate(grp, dataname.c_str(), H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT);
726+
hid_t dataset = H5Dcreate(grp, dataname.c_str(), data_type, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT);
718727
#endif
728+
719729
if(dataset < 0)
720730
std::cout << ParallelDescriptor::MyProc() << "create data failed! ret = " << dataset << std::endl;
721731

@@ -727,9 +737,9 @@ void WriteMultiLevelPlotfileHDF5SingleDset (const std::string& plotfilename,
727737
H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, ch_offset, NULL, hs_procsize, NULL);
728738

729739
#ifdef AMREX_USE_HDF5_ASYNC
730-
ret = H5Dwrite_async(dataset, H5T_NATIVE_DOUBLE, memdataspace, dataspace, dxpl_col, a_buffer.dataPtr(), es_id_g);
740+
ret = H5Dwrite_async(dataset, data_type, memdataspace, dataspace, dxpl_col, a_buffer.dataPtr(), es_id_g);
731741
#else
732-
ret = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, memdataspace, dataspace, dxpl_col, a_buffer.dataPtr());
742+
ret = H5Dwrite(dataset, data_type, memdataspace, dataspace, dxpl_col, a_buffer.dataPtr());
733743
#endif
734744
if(ret < 0) { std::cout << ParallelDescriptor::MyProc() << "Write data failed! ret = " << ret << std::endl; break; }
735745

@@ -961,6 +971,15 @@ void WriteMultiLevelPlotfileHDF5MultiDset (const std::string& plotfilename,
961971
bool doConvert(*whichRD != FPC::NativeRealDescriptor());
962972
int whichRDBytes(whichRD->numBytes());
963973

974+
// Pick data type
975+
hid_t data_type;
976+
if (whichRDBytes == 4) {
977+
data_type = H5T_NATIVE_FLOAT;
978+
}
979+
else {
980+
data_type = H5T_NATIVE_DOUBLE;
981+
}
982+
964983
// Write data for each level
965984
char level_name[32];
966985

@@ -1160,7 +1179,7 @@ void WriteMultiLevelPlotfileHDF5MultiDset (const std::string& plotfilename,
11601179
hid_t dataspace = H5Screate_simple(1, hs_allprocsize, NULL);
11611180
snprintf(dataname, sizeof dataname, "data:datatype=%d", jj);
11621181
#ifdef AMREX_USE_HDF5_ASYNC
1163-
dataset = H5Dcreate_async(grp, dataname, H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT, es_id_g);
1182+
dataset = H5Dcreate_async(grp, dataname, data_type, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT, es_id_g);
11641183
if(dataset < 0) { std::cout << ParallelDescriptor::MyProc() << "create data failed! ret = " << dataset << std::endl; }
11651184

11661185
if (hs_procsize[0] == 0) {
@@ -1169,11 +1188,11 @@ void WriteMultiLevelPlotfileHDF5MultiDset (const std::string& plotfilename,
11691188
H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, ch_offset, NULL, hs_procsize, NULL);
11701189
}
11711190

1172-
ret = H5Dwrite_async(dataset, H5T_NATIVE_DOUBLE, memdataspace, dataspace, dxpl_col, a_buffer_ind.dataPtr(), es_id_g);
1191+
ret = H5Dwrite_async(dataset, data_type, memdataspace, dataspace, dxpl_col, a_buffer_ind.dataPtr(), es_id_g);
11731192
if(ret < 0) { std::cout << ParallelDescriptor::MyProc() << "Write data failed! ret = " << ret << std::endl; break; }
11741193
H5Dclose_async(dataset, es_id_g);
11751194
#else
1176-
dataset = H5Dcreate(grp, dataname, H5T_NATIVE_DOUBLE, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT);
1195+
dataset = H5Dcreate(grp, dataname, data_type, dataspace, H5P_DEFAULT, lev_dcpl_id, H5P_DEFAULT);
11771196
if(dataset < 0) { std::cout << ParallelDescriptor::MyProc() << "create data failed! ret = " << dataset << std::endl; }
11781197

11791198
if (hs_procsize[0] == 0) {
@@ -1182,7 +1201,7 @@ void WriteMultiLevelPlotfileHDF5MultiDset (const std::string& plotfilename,
11821201
H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, ch_offset, NULL, hs_procsize, NULL);
11831202
}
11841203

1185-
ret = H5Dwrite(dataset, H5T_NATIVE_DOUBLE, memdataspace, dataspace, dxpl_col, a_buffer_ind.dataPtr());
1204+
ret = H5Dwrite(dataset, data_type, memdataspace, dataspace, dxpl_col, a_buffer_ind.dataPtr());
11861205
if(ret < 0) { std::cout << ParallelDescriptor::MyProc() << "Write data failed! ret = " << ret << std::endl; break; }
11871206
H5Dclose(dataset);
11881207
#endif

0 commit comments

Comments
 (0)