From 13606efe937e09f830dcb7842c19c44dd18b4e0f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Sun, 14 Jun 2009 16:05:15 -0400 Subject: [PATCH] Add pytools.mpi: Runs a callable with a given number of MPI ranks. --- pytools/mpi.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 pytools/mpi.py diff --git a/pytools/mpi.py b/pytools/mpi.py new file mode 100644 index 0000000..d67106f --- /dev/null +++ b/pytools/mpi.py @@ -0,0 +1,13 @@ +def run_with_mpi_ranks(py_script, ranks, callable, *args, **kwargs): + import os + if "BOOSTMPI_RUN_WITHIN_MPI" in os.environ: + callable(*args, **kwargs) + else: + import sys + newenv = os.environ.copy() + newenv["BOOSTMPI_RUN_WITHIN_MPI"] = "1" + + from subprocess import check_call + check_call(["mpirun", "-np", str(ranks), + sys.executable, py_script], env=newenv) + -- GitLab