Skip to content

Commit 201eb69

Browse files
authored
Merge pull request #4034 from lindsayad/mpi-thread-cli
Add mpi thread command line option
2 parents 96131d2 + fde2dd2 commit 201eb69

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/base/libmesh.C

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ LibMeshInit::LibMeshInit (int argc, const char * const * argv,
383383
libMesh::perflog.disable_logging();
384384
}
385385

386+
auto check_empty_command_line_value = [](auto & cl, const std::string & option) {
387+
libmesh_error_msg_if(cl.search(option),
388+
"Detected option " << option << " with no value. Did you forget '='?");
389+
};
390+
386391
// Build a task scheduler
387392
{
388393
// Get the requested number of threads, defaults to 1 to avoid MPI and
@@ -398,9 +403,7 @@ LibMeshInit::LibMeshInit (int argc, const char * const * argv,
398403
if (libMesh::libMeshPrivateData::_n_threads == -1)
399404
{
400405
for (auto & option : n_threads_opt)
401-
libmesh_error_msg_if(command_line->search(option),
402-
"Detected option " << option <<
403-
" with no value. Did you forget '='?");
406+
check_empty_command_line_value(*command_line, option);
404407

405408
libMesh::libMeshPrivateData::_n_threads = 1;
406409
}
@@ -438,8 +441,37 @@ LibMeshInit::LibMeshInit (int argc, const char * const * argv,
438441
// Allow the user to bypass MPI initialization
439442
if (!libMesh::on_command_line ("--disable-mpi"))
440443
{
444+
int mpi_thread_request = using_threads;
445+
const auto mpi_thread_type = libMesh::command_line_value("--mpi-thread-type", std::string(""));
446+
if (mpi_thread_type.empty())
447+
check_empty_command_line_value(*command_line, "--mpi-thread-type");
448+
else
449+
{
450+
int cli_mpi_thread_request;
451+
if (mpi_thread_type == "single")
452+
{
453+
if (using_threads)
454+
libmesh_error_msg("We are using threads, so we require more mpi thread support "
455+
"than '--mpi-thread-type=single'");
456+
cli_mpi_thread_request = 0;
457+
}
458+
else if (mpi_thread_type == "funneled")
459+
cli_mpi_thread_request = 1;
460+
else if (mpi_thread_type == "serialized")
461+
cli_mpi_thread_request = 2;
462+
else if (mpi_thread_type == "multiple")
463+
cli_mpi_thread_request = 3;
464+
else
465+
libmesh_error_msg(
466+
"Unsupported mpi thread type '"
467+
<< mpi_thread_type
468+
<< "'. Allowed options are 'single', 'funneled', 'serialized', and 'multiple'");
469+
470+
mpi_thread_request = cli_mpi_thread_request;
471+
}
472+
441473
this->_timpi_init =
442-
new TIMPI::TIMPIInit(argc, argv, using_threads,
474+
new TIMPI::TIMPIInit(argc, argv, mpi_thread_request,
443475
handle_mpi_errors, COMM_WORLD_IN);
444476
_comm = new Parallel::Communicator(this->_timpi_init->comm().get());
445477

0 commit comments

Comments
 (0)