1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
From: Drew Parsons <dparsons@debian.org>
Date: Sat, 7 Sep 2024 01:05:07 +0200
Subject: avoid running mpi with serial (1 process) jobs
===================================================================
---
bindings/Python/__init__.py.in | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/bindings/Python/__init__.py.in b/bindings/Python/__init__.py.in
index fb6c0ad..705091b 100644
--- a/bindings/Python/__init__.py.in
+++ b/bindings/Python/__init__.py.in
@@ -1,3 +1,23 @@
-from .adios2_bindings@ADIOS2_LIBRARY_SUFFIX@ import *
+# avoid running mpi with serial (1 process) jobs
+# by checking whether mpi is actually being used over multiple processes
+# Probe number of processes with OMPI_COMM_WORLD_SIZE (openmpi) and MPI_LOCALNRANKS (mpich)
+
+from os import getenv as os_getenv
+from sys import modules as sys_modules
+from importlib import import_module
+
+_OPENMPI_MULTIPROC = os_getenv('OMPI_COMM_WORLD_SIZE') is not None
+_MPICH_MULTIPROC = os_getenv('MPI_LOCALNRANKS') is not None
+_MPI_USE_ALWAYS = os_getenv('ADIOS2_ALWAYS_USE_MPI') is not None
+
+_MPI_ACTIVE = _OPENMPI_MULTIPROC or _MPICH_MULTIPROC or _MPI_USE_ALWAYS
+
+if _MPI_ACTIVE:
+ try:
+ from .adios2_bindings_mpi import *
+ except:
+ from .adios2_bindings_serial import *
+else:
+ from .adios2_bindings_serial import *
__version__ = "@ADIOS2_VERSION@"
|