Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the neighbor comm tags for the CPU implementation of fillNeighbors. #2862

Merged
merged 2 commits into from
Jul 2, 2022
Merged
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
5 changes: 5 additions & 0 deletions Src/Particle/AMReX_NeighborParticles.H
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ protected:
///
void BuildMasks ();

///
/// Are the masks computed by the above function still valid?
///
bool areMasksValid ();

void GetNeighborCommTags ();

void GetCommTagsBox (Vector<NeighborCommTag>& tags, const int lev, const Box& in_box);
Expand Down
6 changes: 4 additions & 2 deletions Src/Particle/AMReX_NeighborParticlesCPUImpl.H
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ void
NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
::fillNeighborsCPU () {
BL_PROFILE("NeighborParticleContainer::fillNeighborsCPU");
BuildMasks();
GetNeighborCommTags();
if (!areMasksValid()) {
BuildMasks();
GetNeighborCommTags();
}
cacheNeighborInfo();
updateNeighborsCPU(false);
}
Expand Down
55 changes: 37 additions & 18 deletions Src/Particle/AMReX_NeighborParticlesI.H
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,30 @@ NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
this->Redistribute();
}

template <int NStructReal, int NStructInt, int NArrayReal, int NArrayInt>
bool
NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
::areMasksValid () {

BL_PROFILE("NeighborParticleContainer::areMasksValid");

resizeContainers(this->numLevels());

for (int lev = 0; lev < this->numLevels(); ++lev)
{
BoxArray ba = this->ParticleBoxArray(lev);
const DistributionMapping& dmap = this->ParticleDistributionMap(lev);

if (mask_ptr[lev] == nullptr ||
! BoxArray::SameRefs(mask_ptr[lev]->boxArray(), ba) ||
! DistributionMapping::SameRefs(mask_ptr[lev]->DistributionMap(), dmap))
{
return false;
}
}
return true;
}

template <int NStructReal, int NStructInt, int NArrayReal, int NArrayInt>
void
NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
Expand All @@ -136,30 +160,25 @@ NeighborParticleContainer<NStructReal, NStructInt, NArrayReal, NArrayInt>
BoxArray ba = this->ParticleBoxArray(lev);
const DistributionMapping& dmap = this->ParticleDistributionMap(lev);

if (mask_ptr[lev] == nullptr ||
! BoxArray::SameRefs(mask_ptr[lev]->boxArray(), ba) ||
! DistributionMapping::SameRefs(mask_ptr[lev]->DistributionMap(), dmap))
{
const Geometry& geom = this->Geom(lev);
const Geometry& geom = this->Geom(lev);

mask_ptr[lev] = std::make_unique<iMultiFab>(ba, dmap, int(num_mask_comps), m_num_neighbor_cells);
mask_ptr[lev]->setVal(-1, m_num_neighbor_cells);
mask_ptr[lev] = std::make_unique<iMultiFab>(ba, dmap, int(num_mask_comps), m_num_neighbor_cells);
mask_ptr[lev]->setVal(-1, m_num_neighbor_cells);

#ifdef AMREX_USE_OMP
#pragma omp parallel
#endif
for (MFIter mfi(*mask_ptr[lev],this->do_tiling ? this->tile_size : IntVect::TheZeroVector());
mfi.isValid(); ++mfi) {
const Box& box = mfi.tilebox();
const int grid_id = mfi.index();
const int tile_id = mfi.LocalTileIndex();
(*mask_ptr[lev])[mfi].template setVal<RunOn::Host>(grid_id, box, MaskComps::grid, 1);
(*mask_ptr[lev])[mfi].template setVal<RunOn::Host>(tile_id, box, MaskComps::tile, 1);
(*mask_ptr[lev])[mfi].template setVal<RunOn::Host>(lev , box, MaskComps::level, 1);
}

mask_ptr[lev]->FillBoundary(geom.periodicity());
for (MFIter mfi(*mask_ptr[lev],this->do_tiling ? this->tile_size : IntVect::TheZeroVector());
mfi.isValid(); ++mfi) {
const Box& box = mfi.tilebox();
const int grid_id = mfi.index();
const int tile_id = mfi.LocalTileIndex();
(*mask_ptr[lev])[mfi].template setVal<RunOn::Host>(grid_id, box, MaskComps::grid, 1);
(*mask_ptr[lev])[mfi].template setVal<RunOn::Host>(tile_id, box, MaskComps::tile, 1);
(*mask_ptr[lev])[mfi].template setVal<RunOn::Host>(lev , box, MaskComps::level, 1);
}

mask_ptr[lev]->FillBoundary(geom.periodicity());
}
}

Expand Down