From 524e1707179653f3737210f4f23a127ad24f715e Mon Sep 17 00:00:00 2001 From: Matias Zwinger Date: Thu, 18 Jul 2024 11:54:15 +0300 Subject: [PATCH 1/4] Refactor Nix flake checks --- flake.nix | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index b1bca618e6..83469e1538 100644 --- a/flake.nix +++ b/flake.nix @@ -53,16 +53,13 @@ buildInputs, cmakeFlags, doCheck, - checkPhase ? '' - runHook preCheckPhase - ctest -j $NIX_BUILD_CORES -L fast - runHook postCheckPhase - '', + checkOptions, + ... } @ inputs: let storepath = placeholder "out"; in pkgs.stdenv.mkDerivation { - inherit name doCheck checkPhase storepath; + inherit name doCheck storepath; pname = "${name}-devel"; @@ -111,6 +108,12 @@ ] ++ inputs.cmakeFlags; + checkPhase = '' + runHook preCheckPhase + ctest -j $NIX_BUILD_CORES -L ${checkOptions} + runHook postCheckPhase + ''; + autoPatchelfIgnoreMissingDeps = ["libmpi_stubs.so"]; preConfigure = '' @@ -123,18 +126,24 @@ ]; }; - default = {doCheck ? false}: + default = { + doCheck ? false, + checkOptions ? "-L quick", + }: basePkg { - inherit doCheck; + inherit doCheck checkOptions; name = "elmer"; nativeBuildInputs = []; buildInputs = []; cmakeFlags = []; }; - gui = {doCheck ? false}: + gui = { + doCheck ? false, + checkOptions ? "-L quick", + }: basePkg { - inherit doCheck; + inherit doCheck checkOptions; name = "elmer-gui"; nativeBuildInputs = [pkgs.libsForQt5.wrapQtAppsHook]; @@ -158,9 +167,12 @@ ]; }; - ice = {doCheck ? false}: + ice = { + doCheck ? false, + checkOptions ? ''-L fast -E "(Hydro_Coupled)|(Hydro_SedOnly)|(Proj_South)"'', + }: basePkg { - inherit doCheck; + inherit doCheck checkOptions; name = "elmer-ice"; nativeBuildInputs = []; @@ -208,12 +220,6 @@ "-DWITH_Trilinos:BOOL=FALSE" ]; - - checkPhase = '' - runHook preCheckPhase - ctest -j $NIX_BUILD_CORES -L fast -E "(Hydro_Coupled)|(Hydro_SedOnly)|(Proj_South)" - runHook postCheckPhase - ''; }; in { checks = { From 35fcbe4961c479fdbb9e85d1463c3c2bb4275b3d Mon Sep 17 00:00:00 2001 From: Matias Zwinger Date: Thu, 18 Jul 2024 11:59:12 +0300 Subject: [PATCH 2/4] Add nix flake check workflow --- .github/workflows/nix.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/workflows/nix.yaml diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml new file mode 100644 index 0000000000..dfaf001698 --- /dev/null +++ b/.github/workflows/nix.yaml @@ -0,0 +1,11 @@ +name: "nix flake check" +on: + pull_request: + push: +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + - run: nix flake check -L From 603e33cf1b65d12464be39c2528e12ddb32dc5e2 Mon Sep 17 00:00:00 2001 From: Matias Zwinger Date: Thu, 18 Jul 2024 14:12:41 +0300 Subject: [PATCH 3/4] Nix flake: filter source better --- flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake.nix b/flake.nix index 83469e1538..21fa6a607d 100644 --- a/flake.nix +++ b/flake.nix @@ -69,8 +69,11 @@ (nix-filter.lib.matchExt "nix") "flake.lock" ".git" + ".github" ".gitignore" ".gitmodules" + ".travis.yml" + ".vscode" ]; }; From f9d7e21d53c31b8282f1f1930e56bd2eedc400df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Thu, 18 Jul 2024 16:49:41 +0200 Subject: [PATCH 4/4] Fix compatibility with newer versions of UMFPACK. In old versions of UMFPACK (like the one that is bundled with ElmerFEM), the `*l_*` versions of its functions used `long` for indices in their interface. That was later changed to use `SuiteSparse_long`. `SuiteSparse_long` was `long long` on Windows and `long` on any other platform. For the latest versions of UMFPACK, `SuiteSparse_long` is `int64_t` (on all platforms). This change fixes compilation errors on Windows (where `long` is 32-bit wide also on 64-bit, LLP64) and macOS (where `int64_t` is `long long` which has the same size as `long` but is still technically a different type than `long`). The change still maintains compatibility with old versions of UMFPACK (like the one that is bundled with ElmerFEM). --- CMakeLists.txt | 26 ++++++++++++++++++++++++-- fem/config.h.cmake | 3 +++ fem/src/DirectSolve.F90 | 10 +++++----- fem/src/umf4_f77wrapper.c | 6 +++++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d38b1b2e4..d6bfdd440c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -607,12 +607,34 @@ IF(WITH_ElmerIce) ENDIF(WITH_ElmerIce) IF (EXTERNAL_UMFPACK) - MESSAGE(STATUS "Using external UMFPACK instead of built-in") - FIND_PACKAGE(UMFPACK REQUIRED) + MESSAGE(STATUS "Using external UMFPACK instead of built-in") + FIND_PACKAGE(UMFPACK REQUIRED) + + # Check for size of "SuiteSparse_long" + INCLUDE(CheckTypeSize) + SET(old_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}) + SET(old_CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES}) + LIST(APPEND CMAKE_REQUIRED_INCLUDES "${UMFPACK_INCLUDE_DIR}") + LIST(APPEND CMAKE_EXTRA_INCLUDE_FILES "umfpack.h") + CHECK_TYPE_SIZE("SuiteSparse_long" SIZEOF_SUITESPARSE_LONG LANGUAGE C) + SET(CMAKE_REQUIRED_INCLUDES ${old_CMAKE_REQUIRED_INCLUDES}) + SET(CMAKE_EXTRA_INCLUDE_FILES ${old_CMAKE_EXTRA_INCLUDE_FILES}) + IF (HAVE_SIZEOF_SUITESPARSE_LONG) + IF (SIZEOF_SUITESPARSE_LONG EQUAL 4) + SET(UMFPACK_LONG_FORTRAN_TYPE "C_INT32_T") + ELSE() + SET(UMFPACK_LONG_FORTRAN_TYPE "C_INT64_T") + ENDIF() + ENDIF() ELSE() MESSAGE(STATUS "Using built-in UMFPACK") ADD_SUBDIRECTORY(umfpack) ENDIF() +IF(NOT DEFINED UMFPACK_LONG_FORTRAN_TYPE) + # Old versions of UMFPACK before "SuiteSparse_long" was defined used "long" + SET(UMFPACK_LONG_FORTRAN_TYPE "C_LONG") +ENDIF() + ADD_SUBDIRECTORY(fhutiter) ADD_SUBDIRECTORY(meshgen2d) ADD_SUBDIRECTORY(fem) diff --git a/fem/config.h.cmake b/fem/config.h.cmake index 524e76377e..67dc31e1f2 100644 --- a/fem/config.h.cmake +++ b/fem/config.h.cmake @@ -141,6 +141,9 @@ /* Define if you have a UMFPACK library. */ #define HAVE_UMFPACK +/* Define to the Fortran type that matches SuiteSparse_long. */ +#cmakedefine UMFPACK_LONG_FORTRAN_TYPE @UMFPACK_LONG_FORTRAN_TYPE@ + /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H diff --git a/fem/src/DirectSolve.F90 b/fem/src/DirectSolve.F90 index 798bac7ef1..98a1c29991 100644 --- a/fem/src/DirectSolve.F90 +++ b/fem/src/DirectSolve.F90 @@ -375,7 +375,7 @@ SUBROUTINE umf4_l_sym( m,n,rows,cols,values,symbolic,control,iinfo ) & BIND(C,name='umf4_l_sym') USE, INTRINSIC :: ISO_C_BINDING !INTEGER(CAddrInt) ::m,n,rows(*),cols(*) - INTEGER(C_LONG) :: m,n,rows(*),cols(*) !TODO: m,n of are called with AddrInt kind + INTEGER(UMFPACK_LONG_FORTRAN_TYPE) :: m,n,rows(*),cols(*) !TODO: m,n of are called with AddrInt kind INTEGER(CAddrInt) :: symbolic REAL(C_DOUBLE) :: Values(*), control(*),iinfo(*) END SUBROUTINE umf4_l_sym @@ -384,7 +384,7 @@ SUBROUTINE umf4_l_num( rows,cols,values,symbolic,numeric, control,iinfo ) & BIND(C,name='umf4_l_num') USE, INTRINSIC :: ISO_C_BINDING !INTEGER(CAddrInt) :: rows(*),cols(*) - INTEGER(C_LONG) :: rows(*),cols(*) + INTEGER(UMFPACK_LONG_FORTRAN_TYPE) :: rows(*),cols(*) INTEGER(CAddrInt) :: numeric, symbolic REAL(C_DOUBLE) :: Values(*), control(*),iinfo(*) END SUBROUTINE umf4_l_num @@ -393,7 +393,7 @@ SUBROUTINE umf4_l_sol( sys, x, b, numeric, control, iinfo ) & BIND(C,name='umf4_l_sol') USE, INTRINSIC :: ISO_C_BINDING !INTEGER(CAddrInt) :: sys - INTEGER(C_LONG) :: sys + INTEGER(UMFPACK_LONG_FORTRAN_TYPE) :: sys INTEGER(CAddrInt) :: numeric REAL(C_DOUBLE) :: x(*), b(*), control(*), iinfo(*) END SUBROUTINE umf4_l_sol @@ -414,8 +414,8 @@ END SUBROUTINE umf4_l_fsym INTEGER :: i, n, status, sys REAL(KIND=dp) :: iInfo(90), Control(20) INTEGER(KIND=AddrInt) :: symbolic, zero=0 - INTEGER(KIND=C_LONG) :: ln, lsys - INTEGER(KIND=C_LONG), ALLOCATABLE :: LRows(:), LCols(:) + INTEGER(KIND=UMFPACK_LONG_FORTRAN_TYPE) :: ln, lsys + INTEGER(KIND=UMFPACK_LONG_FORTRAN_TYPE), ALLOCATABLE :: LRows(:), LCols(:) SAVE iInfo, Control diff --git a/fem/src/umf4_f77wrapper.c b/fem/src/umf4_f77wrapper.c index 683cd1a9aa..fda59b0cee 100644 --- a/fem/src/umf4_f77wrapper.c +++ b/fem/src/umf4_f77wrapper.c @@ -82,6 +82,10 @@ #include "umfpack.h" +#if !defined(SuiteSparse_long) +#define SuiteSparse_long long +#endif + #ifdef NULL #undef NULL #endif @@ -234,7 +238,7 @@ void STDCALLBULL FC_FUNC(umf4fsym,UMF4FSYM) (void **Symbolic) #undef UMFPACK_solve #undef UMFPACK_symbolic -#define Int long +#define Int SuiteSparse_long #define UMFPACK_defaults umfpack_dl_defaults #define UMFPACK_free_numeric umfpack_dl_free_numeric #define UMFPACK_free_symbolic umfpack_dl_free_symbolic