Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions Src/Extern/HDF5/AMReX_ParticleHDF5.H
Original file line number Diff line number Diff line change
Expand Up @@ -453,19 +453,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
Long maxnextid = ParticleType::NextID();

for (int lev = 0; lev < std::ssize(m_particles); lev++) {
const auto& pmap = m_particles[lev];
for (const auto& kv : pmap) {
const auto& aos = kv.second.GetArrayOfStructs();
for (int k = 0; k < aos.numParticles(); ++k) {
const ParticleType& p = aos[k];
if (p.id().is_valid()) {
//
// Only count (and checkpoint) valid particles.
//
nparticles++;
}
}
}
nparticles += NumberOfParticlesAtLevel(lev, true, true);
}
ParallelDescriptor::ReduceLongSum(nparticles, IOProcNumber);

Expand Down Expand Up @@ -729,18 +717,21 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
}

#ifdef AMREX_USE_MPI
// Collect the number of mf and total size of mf from each rank
// Collect the number of non-empty grids from each rank
MPI_Allgather(&my_mfi_cnt, 1, ParallelDescriptor::Mpi_typemap<int>::type(), &(all_mfi_cnt[0]), 1,
ParallelDescriptor::Mpi_typemap<int>::type(), ParallelDescriptor::Communicator());
#else
all_mfi_cnt[0] = my_mfi_cnt;
#endif

for (int i = 0; i < ParallelDescriptor::NProcs(); i++)
total_mfi += all_mfi_cnt[i];

// Create the int data
#ifdef AMREX_USE_MPI
MPI_Allgather(&my_mfi_int_total_size, 1, ParallelDescriptor::Mpi_typemap<ULong>::type(),
&(all_mfi_int_total_size[0]), 1, ParallelDescriptor::Mpi_typemap<ULong>::type(), ParallelDescriptor::Communicator());
#else
all_mfi_cnt[0] = my_mfi_cnt;
all_mfi_int_total_size[0] = my_mfi_int_total_size;
#endif

Expand Down Expand Up @@ -1295,6 +1286,14 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
amrex::Abort(msg.c_str());
}

htri_t const has_particles = H5Lexists(grp, "nparticles_grid", H5P_DEFAULT);
if (has_particles < 0) {
amrex::Abort("ParticleContainer::RestartHDF5(): unable to check for nparticles_grid dataset");
} else if (has_particles == 0) {
H5Gclose(grp);
continue;
}

dset = H5Dopen(grp, "nparticles_grid", H5P_DEFAULT);
Vector<int> count(ngrids[lev]);
ret = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &(count[0]));
Expand Down
14 changes: 1 addition & 13 deletions Src/Particle/AMReX_ParticleIO.H
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,7 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
Long maxnextid = ParticleType::NextID();

for (int lev = 0; lev < std::ssize(m_particles); lev++) {
const auto& pmap = m_particles[lev];
for (const auto& kv : pmap) {
const auto& aos = kv.second.GetArrayOfStructs();
for (int k = 0; k < aos.numParticles(); ++k) {
const ParticleType& p = aos[k];
if (p.id().is_valid()) {
//
// Only count (and checkpoint) valid particles.
//
nparticles++;
}
}
}
nparticles += NumberOfParticlesAtLevel(lev, true, true);
}
ParallelDescriptor::ReduceLongSum(nparticles, IOProcNumber);

Expand Down
5 changes: 5 additions & 0 deletions Tests/Particles/CheckpointRestartDualGridHDF5SOA/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,17 @@ void test_fewer_levels ()
auto mesh2 = build_mesh(ncells, 2, max_grid_size);
MyPC pc_write(mesh2.geom, mesh2.dmap, mesh2.ba, mesh2.ref_ratio);
pc_write.SetVerbose(false);
pc_write.SetUsePrePost(true);
pc_write.InitRandom(nppc * AMREX_D_TERM(ncells, *ncells, *ncells),
iseed, pdata, /*serialize=*/false);
#ifdef AMREX_USE_HDF5
pc_write.CheckpointPreHDF5();
pc_write.CheckpointHDF5(chkdir, "particles", true, real_names, int_names);
pc_write.CheckpointPostHDF5();
#else
pc_write.CheckpointPre();
pc_write.Checkpoint(chkdir, "particles", real_names, int_names);
pc_write.CheckpointPost();
#endif

AsyncOut::Finish();
Expand Down
3 changes: 3 additions & 0 deletions Tests/Particles/CheckpointRestartSOA/inputs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ nparticlefile = 1
restart_check = 1

directory=.

# Exercise the pre/post checkpoint path for pure-SoA particles.
particles.use_prepost = 1
2 changes: 2 additions & 0 deletions Tests/Particles/CheckpointRestartSOA/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ void test ()

amrex::Print() << "Writing particle file [" << fname << "] ..." << '\n';

myPC.CheckpointPre();
myPC.Checkpoint(fname, "particle0", false, particle_realnames, particle_intnames);
myPC.CheckpointPost();

amrex::Print() << " done \n";
}
Expand Down
Loading