CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Openfoam v2106 on MacOS M1 chip (https://www.cfd-online.com/Forums/openfoam/238806-openfoam-v2106-macos-m1-chip.html)

turalmammadli October 4, 2021 17:19

Openfoam v2106 on MacOS M1 chip
 
3 Attachment(s)
Hi everyone,

Have anyone been able to install v2106 version on M1 chip MacOS? I have been trying to get this v2106 on my laptop for two days but havent been succesfull yet. On my laptop i already have a version of openfoam8 but in some cases there have been some errors appearing in which some functions are not matching properly. Here I put the errors that I came across running "Allrun". So the solution seems like either I have to install v2106 version or correct these errors according to Openfoam 8 syntax. Below I attach the "Allrun", and log files that errors appeared in. Any help would be highly appreciated.:)

LongGe October 17, 2021 18:29

Hello All

I am able to use OpenFOAM-v2106 on my M1 Mac. Here are the build instructions for your reference.

https://ttsyshmz.github.io/howtoFoam...2106-on-m1mac/

tkr October 29, 2021 03:59

Could you give us more information, please? How did you build the OpenFOAM environment on the M1?

@LongGe Do you have any information about the performance on the M1 chip? How fast does OpenFOAM work on the Mac?

LongGe October 30, 2021 00:43

Hello All

My development environment is M1 Mac mini and M1 Macbook Air. Here is the development environment in which I built the OpenCFD-ESI version of OpenFOAM-v2106. All 3rdParties have the arm64 version installed in brew.

I usually do a code development on a Mac, but I don't care about the computational speed of the M1 Mac because I put calculation into the Xeon cluster. For your reference, here are the results of the tutorial case calculated on an M1 Mac, so you can compare them with the results on your machine.


OS:
Darwin 20.6.0 Darwin Kernel Version 20.6.0: arm64

Disk:
/Volumes/home3 Case-sensitive APFS

XCode Command Line Tools:
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.6.0
3rdParty:
/opt/homebrew/Cellar/cgal/5.3
/opt/homebrew/Cellar/fftw/3.3.10
/opt/homebrew/Cellar/adios2/2.7.1_1
/opt/homebrew/Cellar/cmake/3.21.3_1
/opt/homebrew/Cellar/kahip/3.11
/opt/homebrew/Cellar/metis/5.1.0
/opt/homebrew/Cellar/open-mpi/4.1.1_2
/opt/homebrew/Cellar/scotch/6.1.1

Benchmark test:
case: OpenFOAM-v2106/tutorials/incompressible/simpleFoam/backwardFacingStep2D
1 core: ExecutionTime = 58.18 s ClockTime = 59 s (simpleFoam only)
4 cores: ExecutionTime = 23.51 s ClockTime = 25 s (simpleFoam only)

xuegy November 2, 2021 21:57

Quote:

Originally Posted by LongGe (Post 814441)
Hello All

I am able to use OpenFOAM-v2106 on my M1 Mac. Here are the build instructions for your reference.

https://ttsyshmz.github.io/howtoFoam...2106-on-m1mac/

Hello Tatsuya. I'm trying to utilize your feexceptErsatz.H in my build. The code can be built, but it doesn't trigger sigFpe like Intel.

