-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
57 lines (39 loc) · 1.41 KB
/
config.py
File metadata and controls
57 lines (39 loc) · 1.41 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
"""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
_THREAD_OPTIONS: Tuple[int, ...] = (1, 2)
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()
_MPI_OPTIONS: Tuple[Optional[int], ...] = (None, 2) if (_MPI_ENABLED and _MPI_RUNNER) else (None,)
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__ = [
"_MPI_OPTIONS",
"_MPI_RUNNER",
"_THREAD_OPTIONS",
"_param_key",
"_nan",
]