Commit b3eb46ae authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Avoid initing MPI in Python interpreter.

When`paraview` is imported in a standard Python interpreter (not via
pvpython), we ended up initializing MPI due to !1987. That caused
failures generating sphinx documentation with Python 3. In any cause, it
sounds like a risky move to init MPI in a standard Python interpreter
unless user explicitly asked for. They do can that by doing the
following:

    import paraview
    paraview.options.batch = True
parent 665d553e
......@@ -530,4 +530,6 @@ void vtkPVOptions::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "SatelliteMessageIds " << this->SatelliteMessageIds << std::endl;
os << indent << "PrintMonitors: " << this->PrintMonitors << std::endl;
os << indent << "DisableXDisplayTests: " << this->DisableXDisplayTests << endl;
os << indent << "ForceNoMPIInitOnClient: " << this->ForceNoMPIInitOnClient << endl;
os << indent << "ForceMPIInitOnClient: " << this->ForceMPIInitOnClient << endl;
}
......@@ -248,6 +248,24 @@ public:
*/
vtkGetMacro(ForceOnscreenRendering, int);
//@{
/**
* Get/Set the ForceNoMPIInitOnClient flag.
*/
vtkGetMacro(ForceNoMPIInitOnClient, int);
vtkSetMacro(ForceNoMPIInitOnClient, int);
vtkBooleanMacro(ForceNoMPIInitOnClient, int);
//@}
//@{
/**
* Get/Set the ForceMPIInitOnClient flag.
*/
vtkGetMacro(ForceMPIInitOnClient, int);
vtkSetMacro(ForceMPIInitOnClient, int);
vtkBooleanMacro(ForceMPIInitOnClient, int);
//@}
enum ProcessTypeEnum
{
PARAVIEW = 0x2,
......
......@@ -32,6 +32,7 @@ PURPOSE. See the above copyright notice for more information.
#include <sstream>
#include <string>
#include <vector>
#include <vtksys/SystemTools.hxx>
// Windows-only helper functionality:
......@@ -144,16 +145,29 @@ void vtkInitializationHelper::Initialize(const char* executable, int type, vtkPV
}
// Pass the program name to make option parser happier
char* argv = new char[strlen(executable) + 1];
strcpy(argv, executable);
vtkSmartPointer<vtkPVOptions> newoptions = options;
if (!options)
{
newoptions = vtkSmartPointer<vtkPVOptions>::New();
}
vtkInitializationHelper::Initialize(1, &argv, type, newoptions);
delete[] argv;
std::vector<char*> argv;
argv.push_back(vtksys::SystemTools::DuplicateString(executable));
if (newoptions->GetForceNoMPIInitOnClient())
{
argv.push_back(vtksys::SystemTools::DuplicateString("--no-mpi"));
}
if (newoptions->GetForceMPIInitOnClient())
{
argv.push_back(vtksys::SystemTools::DuplicateString("--mpi"));
}
vtkInitializationHelper::Initialize(static_cast<int>(argv.size()), &argv[0], type, newoptions);
for (auto tofree : argv)
{
delete[] tofree;
}
}
//----------------------------------------------------------------------------
......
......@@ -36,14 +36,23 @@ public:
vtkTypeMacro(vtkInitializationHelper, vtkObject);
void PrintSelf(ostream&, vtkIndent) VTK_OVERRIDE;
//@{
/**
* Initializes the server manager. Do not use the server manager
* before calling this.
*/
static void Initialize(const char* executable, int type);
/**
* Initializes the server manager. Do not use the server manager
* before calling this. In this variant, one passes in a vtkPVOptions
* instance.
*
* @note `--no-mpi` and `--mpi` options are handled specially, by this call.
* If you want to pass those to vtkProcessModule so it doesn't (or does)
* initialize MPI, set the corresponding ivars on the `options` object passed
* in.
*/
static void Initialize(const char* executable, int type, vtkPVOptions* options);
//@}
/**
* Alternative API to initialize the server manager. This takes in the
......
......@@ -3145,9 +3145,8 @@ def SetActiveConnection(connection=None):
# servermanager.Finalize() may also be needed to exit properly without
# VTK_DEBUG_LEAKS reporting memory leaks.
if not vtkProcessModule.GetProcessModule():
pvoptions = None
pvoptions = vtkPVOptions();
if paraview.options.batch:
pvoptions = vtkPVOptions();
pvoptions.SetProcessType(vtkPVOptions.PVBATCH)
if paraview.options.symmetric:
pvoptions.SetSymmetricMPIMode(True)
......@@ -3165,6 +3164,8 @@ if not vtkProcessModule.GetProcessModule():
pm.UnRegisterSession(sid)
else:
pvoptions.SetProcessType(vtkPVOptions.PVCLIENT)
pvoptions.SetForceNoMPIInitOnClient(1)
vtkInitializationHelper.Initialize(sys.executable,
vtkProcessModule.PROCESS_CLIENT, pvoptions)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment