Skip to content

Commit 7418556

Browse files
HDF5: Correctly handle writing only some components when writing Particle (#4005)
## Summary Correctly names file attribute to match component index with dataset index and correctly calculates size of each particle's data so that the dataset is aligned. ## Additional background Previously, all components of a particle were being counted, whether written or not, leading to misalignment across different processes when writing. ## 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 73e46e6 commit 7418556

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Src/Extern/HDF5/AMReX_ParticleHDF5.H

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,19 +705,32 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
705705
hsize_t total_mfi = 0, total_real_size = 0, total_int_size = 0, real_file_offset = 0, int_file_offset = 0;
706706
hsize_t my_int_offset, my_int_count, my_real_offset, my_real_count;
707707

708+
// Count total number of components written
709+
int real_comp_count = AMREX_SPACEDIM; // position values
710+
711+
for (int i = 0; i < NStructReal + NumRealComps(); ++i ) {
712+
if (write_real_comp[i]) { ++real_comp_count; }
713+
}
714+
715+
int int_comp_count = 2; // cpu and id values
716+
717+
for (int i = 0; i < NStructInt + NumIntComps(); ++i ) {
718+
if (write_int_comp[i]) { ++int_comp_count; }
719+
}
720+
708721
// Get the size for each mf so we know the amount of data from each rank
709722
for (MFIter mfi(state); mfi.isValid(); ++mfi) {
710723
const int grid = mfi.index();
711724
if (count[grid] == 0)
712725
continue;
713726

714-
int_size = count[grid] * (2 + NStructInt + NumIntComps());
727+
int_size = count[grid] * int_comp_count;
715728
my_mfi_int_size.push_back(int_size);
716729
my_nparticles.push_back(count[grid]);
717730
my_mfi_int_total_size += int_size;
718731

719732

720-
real_size = count[grid] * (AMREX_SPACEDIM + NStructReal + NumRealComps());
733+
real_size = count[grid] * real_comp_count;
721734
my_mfi_real_size.push_back(real_size);
722735
my_mfi_real_total_size += real_size;
723736
my_mfi_cnt++;

Src/Extern/HDF5/AMReX_WriteBinaryParticleDataHDF5.H

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,23 +289,30 @@ void WriteHDF5ParticleDataSync (PC const& pc,
289289
CreateWriteHDF5Attr(fid, "num_component_real", 1, &num_output_real, H5T_NATIVE_INT);
290290

291291
char comp_name[128];
292+
292293
// Real component names
294+
int real_comp_count = AMREX_SPACEDIM; // position values
295+
293296
for (int i = 0; i < NStructReal + pc.NumRealComps(); ++i ) {
294297
if (write_real_comp[i]) {
295298
/* HdrFile << real_comp_names[i] << '\n'; */
296-
snprintf(comp_name, sizeof comp_name, "real_component_%d", i);
299+
snprintf(comp_name, sizeof comp_name, "real_component_%d", real_comp_count);
297300
CreateWriteHDF5AttrString(fid, comp_name, real_comp_names[i].c_str());
301+
++real_comp_count;
298302
}
299303
}
300304

301305
// The number of extra int parameters
302306
CreateWriteHDF5Attr(fid, "num_component_int", 1, &num_output_int, H5T_NATIVE_INT);
303307

304308
// int component names
309+
int int_comp_count = 2;
310+
305311
for (int i = 0; i < NStructInt + pc.NumIntComps(); ++i ) {
306312
if (write_int_comp[i]) {
307-
snprintf(comp_name, sizeof comp_name, "int_component_%d", i);
313+
snprintf(comp_name, sizeof comp_name, "int_component_%d", int_comp_count);
308314
CreateWriteHDF5AttrString(fid, comp_name, int_comp_names[i].c_str());
315+
++int_comp_count;
309316
}
310317
}
311318

0 commit comments

Comments
 (0)