Skip to content

Add support for MacOS with ARM CPUs (CMake + GitHub Action) #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
639f0d2
First draft of macOS support in CMakeLists and Github Actions recipe …
siggmo Oct 4, 2024
28b16b6
fix typo in FFTW package name for brew
siggmo Oct 4, 2024
06fed09
Rename macOS workflow to not clash with the Ubuntu workflow
siggmo Oct 4, 2024
5670265
test if OpenMP is really required at all
siggmo Oct 4, 2024
f3e52ea
Remove not used dependency OpenMP
siggmo Oct 4, 2024
2a9ccbd
Merge branch 'bugfix/remove-openmp-dependency' into feature/macOS_M1_…
siggmo Oct 4, 2024
6cfc2a0
Test if setting C++ standard to 11 helps with the whitespace required…
siggmo Oct 4, 2024
9d3970b
Test if setting C++ standard to 14 helps with auto not allowed in lam…
siggmo Oct 4, 2024
05272cd
Test brew hdf5 package without mpi
siggmo Oct 4, 2024
ffd4955
Add macOS installation instructions
siggmo Oct 4, 2024
32bd02a
Test both brew packages hdf5 and hdf5-mpi at the same time (conflicti…
siggmo Oct 4, 2024
8672551
Revert "Test both brew packages hdf5 and hdf5-mpi at the same time (c…
siggmo Oct 4, 2024
120f4a4
Add libomp to macOS dependency installation instructions
siggmo Oct 9, 2024
9415190
Merge branch 'develop' into feature/macOS_M1_support
siggmo Oct 9, 2024
026dffe
Revert "Remove not used dependency OpenMP"
siggmo Oct 9, 2024
8e72fd2
Add libomp to github action
siggmo Oct 9, 2024
ec0c126
Set OpenMP_ROOT in github action recipe to enable CMake on macOS to f…
siggmo Oct 9, 2024
b82d5d9
test explicit path to libomp instead
siggmo Oct 9, 2024
7164b6e
Revert "test explicit path to libomp instead"
siggmo Oct 9, 2024
7323793
Merge branch 'develop' into feature/macOS_M1_support
siggmo Oct 9, 2024
019fcde
try another fix for OpenMP problem
siggmo Oct 9, 2024
c8bd9a9
add missing backslash in multiline command
siggmo Oct 9, 2024
f6a550d
remove cmake from brew install commands as it's included in macos-14 …
siggmo Oct 9, 2024
cc551c4
Mention OpenMP macOS issue with CMake in the README
siggmo Oct 9, 2024
07ee5d8
Merge branch 'develop' into feature/macOS_M1_support
IshaanDesai Apr 14, 2025
0e85e29
Merge branch 'develop' into feature/macOS_M1_support
IshaanDesai May 2, 2025
d7aede7
Do not set C++14 standard
IshaanDesai May 2, 2025
8e101df
Try using the macos-15 image, and set C++11 standard
IshaanDesai May 2, 2025
26ddbbb
Do not set any C++ standard in the CMakeLists
IshaanDesai May 2, 2025
a011ff5
Rename file and workflow
IshaanDesai May 2, 2025
6cb6e06
Merge branch 'develop' into feature/macOS_M1_support
IshaanDesai May 2, 2025
e80b36e
first native macos build config
ac133718 May 2, 2025
ade29fe
Empty-Commit
ac133718 May 2, 2025
f85d2b8
manual pre-commit trigger
ac133718 May 2, 2025
4acc08c
export some env variables to make cmake aligned with other cases
sanathkeshav May 2, 2025
bf0371f
added the env variables in the right place
sanathkeshav May 2, 2025
eb8769f
removed commented line setting cpp standard
sanathkeshav May 5, 2025
f17414e
Add Changelog entry
IshaanDesai May 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/build_and_test_mac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build and test macOS 15
# Builds FANS for macOS 15 on Apple Silicon CPU and runs the tests.

on:
push:
branches:
- main
- develop
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{github.event_name == 'pull_request'}}

jobs:
build-macos:
name: macOS 15
runs-on: macos-15
env:
FANS_BUILD_DIR: build
strategy:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install FANS dependencies
run: |
brew install gnu-time cmake gcc@14
brew install open-mpi --build-from-source --cc=gcc-14
brew install fftw hdf5-mpi eigen

- name: Generate build directory
run: mkdir -p ${{ env.FANS_BUILD_DIR }}

