Skip to content

Commit 3b64e43

Browse files
siggmoIshaanDesaiac133718sanathkeshav
authored
Add support for MacOS with ARM CPUs (CMake + GitHub Action) (#25)
* First draft of macOS support in CMakeLists and Github Actions recipe for build and test * fix typo in FFTW package name for brew * Rename macOS workflow to not clash with the Ubuntu workflow * test if OpenMP is really required at all * Remove not used dependency OpenMP * Test if setting C++ standard to 11 helps with the whitespace required error * Test if setting C++ standard to 14 helps with auto not allowed in lambda parameter * Test brew hdf5 package without mpi * Add macOS installation instructions * Test both brew packages hdf5 and hdf5-mpi at the same time (conflicting?) * Revert "Test both brew packages hdf5 and hdf5-mpi at the same time (conflicting?)" This reverts commit 32bd02a. * Add libomp to macOS dependency installation instructions * Revert "Remove not used dependency OpenMP" This reverts commit f3e52ea. * Add libomp to github action * Set OpenMP_ROOT in github action recipe to enable CMake on macOS to find OpenMP * test explicit path to libomp instead * Revert "test explicit path to libomp instead" This reverts commit b82d5d9. * try another fix for OpenMP problem * add missing backslash in multiline command * remove cmake from brew install commands as it's included in macos-14 runner anyway * Mention OpenMP macOS issue with CMake in the README * Do not set C++14 standard * Try using the macos-15 image, and set C++11 standard * Do not set any C++ standard in the CMakeLists * Rename file and workflow * first native macos build config * Empty-Commit * manual pre-commit trigger * export some env variables to make cmake aligned with other cases * added the env variables in the right place * removed commented line setting cpp standard * Add Changelog entry --------- Co-authored-by: Ishaan Desai <[email protected]> Co-authored-by: ac133718 <[email protected]> Co-authored-by: sanathkeshav <[email protected]>
1 parent c2da6ab commit 3b64e43

File tree

6 files changed

+115
-12
lines changed

6 files changed

+115
-12
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build and test macOS 15
2+
# Builds FANS for macOS 15 on Apple Silicon CPU and runs the tests.
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
pull_request:
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{github.event_name == 'pull_request'}}
15+
16+
jobs:
17+
build-macos:
18+
name: macOS 15
19+
runs-on: macos-15
20+
env:
21+
FANS_BUILD_DIR: build
22+
strategy:
23+
fail-fast: false
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Install FANS dependencies
29+
run: |
30+
brew install gnu-time cmake gcc@14
31+
brew install open-mpi --build-from-source --cc=gcc-14
32+
brew install fftw hdf5-mpi eigen
33+
34+
- name: Generate build directory
35+
run: mkdir -p ${{ env.FANS_BUILD_DIR }}
36+
37+
- name: Configure
38+
working-directory: ${{ env.FANS_BUILD_DIR }}
39+
env:
40+
CC: gcc-14
41+
CXX: g++-14
42+
MPICC: mpicc
43+
MPICXX: mpicxx
44+
run: |
45+
cmake --version
46+
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
47+
48+
- uses: actions/upload-artifact@v4
49+
if: failure()
50+
with:
51+
name: macOS 15 CMakeCache
52+
path: ${{ env.FANS_BUILD_DIR }}/CMakeCache.txt
53+
- uses: actions/upload-artifact@v4
54+
if: failure()
55+
with:
56+
name: macOS 15 CMakeLogs
57+
path: '${{ env.FANS_BUILD_DIR }}/CMakeFiles/*.log'
58+
- uses: actions/upload-artifact@v4
59+
if: failure()
60+
with:
61+
name: macOS 15 CompileCommands
62+
path: ${{ env.FANS_BUILD_DIR }}/compile_commands.json
63+
64+
- name: Compile
65+
working-directory: ${{ env.FANS_BUILD_DIR }}
66+
run:
67+
cmake --build . -j $(nproc) || cmake --build . -j1
68+
69+
- name: Tests
70+
working-directory: ${{ env.FANS_BUILD_DIR }}
71+
env:
72+
CTEST_OUTPUT_ON_FAILURE: 1
73+
run: ctest
74+
75+
- uses: actions/upload-artifact@v4
76+
if: failure()
77+
with:
78+
name: macOS 15 CTest logs
79+
path: ${{ env.FANS_BUILD_DIR }}/Testing/Temporary/LastTest.log

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## latest
44