Also, for third-party path, you can use /opt/homebrew/opt/*** so it won't change after updates.

LongGe November 3, 2021 20:51

Quote:

Originally Posted by xuegy (Post 815649)
Hello Tatsuya. I'm trying to utilize your feexceptErsatz.H in my build. The code can be built, but it doesn't trigger sigFpe like Intel.

Also, for third-party path, you can use /opt/homebrew/opt/*** so it won't change after updates.

Which OpenFOAM are you talking about? I mean OpenCFD-ESI or Foundation Edition.

The sigFpe is different in these two versions. And I only use OpenCFD-ESI, and this is the only version I have tested.

xuegy November 3, 2021 21:01

Quote:

Originally Posted by LongGe (Post 815750)
Which OpenFOAM are you talking about? I mean OpenCFD-ESI or Foundation Edition.

The sigFpe is different in these two versions. And I only use OpenCFD-ESI, and this is the only version I have tested.

It's OpenFOAM-v2106. I need some help to catch sigfpe in M1.
Shall we move to this page to discuss? https://github.com/mrklein/openfoam-os-x/issues/68

LongGe November 4, 2021 20:22

Quote:

Originally Posted by xuegy (Post 815751)
It's OpenFOAM-v2106. I need some help to catch sigfpe in M1.
Shall we move to this page to discuss? https://github.com/mrklein/openfoam-os-x/issues/68

I have seen the thread in the link. You want to implement floating point exception traps in clang. floating point exception traps are implemented in M1 Mac, but clang doesn't have a built-in function to access FPCR. M1 Mac+gcc can access FPCR with "__builtin_aarch64_get_fpcr / __builtin_aarch64_set_fpcr".

In other words, if you use M1 Mac + clang, you will need to implement the FPCR access functions yourself. It may or may not work, but you will need at least the following accessors.

__attribute__((always_inline))
uint64_t getFpcr(){
uint64_t fpcr;
asm volatile("mrs %0, fpcr" : "=r"(fpcr));
return fpcr;
}
__attribute__((always_inline))
void setFpcr(uint64_t x){
asm volatile("msr fpcr, %0" : : "r"(x));
}

LongGe November 5, 2021 04:08

Hello xuegy

Here is some additional information for your reference. If you put "#pragma STDC FENV_ACCESS ON" in "feexceptErsatz.H", "feexceptErsatz.H" will work correctly. This is a common practice for everyone.

Build this "feexceptErsatz.H" with clang. Then you will see the following message, which means that you have to implement the accessor yourself.

POSIX % ./Allwmake
wmake libo (POSIX)
.......
.......
In file included from signals/sigFpe.C:48:
signals/feexceptErsatz.H:28:14: warning: pragma STDC FENV_ACCESS ON is not supported, ignoring pragma [-Wunknown-pragmas]


There are two philosophies when implementing an accessor. One is to put it in fenv.h as a macro, and the other is to put it in feexceptErsatz.H. There is a non-zero chance that clang will support it in the near future, so implementing it in feexceptErsatz.H is also delicate. Therefore, I am aiming to make v2106 buildable first, and then include a mechanism to trap floating point exceptions.

xuegy November 5, 2021 09:26

Thanks for the information. I've already made it buildable by totally disabling sigfpe. Let me try gcc first then go for clang.

xuegy November 8, 2021 23:52

I've managed to build with gcc (homebrew gcc can't find flex, gmp & mpfr) but still got this error message when running
Code:

dyld[2145]: symbol not found in flat namespace '__ZN4Foam9Function1IiE30dictionaryConstructorTablePtr_B5cxx11E'
[1]    2145 abort      blockMesh

I've never seen this type of error on Linux. Which compiler option should I add to gcc?

LongGe November 9, 2021 00:20

Quote:

Originally Posted by xuegy (Post 816089)
I've managed to build with gcc (homebrew gcc can't find flex, gmp & mpfr) but still got this error message when running
Code:

dyld[2145]: symbol not found in flat namespace '__ZN4Foam9Function1IiE30dictionaryConstructorTablePtr_B5cxx11E'
[1]    2145 abort      blockMesh

I've never seen this type of error on Linux. Which compiler option should I add to gcc?

The reason is described in the following link.

https://stackoverflow.com/questions/...-actually-mean

xuegy November 9, 2021 01:12

Could you please share your compiler flags of gcc? Also is that from homebrew or you compiled it yourself?

zhxutong December 14, 2021 04:23

Quote:

Originally Posted by LongGe (Post 814441)
Hello All

I am able to use OpenFOAM-v2106 on my M1 Mac. Here are the build instructions for your reference.

https://ttsyshmz.github.io/howtoFoam...2106-on-m1mac/

Hi Tastuya,

Thanks so much for sharing this instruction. I am quite new with code developing and currently trying to compile OF on my M1 chip following your instruction. When I did ./Allwamke, it somehow returns:

Code:

/Users/zhxutong/OpenFOAM-v2106/src/OpenFOAM/lnInclude/wchar.h:65:45: error: no type named 'wstring' in namespace 'std'
Ostream& operator<<(Ostream& os, const std::wstring& wstr);

followed by

Code:

/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/iosfwd:219:14: error: reference to unresolved using declaration
typedef fpos<mbstate_t>    streampos;
            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/cwchar:117:1: note: using declaration annotated with 'using_if_exists' here
_LIBCPP_USING_IF_EXISTS(::mbstate_t);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__config:232:39: note: expanded from macro '_LIBCPP_USING_IF_EXISTS'
# define _LIBCPP_USING_IF_EXISTS(...) using __VA_ARGS__ __attribute__((using_if_exists))

Does this suggest that some packages missed?

Here is my clang version
Code:

clang++ --version
Apple clang version 13.0.0 (clang-1300.0.27.3)
Target: arm64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Thanks a lot for your attention! Looking forward to hearing back from you.

LongGe December 15, 2021 00:07

Hello Zhong

My guess is that it's either a clang version or a case-sensitive issue.

sourav90 January 1, 2022 14:45

Working (partially at the moment) in M1Pro
 
With the help of the helpful volunteers in the community I am able to run v2106 in M1Pro, posting here the link, thinking it might help some people who might face similar issues:
OpenFOAM-AppleM1-issues

gerlero January 3, 2022 12:58

If you're willing to use Docker, I've made pre-built images of OpenFOAM for ARM, which I make available here in this GitHub project. They run just fine on my M1 Mac, and much faster than the official OpenFOAM x86 Docker images due to the lack of emulation.


All times are GMT -4. The time now is 10:13.