feat(quadrature): quadrature system brought over
Ported and dramatically cleaned up the quadrature system. This includes centralizing all field definitions
This commit is contained in:
@@ -349,6 +349,7 @@ def common_cmake_args(
|
||||
prefix_paths = [os.fspath(args.prefix)]
|
||||
if args.dependency_prefix:
|
||||
prefix_paths.append(args.dependency_prefix)
|
||||
prefix_paths.extend(getattr(args, "openmp_prefixes", []))
|
||||
result = [
|
||||
f"-DCMAKE_BUILD_TYPE={build_type}",
|
||||
f"-DCMAKE_INSTALL_PREFIX={args.prefix}",
|
||||
@@ -453,6 +454,40 @@ def cmake_configure(
|
||||
run(command, env=env)
|
||||
|
||||
|
||||
def check_openmp(
|
||||
args: argparse.Namespace, env: Mapping[str, str], build_type: str
|
||||
) -> None:
|
||||
"""Check both bundle languages before building the expensive dependencies.
|
||||
|
||||
Apple Clang needs a separate runtime. Homebrew's keg-only libomp is
|
||||
discoverable by Meson but is outside CMake's default prefix search.
|
||||
Keep CMake's compiler checks, and use their result for libCEED's Make build.
|
||||
"""
|
||||
args.openmp_prefixes = []
|
||||
if args.host_system == "darwin" and args.allow_system == "true":
|
||||
for prefix in ("/opt/homebrew/opt/libomp", "/usr/local/opt/libomp"):
|
||||
if (Path(prefix) / "include/omp.h").is_file():
|
||||
args.openmp_prefixes.append(prefix)
|
||||
source = args.work_dir / "openmp-check-source"
|
||||
source.mkdir(parents=True, exist_ok=True)
|
||||
write_text_atomic(source / "CMakeLists.txt", """cmake_minimum_required(VERSION 3.18)
|
||||
project(bundle_openmp_check LANGUAGES C CXX)
|
||||
find_package(OpenMP REQUIRED COMPONENTS C CXX)
|
||||
file(WRITE "${CMAKE_BINARY_DIR}/openmp-c.txt"
|
||||
"${OpenMP_C_FLAGS}\\n${OpenMP_C_INCLUDE_DIRS}\\n${OpenMP_C_LIBRARIES}\\n")
|
||||
""")
|
||||
build = args.work_dir / "openmp-check"
|
||||
cmake_configure(
|
||||
args, source, build,
|
||||
common_cmake_args(args, build_type, c_compiler=args.cc, cxx_compiler=args.cxx),
|
||||
env,
|
||||
)
|
||||
flags, includes, libraries = (build / "openmp-c.txt").read_text().splitlines()
|
||||
args.openmp_c_flags = shlex.split(flags)
|
||||
args.openmp_c_flags.extend(f"-I{path}" for path in includes.split(";") if path)
|
||||
args.openmp_c_libraries = [path for path in libraries.split(";") if path]
|
||||
|
||||
|
||||
def cmake_build_install(
|
||||
args: argparse.Namespace,
|
||||
source: Path,
|
||||
@@ -932,6 +967,10 @@ def build_libceed(
|
||||
)
|
||||
)
|
||||
link_flags = [*args.c_link_arg, *args.cxx_link_arg]
|
||||
if features["openmp"]:
|
||||
# libCEED's default clang flag (-fopenmp) does not work with Apple Clang.
|
||||
command.append(f"OMP_FLAG={joined_flags(args.openmp_c_flags)}")
|
||||
link_flags.extend(args.openmp_c_libraries)
|
||||
if args.host_system == "darwin":
|
||||
link_flags.append("-Wl,-headerpad_max_install_names")
|
||||
cuda_root = toolchain_root("nvcc", env) if features["cuda"] else ""
|
||||
@@ -1126,6 +1165,16 @@ def build_algoim(
|
||||
raise RuntimeError("Algoim source archive did not contain src/*.hpp")
|
||||
for header in headers:
|
||||
shutil.copy2(header, include_dir / header.name)
|
||||
# MFEM builds as C++17, but these public headers also reach C++23 consumers.
|
||||
# Preserve the upstream header's non-UTF-8 comments while replacing the
|
||||
# trait removed in C++20 with its C++17-compatible successor.
|
||||
quad_header = include_dir / "algoim_quad.hpp"
|
||||
quad_text = quad_header.read_bytes()
|
||||
old_trait = b"typename std::result_of<F(const TinyVector<Real,N>&)>::type"
|
||||
new_trait = b"std::invoke_result_t<F, const TinyVector<Real,N>&>"
|
||||
if old_trait not in quad_text and new_trait not in quad_text:
|
||||
raise RuntimeError("Algoim's expected quadrature result trait was not found")
|
||||
quad_header.write_bytes(quad_text.replace(old_trait, new_trait))
|
||||
|
||||
|
||||
def prepare_mfem_source(
|
||||
@@ -2373,10 +2422,16 @@ def main() -> int:
|
||||
print("[mfem-bundle] configuration unchanged; reusing private prefix", flush=True)
|
||||
return 0
|
||||
|
||||
remove_tree(args.work_dir)
|
||||
remove_tree(args.prefix)
|
||||
pending_file = args.work_dir.parent / "pending-configuration.json"
|
||||
pending = json.loads(pending_file.read_text()) if pending_file.is_file() else {}
|
||||
if pending.get("fingerprint") != fingerprint:
|
||||
remove_tree(args.work_dir)
|
||||
remove_tree(args.prefix)
|
||||
else:
|
||||
print("[mfem-bundle] resuming incomplete build", flush=True)
|
||||
args.work_dir.mkdir(parents=True, exist_ok=True)
|
||||
args.prefix.mkdir(parents=True, exist_ok=True)
|
||||
write_text_atomic(pending_file, json.dumps({"fingerprint": fingerprint}) + "\n")
|
||||
|
||||
env = dict(os.environ)
|
||||
if features["cuda"]:
|
||||
@@ -2418,6 +2473,9 @@ def main() -> int:
|
||||
if args.dependency_prefix and args.vendor_dependency_prefix == "true":
|
||||
copy_prefix(Path(args.dependency_prefix), args.prefix)
|
||||
|
||||
if features["openmp"] or features["legacy_openmp"]:
|
||||
check_openmp(args, env, build_type)
|
||||
|
||||
if features["zlib"] and not bundle_has(args, "include/zlib.h"):
|
||||
build_zlib(args, env, build_type)
|
||||
mpicc, mpicxx = args.cc, args.cxx
|
||||
|
||||
Reference in New Issue
Block a user