Skip to content

Commit 83f0b0c

Browse files
committed
fmk ifdef added to dakotaProcedures for aprepro>6.20, updating conanfile, makeMac and .gitignore gfor multiple mac arch
1 parent 3058bff commit 83f0b0c

5 files changed

Lines changed: 124 additions & 32 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ fmkTest.sh
100100
modules/performREC/pyrecodes/pyrecodes*
101101
modules/performREC/pyrecodes/residual_demand_traffic_simulator/projects*
102102

103-
applications.*
103+
104+
build*
105+
applications*
106+
104107
modules/performREC/pyrecodes/pyrecodes/*
105108

106109
CMakeUserPresets.json

CMakeLists.txt

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,37 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
1010

1111
include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake)
1212

13+
14+
1315
# On macOS, Apple Clang ships without OpenMP. Homebrew's libomp provides it but
1416
# is keg-only, so we must hint CMake before find_package(OpenMP) is called anywhere.
1517
if(APPLE)
16-
find_program(_brew brew)
17-
if(_brew)
18-
execute_process(COMMAND ${_brew} --prefix libomp
19-
OUTPUT_VARIABLE _libomp_prefix
20-
OUTPUT_STRIP_TRAILING_WHITESPACE
21-
ERROR_QUIET)
22-
if(_libomp_prefix AND EXISTS "${_libomp_prefix}")
23-
# Flags for FindOpenMP — no -I here, handled separately below
24-
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
25-
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
26-
set(OpenMP_CXX_LIB_NAMES "omp")
27-
set(OpenMP_C_LIB_NAMES "omp")
28-
set(OpenMP_omp_LIBRARY "${_libomp_prefix}/lib/libomp.dylib")
29-
# Make omp.h findable for any target in the build
30-
include_directories(SYSTEM "${_libomp_prefix}/include")
31-
link_directories("${_libomp_prefix}/lib")
32-
message(STATUS "macOS: using Homebrew libomp at ${_libomp_prefix}")
33-
else()
34-
message(WARNING "macOS: libomp not found via Homebrew. Run: brew install libomp")
18+
# When cross-compiling for x86_64 on Apple Silicon, brew always points to the
19+
# arm64 Homebrew (/opt/homebrew). The x86_64 Homebrew lives in /usr/local.
20+
if(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
21+
set(_libomp_prefix "/usr/local/opt/libomp")
22+
else()
23+
find_program(_brew brew)
24+
if(_brew)
25+
execute_process(COMMAND ${_brew} --prefix libomp
26+
OUTPUT_VARIABLE _libomp_prefix
27+
OUTPUT_STRIP_TRAILING_WHITESPACE
28+
ERROR_QUIET)
3529
endif()
3630
endif()
31+
32+
if(_libomp_prefix AND EXISTS "${_libomp_prefix}")
33+
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
34+
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
35+
set(OpenMP_CXX_LIB_NAMES "omp")
36+
set(OpenMP_C_LIB_NAMES "omp")
37+
set(OpenMP_omp_LIBRARY "${_libomp_prefix}/lib/libomp.dylib")
38+
include_directories(SYSTEM "${_libomp_prefix}/include")
39+
link_directories("${_libomp_prefix}/lib")
40+
message(STATUS "macOS: using libomp at ${_libomp_prefix}")
41+
else()
42+
message(WARNING "macOS: libomp not found. Run: brew install libomp")
43+
endif()
3744
endif()
3845

3946

@@ -48,5 +55,9 @@ find_package(kissfft REQUIRED)
4855
find_package(Boost REQUIRED)
4956
find_package(nlohmann_json REQUIRED)
5057

58+
if(DAKOTA_VERSION)
59+
add_compile_definitions(DAKOTA_VERSION=${DAKOTA_VERSION})
60+
endif()
61+
5162
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules)
5263
add_subdirectory(modules)

conanfile2.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os # noqa: D100
22

33
from conan import ConanFile
4-
from conan.tools.cmake import CMake
4+
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
55
from conan.tools.files import copy
66

77

@@ -21,7 +21,6 @@ class simCenterBackendApps(ConanFile): # noqa: D101
2121
"boost/*:without_fiber": True,
2222
}
2323

24-
generators = "CMakeToolchain", "CMakeDeps"
2524
build_policy = "missing"
2625

2726
requires = [ # noqa: RUF012
@@ -37,6 +36,20 @@ class simCenterBackendApps(ConanFile): # noqa: D101
3736
"nlohmann_json/3.11.3",
3837
]
3938

39+
def generate(self):
40+
# Generate toolchain + find_package config files
41+
deps = CMakeDeps(self)
42+
deps.generate()
43+
tc = CMakeToolchain(self)
44+
tc.generate()
45+
46+
# The following solves the "DLL not found" error during local development
47+
if self.settings.os == "Windows":
48+
# For CMake, the binary usually ends up in build/Release or build/Debug
49+
bindir = os.path.join(self.build_folder, str(self.settings.build_type))
50+
for dep in self.dependencies.values():
51+
copy(self, "*.dll", dep.cpp_info.bindirs[0], bindir)
52+
4053
def build(self): # noqa: D102
4154
cmake = CMake(self)
4255
cmake.configure()

makeMac.sh

100644100755
Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#!/bin/bash
2+
3+
# Usage: makeMac.sh [--arch <x86_64 or arm64>]
4+
# Defaults: arch = ""
15

26
# NOTE if fails in nataf_gsa on Mac it is because clang still not working with omp,
37
# SOLN: you need a brew install of libomp, issue:
@@ -8,32 +12,91 @@ export CC=clang
812
export CXX=clang++
913
export CMAKE_ARGS=-DCMAKE_POLICY_VERSION_MINIMUM=3.5
1014

15+
CONAN_PROFILE="default"
16+
BUILD_DIR="build"
17+
OUTPUT_DIR="applications"
18+
ARCH=""
19+
20+
while [[ $# -gt 0 ]]; do
21+
case "$1" in
22+
--arch|-a)
23+
# 1. Capture the value
24+
ARCH="$2"
25+
26+
# 2. VALIDATION: Check if it's one of the allowed types
27+
if [[ "$ARCH" != "x86_64" && "$ARCH" != "arm64" ]]; then
28+
echo "Error: Invalid architecture '$ARCH'."
29+
echo "Supported architectures: x86_64, arm64"
30+
exit 1
31+
fi
32+
33+
if [[ "$ARCH" != "x86_64" ]]; then
34+
CMAKE_DAKOTA_VERSION=619
35+
else
36+
CMAKE_DAKOTA_VERSION=620
37+
fi
38+
39+
# 3. If valid, set the variables
40+
CONAN_PROFILE="macos-$ARCH"
41+
BUILD_DIR="build_$ARCH"
42+
OUTPUT_DIR="${OUTPUT_DIR}_$ARCH"
43+
44+
shift 2
45+
;;
46+
*)
47+
echo "Unknown argument: $1"
48+
echo "Usage: $0 --arch <arm64|x86_64>"
49+
exit 1
50+
;;
51+
esac
52+
done
53+
54+
# Define a helper to print error and stop without closing the terminal
55+
die() {
56+
echo "$1"
57+
exit 1
58+
}
59+
60+
echo "Cleaning up old build directory..."
61+
rm -rf "${BUILD_DIR}"
62+
1163
#
1264
# run conan to install dependencies
1365
#
1466

15-
conan install . --output-folder=build --build=missing
67+
conan install . --output-folder="${BUILD_DIR}" --build missing -s build_type=Release -pr "${CONAN_PROFILE}" || die "FAIL: Conan install failed."
1668

1769
#
1870
# run cmake to generate CMakefiles, then build & finally install
19-
#
2071

21-
cmake -B build -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
22-
cmake --build build
23-
cmake --install build --prefix ./applications
72+
CMAKE_ARCH_FLAG=""
73+
if [ -n "${ARCH}" ]; then
74+
CMAKE_ARCH_FLAG="-DCMAKE_OSX_ARCHITECTURES=${ARCH}"
75+
fi
76+
77+
cmake -B "${BUILD_DIR}" -S . \
78+
-DCMAKE_TOOLCHAIN_FILE="${BUILD_DIR}/conan_toolchain.cmake" ${CMAKE_ARCH_FLAG} -DDAKOTA_VERSION=${CMAKE_DAKOTA_VERSION} \
79+
-DCMAKE_BUILD_TYPE=Release || die "FAIL: CMake configure failed."
80+
81+
cmake --build "${BUILD_DIR}" --parallel 8 || die "FAIL: CMake build failed."
82+
83+
cmake --install "${BUILD_DIR}" --prefix "${OUTPUT_DIR}" || die "FAIL: CMake install failed."
2484

2585
#
2686
# Bundle libomp.dylib with nataf_gsa and run install_name_tool on natf_gsa so it runs without needing a brew install on user machine
2787
#
2888

29-
NATAF_DIR="${PWD}/applications/performUQ/SimCenterUQ"
30-
LIBOMP_DIR="$(brew --prefix libomp)/lib"
89+
NATAF_DIR="${PWD}/${OUTPUT_DIR}/performUQ/SimCenterUQ"
90+
if [ "${ARCH}" = "x86_64" ]; then
91+
LIBOMP_DIR="/usr/local/opt/libomp/lib"
92+
else
93+
LIBOMP_DIR="$(brew --prefix libomp)/lib"
94+
fi
3195
LIBOMP_SRC="${LIBOMP_DIR}/libomp.dylib"
3296
echo "$PWD ${LIBOMP_SRC} ${NATAF_DIR}/libomp.dylib "
3397

34-
3598
if [ -f "${NATAF_DIR}/nataf_gsa" ] && [ -f "${LIBOMP_SRC}" ]; then
36-
cp "${LIBOMP_SRC}" "${NATAF_DIR}"
99+
cp -f "${LIBOMP_SRC}" "${NATAF_DIR}"
37100
install_name_tool -change "${LIBOMP_SRC}" "@executable_path/libomp.dylib" "${NATAF_DIR}/nataf_gsa"
38101
echo "Bundled libomp.dylib into ${NATAF_DIR}"
39102
else

modules/performUQ/dakota/dakotaProcedures.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,13 @@ writeInterface(std::ostream &dakotaFile, json_t *uqData, std::string &workflowDr
440440

441441
dakotaFile << " parameters_file = 'paramsDakota.in'\n";
442442
dakotaFile << " results_file = 'results.out' \n";
443-
#ifdef _DAKOTA_6_22
443+
444+
#if defined(DAKOTA_VERSION) && DAKOTA_VERSION >= 622
444445
dakotaFile << " parameters_format\n aprepro \n";
445446
#else
446447
dakotaFile << " aprepro \n";
447448
#endif
449+
448450
dakotaFile << " work_directory\n";
449451
dakotaFile << " named \'workdir\' \n";
450452
if (saveWorkDirs) {

0 commit comments

Comments
 (0)