Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Formula/c/cp2k.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,8 +34,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
Expand All @@ -59,12 +60,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.
Expand All @@ -86,9 +87,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
Expand Down
61 changes: 55 additions & 6 deletions Formula/d/dynare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,11 +39,22 @@ class Dynare < Formula
depends_on "openblas"
depends_on "suite-sparse"

on_macos do
depends_on "llvm" => :build if DevelopmentTools.clang_build_version <= 1600
depends_on "libomp"

# Work around LLVM issue with structured bindings[^1] by partly reverting
# commit[^2]. Upstream isn't interested in supporting Clang build[^3].
#
# [^1]: https://github.com/llvm/llvm-project/issues/33025
# [^2]: https://git.dynare.org/Dynare/dynare/-/commit/6ff7d4c56c26a2b7546de633dbcfe2f163bf846d
# [^3]: https://git.dynare.org/Dynare/dynare/-/issues/1977
patch :DATA
end

fails_with :clang do
cause <<~EOS
GCC is the only compiler supported by upstream
https://git.dynare.org/Dynare/dynare/-/blob/master/README.md#general-instructions
EOS
build 1600
cause "needs C++20 std::jthreads"
end

resource "slicot" do
Expand All @@ -68,8 +79,14 @@ def install

# Help meson find `boost`, `suite-sparse` and `slicot`
ENV["BOOST_ROOT"] = Formula["boost"].opt_prefix
ENV.append_path "LIBRARY_PATH", Formula["suite-sparse"].opt_lib
ENV.append_path "LIBRARY_PATH", buildpath/"slicot/lib"
# NOTE: LIBRARY_PATH doesn't seem to work in Clang when `static` arg is used.
# May be related to https://github.com/mesonbuild/meson/issues/10172
inreplace "meson.build", "'umfpack', dirs : octlibdir / '../..',",
"'umfpack', dirs : '#{Formula["suite-sparse"].opt_lib}',"

# Enable jthreads in Xcode 16.3-16.4: https://github.com/llvm/llvm-project/issues/104154
ENV.append_to_cflags "-fexperimental-library" if OS.mac? && MacOS.version == :sequoia

system "meson", "setup", "build", "-Dbuild_for=octave", *std_meson_args
system "meson", "compile", "-C", "build", "--verbose"
Expand Down Expand Up @@ -112,3 +129,35 @@ def caveats
"--no-history", "--path", "#{lib}/dynare/matlab", "dyn_test.m"
end
end

