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

Track Message Type in Execution Graph #175

Merged
merged 4 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions include/faabric/scheduler/MpiWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
#include <atomic>
#include <unordered_map>

// Constants for profiling MPI parameters like number of messages sent or
// message breakdown by type in the execution graph. Remember to increase the
// counter if you add another one
#define NUM_MPI_EXEC_GRAPH_DETAILS 2
#define MPI_MSG_COUNT_PREFIX "mpi-msgcount-torank-"
#define MPI_MSGTYPE_COUNT_PREFIX "mpi-msgtype-torank"

namespace faabric::scheduler {
typedef faabric::util::Queue<std::shared_ptr<faabric::MPIMessage>>
InMemoryMpiQueue;
Expand Down
5 changes: 1 addition & 4 deletions include/faabric/util/exec_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
#include <map>

namespace faabric::util::exec_graph {

void addDetail(faabric::Message& msg,
const std::string& key,
const std::string& value);

void incrementCounter(faabric::Message& msg,
const std::string& key,
const int valueToIncrement = 1);

static inline std::string const mpiMsgCountPrefix = "mpi-msgcount-torank-";

static inline std::string const mpiMsgTypeCountPrefix = "mpi-msgtype-torank";
}
6 changes: 2 additions & 4 deletions src/scheduler/MpiWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,13 @@ void MpiWorld::send(int sendRank,
// If the message is set and recording on, track we have sent this message
if (thisRankMsg != nullptr && thisRankMsg->recordexecgraph()) {
faabric::util::exec_graph::incrementCounter(
*thisRankMsg,
faabric::util::exec_graph::mpiMsgCountPrefix +
std::to_string(recvRank));
*thisRankMsg, MPI_MSG_COUNT_PREFIX + std::to_string(recvRank));

// Work out the message type breakdown
faabric::util::exec_graph::incrementCounter(
*thisRankMsg,
fmt::format("{}-{}-{}",
faabric::util::exec_graph::mpiMsgTypeCountPrefix,
MPI_MSGTYPE_COUNT_PREFIX,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this string format then result in a double hyphen at the beginning (as the prefix already has a hyphen)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the MSGTYPE_COUNT we have to provide two values, so the constant actually hasn't got a trailing hyphen. I will change it to make them both consistent.

std::to_string(messageType),
std::to_string(recvRank)));
}
Expand Down
31 changes: 15 additions & 16 deletions tests/test/scheduler/test_mpi_exec_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ TEST_CASE_METHOD(MpiTestFixture,
auto buffer = new int[messageData.size()];

int numToSend = 10;
std::string expectedKey =
faabric::util::exec_graph::mpiMsgCountPrefix + std::to_string(rankA2);
std::string expectedKey = MPI_MSG_COUNT_PREFIX + std::to_string(rankA2);

for (int i = 0; i < numToSend; i++) {
world.send(rankA1,
Expand All @@ -36,6 +35,8 @@ TEST_CASE_METHOD(MpiTestFixture,
rankA1, rankA2, BYTES(buffer), MPI_INT, messageData.size(), &status);
}

REQUIRE(msg.intexecgraphdetails_size() == NUM_MPI_EXEC_GRAPH_DETAILS);
REQUIRE(msg.execgraphdetails_size() == 0);
REQUIRE(msg.intexecgraphdetails().count(expectedKey) == 1);
REQUIRE(msg.intexecgraphdetails().at(expectedKey) == numToSend);
}
Expand All @@ -56,8 +57,7 @@ TEST_CASE_METHOD(MpiTestFixture,
auto buffer = new int[messageData.size()];

int numToSend = 10;
std::string expectedKey =
faabric::util::exec_graph::mpiMsgCountPrefix + std::to_string(rankA2);
std::string expectedKey = MPI_MSG_COUNT_PREFIX + std::to_string(rankA2);

for (int i = 0; i < numToSend; i++) {
world.send(rankA1,
Expand Down Expand Up @@ -121,8 +121,7 @@ TEST_CASE_METHOD(MpiBaseTestFixture,
otherWorldThread.join();
}

std::string expectedKey =
faabric::util::exec_graph::mpiMsgCountPrefix + std::to_string(rank);
std::string expectedKey = MPI_MSG_COUNT_PREFIX + std::to_string(rank);
REQUIRE(otherMsg.mpirank() == otherRank);
REQUIRE(otherMsg.intexecgraphdetails().count(expectedKey) == 1);
REQUIRE(otherMsg.intexecgraphdetails().at(expectedKey) == 1);
Expand All @@ -147,11 +146,10 @@ TEST_CASE_METHOD(MpiTestFixture,

SECTION("Normal send")
{
expectedKey =
fmt::format("{}-{}-{}",
faabric::util::exec_graph::mpiMsgTypeCountPrefix,
faabric::MPIMessage::NORMAL,
std::to_string(rankA2));
expectedKey = fmt::format("{}-{}-{}",
MPI_MSGTYPE_COUNT_PREFIX,
faabric::MPIMessage::NORMAL,
std::to_string(rankA2));
msgCount = 1;

world.send(rankA1,
Expand All @@ -167,11 +165,10 @@ TEST_CASE_METHOD(MpiTestFixture,
{
std::vector<int> data(2, 0);

expectedKey =
fmt::format("{}-{}-{}",
faabric::util::exec_graph::mpiMsgTypeCountPrefix,
faabric::MPIMessage::REDUCE,
std::to_string(rankA2));
expectedKey = fmt::format("{}-{}-{}",
MPI_MSGTYPE_COUNT_PREFIX,
faabric::MPIMessage::REDUCE,
std::to_string(rankA2));
msgCount = worldSize - 1;

// Reduce expects to receive a message from all other ranks
Expand All @@ -191,6 +188,8 @@ TEST_CASE_METHOD(MpiTestFixture,
MPI_SUM);
}

REQUIRE(msg.intexecgraphdetails_size() == NUM_MPI_EXEC_GRAPH_DETAILS);
REQUIRE(msg.execgraphdetails_size() == 0);
REQUIRE(msg.intexecgraphdetails().count(expectedKey) == 1);
REQUIRE(msg.intexecgraphdetails().at(expectedKey) == msgCount);
}
Expand Down