Skip to content

Commit

Permalink
pybamm-team#3646 fix parallel level, set environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Dec 21, 2023
1 parent e4f4af3 commit a04fce6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions scripts/install_KLU_Sundials.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def download_extract_library(url, download_dir):
except OSError:
raise RuntimeError("CMake must be installed.")

# Build in parallel wherever possible
os.environ["CMAKE_BUILD_PARALLEL_LEVEL"] = str(cpu_count())

# Create download directory in PyBaMM dir
pybamm_dir = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
download_dir = os.path.join(pybamm_dir, "install_KLU_Sundials")
Expand Down Expand Up @@ -78,6 +81,7 @@ def download_extract_library(url, download_dir):
]
install_cmd = [
"make",
f"-j{cpu_count()}",
"install",
]
print("-" * 10, "Building SuiteSparse", "-" * 40)
Expand All @@ -89,13 +93,13 @@ def download_extract_library(url, download_dir):
# multiple paths at the time of wheel repair. Therefore, it should not be
# built with an RPATH since it is copied to the install prefix.
if libdir == "SuiteSparse_config":
env["CMAKE_OPTIONS"] = f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_BUILD_PARALLEL_LEVEL={cpu_count()}"
env["CMAKE_OPTIONS"] = f"-DCMAKE_INSTALL_PREFIX={install_dir}"
else:
# For AMD, COLAMD, BTF and KLU; do not set a BUILD RPATH but use an
# INSTALL RPATH in order to ensure that the dynamic libraries are found
# at runtime just once. Otherwise, delocate complains about multiple
# references to the SuiteSparse_config dynamic library (auditwheel does not).
env["CMAKE_OPTIONS"] = f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE -DCMAKE_BUILD_PARALLEL_LEVEL={cpu_count()}"
env["CMAKE_OPTIONS"] = f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
subprocess.run(make_cmd, cwd=build_dir, env=env, shell=True, check=True)
subprocess.run(install_cmd, cwd=build_dir, check=True)

Expand Down Expand Up @@ -168,5 +172,5 @@ def download_extract_library(url, download_dir):
subprocess.run(["cmake", sundials_src, *cmake_args], cwd=build_dir, check=True)

print("-" * 10, "Building the sundials", "-" * 40)
make_cmd = ["make", "install"]
make_cmd = ["make", f"-j{cpu_count()}", "install"]
subprocess.run(make_cmd, cwd=build_dir, check=True)

0 comments on commit a04fce6

Please sign in to comment.