From 2771840a6d9bb74ffa1090a7baa94ff773c2cbcd Mon Sep 17 00:00:00 2001
From: Boris Basic <boris.basic@edf.fr>
Date: Thu, 15 Dec 2022 18:53:10 +0100
Subject: [PATCH] Replace LAPACK with OpenBLAS

---
 README.md                     |  4 +++-
 build-telemac-deps.bat        | 23 +++++++++++------------
 config/pysource.win.bat       |  4 ++--
 config/pysource.win.debug.bat |  4 ++--
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/README.md b/README.md
index 18cadda..7fb6102 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,9 @@ TELEMAC-MASCARET can be built with or without several dependencies, which are li
 - MED (requires HDF5)
 - METIS
 - MPI
-- MUMPS (requires MPI, LAPACK and ScaLAPACK)
+- MUMPS (additionally requires):
+    - OpenBLAS (includes LAPACK)
+    - ScaLAPACK
 - AED2
 - GOTM
 
diff --git a/build-telemac-deps.bat b/build-telemac-deps.bat
index cb2a68a..95f9f3c 100644
--- a/build-telemac-deps.bat
+++ b/build-telemac-deps.bat
@@ -58,7 +58,7 @@ set hdf5=hdf5-1.10.9
 set med=med-4.1.1
 set metis=metis-5.1.1
 set msmpi=msmpi-10.1.2
-set lapack=lapack-3.10.0
+set openblas=openblas-0.3.21
 set scalapack=scalapack-2.1.0
 set mumps=mumps-5.4.1
 set aed2=libaed2-1.3.0
@@ -106,7 +106,7 @@ call :build_hdf5 || goto exit
 call :build_med || goto exit
 call :build_metis || goto exit
 call :build_msmpi || goto exit
-call :build_lapack || goto exit
+call :build_openblas || goto exit
 call :build_scalapack || goto exit
 call :build_mumps || goto exit
 call :build_aed2 || goto exit
@@ -198,13 +198,13 @@ xcopy /e/y sdk\build-x86_64 %install_path:/=\%\%msmpi%\
 popd
 exit /b 0
 
-:build_lapack
-rem **********
-rem * LAPACK *
-rem **********
-call :download %lapack% "https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.10.0.zip" || exit /b 1
-set cmake_config_options=-DCMAKE_BUILD_TYPE=Release
-call :cmake_build %lapack% || exit /b 1
+:build_openblas
+rem ************
+rem * OpenBLAS *
+rem ************
+call :download %openblas% "https://github.com/xianyi/OpenBLAS/archive/refs/tags/v0.3.21.tar.gz" || exit /b 1
+set cmake_config_options=
+call :cmake_build %openblas% || exit /b 1
 exit /b 0
 
 :build_scalapack
@@ -213,7 +213,7 @@ rem * ScaLAPACK *
 rem *************
 call :download %scalapack% "https://github.com/Reference-ScaLAPACK/scalapack/archive/refs/tags/v2.1.0.zip" || exit /b 1
 rem We need to use a foward slash for lapack and blas libraries paths since CMake CheckFortranFunctionExists is bugged when using a backward slash
-set cmake_config_options=-DMPI_BASE_DIR:PATH=%install_path%/%msmpi% -DLAPACK_LIBRARIES:STRING=%install_path%/%lapack%/lib/liblapack.a -DBLAS_LIBRARIES:STRING=%install_path%/%lapack%/lib/libblas.a -DBUILD_TESTING:BOOL=OFF
+set cmake_config_options=-DMPI_BASE_DIR:PATH=%install_path%/%msmpi% -DLAPACK_LIBRARIES:STRING=%install_path%/%openblas%/lib/libopenblas.a -DBLAS_LIBRARIES:STRING=%install_path%/%openblas%/lib/libopenblas.a -DBUILD_TESTING:BOOL=OFF
 call :cmake_build %scalapack% || exit /b 1
 exit /b 0
 
@@ -222,7 +222,7 @@ rem *********
 rem * MUMPS *
 rem *********
 call :download %mumps% "https://github.com/scivision/mumps/archive/refs/tags/v5.4.1.11.zip" || exit /b 1
-set cmake_config_options=-DLAPACK_ROOT:PATH=%install_path%/%lapack% -DSCALAPACK_ROOT:PATH=%install_path%/%scalapack%
+set cmake_config_options=-DBLAS_LIBRARY=%install_path%/%openblas%/lib/libopenblas.a -DLAPACK_LIBRARY=%install_path%/%openblas%/lib/libopenblas.a -DSCALAPACK_ROOT:PATH=%install_path%/%scalapack%
 if %compiler% == mingw (
   set cmake_config_options=%cmake_config_options% -DMPI_ROOT:PATH=%install_path%/%msmpi%
 ) else (
@@ -312,7 +312,6 @@ exit /b 0
 popd
 exit /b 1
 
-
 :download
 rem ******************************************
 rem * Download a library if not already done *
diff --git a/config/pysource.win.bat b/config/pysource.win.bat
index d6bb6af..10d8840 100644
--- a/config/pysource.win.bat
+++ b/config/pysource.win.bat
@@ -49,8 +49,8 @@ set PATH=%METISHOME%\bin;%PATH%
 rem MSPMPI
 set MPIHOME=%TELEMACDEPS%\msmpi-10.1.2
 set PATH=%MPIHOME%\bin;%PATH%
-rem LAPACK, SCALAPACK and MUMPS
-set LAPACKHOME=%TELEMACDEPS%\lapack-3.10.0
+rem OPENBLAS, SCALAPACK and MUMPS
+set OPENBLASHOME=%TELEMACDEPS%\openblas-0.3.21
 set SCALAPACKHOME=%TELEMACDEPS%\scalapack-2.1.0
 set MUMPSHOME=%TELEMACDEPS%\mumps-5.4.1
 rem AED
diff --git a/config/pysource.win.debug.bat b/config/pysource.win.debug.bat
index 3b855f1..23bd846 100644
--- a/config/pysource.win.debug.bat
+++ b/config/pysource.win.debug.bat
@@ -49,8 +49,8 @@ set PATH=%METISHOME%\bin;%PATH%
 rem MSPMPI
 set MPIHOME=%TELEMACDEPS%\msmpi-10.1.2
 set PATH=%MPIHOME%\bin;%PATH%
-rem LAPACK, SCALAPACK and MUMPS
-set LAPACKHOME=%TELEMACDEPS%\lapack-3.10.0
+rem OPENBLAS, SCALAPACK and MUMPS
+set OPENBLASHOME=%TELEMACDEPS%\openblas-0.3.21
 set SCALAPACKHOME=%TELEMACDEPS%\scalapack-2.1.0
 set MUMPSHOME=%TELEMACDEPS%\mumps-5.4.1
 rem AED
-- 
GitLab