CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Installation

[OpenFOAM.com] Installing OpenFOAM on MacOS with Apple Silicon

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree5Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 16, 2023, 12:18
Default Installing OpenFOAM on MacOS with Apple Silicon
  #1
New Member
 
Kevin Nolan
Join Date: Nov 2012
Posts: 13
Rep Power: 14
Kolan is on a distinguished road
I recently got a new Mac and wanted to build OpenFOAM natively without the need for virtualisation to make the most of the core count of the M3 Max.

Here is what I needed to do to get it running based on the patches and guide by Alexey Matveichev, so many thanks to his efforts!

https://github.com/mrklein/openfoam-os-x

I installed v2206.

My 16" MacBook Pro is running Sonoma 14.2 (23C64).
I have a 16 core M3 Max.

The main issues I had were related to clearing of environmental variables by SIP when running scripts and linking scotch. This post will follow and tweak this guide:
https://github.com/mrklein/openfoam-...ase-&-Homebrew

First install Xcode and the Xcode command line tools.
You can do this from the app store. Check the command line tools are installed:
Code:
$ xcode-select --install
Next install homebrew
https://brew.sh

The guide then asks you to install some dependencies, however the version of scotch failed to install. Instead install the unmodified version of scotch which in my case is 7.0.4.

Code:
brew install --cask paraview
$ brew install open-mpi
$ brew install boost
$ brew install cgal
$ brew install metis
$ brew install libomp
$ brew install scotch
$ brew install mrklein/foam/parmgridgen
Following the guide I created a case sensitive sparse bundle in my home directory. Go to your home directory and create and mount the volume to a directory called OpenFOAM:

Code:
$ cd $HOME
$ hdiutil create -size 8.3g -type SPARSEBUNDLE -fs HFSX -volname OpenFOAM -fsargs -s OpenFOAM.sparsebundle
$ mkdir -p OpenFOAM
$ hdiutil attach -mountpoint $HOME/OpenFOAM OpenFOAM.sparsebundle
Now we can download the tarballs of the OpenFOAM source. Again I'm downloading v2206 here because there is a patch for this version.

Code:
$ curl -L http://dl.openfoam.com/source/v2206/OpenFOAM-v2206.tgz > OpenFOAM-v2206.tgz
$ curl -L http://dl.openfoam.com/source/v2206/ThirdParty-v2206.tgz > ThirdParty-v2206.tgz
There will be downloaded to your home directory, you can delete them later.

Next extract the tarballs into the new OpenFOAM volume.
Code:
$ cd OpenFOAM
$ tar xzf $HOME/OpenFOAM-v2206.tgz
$ tar xzf $HOME/ThirdParty-v2206.tgz
This creates two directories in ~/OpenFOAM, OpenFOAM-v2206 and ThirdParty-v2206.

Let's go into OpenFOAM-v2206 and download the patch file and then apply it.

Code:
cd OpenFOAM-v2206
$ curl -L https://raw.githubusercontent.com/mrklein/openfoam-os-x/master/OpenFOAM-v2206.patch > OpenFOAM-v2206.patch
$ git apply OpenFOAM-v2206.patch
Before we go and build OpenFOAM we need to fix how scotch is linked.