- name: Configure
working-directory: ${{ env.FANS_BUILD_DIR }}
env:
CC: gcc-14
CXX: g++-14
MPICC: mpicc
MPICXX: mpicxx
run: |
cmake --version
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..

- uses: actions/upload-artifact@v4
if: failure()
with:
name: macOS 15 CMakeCache
path: ${{ env.FANS_BUILD_DIR }}/CMakeCache.txt
- uses: actions/upload-artifact@v4
if: failure()
with:
name: macOS 15 CMakeLogs
path: '${{ env.FANS_BUILD_DIR }}/CMakeFiles/*.log'
- uses: actions/upload-artifact@v4
if: failure()
with:
name: macOS 15 CompileCommands
path: ${{ env.FANS_BUILD_DIR }}/compile_commands.json

- name: Compile
working-directory: ${{ env.FANS_BUILD_DIR }}
run:
cmake --build . -j $(nproc) || cmake --build . -j1

- name: Tests
working-directory: ${{ env.FANS_BUILD_DIR }}
env:
CTEST_OUTPUT_ON_FAILURE: 1
run: ctest

- uses: actions/upload-artifact@v4
if: failure()
with:
name: macOS 15 CTest logs
path: ${{ env.FANS_BUILD_DIR }}/Testing/Temporary/LastTest.log
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## latest

- Native support for MacOS https://github.com/DataAnalyticsEngineering/FANS/pull/25
- Remove Ubuntu 20.04 from testing and Docker support https://github.com/DataAnalyticsEngineering/FANS/pull/51
- Add support for `--version` command line argument for checking the version of FANS
- Modify way to provide micro structure in JSON input https://github.com/DataAnalyticsEngineering/FANS/pull/43
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# From https://stackoverflow.com/questions/73248130/how-to-avoid-the-removal-of-the-rpath-during-cmake-install-step

# Set RPATH to be relative and honor user overrides, whether at the command line or FetchContent
set(RPATH_BASE "$ORIGIN")
if(APPLE)
set(RPATH_BASE "@loader_path")
else()
set(RPATH_BASE "$ORIGIN")
endif()
file(RELATIVE_PATH REL_PATH_LIB
"/${CMAKE_INSTALL_BINDIR}/"
"/${CMAKE_INSTALL_LIBDIR}/")
Expand Down Expand Up @@ -109,7 +113,7 @@ endif ()
add_library(FANS::FANS ALIAS FANS_FANS)

if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64")
target_compile_options(FANS_FANS PUBLIC -march=armv8-a+simd+fp+crypto)

elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
# Detecting if there is avx2 and fma support on linux
# Deteced together, because these flags were introduced by Intel Haskell 4th. Gen
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ apt-get install \
libfftw3-mpi-dev
```

On macOS, you can obtain the dependencies using `brew` and set the environment variables:

```zsh
brew install gnu-time cmake gcc@14
brew install open-mpi --build-from-source --cc=gcc-14
brew install fftw hdf5-mpi eigen

export CC=gcc-14 CXX=g++-14 MPICC=mpicc MPICXX=mpicxx
```

Also, we recommend to set up a Python virtual environment for the `FANS_Dashboard`:

```bash
Expand Down
18 changes: 12 additions & 6 deletions include/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ using namespace Eigen;
#define FANS_MALLOC_H

/* Usage: V *data = FANS_malloc<V>(n); */

template <class V>
inline V *FANS_malloc(size_t n)
inline V *FANS_malloc(std::size_t n)
{
// V* out = new V[n];
V *out = (V *) aligned_alloc(4 * sizeof(V), n * sizeof(V));

return out;
if (n == 0)
throw std::invalid_argument("FANS_malloc: zero-byte request");
void *p = fftw_malloc(n * sizeof(V)); // SIMD-friendly alignment
if (!p)
throw std::bad_alloc();
return static_cast<V *>(p);
}
template <class V>
inline void FANS_free(V *p)
{
fftw_free(p);
}
#endif // FANS_MALLOC_H

Expand Down
11 changes: 7 additions & 4 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ fi

num_processes=$2

TIME_CMD="command time -v"
[[ "$OSTYPE" == "darwin"* ]] && TIME_CMD="command gtime -v"

# Run the jobs serially
command time -v mpiexec -n $num_processes ./FANS input_files/test_LinearThermal.json test_LinearThermal.h5 > test_LinearThermal.log 2>&1
$TIME_CMD mpiexec -n $num_processes ./FANS input_files/test_LinearThermal.json test_LinearThermal.h5 > test_LinearThermal.log 2>&1

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

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

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