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

fix for -ll:networks none, we will init MPI if it has not been initialized #465

Merged
merged 4 commits into from
Nov 7, 2022
Merged
Changes from all commits
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
33 changes: 22 additions & 11 deletions src/core/comm/coll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static int current_unique_id = 0;

static bool coll_inited = false;

static bool self_mpi_init = false;

// functions start here
#ifdef LEGATE_USE_NETWORK
static inline std::pair<int, int> mostFrequent(const int* arr, int n);
Expand Down Expand Up @@ -242,23 +244,31 @@ int collInit(int argc, char* argv[])
{
current_unique_id = 0;
#ifdef LEGATE_USE_NETWORK
int provided, init_flag = 0;
int init_flag = 0;
CHECK_MPI(MPI_Initialized(&init_flag));
if (!init_flag) {
log_coll.fatal(
"MPI has not been initialized, it should be initialized by "
"the networking backend");
LEGATE_ABORT;
} else {
int mpi_thread_model;
MPI_Query_thread(&mpi_thread_model);
if (mpi_thread_model != MPI_THREAD_MULTIPLE) {
char* network = getenv("LEGATE_NEED_NETWORK");
int need_network = 0;
if (network != nullptr) { need_network = atoi(network); }
if (need_network) {
log_coll.fatal(
"MPI has been initialized by others, but is not initialized with "
"MPI_THREAD_MULTIPLE");
"MPI has not been initialized, it should be initialized by "
"the networking backend.");
LEGATE_ABORT;
} else {
int provided;
MPI_Init_thread(0, 0, MPI_THREAD_MULTIPLE, &provided);
self_mpi_init = true;
}
}
int mpi_thread_model;
MPI_Query_thread(&mpi_thread_model);
if (mpi_thread_model != MPI_THREAD_MULTIPLE) {
log_coll.fatal(
"MPI has been initialized by others, but is not initialized with "
"MPI_THREAD_MULTIPLE");
LEGATE_ABORT;
}
// check
int *tag_ub, flag;
CHECK_MPI(MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_TAG_UB, &tag_ub, &flag));
Expand All @@ -285,6 +295,7 @@ int collFinalize()
log_coll.fatal("MPI should not have been finalized");
LEGATE_ABORT;
}
if (self_mpi_init) { CHECK_MPI(MPI_Finalize()); }
#else
for (ThreadComm* thread_comm : thread_comms) {
assert(!thread_comm->ready_flag);
Expand Down