-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
64 lines (46 loc) · 1.48 KB
/
config.py
File metadata and controls
64 lines (46 loc) · 1.48 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
"""Shared configuration and helpers for OpenMC benchmarks."""
from __future__ import annotations
import math
import os
import shutil
from typing import Optional, Tuple
from .openmc_runner import OpenMCRunner
def _detect_mpi_runner() -> Optional[Tuple[str, ...]]:
for candidate in ("mpirun", "mpiexec"):
if shutil.which(candidate):
return (candidate,)
return None
_MPI_RUNNER = _detect_mpi_runner()
def _detect_mpi_enabled() -> bool:
runner = OpenMCRunner(default_mpi_runner=_MPI_RUNNER)
try:
build_info = runner._get_build_info(runner.openmc_exec, os.environ)
except Exception:
return True
return runner._build_supports_mpi(build_info)
_MPI_ENABLED = _detect_mpi_enabled()
# Explicit list of (threads, MPI procs) configurations to benchmark
_CONFIGS: Tuple[Tuple[int, Optional[int]], ...] = (
(1, None),
(4, None),
)
if _MPI_ENABLED and _MPI_RUNNER:
_CONFIGS += (
(1, 4),
(2, 2),
)
def _param_key(threads: object, mpi_procs: object) -> Tuple[int, Optional[int]]:
thread_val = int(threads) if isinstance(threads, str) else threads
if mpi_procs in (None, "None"):
mpi_val: Optional[int] = None
else:
mpi_val = int(mpi_procs) if isinstance(mpi_procs, str) else mpi_procs
return int(thread_val), mpi_val
def _nan(value: Optional[float]) -> float:
return value if value is not None else math.nan
__all__ = [
"_CONFIGS",
"_MPI_RUNNER",
"_param_key",
"_nan",
]