From 0791bcd5726b77d89d882c16b335132573292753 Mon Sep 17 00:00:00 2001 From: Christopher Albert Date: Fri, 23 Oct 2026 10:56:33 +0200 Subject: [PATCH] Use Accelerate for BLAS/LAPACK on Apple Silicon Homebrew OpenBLAS is built against LLVM libomp while gfortran uses libgomp, so one process carries two OpenMP runtimes. OpenBLAS 0.3.31-0.3.33 returned wrong DGEMM results when called from gfortran OpenMP threads (OpenMathLib/OpenBLAS#5825, fixed in 0.3.34). Accelerate keeps a single OpenMP runtime. A gfortran OpenMP DGEMM reproducer built with these settings agrees across 1, 4 and 8 threads. --- activate.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/activate.sh b/activate.sh index ce8fd41..edb1710 100644 --- a/activate.sh +++ b/activate.sh @@ -25,8 +25,13 @@ if [ "$(uname)" = "Darwin" ]; then # Check the processor type if [ "$(uname -m)" = "arm64" ]; then echo "This is an Apple Silicon Mac." - export BLAS_LIBRARIES=/opt/homebrew/opt/openblas/lib/libopenblas.dylib - export LAPACK_LIBRARIES=/opt/homebrew/opt/openblas/lib/liblapack.dylib + # Accelerate, not Homebrew OpenBLAS: OpenBLAS is built with LLVM libomp + # while gfortran uses libgomp, and OpenBLAS 0.3.31-0.3.33 gave wrong + # DGEMM results when called from gfortran OpenMP threads + # (OpenMathLib/OpenBLAS#5825). One OpenMP runtime per process. + export BLAS_LIBRARIES=/System/Library/Frameworks/Accelerate.framework + export LAPACK_LIBRARIES=/System/Library/Frameworks/Accelerate.framework + export BLA_VENDOR=Apple elif [ "$(uname -m)" = "x86_64" ]; then echo "This is an Intel Mac." export BLAS_LIBRARIES=/usr/local/opt/openblas/lib/libopenblas.dylib