homebrew-core/Formula/fftw.rb

92 lines
3.1 KiB
Ruby

class Fftw < Formula
desc "C routines to compute the Discrete Fourier Transform"
homepage "https://fftw.org"
url "https://fftw.org/fftw-3.3.9.tar.gz"
sha256 "bf2c7ce40b04ae811af714deb512510cc2c17b9ab9d6ddcf49fe4487eea7af3d"
license all_of: ["GPL-2.0-or-later", "BSD-2-Clause"]
revision 1
livecheck do
url :homepage
regex(%r{latest official release.*? <b>v?(\d+(?:\.\d+)+)</b>}i)
end
bottle do
sha256 arm64_big_sur: "f0bcc63e25061ac29e5d8f2700beab98e8bdf8e2bb428ceb8e77018e004d2473"
sha256 cellar: :any, big_sur: "8ee0fe663966dcc2ba924768dc921536873b172b024302f1f06e663237d11a29"
sha256 cellar: :any, catalina: "e5c826687292998daa2f2e76d13325fde551b54450846c3190efde540a02650e"
sha256 cellar: :any, mojave: "17af7472492ccf0704b958db622505872d7bca0f2d2f05869d07f1b01557c0ab"
sha256 cellar: :any_skip_relocation, x86_64_linux: "4d8acd47e1deb1964882d56f086c31890b3fdbfa7da9699b6ef161dc983f620e"
end
depends_on "open-mpi"
on_macos do
depends_on "gcc"
end
fails_with :clang
def install
args = [
"--enable-shared",
"--disable-debug",
"--prefix=#{prefix}",
"--enable-threads",
"--disable-dependency-tracking",
"--enable-mpi",
"--enable-openmp",
]
# FFTW supports runtime detection of CPU capabilities, so it is safe to
# use with --enable-avx and the code will still run on all CPUs
simd_args = []
simd_args << "--enable-sse2" << "--enable-avx" if Hardware::CPU.intel?
# single precision
# enable-sse2, enable-avx and enable-avx2 work for both single and double precision
system "./configure", "--enable-single", *(args + simd_args)
system "make", "install"
# clean up so we can compile the double precision variant
system "make", "clean"
# double precision
# enable-sse2, enable-avx and enable-avx2 work for both single and double precision
system "./configure", *(args + simd_args)
system "make", "install"
# clean up so we can compile the long-double precision variant
system "make", "clean"
# long-double precision
# no SIMD optimization available
system "./configure", "--enable-long-double", *args
system "make", "install"
end
test do
# Adapted from the sample usage provided in the documentation:
# https://www.fftw.org/fftw3_doc/Complex-One_002dDimensional-DFTs.html
(testpath/"fftw.c").write <<~EOS
#include <fftw3.h>
int main(int argc, char* *argv)
{
fftw_complex *in, *out;
fftw_plan p;
long N = 1;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(p); /* repeat as needed */
fftw_destroy_plan(p);
fftw_free(in); fftw_free(out);
return 0;
}
EOS
system ENV.cc, "-o", "fftw", "fftw.c", "-L#{lib}", "-lfftw3"
system "./fftw"
end
end