5+
- Native support for MacOS https://github.com/DataAnalyticsEngineering/FANS/pull/25
56
- Remove Ubuntu 20.04 from testing and Docker support https://github.com/DataAnalyticsEngineering/FANS/pull/51
67
- Add support for `--version` command line argument for checking the version of FANS
78
- Modify way to provide micro structure in JSON input https://github.com/DataAnalyticsEngineering/FANS/pull/43

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
5656
# From https://stackoverflow.com/questions/73248130/how-to-avoid-the-removal-of-the-rpath-during-cmake-install-step
5757

5858
# Set RPATH to be relative and honor user overrides, whether at the command line or FetchContent
59-
set(RPATH_BASE "$ORIGIN")
59+
if(APPLE)
60+
set(RPATH_BASE "@loader_path")
61+
else()
62+
set(RPATH_BASE "$ORIGIN")
63+
endif()
6064
file(RELATIVE_PATH REL_PATH_LIB
6165
"/${CMAKE_INSTALL_BINDIR}/"
6266
"/${CMAKE_INSTALL_LIBDIR}/")
@@ -109,7 +113,7 @@ endif ()
109113
add_library(FANS::FANS ALIAS FANS_FANS)
110114

111115
if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
112-
target_compile_options(FANS_FANS PUBLIC -march=armv8-a+simd+fp+crypto)
116+
113117
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
114118
# Detecting if there is avx2 and fma support on linux
115119
# Deteced together, because these flags were introduced by Intel Haskell 4th. Gen

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ apt-get install \
3737
libfftw3-mpi-dev
3838
```
3939

40+
On macOS, you can obtain the dependencies using `brew` and set the environment variables:
41+
42+
```zsh
43+
brew install gnu-time cmake gcc@14
44+
brew install open-mpi --build-from-source --cc=gcc-14
45+
brew install fftw hdf5-mpi eigen
46+
47+
export CC=gcc-14 CXX=g++-14 MPICC=mpicc MPICXX=mpicxx
48+
```
49+
4050
Also, we recommend to set up a Python virtual environment for the `FANS_Dashboard`:
4151

4252
```bash

include/general.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ using namespace Eigen;
4141
#define FANS_MALLOC_H
4242

4343
/* Usage: V *data = FANS_malloc<V>(n); */
44-
4544
template <class V>
46-
inline V *FANS_malloc(size_t n)
45+
inline V *FANS_malloc(std::size_t n)
4746
{
48-
// V* out = new V[n];
49-
V *out = (V *) aligned_alloc(4 * sizeof(V), n * sizeof(V));
50-
51-
return out;
47+
if (n == 0)
48+
throw std::invalid_argument("FANS_malloc: zero-byte request");
49+
void *p = fftw_malloc(n * sizeof(V)); // SIMD-friendly alignment
50+
if (!p)
51+
throw std::bad_alloc();
52+
return static_cast<V *>(p);
53+
}
54+
template <class V>
55+
inline void FANS_free(V *p)
56+
{
57+
fftw_free(p);
5258
}
5359
#endif // FANS_MALLOC_H
5460

test/run_tests.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ fi
88

99
num_processes=$2
1010

11+
TIME_CMD="command time -v"
12+
[[ "$OSTYPE" == "darwin"* ]] && TIME_CMD="command gtime -v"
13+
1114
# Run the jobs serially
12-
command time -v mpiexec -n $num_processes ./FANS input_files/test_LinearThermal.json test_LinearThermal.h5 > test_LinearThermal.log 2>&1
15+
$TIME_CMD mpiexec -n $num_processes ./FANS input_files/test_LinearThermal.json test_LinearThermal.h5 > test_LinearThermal.log 2>&1
1316

14-
command time -v mpiexec -n $num_processes ./FANS input_files/test_LinearElastic.json test_LinearElastic.h5 > test_LinearElastic.log 2>&1
17+
$TIME_CMD mpiexec -n $num_processes ./FANS input_files/test_LinearElastic.json test_LinearElastic.h5 > test_LinearElastic.log 2>&1
1518

16-
command time -v mpiexec -n $num_processes ./FANS input_files/test_PseudoPlastic.json test_PseudoPlastic.h5 > test_PseudoPlastic.log 2>&1
19+
$TIME_CMD mpiexec -n $num_processes ./FANS input_files/test_PseudoPlastic.json test_PseudoPlastic.h5 > test_PseudoPlastic.log 2>&1
1720

18-
command time -v mpiexec -n $num_processes ./FANS input_files/test_J2Plasticity.json test_J2Plasticity.h5 > test_J2Plasticity.log 2>&1
21+
$TIME_CMD mpiexec -n $num_processes ./FANS input_files/test_J2Plasticity.json test_J2Plasticity.h5 > test_J2Plasticity.log 2>&1

0 commit comments

Comments
 (0)