Skip to content

Commit

Permalink
format and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lroberts36 committed Oct 23, 2024
1 parent 809dcb1 commit 43c376b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/bvals/comms/boundary_communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ TaskStatus SendBoundBufs(std::shared_ptr<MeshData<Real>> &md) {
return TaskStatus::complete;
}

bool can_write_combined = pmesh->pcombined_buffers->IsAvailableForWrite(md->partition, bound_type);
bool can_write_combined =
pmesh->pcombined_buffers->IsAvailableForWrite(md->partition, bound_type);
if (other_communication_unfinished || !can_write_combined) {
return TaskStatus::incomplete;
}
Expand Down
36 changes: 21 additions & 15 deletions src/bvals/comms/combined_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cstdio>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -278,17 +279,18 @@ void CombinedBuffersRank::CompareReceivedBuffers(int partition) {
});
}

void CombinedBuffers::AddSendBuffer(int partition, MeshBlock *pmb, const NeighborBlock &nb,
const std::shared_ptr<Variable<Real>> &var, BoundaryType b_type) {
void CombinedBuffers::AddSendBuffer(int partition, MeshBlock *pmb,
const NeighborBlock &nb,
const std::shared_ptr<Variable<Real>> &var,
BoundaryType b_type) {
if (combined_send_buffers.count({nb.rank, b_type}) == 0)
combined_send_buffers[{nb.rank, b_type}] =
CombinedBuffersRank(nb.rank, b_type, true);
combined_send_buffers[{nb.rank, b_type}].AddSendBuffer(partition, pmb, nb, var,
b_type);
combined_send_buffers[{nb.rank, b_type}] = CombinedBuffersRank(nb.rank, b_type, true);
combined_send_buffers[{nb.rank, b_type}].AddSendBuffer(partition, pmb, nb, var, b_type);
}

void CombinedBuffers::AddRecvBuffer(MeshBlock *pmb, const NeighborBlock &nb,
const std::shared_ptr<Variable<Real>>, BoundaryType b_type) {
const std::shared_ptr<Variable<Real>>,
BoundaryType b_type) {
// We don't actually know enough here to register this particular buffer, but we do
// know that it's existence implies that we need to receive a message from the
// neighbor block rank eventually telling us the details
Expand Down Expand Up @@ -322,7 +324,8 @@ bool CombinedBuffers::IsAvailableForWrite(int partition, BoundaryType b_type) {
bool available{true};
for (int rank = 0; rank < Globals::nranks; ++rank) {
if (combined_send_buffers.count({rank, b_type})) {
available = available && combined_send_buffers[{rank, b_type}].IsAvailableForWrite(partition);
available = available &&
combined_send_buffers[{rank, b_type}].IsAvailableForWrite(partition);
}
}
return available;
Expand All @@ -336,14 +339,16 @@ void CombinedBuffers::PackAndSend(int partition, BoundaryType b_type) {
}
}

void CombinedBuffers::RepointSendBuffers(Mesh *pmesh, int partition, BoundaryType b_type) {
void CombinedBuffers::RepointSendBuffers(Mesh *pmesh, int partition,
BoundaryType b_type) {
for (int rank = 0; rank < Globals::nranks; ++rank) {
if (combined_send_buffers.count({rank, b_type}))
combined_send_buffers[{rank, b_type}].RepointBuffers(pmesh, partition);
}
}

void CombinedBuffers::RepointRecvBuffers(Mesh *pmesh, int partition, BoundaryType b_type) {
void CombinedBuffers::RepointRecvBuffers(Mesh *pmesh, int partition,
BoundaryType b_type) {
for (int rank = 0; rank < Globals::nranks; ++rank) {
if (combined_recv_buffers.count({rank, b_type}))
combined_recv_buffers[{rank, b_type}].RepointBuffers(pmesh, partition);
Expand All @@ -360,22 +365,23 @@ void CombinedBuffers::TryReceiveAny(Mesh *pmesh, BoundaryType b_type) {
if (flag) {
const int rank = status.MPI_SOURCE;
const int partition = status.MPI_TAG - 913;
bool finished = combined_recv_buffers[{rank, b_type}].TryReceiveAndUnpack(pmesh, partition);
bool finished =
combined_recv_buffers[{rank, b_type}].TryReceiveAndUnpack(pmesh, partition);
if (!finished) processing_messages.insert({rank, partition});
}
} while (flag);

// Process in flight messages
std::set<std::pair<int, int>> finished_messages;
for (auto &[rank, partition] : processing_messages) {
bool finished = combined_recv_buffers[{rank, b_type}].TryReceiveAndUnpack(pmesh, partition);
std::set<std::pair<int, int>> finished_messages;
for (auto &[rank, partition] : processing_messages) {
bool finished =
combined_recv_buffers[{rank, b_type}].TryReceiveAndUnpack(pmesh, partition);
if (finished) finished_messages.insert({rank, partition});
}

for (auto &m : finished_messages)
processing_messages.erase(m);


#endif
}

Expand Down
3 changes: 2 additions & 1 deletion src/bvals/comms/combined_buffers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -91,7 +92,7 @@ struct CombinedBuffers {
// Combined buffers for each rank
std::map<std::pair<int, BoundaryType>, CombinedBuffersRank> combined_send_buffers;
std::map<std::pair<int, BoundaryType>, CombinedBuffersRank> combined_recv_buffers;

std::set<std::pair<int, int>> processing_messages;

void clear() {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/communication_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ template <class T>
void CommBuffer<T>::Stale() {
// PARTHENON_REQUIRE(*comm_type_ != BuffCommType::sender, "Should never get here.");

//if (!(*state_ == BufferState::received || *state_ == BufferState::received_null))
// PARTHENON_DEBUG_WARN("Staling buffer not in the received state.");
// if (!(*state_ == BufferState::received || *state_ == BufferState::received_null))
// PARTHENON_DEBUG_WARN("Staling buffer not in the received state.");
#ifdef MPI_PARALLEL
if (MPI_REQUEST_NULL != *my_request_)
PARTHENON_WARN("Staling buffer with pending request.");
Expand Down

0 comments on commit 43c376b

Please sign in to comment.