Skip to content

Commit

Permalink
move functions and add max_iters to clear
Browse files Browse the repository at this point in the history
  • Loading branch information
lroberts36 committed Nov 27, 2024
1 parent c67a5fb commit 6aa7dcd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
44 changes: 44 additions & 0 deletions src/bvals/comms/coalesced_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,50 @@ bool CoalescedBuffersRank::TryReceiveAndUnpack(MeshData<Real> *pmd, int partitio

//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
CoalescedComms::CoalescedComms(Mesh *pmesh) : pmesh(pmesh) {
// TODO(LFR): Switch to a different communicator for each BoundaryType pair
for (auto b_type :
{BoundaryType::any, BoundaryType::flxcor_send, BoundaryType::gmg_same,
BoundaryType::gmg_restrict_send, BoundaryType::gmg_prolongate_send}) {
auto &comm = comms[b_type];
#ifdef MPI_PARALLEL
PARTHENON_MPI_CHECK(MPI_Comm_dup(MPI_COMM_WORLD, &comm));
#else
comm = 0;
#endif
}
}

//----------------------------------------------------------------------------------------
CoalescedComms::~CoalescedComms() {
#ifdef MPI_PARALLEL
for (auto &[b_type, comm] : comms)
PARTHENON_MPI_CHECK(MPI_Comm_free(&comm));
#endif
}

//----------------------------------------------------------------------------------------
void CoalescedComms::clear() {
bool can_delete;
int iter{0};
const int max_iters = 1e8;
do {
can_delete = true;
for (auto &[p, cbr] : coalesced_send_buffers) {
can_delete = cbr.message.IsAvailableForWrite() && can_delete;
for (auto &[r, cbrp] : cbr.coalesced_bufs) {
can_delete = cbrp.IsAvailableForWrite() && can_delete;
}
}
iter++;
} while (!can_delete && iter < max_iters);
if (iter == max_iters) PARTHENON_FAIL("Waited too long to clear CoalescedComms.");

coalesced_send_buffers.clear();
coalesced_recv_buffers.clear();
}

//----------------------------------------------------------------------------------------
void CoalescedComms::AddSendBuffer(int partition, MeshBlock *pmb, const NeighborBlock &nb,
const std::shared_ptr<Variable<Real>> &var,
Expand Down
36 changes: 3 additions & 33 deletions src/bvals/comms/coalesced_buffers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,41 +153,11 @@ struct CoalescedComms {

Mesh *pmesh;

explicit CoalescedComms(Mesh *pmesh) : pmesh(pmesh) {
// TODO(LFR): Switch to a different communicator for each BoundaryType pair
for (auto b_type :
{BoundaryType::any, BoundaryType::flxcor_send, BoundaryType::gmg_same,
BoundaryType::gmg_restrict_send, BoundaryType::gmg_prolongate_send}) {
auto &comm = comms[b_type];
#ifdef MPI_PARALLEL
PARTHENON_MPI_CHECK(MPI_Comm_dup(MPI_COMM_WORLD, &comm));
#else
comm = 0;
#endif
}
}
explicit CoalescedComms(Mesh *pmesh);

~CoalescedComms() {
#ifdef MPI_PARALLEL
for (auto &[b_type, comm] : comms)
PARTHENON_MPI_CHECK(MPI_Comm_free(&comm));
#endif
}
~CoalescedComms();

void clear() {
bool can_delete;
do {
can_delete = true;
for (auto &[p, cbr] : coalesced_send_buffers) {
can_delete = cbr.message.IsAvailableForWrite() && can_delete;
for (auto &[r, cbrp] : cbr.coalesced_bufs) {
can_delete = cbrp.IsAvailableForWrite() && can_delete;
}
}
} while (!can_delete);
coalesced_send_buffers.clear();
coalesced_recv_buffers.clear();
}
void clear();

void AddSendBuffer(int partition, MeshBlock *pmb, const NeighborBlock &nb,
const std::shared_ptr<Variable<Real>> &var, BoundaryType b_type);
Expand Down

0 comments on commit 6aa7dcd

Please sign in to comment.