Skip to content

Commit

Permalink
cache different var sets
Browse files Browse the repository at this point in the history
  • Loading branch information
lroberts36 committed Nov 18, 2024
1 parent 1f1c5f3 commit 0c3131e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/bvals/comms/coalesced_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ void CoalescedBuffer::AllocateCoalescedBuffer() {

//----------------------------------------------------------------------------------------
ParArray1D<BndId> &CoalescedBuffer::GetBndIdsOnDevice(const std::set<Uid_t> &vars) {
int nbnd_id{0};
const auto &var_set = vars.size() == 0 ? all_vars : vars;
auto &bnd_ids_device = bnd_ids_device_map[var_set];
auto &bnd_ids_host = bnd_ids_host_map[var_set];

int nbnd_id{0};
for (auto uid : var_set)
nbnd_id += coalesced_info_buf.at(uid).size();

Expand Down
16 changes: 14 additions & 2 deletions src/bvals/comms/coalesced_buffers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ namespace parthenon {
// Structure containing the information required for sending coalesced
// messages between ranks

struct uid_set_hash {
std::size_t operator()(const std::set<Uid_t> &in) const {
std::size_t lhs{0};
for (const auto &uid : in) {
std::size_t rhs = std::hash<Uid_t>()(uid);
lhs ^= rhs + 0x9e3779b9 + (lhs << 6) + (lhs >> 2);
}
return lhs;
}
};

struct CoalescedBuffer {
using buf_t = BufArray1D<Real>;

Expand All @@ -49,8 +60,9 @@ struct CoalescedBuffer {
using var_buf_t = CommBuffer<buf_pool_t<Real>::owner_t>;
std::map<Uid_t, std::vector<std::pair<BndId, var_buf_t *>>> coalesced_info_buf;
std::set<Uid_t> all_vars;
ParArray1D<BndId> bnd_ids_device;
ParArray1D<BndId>::host_mirror_type bnd_ids_host;
std::unordered_map<std::set<Uid_t>, ParArray1D<BndId>, uid_set_hash> bnd_ids_device_map;
std::unordered_map<std::set<Uid_t>, ParArray1D<BndId>::host_mirror_type, uid_set_hash>
bnd_ids_host_map;
CommBuffer<buf_t> coalesced_comm_buffer;
CommBuffer<std::vector<int>> sparse_status_buffer;
int current_size;
Expand Down

0 comments on commit 0c3131e

Please sign in to comment.