Skip to content

Commit cec4ac6

Browse files
authored
Merge pull request #3464 from jack-morrison/jackm/launcher-fwd-env-vars
[feat] Enable launchers to forward environment variables
2 parents d18ad22 + 995a9e7 commit cec4ac6

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

docs/config_reference.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,10 @@ System Partition Configuration
518518
The program will be launched locally.
519519
- ``lrun``: Parallel programs will be launched using `LC Launcher <https://hpc.llnl.gov/training/tutorials/using-lcs-sierra-system#lrun>`__'s ``lrun`` command.
520520
- ``lrun-gpu``: Parallel programs will be launched using `LC Launcher <https://hpc.llnl.gov/training/tutorials/using-lcs-sierra-system#lrun>`__'s ``lrun -M "-gpu"`` command that enables the CUDA-aware Spectrum MPI.
521-
- ``mpirun``: Parallel programs will be launched using the ``mpirun`` command.
522521
- ``mpiexec``: Parallel programs will be launched using the ``mpiexec`` command.
522+
- ``mpirun``: Parallel programs will be launched using the (generic) ``mpirun`` command.
523+
- ``mpirun-intelmpi``: Parallel programs will be launched using the Intel MPI's ``mpirun`` command.
524+
- ``mpirun-openmpi``: Parallel programs will be launched using the OpenMPI's ``mpirun`` command.
523525
- ``pdsh``: Parallel programs will be launched using the ``pdsh`` command. This launcher uses the partition's :attr:`~config.systems.partitions.access` property in order to determine the options to be passed to ``pdsh``.
524526
- ``srun``: Parallel programs will be launched using `Slurm <https://slurm.schedmd.com/srun.html>`__'s ``srun`` command.
525527
- ``srunalloc``: Parallel programs will be launched using `Slurm <https://slurm.schedmd.com/srun.html>`__'s ``srun`` command, but job allocation options will also be emitted.
@@ -542,6 +544,10 @@ System Partition Configuration
542544
- ``upcrun``: Parallel programs will be launched using the `UPC <https://upc.lbl.gov/>`__ ``upcrun`` command.
543545
- ``upcxx-run``: Parallel programs will be launched using the `UPC++ <https://bitbucket.org/berkeleylab/upcxx/wiki/Home>`__ ``upcxx-run`` command.
544546

547+
.. versionadded:: 4.9
548+
549+
The ``mpirun-intelmpi`` and ``mpirun-openmpi`` parallel launchers were added.
550+
545551
.. tip::
546552

547553
.. versionadded:: 4.0.0

reframe/core/launchers/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ class JobLauncher(metaclass=_JobLauncherMeta):
3636
#: :default: ``[]``
3737
options = variable(typ.List[str], value=[])
3838

39+
#: Dictionary of environment variables to be passed via the job launcher
40+
#: invocation. The keys are the variable names and the values are their
41+
#: corresponding values.
42+
#:
43+
#: This is supported by the following launchers only:
44+
#:
45+
#: - ``srun``
46+
#: - ``mpirun-openmpi``
47+
#: - ``mpirun-intelmpi``
48+
#:
49+
#: :type: :class:`Dict[str, str]`
50+
#: :default: ``{}``
51+
#:
52+
#: .. versionadded:: 4.9
53+
env_vars = variable(typ.Dict[str, str], value={})
54+
3955
#: Optional modifier of the launcher command.
4056
#:
4157
#: This will be combined with the :attr:`modifier_options` and prepended to
@@ -59,6 +75,7 @@ class JobLauncher(metaclass=_JobLauncherMeta):
5975

6076
def __init__(self):
6177
self.options = []
78+
self.env_vars = {}
6279

6380
@abc.abstractmethod
6481
def command(self, job):

reframe/core/launchers/mpi.py

+22
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def command(self, job):
4848
if self.use_cpus_per_task and job.num_cpus_per_task:
4949
ret.append(f'--cpus-per-task={job.num_cpus_per_task}')
5050

51+
if self.env_vars:
52+
env_vars = ','.join(f'{k}={v}' for k, v in self.env_vars.items())
53+
ret.append(f'--export={env_vars}')
54+
5155
return ret
5256

5357

@@ -109,6 +113,24 @@ def command(self, job):
109113
return ['mpirun', '-np', str(job.num_tasks)]
110114

111115

116+
@register_launcher('mpirun-openmpi')
117+
class MpirunOpenMPILauncher(JobLauncher):
118+
def command(self, job):
119+
cmd = ['mpirun', '-np', str(job.num_tasks)]
120+
for name, value in self.env_vars.items():
121+
cmd += ['-x', f'{name}={value}']
122+
return cmd
123+
124+
125+
@register_launcher('mpirun-intelmpi')
126+
class MpirunIntelMPILauncher(JobLauncher):
127+
def command(self, job):
128+
cmd = ['mpirun', '-np', str(job.num_tasks)]
129+
for name, value in self.env_vars.items():
130+
cmd += ['-genv', name, value]
131+
return cmd
132+
133+
112134
@register_launcher('mpiexec')
113135
class MpiexecLauncher(JobLauncher):
114136
def command(self, job):

unittests/test_launchers.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def job(make_job, launcher):
9292
job.exclusive_access = True
9393
job.options = ['--gres=gpu:4', '#DW jobdw anything']
9494
job.launcher.options = ['--foo']
95+
job.launcher.env_vars = {'FOO': 'bar', 'BAR': 'baz'}
9596
return job
9697

9798

@@ -127,7 +128,20 @@ def test_run_command(job):
127128
elif launcher_name == 'mpirun':
128129
assert command == 'mpirun -np 4 --foo'
129130
elif launcher_name == 'srun':
130-
assert command == 'srun --cpus-per-task=2 --foo'
131+
assert command == ('srun '
132+
'--cpus-per-task=2 '
133+
'--export=FOO=bar,BAR=baz '
134+
'--foo')
135+
elif launcher_name == 'mpirun-openmpi':
136+
assert command == ('mpirun -np 4 '
137+
'-x FOO=bar '
138+
'-x BAR=baz '
139+
'--foo')
140+
elif launcher_name == 'mpirun-intelmpi':
141+
assert command == ('mpirun -np 4 '
142+
'-genv FOO bar '
143+
'-genv BAR baz '
144+
'--foo')
131145
elif launcher_name == 'srunalloc':
132146
assert command == ('srun '
133147
'--job-name=fake_job '

0 commit comments

Comments
 (0)