From 04892b3dadda222e59a1ae497b93be9c7cef066f Mon Sep 17 00:00:00 2001 From: "Igoshev, Iaroslav" Date: Tue, 7 Nov 2023 21:44:15 +0000 Subject: [PATCH] REFACTOR-#000: Change IsMpiSpawnWorkers to MpiSpawn to make it more concise Signed-off-by: Igoshev, Iaroslav --- docs/flow/unidist/config.rst | 2 +- docs/using_unidist/unidist_on_mpi.rst | 20 +++++++++---------- unidist/config/__init__.py | 4 ++-- unidist/config/backends/mpi/__init__.py | 4 ++-- unidist/config/backends/mpi/envvars.py | 4 ++-- unidist/core/backends/mpi/core/common.py | 4 ++-- .../core/backends/mpi/core/controller/api.py | 12 +++++------ 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/flow/unidist/config.rst b/docs/flow/unidist/config.rst index 5b623f52..5992e73f 100644 --- a/docs/flow/unidist/config.rst +++ b/docs/flow/unidist/config.rst @@ -48,7 +48,7 @@ Unidist Configuration Settings List +-------------------------------+-------------------------------------------+--------------------------------------------------------------------------+ | DaskSchedulerAddress | UNIDIST_DASK_SCHEDULER_ADDRESS | Dask Scheduler address to connect to when running in Dask cluster | +-------------------------------+-------------------------------------------+--------------------------------------------------------------------------+ -| IsMpiSpawnWorkers | UNIDIST_IS_MPI_SPAWN_WORKERS | Whether to enable MPI spawn or not | +| MpiSpawn | UNIDIST_MPI_SPAWN | Whether to enable MPI spawn or not | +-------------------------------+-------------------------------------------+--------------------------------------------------------------------------+ | MpiHosts | UNIDIST_MPI_HOSTS | MPI hosts to run unidist on | +-------------------------------+-------------------------------------------+--------------------------------------------------------------------------+ diff --git a/docs/using_unidist/unidist_on_mpi.rst b/docs/using_unidist/unidist_on_mpi.rst index 37a2159d..2f96e885 100644 --- a/docs/using_unidist/unidist_on_mpi.rst +++ b/docs/using_unidist/unidist_on_mpi.rst @@ -71,25 +71,25 @@ SPMD model ---------- First of all, to run unidist on MPI in a single node using `SPMD model `_, -you should set the ``UNIDIST_IS_MPI_SPAWN_WORKERS`` environment variable to ``False``: +you should set the ``UNIDIST_MPI_SPAWN`` environment variable to ``False``: .. code-block:: bash - $ export UNIDIST_IS_MPI_SPAWN_WORKERS=False + $ export UNIDIST_MPI_SPAWN=False .. code-block:: python import os - os.environ["UNIDIST_IS_MPI_SPAWN_WORKERS"] = "False" + os.environ["UNIDIST_MPI_SPAWN"] = "False" or set the associated configuration value: .. code-block:: python - from unidist.config import IsMpiSpawnWorkers + from unidist.config import MpiSpawn - IsMpiSpawnWorkers.put(False) + MpiSpawn.put(False) This will enable unidist not to spawn MPI processes dynamically because the user himself spawns the processes. @@ -146,25 +146,25 @@ SPMD model """""""""" First of all, to run unidist on MPI in a cluster using `SPMD model `_, -you should set the ``UNIDIST_IS_MPI_SPAWN_WORKERS`` environment variable to ``False``: +you should set the ``UNIDIST_MPI_SPAWN`` environment variable to ``False``: .. code-block:: bash - $ export UNIDIST_IS_MPI_SPAWN_WORKERS=False + $ export UNIDIST_MPI_SPAWN=False .. code-block:: python import os - os.environ["UNIDIST_IS_MPI_SPAWN_WORKERS"] = "False" + os.environ["UNIDIST_MPI_SPAWN"] = "False" or set the associated configuration value: .. code-block:: python - from unidist.config import IsMpiSpawnWorkers + from unidist.config import MpiSpawn - IsMpiSpawnWorkers.put(False) + MpiSpawn.put(False) This will enable unidist not to spawn MPI processes dynamically because the user himself spawns the processes. diff --git a/unidist/config/__init__.py b/unidist/config/__init__.py index cb6ae4f2..ae055ae3 100644 --- a/unidist/config/__init__.py +++ b/unidist/config/__init__.py @@ -14,7 +14,7 @@ ) from .backends.dask import DaskMemoryLimit, IsDaskCluster, DaskSchedulerAddress from .backends.mpi import ( - IsMpiSpawnWorkers, + MpiSpawn, MpiHosts, MpiPickleThreshold, MpiBackoff, @@ -38,7 +38,7 @@ "DaskMemoryLimit", "IsDaskCluster", "DaskSchedulerAddress", - "IsMpiSpawnWorkers", + "MpiSpawn", "MpiHosts", "ValueSource", "MpiPickleThreshold", diff --git a/unidist/config/backends/mpi/__init__.py b/unidist/config/backends/mpi/__init__.py index 8e42caf7..3cf11ac1 100644 --- a/unidist/config/backends/mpi/__init__.py +++ b/unidist/config/backends/mpi/__init__.py @@ -5,7 +5,7 @@ """Config entities specific for MPI backend which can be used for unidist behavior tuning.""" from .envvars import ( - IsMpiSpawnWorkers, + MpiSpawn, MpiHosts, MpiPickleThreshold, MpiBackoff, @@ -18,7 +18,7 @@ ) __all__ = [ - "IsMpiSpawnWorkers", + "MpiSpawn", "MpiHosts", "MpiPickleThreshold", "MpiBackoff", diff --git a/unidist/config/backends/mpi/envvars.py b/unidist/config/backends/mpi/envvars.py index 95a69bcf..3fe01ef8 100644 --- a/unidist/config/backends/mpi/envvars.py +++ b/unidist/config/backends/mpi/envvars.py @@ -7,11 +7,11 @@ from unidist.config.parameter import EnvironmentVariable, ExactStr -class IsMpiSpawnWorkers(EnvironmentVariable, type=bool): +class MpiSpawn(EnvironmentVariable, type=bool): """Whether to enable MPI spawn or not.""" default = True - varname = "UNIDIST_IS_MPI_SPAWN_WORKERS" + varname = "UNIDIST_MPI_SPAWN" class MpiHosts(EnvironmentVariable, type=ExactStr): diff --git a/unidist/core/backends/mpi/core/common.py b/unidist/core/backends/mpi/core/common.py index 40abfa75..2bb8af80 100755 --- a/unidist/core/backends/mpi/core/common.py +++ b/unidist/core/backends/mpi/core/common.py @@ -8,7 +8,7 @@ import inspect import weakref -from unidist.config.backends.mpi.envvars import IsMpiSpawnWorkers +from unidist.config.backends.mpi.envvars import MpiSpawn from unidist.core.backends.mpi.utils import ImmutableDict try: @@ -485,7 +485,7 @@ def is_shared_memory_supported(): # Mpich shared memory does not work with spawned processes prior to version 4.2.0. if ( "MPICH" in MPI.Get_library_version() - and IsMpiSpawnWorkers.get() + and MpiSpawn.get() and not check_mpich_version("4.2.0") ): return False diff --git a/unidist/core/backends/mpi/core/controller/api.py b/unidist/core/backends/mpi/core/controller/api.py index 6686385a..e406d53d 100644 --- a/unidist/core/backends/mpi/core/controller/api.py +++ b/unidist/core/backends/mpi/core/controller/api.py @@ -34,7 +34,7 @@ from unidist.core.backends.mpi.core.async_operations import AsyncOperations from unidist.config import ( CpuCount, - IsMpiSpawnWorkers, + MpiSpawn, MpiHosts, ValueSource, MpiPickleThreshold, @@ -145,7 +145,7 @@ def init(): # Path to dynamically spawn MPI processes. # If a requirement is not met, processes have been started with mpiexec -n , where N > 1. - if rank == 0 and parent_comm == MPI.COMM_NULL and IsMpiSpawnWorkers.get(): + if rank == 0 and parent_comm == MPI.COMM_NULL and MpiSpawn.get(): args = _get_py_flags() args += ["-c"] py_str = [ @@ -153,8 +153,8 @@ def init(): "import unidist.config as cfg", "cfg.Backend.put('mpi')", ] - if IsMpiSpawnWorkers.get_value_source() != ValueSource.DEFAULT: - py_str += [f"cfg.IsMpiSpawnWorkers.put({IsMpiSpawnWorkers.get()})"] + if MpiSpawn.get_value_source() != ValueSource.DEFAULT: + py_str += [f"cfg.MpiSpawn.put({MpiSpawn.get()})"] if MpiHosts.get_value_source() != ValueSource.DEFAULT: py_str += [f"cfg.MpiHosts.put('{MpiHosts.get()}')"] if CpuCount.get_value_source() != ValueSource.DEFAULT: @@ -276,7 +276,7 @@ def init(): # If the user executes a program in SPMD mode, # we do not want workers to continue the flow after `unidist.init()` # so just killing them. - if not IsMpiSpawnWorkers.get(): + if not MpiSpawn.get(): sys.exit() return else: @@ -286,7 +286,7 @@ def init(): # If the user executes a program in SPMD mode, # we do not want workers to continue the flow after `unidist.init()` # so just killing them. - if not IsMpiSpawnWorkers.get(): + if not MpiSpawn.get(): sys.exit() return