Isolate util/cpus.py

This commit is contained in:
Douglas Jacobsen 2023-10-12 13:56:24 -06:00
parent a543fd79f1
commit 736c46e22d
4 changed files with 14 additions and 9 deletions

View File

@ -137,7 +137,7 @@ def _install_with_depfile(self) -> None:
"-C", "-C",
str(self.environment_root()), str(self.environment_root()),
"-j", "-j",
str(spack.util.cpus.determine_number_of_jobs(parallel=True)), str(spack.util.cpus.determine_number_of_jobs(parallel=True, config=spack.config.CONFIG)),
**kwargs, **kwargs,
) )

View File

@ -10,6 +10,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
import spack.builder import spack.builder
import spack.config
from spack.build_environment import SPACK_NO_PARALLEL_MAKE from spack.build_environment import SPACK_NO_PARALLEL_MAKE
from spack.directives import build_system, extends, maintainers from spack.directives import build_system, extends, maintainers
from spack.package_base import PackageBase from spack.package_base import PackageBase
@ -93,7 +94,7 @@ def install(self, pkg, spec, prefix):
"--copy", "--copy",
"-i", "-i",
"-j", "-j",
str(determine_number_of_jobs(parallel=parallel)), str(determine_number_of_jobs(parallel=parallel, config=spack.config.CONFIG)),
"--", "--",
os.getcwd(), os.getcwd(),
] ]

View File

@ -101,7 +101,6 @@
on_package_attributes, on_package_attributes,
) )
from spack.spec import InvalidSpecDetected, Spec from spack.spec import InvalidSpecDetected, Spec
from spack.util.cpus import determine_number_of_jobs
from spack.util.executable import * from spack.util.executable import *
from spack.variant import ( from spack.variant import (
any_combination_of, any_combination_of,

View File

@ -7,8 +7,6 @@
import os import os
from typing import Optional from typing import Optional
import spack.config
def cpus_available(): def cpus_available():
""" """
@ -28,6 +26,7 @@ def determine_number_of_jobs(
parallel: bool = False, parallel: bool = False,
max_cpus: int = cpus_available(), max_cpus: int = cpus_available(),
config: Optional["spack.config.Configuration"] = None, config: Optional["spack.config.Configuration"] = None,
config_path: str = 'config:build_jobs',
) -> int: ) -> int:
""" """
Packages that require sequential builds need 1 job. Otherwise we use the Packages that require sequential builds need 1 job. Otherwise we use the
@ -39,18 +38,24 @@ def determine_number_of_jobs(
parallel: true when package supports parallel builds parallel: true when package supports parallel builds
max_cpus: maximum number of CPUs to use (defaults to cpus_available()) max_cpus: maximum number of CPUs to use (defaults to cpus_available())
config: configuration object (defaults to global config) config: configuration object (defaults to global config)
config_path: configuration path to read number of jobs from
""" """
if not parallel: if not parallel:
return 1 return 1
cfg = config or spack.config.CONFIG
# Command line overrides all # Command line overrides all
config_jobs = 16
try: try:
command_line = cfg.get("config:build_jobs", default=None, scope="command_line") command_line = None
if config is not None:
command_line = config.get(config_path, default=None, scope="command_line")
if command_line is not None: if command_line is not None:
return command_line return command_line
except ValueError: except ValueError:
pass pass
return min(max_cpus, cfg.get("config:build_jobs", 16)) if config is not None:
config_jobs = config.get(config_path, 16)
return min(max_cpus, config_jobs)