From 592da03a8e4b4f455007a6d460b11af72b654914 Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Mon, 23 Dec 2024 01:50:22 -0800 Subject: [PATCH 1/4] arpack: use openblas on darwin Change 07cdea2ae5005c6396eafd9d87e1cdec6c0c2a4b uncovered a bug in how we build arpack on darwin with the Accelerate. Disable the Accelerate framework and use openblas the default nixpkgs blas/lapack implementation. --- pkgs/by-name/ar/arpack/package.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/by-name/ar/arpack/package.nix b/pkgs/by-name/ar/arpack/package.nix index d8da13ac5680..f4c45e7de2f8 100644 --- a/pkgs/by-name/ar/arpack/package.nix +++ b/pkgs/by-name/ar/arpack/package.nix @@ -37,6 +37,10 @@ stdenv.mkDerivation rec { "-DINTERFACE64=${if blas.isILP64 then "1" else "0"}" "-DMPI=${if useMpi then "ON" else "OFF"}" "-DICB=ON" + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ + # prevent cmake from using Accelerate, which causes single precision tests + # to segfault + "-DBLA_VENDOR=Generic" ]; preCheck = '' From 00baa26ab41dfa7b6eb304467e94fcc2d9d5e592 Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Fri, 27 Dec 2024 21:43:56 -0800 Subject: [PATCH 2/4] arpack: minor cleanups use ninja, cmakeBool and remove unneeded install_name_tool usage in postFixup as the library name is already properly set by the build --- pkgs/by-name/ar/arpack/package.nix | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pkgs/by-name/ar/arpack/package.nix b/pkgs/by-name/ar/arpack/package.nix index f4c45e7de2f8..28c4c77c5dd3 100644 --- a/pkgs/by-name/ar/arpack/package.nix +++ b/pkgs/by-name/ar/arpack/package.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, cmake +{ lib, stdenv, fetchFromGitHub, cmake, ninja , gfortran, blas, lapack, eigen , useMpi ? false , mpi @@ -21,7 +21,7 @@ stdenv.mkDerivation rec { sha256 = "sha256-HCvapLba8oLqx9I5+KDAU0s/dTmdWOEilS75i4gyfC0="; }; - nativeBuildInputs = [ cmake gfortran ]; + nativeBuildInputs = [ cmake gfortran ninja ]; buildInputs = assert (blas.isILP64 == lapack.isILP64); [ blas lapack @@ -33,10 +33,10 @@ stdenv.mkDerivation rec { doCheck = true; cmakeFlags = [ - "-DBUILD_SHARED_LIBS=ON" - "-DINTERFACE64=${if blas.isILP64 then "1" else "0"}" - "-DMPI=${if useMpi then "ON" else "OFF"}" - "-DICB=ON" + (lib.cmakeBool "BUILD_SHARED_LIBS" stdenv.hostPlatform.hasSharedLibraries) + (lib.cmakeBool "ICB" true) + (lib.cmakeBool "INTERFACE64" blas.isILP64) + (lib.cmakeBool "MPI" useMpi) ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ # prevent cmake from using Accelerate, which causes single precision tests # to segfault @@ -48,10 +48,6 @@ stdenv.mkDerivation rec { export OMP_NUM_THREADS=2 ''; - postFixup = lib.optionalString stdenv.hostPlatform.isDarwin '' - install_name_tool -change libblas.dylib ${blas}/lib/libblas.dylib $out/lib/libarpack.dylib - ''; - passthru = { inherit (blas) isILP64; tests = { From 89e9ea24c773e80a19962fe489c017c4df959b2d Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Fri, 27 Dec 2024 21:44:48 -0800 Subject: [PATCH 3/4] arpack: Enable eigenvalue-problems solver based on ICB and eigen The arpack package included the eigen library and added it to the build inputs but neglected to enable its use by setting `EIGEN=ON` in the build flags. Enable support for eigenvalue-problems solver based on ICB and eigen and disable parallel checking as the tests fail when run in parallel. --- pkgs/by-name/ar/arpack/package.nix | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/ar/arpack/package.nix b/pkgs/by-name/ar/arpack/package.nix index 28c4c77c5dd3..3023e9a3e9b5 100644 --- a/pkgs/by-name/ar/arpack/package.nix +++ b/pkgs/by-name/ar/arpack/package.nix @@ -30,10 +30,14 @@ stdenv.mkDerivation rec { nativeCheckInputs = lib.optional useMpi openssh; + # a couple tests fail when run in parallel doCheck = true; + enableParallelChecking = false; cmakeFlags = [ (lib.cmakeBool "BUILD_SHARED_LIBS" stdenv.hostPlatform.hasSharedLibraries) + (lib.cmakeBool "EIGEN" true) + (lib.cmakeBool "EXAMPLES" true) (lib.cmakeBool "ICB" true) (lib.cmakeBool "INTERFACE64" blas.isILP64) (lib.cmakeBool "MPI" useMpi) @@ -43,11 +47,6 @@ stdenv.mkDerivation rec { "-DBLA_VENDOR=Generic" ]; - preCheck = '' - # Prevent tests from using all cores - export OMP_NUM_THREADS=2 - ''; - passthru = { inherit (blas) isILP64; tests = { From 2f215b76aeda958c64130fe4f2805e8e754d988f Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Fri, 27 Dec 2024 22:14:47 -0800 Subject: [PATCH 4/4] arpack: add option to use macOS Accelerate Copy darwin flags `-ff2c -fno-second-underscore` from workflow to use Accelerate without segfaulting / failing tests and enable the Accelerate framework when `useAccel` is true. https://github.com/opencollab/arpack-ng/blob/804fa3149a0f773064198a8e883bd021832157ca/.github/workflows/jobs.yml#L184-L192 --- pkgs/by-name/ar/arpack/package.nix | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkgs/by-name/ar/arpack/package.nix b/pkgs/by-name/ar/arpack/package.nix index 3023e9a3e9b5..4e059b3ea95c 100644 --- a/pkgs/by-name/ar/arpack/package.nix +++ b/pkgs/by-name/ar/arpack/package.nix @@ -4,11 +4,13 @@ , mpi , openssh , igraph +, useAccel ? false #use Accelerate framework on darwin }: # MPI version can only be built with LP64 interface. # See https://github.com/opencollab/arpack-ng#readme assert useMpi -> !blas.isILP64; +assert useAccel -> stdenv.hostPlatform.isDarwin; stdenv.mkDerivation rec { pname = "arpack"; @@ -22,11 +24,11 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = [ cmake gfortran ninja ]; - buildInputs = assert (blas.isILP64 == lapack.isILP64); [ - blas - lapack + buildInputs = [ eigen - ] ++ lib.optional useMpi mpi; + ] ++ lib.optionals (!useAccel) (assert (blas.isILP64 == lapack.isILP64); [ + blas lapack + ]) ++ lib.optional useMpi mpi; nativeCheckInputs = lib.optional useMpi openssh; @@ -34,21 +36,26 @@ stdenv.mkDerivation rec { doCheck = true; enableParallelChecking = false; + env = lib.optionalAttrs useAccel { + # Without these flags some tests will fail / segfault when using Accelerate + # framework. They were pulled from the CI Workflow + # https://github.com/opencollab/arpack-ng/blob/804fa3149a0f773064198a8e883bd021832157ca/.github/workflows/jobs.yml#L184-L192 + FFLAGS = "-ff2c -fno-second-underscore"; + }; + cmakeFlags = [ (lib.cmakeBool "BUILD_SHARED_LIBS" stdenv.hostPlatform.hasSharedLibraries) (lib.cmakeBool "EIGEN" true) (lib.cmakeBool "EXAMPLES" true) (lib.cmakeBool "ICB" true) - (lib.cmakeBool "INTERFACE64" blas.isILP64) + (lib.cmakeBool "INTERFACE64" (!useAccel && blas.isILP64)) (lib.cmakeBool "MPI" useMpi) ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ - # prevent cmake from using Accelerate, which causes single precision tests - # to segfault - "-DBLA_VENDOR=Generic" + "-DBLA_VENDOR=${if useAccel then "Apple" else "Generic"}" ]; passthru = { - inherit (blas) isILP64; + isILP64 = !useAccel && blas.isILP64; tests = { inherit igraph; };