Merge topic 'mpi-init'

90c7e7707 Initialize DIY in vtkm::cont::Initialize

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Vicente Bolea <vicente.bolea@kitware.com>
Merge-request: !2880
This commit is contained in:
Kenneth Moreland 2022-10-09 16:58:54 +00:00 committed by Kitware Robot
commit 53420f2b36
2 changed files with 27 additions and 3 deletions

@ -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.

@ -15,6 +15,8 @@
#include <vtkm/cont/internal/OptionParser.h>
#include <vtkm/cont/internal/OptionParserArguments.h>
#include <vtkm/thirdparty/diy/environment.h>
#include <memory>
#include <sstream>
@ -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<opt::Descriptor> 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