__END__
diff --git a/mex/sources/local_state_space_iterations/local_state_space_iteration_2.cc b/mex/sources/local_state_space_iterations/local_state_space_iteration_2.cc
index 5d0b0800b..97708e607 100644
--- a/mex/sources/local_state_space_iterations/local_state_space_iteration_2.cc
+++ b/mex/sources/local_state_space_iterations/local_state_space_iteration_2.cc
@@ -69,8 +69,10 @@ ss2Iteration_pruning(double* y2, double* y1, const double* yhat2, const double*
const double one = 1.0;
const blas_int ONE = 1;
#endif
- auto [ii1, ii2, ii3] = set_vector_of_indices(n, m); // vector indices for ghxx
- auto [jj1, jj2, jj3] = set_vector_of_indices(q, m); // vector indices for ghuu
+ std::vector<int> ii1, ii2, ii3;// vector indices for ghxx
+ std::tie(ii1, ii2, ii3) = set_vector_of_indices(n, m);
+ std::vector<int> jj1, jj2, jj3;// vector indices for ghuu
+ std::tie(jj1, jj2, jj3) = set_vector_of_indices(q, m);
#pragma omp parallel for num_threads(number_of_threads)
for (int particle = 0; particle < s; particle++)
{
@@ -148,8 +150,10 @@ ss2Iteration(double* y, const double* yhat, const double* epsilon, const double*
const double one = 1.0;
const blas_int ONE = 1;
#endif
- auto [ii1, ii2, ii3] = set_vector_of_indices(n, m); // vector indices for ghxx
- auto [jj1, jj2, jj3] = set_vector_of_indices(q, m); // vector indices for ghuu
+ std::vector<int> ii1, ii2, ii3;// vector indices for ghxx
+ std::tie(ii1, ii2, ii3) = set_vector_of_indices(n, m);
+ std::vector<int> jj1, jj2, jj3;// vector indices for ghuu
+ std::tie(jj1, jj2, jj3) = set_vector_of_indices(q, m);
#pragma omp parallel for num_threads(number_of_threads)
for (int particle = 0; particle < s; particle++)
{
11 changes: 7 additions & 4 deletions Formula/f/fftw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,11 +28,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"
Expand All @@ -42,6 +40,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",
Expand Down
26 changes: 7 additions & 19 deletions Formula/g/gromacs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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
revision 2

livecheck do
url "https://ftp.gromacs.org/pub/gromacs/"
Expand All @@ -23,31 +23,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
Expand Down Expand Up @@ -75,15 +69,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"
Expand Down
1 change: 0 additions & 1 deletion Formula/m/muparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Muparser < Formula

on_macos do
depends_on "libomp"
conflicts_with "gromacs", because: "gromacs ships its own copy of muparser"
end

def install
Expand Down
9 changes: 8 additions & 1 deletion Formula/n/nwchem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,6 +37,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"
Expand All @@ -47,6 +51,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/
Expand Down
54 changes: 33 additions & 21 deletions Formula/o/openblas.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
class Openblas < Formula
desc "Optimized BLAS library"
homepage "https://www.openblas.net/"
url "https://github.com/OpenMathLib/OpenBLAS/archive/refs/tags/v0.3.30.tar.gz"
url "https://github.com/OpenMathLib/OpenBLAS/releases/download/v0.3.30/OpenBLAS-0.3.30.tar.gz"
sha256 "27342cff518646afb4c2b976d809102e368957974c250a25ccc965e53063c95d"
# The main license is BSD-3-Clause. Additionally,
# 1. OpenBLAS is based on GotoBLAS2 so some code is under original BSD-2-Clause-Views
# 2. lapack-netlib/ is a bundled LAPACK so it is BSD-3-Clause-Open-MPI
# 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
Expand All @@ -30,22 +31,18 @@ class Openblas < Formula

keg_only :shadowed_by_macos, "macOS provides BLAS in Accelerate.framework"

depends_on "cmake" => :build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depends_on "pkgconf" => :test
depends_on "gcc" # for gfortran
fails_with :clang

on_macos do
depends_on "libomp"
end

def install
ENV.runtime_cpu_detection
ENV.deparallelize # build is parallel by default, but setting -j confuses it

# The build log has many warnings of macOS build version mismatches.
ENV["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version.to_s if OS.mac?
ENV["DYNAMIC_ARCH"] = "1"
ENV["USE_OPENMP"] = "1"
# Force a large NUM_THREADS to support larger Macs than the VMs that build the bottles
ENV["NUM_THREADS"] = "56"
# See available targets in TargetList.txt
ENV["TARGET"] = case Hardware.oldest_cpu

target = case Hardware.oldest_cpu
when :arm_vortex_tempest
"VORTEX"
when :westmere
Expand All @@ -54,17 +51,30 @@ def install
Hardware.oldest_cpu.upcase.to_s
end

# Apple Silicon does not support SVE
# https://github.com/OpenMathLib/OpenBLAS/issues/4212
ENV["NO_SVE"] = "1" if Hardware::CPU.arm?
args = %W[
-DUSE_OPENMP=ON
-DBUILD_SHARED_LIBS=ON
-DBUILD_STATIC_LIBS=ON
-DNUM_THREADS=64
-DTARGET=#{target}
]

args << "-DDYNAMIC_ARCH=ON" if !OS.mac? || Hardware::CPU.intel?

if OS.mac?
args << "-DOpenMP_Fortran_LIB_NAMES=omp"
args << "-DOpenMP_omp_LIBRARY=#{Formula["libomp"].opt_lib}/libomp.dylib"
end

# Must call in two steps
system "make", "CC=#{ENV.cc}", "FC=gfortran", "libs", "netlib", "shared"
system "make", "PREFIX=#{prefix}", "install"
system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"

lib.install_symlink shared_library("libopenblas") => shared_library("libblas")
lib.install_symlink shared_library("libopenblas") => shared_library("liblapack")
pkgshare.install "cpp_thread_test"

inreplace lib/"pkgconfig/openblas.pc", prefix, opt_prefix
end

test do
Expand All @@ -89,12 +99,14 @@ def install
return 0;
}
C
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" if OS.mac?
flags = shell_output("pkgconf --cflags --libs openblas").chomp.split
system ENV.cc, "test.c", "-o", "test", *flags
system "./test"

flags += %W[-I#{Formula["libomp"].opt_include} -L#{Formula["libomp"].opt_lib} -lomp] if OS.mac?
Copy link
Member

@cho-m cho-m Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will note that one problem with change is pkg-config file is it in an odd half-way state

Libs: -L${libdir} -l${libnameprefix}openblas${libnamesuffix}${libsuffix} 
Cflags: -I${includedir} -Xclang -fopenmp 

This won't work as is with libomp unless user provides the missing arguments like the above line whereas GCC worked with just the pkg-config output.

Similarly, installed CMake config file may not behave as expected (as OpenMP_Fortran will link libgomp without some extra hacks):

set_target_properties(OpenBLAS::OpenBLAS PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/openblas"
  INTERFACE_LINK_LIBRARIES "m;OpenMP::OpenMP_C;OpenMP::OpenMP_Fortran"
)

However, users are more likely to use FindBLAS and FindOpenMP so may not see issue with OpenBLASConfig.cmake

cp_r pkgshare/"cpp_thread_test/.", testpath
%w[dgemm_thread_safety dgemv_thread_safety].each do |test|
inreplace "#{test}.cpp", '"../cblas.h"', '"cblas.h"'
system ENV.cxx, *ENV.cxxflags.to_s.split, "-std=c++11", "#{test}.cpp", "-o", test, *flags
Expand Down
2 changes: 1 addition & 1 deletion Formula/p/pytorch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 3
revision 4

livecheck do
url :stable
Expand Down
Loading