From 90c7e77075c33e4d5da2a483830412c3f7d0a108 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Fri, 7 Oct 2022 14:51:21 -0600 Subject: [PATCH] Initialize DIY in vtkm::cont::Initialize This has the side effect of initialing MPI_Init (and will also call MPI_Finalize at program exit). However, if the calling code has already called MPI_Init, then nothing will happen. Thus, if the calling code wants to manage MPI_Init/Finalize, it can do so as long as it does before it initializes VTK-m. --- docs/changelog/mpi-init.md | 8 ++++++++ vtkm/cont/Initialize.cxx | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/mpi-init.md diff --git a/docs/changelog/mpi-init.md b/docs/changelog/mpi-init.md new file mode 100644 index 000000000..fe6041807 --- /dev/null +++ b/docs/changelog/mpi-init.md @@ -0,0 +1,8 @@ +# Initialize DIY in vtkm::cont::Initialize + +This has the side effect of initialing MPI_Init (and will also +call MPI_Finalize at program exit). However, if the calling +code has already called MPI_Init, then nothing will happen. +Thus, if the calling code wants to manage MPI_Init/Finalize, +it can do so as long as it does before it initializes VTK-m. + diff --git a/vtkm/cont/Initialize.cxx b/vtkm/cont/Initialize.cxx index 2c909a1ea..56483691c 100644 --- a/vtkm/cont/Initialize.cxx +++ b/vtkm/cont/Initialize.cxx @@ -15,6 +15,8 @@ #include #include +#include + #include #include @@ -114,7 +116,7 @@ InitializeResult Initialize(int& argc, char* argv[], InitializeOptions opts) const std::string loggingHelp = " " + loggingFlag + " <#|INFO|WARNING|ERROR|FATAL|OFF> \tSpecify a log level (when logging is enabled)."; - // initialize logging first -- it'll pop off the options it consumes: + // initialize logging and diy first -- they'll pop off the options they consume: if (argc == 0 || argv == nullptr) { vtkm::cont::InitLogging(); @@ -123,6 +125,19 @@ InitializeResult Initialize(int& argc, char* argv[], InitializeOptions opts) { vtkm::cont::InitLogging(argc, argv, loggingFlag); } + if (!vtkmdiy::mpi::environment::initialized()) + { + if (argc == 0 || argv == nullptr) + { + // If initialized, will be deleted on program exit (calling MPI_Finalize if necessary) + static vtkmdiy::mpi::environment diyEnvironment; + } + else + { + // If initialized, will be deleted on program exit (calling MPI_Finalize if necessary) + static vtkmdiy::mpi::environment diyEnvironment(argc, argv); + } + } { // Parse VTKm options std::vector usage; @@ -359,8 +374,9 @@ InitializeResult Initialize(int& argc, char* argv[], InitializeOptions opts) VTKM_CONT InitializeResult Initialize() { - vtkm::cont::InitLogging(); - return InitializeResult{}; + int argc = 0; + char** argv = nullptr; + return Initialize(argc, argv); } } } // end namespace vtkm::cont