forked from E3SM-Project/mache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parallel_args.py
More file actions
206 lines (163 loc) · 5.39 KB
/
test_parallel_args.py
File metadata and controls
206 lines (163 loc) · 5.39 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
from configparser import ConfigParser
from mache.parallel.pbs import PbsSystem
from mache.parallel.slurm import SlurmSystem
def _get_config(parallel_items: dict[str, str]) -> ConfigParser:
config = ConfigParser()
config.add_section('build')
config.set('build', 'compiler', 'gnu')
config.add_section('parallel')
for key, value in parallel_items.items():
config.set('parallel', key, value)
return config
def test_slurm_default_gpus_per_task_flag(monkeypatch):
config = _get_config(
{
'parallel_executable': 'srun --label',
'cores_per_node': '32',
'max_mpi_tasks_per_node': '16',
}
)
monkeypatch.setenv('SLURM_JOB_ID', '12345')
monkeypatch.setattr(
'mache.parallel.slurm._get_subprocess_int', lambda args: 2
)
system = SlurmSystem(config)
args = system._get_parallel_args(
cpus_per_task=2, gpus_per_task=3, ntasks=4
)
assert '--gpus-per-task' in args
index = args.index('--gpus-per-task')
assert args[index + 1] == '3'
def test_slurm_custom_gpus_per_task_flag(monkeypatch):
config = _get_config(
{
'parallel_executable': 'srun --label',
'cores_per_node': '32',
'max_mpi_tasks_per_node': '16',
'gpus_per_task_flag': '--gres=gpu',
}
)
monkeypatch.setenv('SLURM_JOB_ID', '12345')
monkeypatch.setattr(
'mache.parallel.slurm._get_subprocess_int', lambda args: 2
)
system = SlurmSystem(config)
args = system._get_parallel_args(
cpus_per_task=2, gpus_per_task=1, ntasks=4
)
assert '--gres=gpu' in args
index = args.index('--gres=gpu')
assert args[index + 1] == '1'
def test_slurm_uses_minimum_nodes_for_single_task(monkeypatch):
config = _get_config(
{
'parallel_executable': 'srun --label',
'cores_per_node': '32',
'max_mpi_tasks_per_node': '4',
}
)
monkeypatch.setenv('SLURM_JOB_ID', '12345')
monkeypatch.setattr(
'mache.parallel.slurm._get_subprocess_int', lambda args: 6
)
system = SlurmSystem(config)
args = system._get_parallel_args(
cpus_per_task=1, gpus_per_task=1, ntasks=1
)
index = args.index('-N')
assert args[index + 1] == '1'
def test_slurm_uses_minimum_nodes_for_task_count(monkeypatch):
config = _get_config(
{
'parallel_executable': 'srun --label',
'cores_per_node': '32',
'max_mpi_tasks_per_node': '4',
}
)
monkeypatch.setenv('SLURM_JOB_ID', '12345')
monkeypatch.setattr(
'mache.parallel.slurm._get_subprocess_int', lambda args: 6
)
system = SlurmSystem(config)
args = system._get_parallel_args(
cpus_per_task=1, gpus_per_task=0, ntasks=17
)
index = args.index('-N')
assert args[index + 1] == '5'
def test_pbs_skips_gpu_flag_when_not_configured(monkeypatch):
config = _get_config(
{
'parallel_executable': 'mpiexec --label',
'cores_per_node': '32',
'max_mpi_tasks_per_node': '4',
'cpus_per_task_flag': '--depth',
}
)
monkeypatch.setenv('PBS_JOBID', '12345.server')
monkeypatch.setattr(
PbsSystem, '_get_node_count_from_qstat', lambda self: 2
)
system = PbsSystem(config)
args = system._get_parallel_args(
cpus_per_task=2, gpus_per_task=1, ntasks=4
)
assert '--gpus-per-task' not in args
def test_pbs_uses_configured_gpu_flag(monkeypatch):
config = _get_config(
{
'parallel_executable': 'mpiexec --label',
'cores_per_node': '32',
'max_mpi_tasks_per_node': '4',
'cpus_per_task_flag': '--depth',
'gpus_per_task_flag': '--gpus-per-task',
}
)
monkeypatch.setenv('PBS_JOBID', '12345.server')
monkeypatch.setattr(
PbsSystem, '_get_node_count_from_qstat', lambda self: 2
)
system = PbsSystem(config)
args = system._get_parallel_args(
cpus_per_task=2, gpus_per_task=1, ntasks=4
)
assert '--gpus-per-task' in args
index = args.index('--gpus-per-task')
assert args[index + 1] == '1'
def test_pbs_uses_minimum_nodes_for_single_task(monkeypatch):
config = _get_config(
{
'parallel_executable': 'mpiexec --label',
'cores_per_node': '32',
'max_mpi_tasks_per_node': '4',
'cpus_per_task_flag': '--depth',
}
)
monkeypatch.setenv('PBS_JOBID', '12345.server')
monkeypatch.setattr(
PbsSystem, '_get_node_count_from_qstat', lambda self: 6
)
system = PbsSystem(config)
args = system._get_parallel_args(
cpus_per_task=1, gpus_per_task=0, ntasks=1
)
index = args.index('--ppn')
assert args[index + 1] == '1'
def test_pbs_uses_minimum_nodes_for_task_count(monkeypatch):
config = _get_config(
{
'parallel_executable': 'mpiexec --label',
'cores_per_node': '32',
'max_mpi_tasks_per_node': '4',
'cpus_per_task_flag': '--depth',
}
)
monkeypatch.setenv('PBS_JOBID', '12345.server')
monkeypatch.setattr(
PbsSystem, '_get_node_count_from_qstat', lambda self: 6
)
system = PbsSystem(config)
args = system._get_parallel_args(
cpus_per_task=1, gpus_per_task=0, ntasks=17
)
index = args.index('--ppn')
assert args[index + 1] == '4'