Skip to content

Commit

Permalink
#2387: overload + op for UserEventRegistry and implement gather for u…
Browse files Browse the repository at this point in the history
…ser_event_
  • Loading branch information
cwschilly committed Jan 14, 2025
1 parent d25f3f2 commit e4e471f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 61 deletions.
4 changes: 0 additions & 4 deletions src/vt/trace/trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ void insertNewUserEvent(
#endif
}

void Trace::addHashedEvent(UserEventIDType event_id) {
theTrace()->user_hashed_events_.push_back(event_id);
}

void Trace::addUserEvent(UserEventIDType event) {
if (not checkDynamicRuntimeEnabled()) {
return;
Expand Down
8 changes: 0 additions & 8 deletions src/vt/trace/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,6 @@ struct Trace : runtime::component::Component<Trace>, TraceLite {
*/
void registerUserEventManual(std::string const& name, UserSpecEventIDType id);

/**
* \brief Store a hashed event ID
*
* \param[in] event_id the hashed event ID
*/
void addHashedEvent(UserEventIDType event_id);

/**
* \brief Log a user event
*
Expand Down Expand Up @@ -381,7 +374,6 @@ struct Trace : runtime::component::Component<Trace>, TraceLite {
| idle_begun_
| start_time_
| user_event_
| user_hashed_events_
| prog_name_
| trace_name_
| full_trace_name_
Expand Down
37 changes: 3 additions & 34 deletions src/vt/trace/trace_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include <sys/stat.h>
#include <zlib.h>
#include <map>
#include <numeric>

namespace vt {
#if vt_check_enabled(trace_only)
Expand Down Expand Up @@ -546,39 +545,9 @@ void TraceLite::writeTracesFile(int flush, bool is_incremental_flush) {
auto const comm = theContext()->getComm();
auto const comm_size = theContext()->getNumNodes();

// Gather all hashed events to rank 0 before writing sts file
using events_t = std::vector<UserEventIDType>;
auto const root = 0;
events_t local_hashed_events = theTrace()->user_hashed_events_;
int local_size = local_hashed_events.size();
std::vector<int> all_sizes(comm_size);
MPI_Gather(&local_size, 1, MPI_INT, all_sizes.data(), 1, MPI_INT, 0, comm);

// Compute displacements
std::vector<int> displs(comm_size, 0);
if (node == 0) {
std::partial_sum(all_sizes.begin(), all_sizes.end() - 1, displs.begin() + 1);
}

// Create vector in which to store all events
events_t all_hashed_events;
if (node == 0) {
int total_size = std::accumulate(all_sizes.begin(), all_sizes.end(), 0);
all_hashed_events.resize(total_size);
}

// Gather events
MPI_Gatherv(
local_hashed_events.data(), // Send buffer
local_size, // Number of elements to send
MPI_UINT32_T, // Data type (adjust to match UserEventIDType)
all_hashed_events.data(), // Receive buffer (on root)
all_sizes.data(), // Number of elements to receive from each rank
displs.data(), // Displacements for each rank
MPI_UINT32_T, // Data type (adjust to match UserEventIDType)
root, // Root node
comm // Communicator
);
vt::runInEpochCollective([&]{
proxy.reduce<vt::collective::PlusOp>(0, std::move(user_event_));
});

size_t to_write = traces_.size();

Expand Down
1 change: 0 additions & 1 deletion src/vt/trace/trace_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ struct TraceLite {
int incremental_flush_mode_ = 0;

UserEventRegistry user_event_ = {};
std::vector<UserEventIDType> user_hashed_events_;
EventHoldStackType event_holds_;
TraceStackType open_events_;
TraceContainerType traces_;
Expand Down
23 changes: 9 additions & 14 deletions src/vt/trace/trace_user_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,12 @@ UserEventIDType UserEventRegistry::hash(std::string const& in_event_name) {
id_hash = id_hash & 0x0FFF;
auto ret = newEventImpl(false, false, in_event_name, id_hash, true);
auto id = std::get<0>(ret);
auto inserted = std::get<1>(ret);
if (inserted) {
vt::theTrace()->addHashedEvent(id);
}
return id;
}

UserEventIDType UserEventRegistry::rooted(std::string const& in_event_name) {
auto ret = newEventImpl(false, true, in_event_name, cur_root_event_++);
auto id = std::get<0>(ret);
auto const node = theContext()->getNode();
if (node != 0) {
auto msg = makeMessage<NewUserEventMsg>(false, id, in_event_name);
theMsg()->sendMsg<newEventHan>(0, msg);
}
return id;
}

Expand All @@ -105,11 +96,6 @@ UserEventIDType UserEventRegistry::user(
) {
auto ret = newEventImpl(true, false, in_event_name, seq);
auto id = std::get<0>(ret);
auto const node = theContext()->getNode();
if (node != 0) {
auto msg = makeMessage<NewUserEventMsg>(true, id, in_event_name);
theMsg()->sendMsg<newEventHan>(0, msg);
}
return id;
}
#endif
Expand Down Expand Up @@ -141,9 +127,18 @@ bool UserEventRegistry::insertEvent(
);
return true;
} else {
user_event_[event] += " COLLISION " + name;
return false;
}
}

UserEventRegistry operator+(
UserEventRegistry r1, UserEventRegistry const& r2
) {
for (auto& [hash, event_str] : r2.getEvents()) {
r1.insertEvent(hash, event_str);
}
return r1;
}

}} /* end namespace vt::trace */

0 comments on commit e4e471f

Please sign in to comment.