-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathpalsSettings.py
More file actions
243 lines (190 loc) · 8.38 KB
/
palsSettings.py
File metadata and controls
243 lines (190 loc) · 8.38 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# BSD 2-Clause License
#
# Copyright (c) 2021-2025, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import typing as t
from ..log import get_logger
from .mpiSettings import _BaseMPISettings
logger = get_logger(__name__)
class PalsMpiexecSettings(_BaseMPISettings):
"""Settings to run job with ``mpiexec`` under the HPE Cray
Parallel Application Launch Service (PALS)
Note that environment variables can be passed with a None
value to signify that they should be exported from the current
environment
Any arguments passed in the ``run_args`` dict will be converted
into ``mpiexec`` arguments and prefixed with ``--``. Values of
None can be provided for arguments that do not have values.
:param exe: executable
:param exe_args: executable arguments
:param run_args: arguments for run command
:param env_vars: environment vars to launch job with
"""
def __init__(
self,
exe: str,
exe_args: str | list[str] | None = None,
run_args: dict[str, int | str | float | None] | None = None,
env_vars: dict[str, str | None] | None = None,
fail_if_missing_exec: bool = True,
**kwargs: t.Any,
) -> None:
"""Settings to format run job with an MPI-standard binary
Note that environment variables can be passed with a None
value to signify that they should be exported from the current
environment
Any arguments passed in the ``run_args`` dict will be converted
command line arguments and prefixed with ``--``. Values of
None can be provided for arguments that do not have values.
:param exe: executable
:param exe_args: executable arguments
:param run_args: arguments for run command
:param env_vars: environment vars to launch job with
:param fail_if_missing_exec: Throw an exception of the MPI command
is missing. Otherwise, throw a warning
"""
super().__init__(
exe,
exe_args,
run_command="mpiexec",
run_args=run_args,
env_vars=env_vars,
fail_if_missing_exec=fail_if_missing_exec,
**kwargs,
)
def set_task_map(self, task_mapping: str) -> None:
"""Set ``mpirun`` task mapping
this sets ``--map-by <mapping>``
For examples, see the man page for ``mpirun``
:param task_mapping: task mapping
"""
logger.warning("set_task_map not supported under PALS")
def set_cpus_per_task(self, cpus_per_task: int) -> None:
"""Set the number of tasks for this job
This sets ``--cpus-per-proc`` for MPI compliant implementations
note: this option has been deprecated in openMPI 4.0+
and will soon be replaced.
:param cpus_per_task: number of tasks
"""
logger.warning("set_cpus_per_task not supported under PALS")
def set_cpu_binding_type(self, bind_type: str) -> None:
"""Specifies the cores to which MPI processes are bound
This sets ``--bind-to`` for MPI compliant implementations
:param bind_type: binding type
"""
self.run_args["cpu-bind"] = bind_type
def set_tasks(self, tasks: int) -> None:
"""Set the number of tasks
:param tasks: number of total tasks to launch
"""
self.run_args["np"] = int(tasks)
def set_tasks_per_node(self, tasks_per_node: int) -> None:
"""Set the number of tasks per node
:param tasks_per_node: number of tasks to launch per node
"""
self.run_args["ppn"] = int(tasks_per_node)
def set_quiet_launch(self, quiet: bool) -> None:
"""Set the job to run in quiet mode
This sets ``--quiet``
:param quiet: Whether the job should be run quietly
"""
logger.warning("set_quiet_launch not supported under PALS")
def set_broadcast(self, dest_path: str | None = None) -> None:
"""Copy the specified executable(s) to remote machines
This sets ``--preload-binary``
:param dest_path: Destination path (Ignored)
"""
if dest_path is not None and isinstance(dest_path, str):
logger.warning(
(
f"{type(self)} cannot set a destination path during broadcast. "
"Using session directory instead"
)
)
self.run_args["transfer"] = None
def set_launcher_args(
self, arguments: t.Dict[str, t.Union[int, str, float, None]]
) -> None:
"""Set any other task launcher argument
:param arguments: dictionary with string name and value
"""
for name, value in arguments.items():
self.run_args[name] = value
def set_walltime(self, walltime: str) -> None:
"""Set the maximum number of seconds that a job will run
:param walltime: number like string of seconds that a job will run in secs
"""
logger.warning("set_walltime not supported under PALS")
def set_gpu_affinity_script(self, affinity: str, *args: t.Any) -> None:
"""Set the GPU affinity through a bash script
:param affinity: path to the affinity script
"""
self.affinity_script.append(str(affinity))
for arg in args:
self.affinity_script.append(str(arg))
def format_run_args(self) -> list[str]:
"""Return a list of MPI-standard formatted run arguments
:return: list of MPI-standard arguments for these settings
"""
# args launcher uses
args = []
restricted = ["wdir", "wd"]
for opt, value in self.run_args.items():
if opt not in restricted:
prefix = "--"
if not value:
args += [prefix + opt]
else:
args += [prefix + opt, str(value)]
if self.affinity_script:
args += self.affinity_script
return args
def format_env_vars(self) -> list[str]:
"""Format the environment variables for mpirun
:return: list of env vars
"""
formatted = []
export_vars = []
if self.env_vars:
for name, value in self.env_vars.items():
if value:
formatted += ["--env", "=".join((name, str(value)))]
else:
export_vars.append(name)
if export_vars:
formatted += ["--envlist", ",".join(export_vars)]
return formatted
def set_hostlist(self, host_list: str | list[str]) -> None:
"""Set the hostlist for the PALS ``mpiexec`` command
This sets ``--hosts``
:param host_list: list of host names
:raises TypeError: if not str or list of str
"""
if isinstance(host_list, str):
host_list = [host_list.strip()]
if not isinstance(host_list, list):
raise TypeError("host_list argument must be a list of strings")
if not all(isinstance(host, str) for host in host_list):
raise TypeError("host_list argument must be list of strings")
self.run_args["hosts"] = ",".join(host_list)