Looking at our scotch install info:
Code:
brew info scotch
we can see where brew put it:
Code:
==> scotch: stable 7.0.4 (bottled), HEAD
Package for graph partitioning, graph clustering, and sparse matrix ordering
https://gitlab.inria.fr/scotch/scotch
/opt/homebrew/Cellar/scotch/7.0.4 (227 files, 11.3MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-12-15 at 15:32:38
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/s/scotch.rb
License: CECILL-C
==> Dependencies
Build: bison ✘
Required: open-mpi ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 62 (30 days), 169 (90 days), 435 (365 days)
install-on-request: 60 (30 days), 167 (90 days), 432 (365 days)
build-error: 0 (30 days)
So we need to add this information before building. To do this you need to edit the edit etc/config.sh/scotch file to include:

Code:
export SCOTCH_VERSION=scotch-system
export SCOTCH_ARCH_PATH=/opt/homebrew/Cellar/scotch/7.0.4
Note that on my old Intel Mac scotch was in /usr/local/Cellar/scotch/7.0.4

Comment out the existing entries and save the file.

Next run these commands to update some necessary settings:
Code:
$ mkdir -p $HOME/.OpenFOAM
$ echo 'WM_COMPILER=Clang' > $HOME/.OpenFOAM/prefs.sh
$ echo 'WM_COMPILE_OPTION=Opt' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'WM_MPLIB=SYSTEMOPENMPI' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'export WM_NCOMPPROCS=$(sysctl -n hw.ncpu)' >> $HOME/.OpenFOAM/prefs.sh
$ echo 'WM_LABEL_SIZE=32' >> $HOME/.OpenFOAM/prefs.sh
$ source etc/bashrc
$ [ "$(ulimit -n)" -lt "4096" ] && ulimit -n 4096

Now we can build
Code:
$ cd $HOME/OpenFOAM/OpenFOAM-v2206 
$ ./Allwmake > log.Allwmake 2>&1
Give it some time to build. You can monitor the build log in another terminal window with:
Code:
$ tail -f $HOME/OpenFOAM/OpenFOAM-v2206/log.Allwmake
After the build is complete we need to add some files and environmental variables so OpenFOAM is available when we open the Terminal.

Code:
mkdir -p $HOME/.OpenFOAM
echo 'v2206' > $HOME/.OpenFOAM/OpenFOAM-release
Finally you need to add the following to your $HOME/.zprofile or where you prefer to put this stuff.

Code:
if [ -f "$HOME/.OpenFOAM/OpenFOAM-release" ]; then
    FOAM_DISK_IMAGE=${FOAM_DISK_IMAGE:-"$HOME/OpenFOAM.sparsebundle"}
    FOAM_MOUNT_POINT=${FOAM_MOUNT_POINT:-"$HOME/OpenFOAM"}
    FOAM_VERSION=$(cat $HOME/.OpenFOAM/OpenFOAM-release)
    if [ ! -f "$HOME/OpenFOAM/OpenFOAM-$FOAM_VERSION/etc/bashrc" ]; then
        hdiutil attach -quiet -mountpoint "$FOAM_MOUNT_POINT" "$FOAM_DISK_IMAGE" &&
                . "$HOME/OpenFOAM/OpenFOAM-$FOAM_VERSION/etc/bashrc"
    else
        source "$HOME/OpenFOAM/OpenFOAM-$FOAM_VERSION/etc/bashrc"
    fi
fi
There is still an issue linking Metis but this can be fixed the same way scotch is fixed if you need it.

Finally you can run the OpenFoam Benchmark, but you need to tweak a could have things. Download the OpenFOAM.com specific zip file from this post:
\OpenFOAM benchmarks on various hardware

This runs simpleFOAM on various core counts using a script. As mentioned before System Integrity Protection can clear required environmental variables when running scripts. The suggested fix for this is to include

Code:
source $WM_PROJECT_DIR/etc/bashrc
Near the top of any script you run, including this benchmark run.tst script.

The run.tst script needs to be edited. I changed the core counts to:
Quote:
cores='16 12 10 8 6 4 2 1'
Also the sed command is slightly different on MacOS. Change:

Quote:
sed -i "s/method.*/method scotch;/" system/decomposeParDict
sed -i "s/numberOfSubdomains.*/numberOfSubdomains ${i};/" system/decomposeParDict
to:

Quote:
sed -i '' "s/method.*/method scotch;/" system/decomposeParDict
sed -i '' "s/numberOfSubdomains.*/numberOfSubdomains ${i};/" system/decomposeParDict
Next you need to edit basecase/system/snappyHexMeshDict
to replace the reference in line 279 from
Quote:
minMedianAxisAngle 90;
to
Quote:
minMedialAxisAngle 90;
I also noticed that there was a warning related to basecase/system/controlDict.
It's not important but you can change:

Code:
writeCompression uncompressed;
to

Code:
writeCompression off;
Run the benchmark with

Code:
./run.tst
gives some very impressive times.

# cores Wall time (s):
------------------------
16 87.19
12 53.91
10 57.39
8 63.66
6 74.18
4 110.1
2 197.9
1 345.8

Last edited by Kolan; December 17, 2023 at 12:17.
Kolan is offline   Reply With Quote

Old   December 21, 2023, 14:14
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
More changes for handling SIP, rpath installation and xcode will be in OpenFOAM-v2312. Presumably will need less patching (hopefully no patching).
It would be useful if you would also give that a spin in the next days/weeks and see if some of your recipe can be reduced.
olesen is offline   Reply With Quote

Old   December 21, 2023, 14:16
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Is the homebrew recipe for scotch now fixed to compile without threaded MPI (which is a real performance killer for OpenFOAM)?
olesen is offline   Reply With Quote

Old   December 22, 2023, 09:56
Default
  #4
New Member
 
Kevin Nolan
Join Date: Nov 2012
Posts: 13
Rep Power: 14
Kolan is on a distinguished road
Yes, it seems that scotch is now behaving as expected.

Once I get my exam grading done I'll give v2312 a look!
Kolan is offline   Reply With Quote

Old   December 23, 2023, 09:40
Default
  #5
New Member
 
Gabriel Gerlero
Join Date: Jan 2022
Posts: 21
Rep Power: 4
gerlero is on a distinguished road
Quote:
Yes, it seems that scotch is now behaving as expected.
This needs to be tested to verify but it would be great news! AFAICT there haven't been any commits at Homebrew that have changed the build options, but I might very well be missing something.

BTW, for those interested in running OpenFOAM natively on macOS, my project at https://github.com/gerlero/openfoam-app automates the builds (for those who want to compile from source) and also provides pre-compiled binaries (for those who just want to get up and running as fast as possible).
gerlero is offline   Reply With Quote

Old   December 23, 2023, 10:03
Default
  #6
New Member
 
Kevin Nolan
Join Date: Nov 2012
Posts: 13
Rep Power: 14
Kolan is on a distinguished road
And it is an excellent way to get it running too.

You will know better than me but I’ll report back soon on how I get on.
Kolan is offline   Reply With Quote

Old   March 15, 2024, 01:56
Default
  #7
Senior Member
 
Simbelmynė's Avatar
 
Join Date: May 2012
Posts: 551
Rep Power: 16
Simbelmynė is on a distinguished road
Hi,

Did you test v2312? Any improvements with SIP?

I have problems with
Code:
The dummy Pstream library cannot be used in parallel mode
which I did not have on Ventura (I think). Not sure if it is a SIP issue though, since adding
Code:
source $WM_PROJECT_DIR/etc/bashrc
to the Allrun script has no effect.

Did you have similar issues and how did you solve it?
Simbelmynė is offline   Reply With Quote

Old   March 15, 2024, 08:54
Default
  #8
New Member
 
Kevin Nolan
Join Date: Nov 2012
Posts: 13
Rep Power: 14
Kolan is on a distinguished road
I've yet to have time to test v2312 but I've had no issues with SIP. After following the steps in my initial post I've had no further issues with v2306.
Kolan is offline   Reply With Quote

Old   April 2, 2024, 06:19
Default
  #9
New Member
 
Wei Liu
Join Date: Apr 2011
Location: West Lafayette, IN
Posts: 29
Rep Power: 15
mathslw is on a distinguished road
Many thanks for the post. I also have a mac with M3 Max and followed the posted steps to install OpenFOAM 5.0, but got an error "symbol not found in flat namespace '_ompi_mpi_byte'". Then followed this link https://github.com/mrklein/openfoam-os-x/issues/91

Now it seems working well.
mathslw is offline   Reply With Quote

Old   April 2, 2024, 06:22
Default
  #10
New Member
 
Kevin Nolan
Join Date: Nov 2012
Posts: 13
Rep Power: 14
Kolan is on a distinguished road
Good stuff, I had posted there also but hadn't followed up.
I also need to install the Foundation version so that is very helpful to know. Thank you.
Kolan is offline   Reply With Quote

Old   April 2, 2024, 07:41
Default
  #11
Senior Member
 
Simbelmynė's Avatar
 
Join Date: May 2012
Posts: 551
Rep Power: 16
Simbelmynė is on a distinguished road
Quote:
Originally Posted by Kolan View Post
Good stuff, I had posted there also but hadn't followed up.
I also need to install the Foundation version so that is very helpful to know. Thank you.
If you manage to get v11 to run please let us know

Edit: I can confirm that v11 works fine with the above method. I have tested both serial and parallel tutorial cases. Perhaps a bit more extensive testing is needed though, but it seems promising

Last edited by Simbelmynė; April 6, 2024 at 08:21.
Simbelmynė is offline   Reply With Quote

Old   April 11, 2024, 07:58
Default
  #12
New Member
 
Marius
Join Date: Sep 2022
Posts: 27
Rep Power: 4
Counterdoc is on a distinguished road
Did someone compare the times with running Docker on macOS? Would be interesting to know the difference in performance. I am currently running it on docker with my M1 Max.
Counterdoc is offline   Reply With Quote

Old   April 11, 2024, 11:40
Default
  #13
Senior Member
 
Simbelmynė's Avatar
 
Join Date: May 2012
Posts: 551
Rep Power: 16
Simbelmynė is on a distinguished road
Quote:
Originally Posted by Counterdoc View Post
Did someone compare the times with running Docker on macOS? Would be interesting to know the difference in performance. I am currently running it on docker with my M1 Max.
I have posted results in the benchmark thread for M1 Max using native (Gerlero) compilation. You could compare your Docker results to those.
gerlero likes this.
Simbelmynė is offline   Reply With Quote

Old   May 8, 2024, 07:48
Default
  #14
New Member
 
Join Date: Dec 2019
Posts: 5
Rep Power: 6
moh raafat is on a distinguished road
hello, I have this error every Time I try to install on Mac Pro M3, Mac suggests to install
command line developer tools and I click install it, however it keeps the error and the installation fails.

xcode-select: Failed to locate 'm4', requesting installation of command line developer tools.
m4 stage failed on expressions/fields/fieldExprLemonParser.lyy-m4

Retaining intermediate: /Users/mohammedshahin/OpenFOAM22/OpenFOAM-v2206/build/darwin64ClangDPInt32Opt/src/OpenFOAM/expressions/fields/fieldExprLemonParser.lyy
make: *** [/Users/mohammedshahin/OpenFOAM22/OpenFOAM-v2206/build/darwin64ClangDPInt32Opt/src/OpenFOAM/expressions/fields/fieldExprLemonParser.o] Error 1
make: *** Waiting for unfinished jobs....
moh raafat is offline   Reply With Quote

Old   May 8, 2024, 09:02
Default
  #15
Senior Member
 
Simbelmynė's Avatar
 
Join Date: May 2012
Posts: 551
Rep Power: 16
Simbelmynė is on a distinguished road
More information is needed.

This problem can be associated with multiple installations of OF (Gerlero and other). Try to remove config files for OpenFOAM in your user directory
Simbelmynė is offline   Reply With Quote

Old   August 6, 2024, 14:54
Default
  #16
Member
 
Hyun Ko
Join Date: Jun 2009
Posts: 35
Rep Power: 17
hyunko is on a distinguished road
Hello Kolan,

I have followed your instruction to compile and install OF2206.

After compilation and decomposing a mesh,

I got a following error.
================================================== =
--> FOAM FATAL ERROR: (openfoam-2206)
Attempted to use <scotch> without the scotchDecomp library loaded.
This message is from the dummy scotchDecomp stub library instead.

Please install <scotch> and ensure libscotch.so is in LD_LIBRARY_PATH.
The scotchDecomp library can then be built from src/parallel/decompose/scotchDecomp.
Dynamically loading or linking this library will add <scotch> as a decomposition method.
================================================== =

Do you have any idea for this error?

As per your instruction, I have edited etc/config.sh/scotch file.
================================================== =
#------------------------------------------------------------------------------
# USER EDITABLE PART: Changes made here may be lost with the next upgrade

#SCOTCH_VERSION=scotch_6.1.0
#export SCOTCH_ARCH_PATH=$WM_THIRD_PARTY_DIR/
#platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_ OPTION/$SCOTCH_VERSION

export SCOTCH_VERSION=scotch-system
export SCOTCH_ARCH_PATH=/opt/homebrew/Cellar/scotch/7.0.4

# END OF (NORMAL) USER EDITABLE PART
#------------------------------------------------------------------------------
================================================== =

thank you.
hyunko is offline   Reply With Quote

Old   September 10, 2024, 12:13
Default video on compilation of OpenFOAM-v2406 from source on MacOS
  #17
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 94
Rep Power: 15
einstein_zee is on a distinguished road
Thanks for all the contributions! As they say a picture is worth a thousand words, a video is worth even more . Just in case if someone is still struggling, this video may help : https://youtu.be/_z7K97NE2pg
compilation done on M1 apple silicon with macOS Monterey
einstein_zee is offline   Reply With Quote

Old   September 10, 2024, 14:09
Default
  #18
New Member
 
Kevin Nolan
Join Date: Nov 2012
Posts: 13
Rep Power: 14
Kolan is on a distinguished road
Hi hyunko,
What does

Code:
% brew info scotch
tell you?

My system is currently reporting:

Code:
==> scotch: stable 7.0.5 (bottled), HEAD
Package for graph partitioning, graph clustering, and sparse matrix ordering
https://gitlab.inria.fr/scotch/scotch
Installed
/opt/homebrew/Cellar/scotch/7.0.5 (231 files, 11.2MB) *
  Poured from bottle using the formulae.brew.sh API on 2024-08-15 at 16:26:11
From: https://github.com/Homebrew/homebrew...la/s/scotch.rb
License: CECILL-C
==> Dependencies
Build: bison ✘
Required: open-mpi ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 86 (30 days), 147 (90 days), 553 (365 days)
install-on-request: 84 (30 days), 143 (90 days), 544 (365 days)
build-error: 0 (30 days)
But I had compiled with 7.0.4. Have you installed a version other than 7.0.4 by any chance?
Kolan is offline   Reply With Quote

Old   September 10, 2024, 23:52
Default
  #19
Member
 
Hyun Ko
Join Date: Jun 2009
Posts: 35
Rep Power: 17
hyunko is on a distinguished road
Thank you Kolan.

I successfully compiled OF with following instruction.

https://github.com/mrklein/openfoam-...ase-&-Homebrew
hyunko is offline   Reply With Quote

Old   September 16, 2024, 18:43
Default cfMesh tools
  #20
New Member
 
Join Date: Sep 2024
Posts: 1
Rep Power: 0
bzollars is on a distinguished road
Quote:
Originally Posted by gerlero View Post
BTW, for those interested in running OpenFOAM natively on macOS, my project at https://github.com/gerlero/openfoam-app automates the builds (for those who want to compile from source) and also provides pre-compiled binaries (for those who just want to get up and running as fast as possible).
Gerlero, is cfMesh part of your pre-compiled OpenFOAM package? I have just installed v2406 and it does not seem to be there.

BTW, You have made it very nice and easy to get up and going with OpenFoam!

Thanks
bzollars is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM.com] Native OpenFOAM for macOS: OpenFOAM-v2112.app (install instructions and GitHub link) gerlero OpenFOAM Installation 32 November 21, 2024 03:20
Frequently Asked Questions about Installing OpenFOAM wyldckat OpenFOAM Installation 3 November 14, 2023 12:58
[Other] Basic questions about OpenFOAM cluster running and installing Fauster OpenFOAM Installation 0 May 25, 2018 16:00
[OpenFOAM.com] Issues with installing v1712 on MacOS Spacegirl1923 OpenFOAM Installation 8 April 12, 2018 18:44
Suggestion for a new sub-forum at OpenFOAM's Forum wyldckat Site Help, Feedback & Discussions 20 October 28, 2014 10:04


All times are GMT -4. The time now is 17:41.