diff --git a/Formula/c/cp2k.rb b/Formula/c/cp2k.rb index 35da18eee0b2c..4df716640eb7a 100644 --- a/Formula/c/cp2k.rb +++ b/Formula/c/cp2k.rb @@ -4,6 +4,7 @@ class Cp2k < Formula url "https://github.com/cp2k/cp2k/releases/download/v2025.1/cp2k-2025.1.tar.bz2" sha256 "65c8ad5488897b0f995919b9fa77f2aba4b61677ba1e3c19bb093d5c08a8ce1d" license "GPL-2.0-or-later" + revision 1 livecheck do url :stable @@ -32,8 +33,8 @@ class Cp2k < Formula depends_on "openblas" depends_on "scalapack" - fails_with :clang do - cause "needs OpenMP support for C/C++ and Fortran" + on_macos do + depends_on "libomp" end resource "libint" do @@ -58,12 +59,12 @@ def install ENV.prepend_path "PKG_CONFIG_PATH", libexec/"lib/pkgconfig" end - # TODO: Add workaround to link to LLVM OpenMP (libomp) with gfortran after migrating OpenBLAS + # Workaround to link to LLVM OpenMP (libomp) with gfortran omp_args = [] - # if OS.mac? - # omp_args << "-DOpenMP_Fortran_LIB_NAMES=omp" - # omp_args << "-DOpenMP_omp_LIBRARY=#{Formula["libomp"].opt_lib}/libomp.dylib" - # end + if OS.mac? + omp_args << "-DOpenMP_Fortran_LIB_NAMES=omp" + omp_args << "-DOpenMP_omp_LIBRARY=#{Formula["libomp"].opt_lib}/libomp.dylib" + end # TODO: Remove dbcsr build along with corresponding CMAKE_PREFIX_PATH # and add -DCP2K_BUILD_DBCSR=ON once `cp2k` build supports this option. @@ -85,9 +86,7 @@ def install # Avoid trying to access /proc/self/statm on macOS ENV.append "FFLAGS", "-D__NO_STATM_ACCESS" if OS.mac? - # Set -lstdc++ to allow gfortran to link libint cp2k_cmake_args = %W[ - -DCMAKE_SHARED_LINKER_FLAGS=-lstdc++ -DCMAKE_INSTALL_RPATH=#{rpath};#{rpath(target: libexec/"lib")} -DCP2K_BLAS_VENDOR=OpenBLAS -DCP2K_USE_LIBINT2=ON diff --git a/Formula/d/dynare.rb b/Formula/d/dynare.rb index 93180f65d96b4..fa823bc897510 100644 --- a/Formula/d/dynare.rb +++ b/Formula/d/dynare.rb @@ -4,7 +4,7 @@ class Dynare < Formula url "https://www.dynare.org/release/source/dynare-6.4.tar.xz" sha256 "9865e2e7f6b3705155538d5fb1fb0b01bc9decf07250b3b054d3555d651c3843" license "GPL-3.0-or-later" - revision 1 + revision 2 head "https://git.dynare.org/Dynare/dynare.git", branch: "master" livecheck do @@ -37,6 +37,10 @@ class Dynare < Formula depends_on "openblas" depends_on "suite-sparse" + on_macos do + depends_on "libomp" + end + fails_with :clang do cause <<~EOS GCC is the only compiler supported by upstream @@ -72,6 +76,12 @@ def install ENV.append_path "LIBRARY_PATH", Formula["suite-sparse"].opt_lib ENV.append_path "LIBRARY_PATH", buildpath/"slicot/lib" + # Workaround to unofficially link to LLVM OpenMP (libomp) with GCC + if OS.mac? + inreplace "meson.build", "openmp_dep = dependency('openmp')", + "openmp_dep = declare_dependency(compile_args : '-fopenmp', link_args : '-lomp')" + end + system "meson", "setup", "build", "-Dbuild_for=octave", *std_meson_args system "meson", "compile", "-C", "build", "--verbose" system "meson", "install", "-C", "build" diff --git a/Formula/f/fftw.rb b/Formula/f/fftw.rb index 7978d812029dc..876b4a79c5d9b 100644 --- a/Formula/f/fftw.rb +++ b/Formula/f/fftw.rb @@ -4,7 +4,7 @@ class Fftw < Formula url "https://fftw.org/fftw-3.3.10.tar.gz" sha256 "56c932549852cddcfafdab3820b0200c7742675be92179e59e6215b340e26467" license all_of: ["GPL-2.0-or-later", "BSD-2-Clause"] - revision 2 + revision 3 livecheck do url :homepage @@ -27,11 +27,9 @@ class Fftw < Formula depends_on "open-mpi" on_macos do - depends_on "gcc" + depends_on "libomp" end - fails_with :clang - # Fix the cmake config file when configured with autotools, upstream pr ref, https://github.com/FFTW/fftw3/pull/338 patch do url "https://github.com/FFTW/fftw3/commit/394fa85ab5f8914b82b3404844444c53f5c7f095.patch?full_index=1" @@ -41,6 +39,11 @@ class Fftw < Formula def install ENV.runtime_cpu_detection + if OS.mac? + ENV["OPENMP_CFLAGS"] = "-Xpreprocessor -fopenmp" + ENV.append "LIBS", "-lomp" + end + args = [ "--enable-shared", "--disable-debug", diff --git a/Formula/g/gromacs.rb b/Formula/g/gromacs.rb index 3dafa5a4ec080..ee3dc60a4e0ab 100644 --- a/Formula/g/gromacs.rb +++ b/Formula/g/gromacs.rb @@ -4,6 +4,7 @@ class Gromacs < Formula url "https://ftp.gromacs.org/pub/gromacs/gromacs-2025.3.tar.gz" sha256 "8bdfca0268f3f10a7ca3c06e59b62f73ea02420c67211c0ff3912f32d7833c65" license "LGPL-2.1-or-later" + revision 1 livecheck do url "https://ftp.gromacs.org/pub/gromacs/" @@ -23,31 +24,25 @@ class Gromacs < Formula depends_on "cmake" => :build depends_on "pkgconf" => :build depends_on "fftw" - depends_on "gcc" # for OpenMP depends_on "lmfit" + depends_on "muparser" depends_on "openblas" uses_from_macos "zlib" on_macos do - conflicts_with "muparser", because: "gromacs ships its own copy of muparser" + depends_on "libomp" end - on_linux do - depends_on "muparser" - end - - fails_with :clang - def install # Non-executable GMXRC files should be installed in DATADIR inreplace "scripts/CMakeLists.txt", "CMAKE_INSTALL_BINDIR", "CMAKE_INSTALL_DATADIR" # Avoid superenv shim reference - gcc = Formula["gcc"] - cc = gcc.opt_bin/"gcc-#{gcc.any_installed_version.major}" - cxx = gcc.opt_bin/"g++-#{gcc.any_installed_version.major}" + cc = DevelopmentTools.locate(ENV.cc) + cxx = DevelopmentTools.locate(ENV.cxx) + inreplace "src/gromacs/gromacs-hints.in.cmake" do |s| s.gsub! "@CMAKE_LINKER@", "/usr/bin/ld" s.gsub! "@CMAKE_C_COMPILER@", cc @@ -75,15 +70,9 @@ def install -DGMX_INSTALL_LEGACY_API=ON -DGMX_EXTERNAL_ZLIB=ON -DGMX_USE_LMFIT=EXTERNAL + -DGMX_USE_MUPARSER=EXTERNAL -DGMX_SIMD=#{gmx_simd} ] - args << if OS.mac? - # Use bundled `muparser` as brew formula is linked to libc++ on macOS but we need libstdc++. - # TODO: Try switching `gromacs` and its dependency tree to use Apple Clang + `libomp` - "-DFETCHCONTENT_SOURCE_DIR_MUPARSER=#{buildpath}/src/external/muparser" - else - "-DGMX_USE_MUPARSER=EXTERNAL" - end system "cmake", "-S", ".", "-B", "build", *std_cmake_args, *args system "cmake", "--build", "build" diff --git a/Formula/m/muparser.rb b/Formula/m/muparser.rb index 25bee26685eb9..303b9991f9883 100644 --- a/Formula/m/muparser.rb +++ b/Formula/m/muparser.rb @@ -4,7 +4,7 @@ class Muparser < Formula url "https://github.com/beltoforion/muparser/archive/refs/tags/v2.3.5.tar.gz" sha256 "20b43cc68c655665db83711906f01b20c51909368973116dfc8d7b3c4ddb5dd4" license "BSD-2-Clause" - revision 1 + revision 2 head "https://github.com/beltoforion/muparser.git", branch: "master" bottle do @@ -20,13 +20,13 @@ class Muparser < Formula depends_on "cmake" => :build on_macos do - conflicts_with "gromacs", because: "gromacs ships its own copy of muparser" + depends_on "libomp" end def install ENV.cxx11 if OS.linux? - system "cmake", "-S", ".", "-B", "build", "-DENABLE_OPENMP=#{OS.mac? ? "OFF" : "ON"}", *std_cmake_args + system "cmake", "-S", ".", "-B", "build", "-DENABLE_OPENMP=ON", *std_cmake_args system "cmake", "--build", "build" system "cmake", "--install", "build" end diff --git a/Formula/n/nwchem.rb b/Formula/n/nwchem.rb index f3a3e0b9d3fee..4cbcb423c9865 100644 --- a/Formula/n/nwchem.rb +++ b/Formula/n/nwchem.rb @@ -5,7 +5,7 @@ class Nwchem < Formula version "7.2.3" sha256 "7788e6af9be8681e6384b8df4df5ac57d010b2c7aa50842d735c562d92f94c25" license "ECL-2.0" - revision 1 + revision 2 livecheck do url :stable @@ -36,6 +36,10 @@ class Nwchem < Formula uses_from_macos "libxcrypt" + on_macos do + depends_on "libomp" + end + # fix download url in build_dftd3a.sh, upstream pr ref, https://github.com/nwchemgit/nwchem/pull/1054 patch do url "https://github.com/nwchemgit/nwchem/commit/65ce7726d9fa418f7c01665bebfc1e2181f15adf.patch?full_index=1" @@ -46,6 +50,9 @@ def install pkgshare.install "QA" cd "src" do + # Workaround to link to LLVM OpenMP (libomp) with gfortran + inreplace "config/makefile.h", /(\bLDOPTIONS *\+= *)-fopenmp$/, "\\1-lomp" if OS.mac? + (prefix/"etc").mkdir (prefix/"etc/nwchemrc").write <<~EOS nwchem_basis_library #{pkgshare}/libraries/ diff --git a/Formula/o/openblas.rb b/Formula/o/openblas.rb index e1e58948a4322..3f7de066bde78 100644 --- a/Formula/o/openblas.rb +++ b/Formula/o/openblas.rb @@ -9,6 +9,7 @@ class Openblas < Formula # 3. interface/{gemmt.c,sbgemmt.c} is BSD-2-Clause # 4. relapack/ is MIT but license is omitted as it is not enabled license all_of: ["BSD-3-Clause", "BSD-2-Clause-Views", "BSD-3-Clause-Open-MPI", "BSD-2-Clause"] + revision 1 head "https://github.com/OpenMathLib/OpenBLAS.git", branch: "develop" livecheck do @@ -28,10 +29,27 @@ class Openblas < Formula keg_only :shadowed_by_macos, "macOS provides BLAS in Accelerate.framework" + depends_on "pkgconf" => :test depends_on "gcc" # for gfortran - fails_with :clang + + on_macos do + depends_on "libomp" + end def install + # Workaround to use Apple Clang and link to `libomp` + if ENV.compiler == :clang + inreplace "Makefile.system" do |s| + s.gsub! "+= -fopenmp", "+= -Xpreprocessor -fopenmp" + # Also add GCC path to pkgconfig file as we don't symlink libgfortran to HOMEBREW_PREFIX/lib + s.gsub! "+= -lgfortran", "+= -L#{Formula["gcc"].opt_lib}/gcc/current -lgfortran" + end + inreplace "Makefile.install" do |s| + s.gsub! ":= -fopenmp", ":= -I#{Formula["libomp"].opt_include} -Xpreprocessor -fopenmp" + s.gsub! "+= -lgomp", "+= -L#{Formula["libomp"].opt_lib} -lomp" + end + end + ENV.runtime_cpu_detection ENV.deparallelize # build is parallel by default, but setting -j confuses it @@ -61,6 +79,7 @@ def install lib.install_symlink shared_library("libopenblas") => shared_library("libblas") lib.install_symlink shared_library("libopenblas") => shared_library("liblapack") + pkgshare.install "cpp_thread_test" end test do @@ -88,5 +107,24 @@ def install system ENV.cc, "test.c", "-I#{include}", "-L#{lib}", "-lopenblas", "-o", "test" system "./test" + + cp_r pkgshare/"cpp_thread_test/.", testpath + ENV.prepend_path "PKG_CONFIG_PATH", lib/"pkgconfig" + flags = shell_output("pkgconf --cflags --libs --static openblas").chomp.split + ["dgemm_thread_safety", "dgemv_thread_safety"].each do |test| + inreplace "#{test}.cpp", '"../cblas.h"', '"cblas.h"' + system ENV.cxx, "#{test}.cpp", "-o", test, *flags + system "./#{test}" + end + + return unless OS.mac? + + # Check linkage uses correct OpenMP + require "utils/linkage" + libopenblas = lib/shared_library("libopenblas") + libomp = Formula["libomp"].opt_lib/shared_library("libomp") + libgomp = Formula["gcc"].opt_lib/"gcc/current"/shared_library("libgomp") + assert Utils.binary_linked_to_library?(libopenblas, libomp), "No linkage with #{libomp.basename}!" + refute Utils.binary_linked_to_library?(libopenblas, libgomp), "Unwanted linkage with #{libgomp.basename}!" end end diff --git a/Formula/p/pytorch.rb b/Formula/p/pytorch.rb index 7caf7d2562667..ce52dbe56c7bb 100644 --- a/Formula/p/pytorch.rb +++ b/Formula/p/pytorch.rb @@ -6,7 +6,7 @@ class Pytorch < Formula url "https://github.com/pytorch/pytorch/releases/download/v2.8.0/pytorch-v2.8.0.tar.gz" sha256 "c70a2c9488f6f6e8af5982a10d1cc2c37b7df5e6506d839daa5d5e250953d7b5" license "BSD-3-Clause" - revision 2 + revision 3 livecheck do url :stable