Skip to content

Commit

Permalink
mpi: make local fast path faster
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Feb 15, 2024
1 parent fb3816e commit 8375d31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/mpi/MpiWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,7 @@ void MpiWorld::send(int sendRank,
m->set_messagetype(messageType);

// Set up message data
if (count > 0 && buffer != nullptr) {
m->set_buffer(buffer, dataType->size * count);
}
bool mustSendData = count > 0 && buffer != nullptr;

// Mock the message sending in tests
if (faabric::util::isMockMode()) {
Expand All @@ -528,10 +526,18 @@ void MpiWorld::send(int sendRank,

// Dispatch the message locally or globally
if (isLocal) {
if (mustSendData) {
m->set_bufferptr((uint64_t)buffer);
}

SPDLOG_TRACE(
"MPI - send {} -> {} ({})", sendRank, recvRank, messageType);
getLocalQueue(sendRank, recvRank)->enqueue(std::move(m));
} else {
if (mustSendData) {
m->set_buffer(buffer, dataType->size * count);
}

SPDLOG_TRACE(
"MPI - send remote {} -> {} ({})", sendRank, recvRank, messageType);
sendRemoteMpiMessage(otherHost, sendRank, recvRank, m);
Expand Down Expand Up @@ -596,10 +602,16 @@ void MpiWorld::doRecv(std::shared_ptr<MPIMessage>& m,
assert(m->messagetype() == messageType);
assert(m->count() <= count);

// TODO - avoid copy here
// Copy message data
const std::string otherHost = getHostForRank(m->destination());
bool isLocal = otherHost == thisHost;

if (m->count() > 0) {
std::move(m->buffer().begin(), m->buffer().end(), buffer);
if (isLocal) {
std::memcpy(buffer, (void*)m->bufferptr(), count * dataType->size);
} else {
// TODO - avoid copy here
std::move(m->buffer().begin(), m->buffer().end(), buffer);
}
}

// Set status values if required
Expand Down
7 changes: 6 additions & 1 deletion src/mpi/mpi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ message MPIMessage {
int32 destination = 5;
int32 type = 6;
int32 count = 7;
bytes buffer = 8;

// For remote messaging
optional bytes buffer = 8;

// For local messaging
optional int64 bufferPtr = 9;
}

0 comments on commit 8375d31

Please sign in to comment.