Commit 7814422e authored by Phillip Seeber's avatar Phillip Seeber
Browse files

openmolcas: fix blas/lapack usage and qcmaquis builds

parent d1a19f52
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
diff --git a/src/gctime.c b/src/gctime.c
index 34fcb6f..832459c 100644
--- a/src/gctime.c
+++ b/src/gctime.c
@@ -1,14 +1,15 @@
+#include <string.h>
 typedef long f77_int;     /* Fortran integer type */
 typedef char * f77_char;    /* Fortran character argument */
 #define CH_F2C(X) ((char *) (X))  /* How to get char ptr from F77 argument */
-gctime (fstr, lstr) f77_char *fstr; int lstr; {
+int gctime (fstr, lstr) f77_char *fstr; int lstr; {
    long time(), t;
    char *ctime();
    t = time ( (long *) 0);
    strcpy(CH_F2C(fstr),ctime(&t));
    return (0);
    }
-gctime_(fstr, lstr) f77_char *fstr; int lstr; {
+int gctime_(fstr, lstr) f77_char *fstr; int lstr; {
    long time(), t;
    char *ctime();
    t = time ( (long *) 0);
+0 −12
Original line number Diff line number Diff line
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 276ae4e2..db13e6e3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1507,7 +1507,6 @@ if (LINALG STREQUAL "OpenBLAS")
     NAMES openblas
     PATHS ${OPENBLASROOT}
     PATH_SUFFIXES lib
-    NO_DEFAULT_PATH
   )
 
   if (NOT LIBOPENBLAS)
+53 −49
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
  gfortran,
  perl,
  blas-ilp64,
  lapack-ilp64,
  hdf5-cpp,
  python3,
  texliveMinimal,
@@ -16,7 +17,7 @@
  gsl,
  boost,
  autoPatchelfHook,
  enableQcmaquis ? false,
  enableQcmaquis ? true,
  # Note that the CASPT2 module is broken with MPI
  # See https://gitlab.com/Molcas/OpenMolcas/-/issues/169
  enableMpi ? false,
@@ -25,11 +26,7 @@
}:

assert blas-ilp64.isILP64;
assert lib.elem blas-ilp64.passthru.implementation [
  "openblas"
  "mkl"
];
assert enableQcmaquis -> lib.elem blas-ilp64.passthru.implementation "mkl";
assert lapack-ilp64.isILP64;

let
  python = python3.withPackages (
@@ -46,12 +43,28 @@ let
    rev = "release-3.1.4"; # Must match tag in cmake/custom/qcmaquis.cmake
    hash = "sha256-vhC5k+91IPFxdCi5oYt1NtF9W08RxonJjPpA0ls4I+o=";
  };
  nevtp2Src = fetchFromGitHub {

  # NEVPT2 sources must be patched to be valid C code in gctime.c
  nevpt2Src = stdenv.mkDerivation {
    pname = "nevpt2-src";
    version = "unstable";
    phases = [
      "unpackPhase"
      "patchPhase"
      "installPhase"
    ];
    src = fetchFromGitHub {
      owner = "qcscine";
      repo = "nevpt2";
      rev = "e1484fd"; # Must match tag in cmake/custom/nevpt2.cmake
      hash = "sha256-Vl+FhwhJBbD/7U2CwsYE9BClSQYLJ8DKXV9EXxQUmz0=";
    };
    patches = [ ./nevpt2.patch ];
    installPhase = ''
      mkdir $out
      cp -r * $out/.
    '';
  };

in
stdenv.mkDerivation rec {
@@ -66,10 +79,7 @@ stdenv.mkDerivation rec {
  };

  patches = [
    # Required to handle openblas multiple outputs
    ./openblasPath.patch

    # Required for a local QCMaquis build
    # Required for a local QCMaquis build. Also sanitises QCMaquis BLAS/LAPACK handling
    ./qcmaquis.patch
  ];

@@ -83,7 +93,7 @@ stdenv.mkDerivation rec {
      --subst-var-by "qcmaquis_src_url" "file://${qcmaquisSrc}"

    substituteInPlace cmake/custom/nevpt2.cmake \
      --subst-var-by "nevpt2_src_url" "file://${nevtp2Src}"
      --subst-var-by "nevpt2_src_url" "file://${nevpt2Src}"
  '';

  nativeBuildInputs = [
@@ -97,13 +107,14 @@ stdenv.mkDerivation rec {

  buildInputs =
    [
      blas-ilp64.passthru.provider
      hdf5-cpp
      python
      armadillo
      libxc
      gsl.dev
      boost
      blas-ilp64
      lapack-ilp64
    ]
    ++ lib.optionals enableMpi [
      mpi
@@ -112,38 +123,31 @@ stdenv.mkDerivation rec {

  passthru = lib.optionalAttrs enableMpi { inherit mpi; };

  cmakeFlags =
    [
  preConfigure =
    ''
      cmakeFlagsArray+=(
        "-DOPENMP=ON"
        "-DTOOLS=ON"
        "-DHDF5=ON"
        "-DFDE=ON"
        "-DEXTERNAL_LIBXC=${lib.getDev libxc}"
      (lib.strings.cmakeBool "DMRG" enableQcmaquis)
      (lib.strings.cmakeBool "NEVPT2" enableQcmaquis)
        ${lib.strings.cmakeBool "DMRG" enableQcmaquis}
        ${lib.strings.cmakeBool "NEVPT2" enableQcmaquis}
        "-DCMAKE_SKIP_BUILD_RPATH=ON"
      (lib.strings.cmakeBool "BUILD_STATIC_LIBS" stdenv.hostPlatform.isStatic)
      (lib.strings.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic))
    ]
    ++ lib.optionals (blas-ilp64.passthru.implementation == "openblas") [
      "-DOPENBLASROOT=${blas-ilp64.passthru.provider.dev}"
      "-DLINALG=OpenBLAS"
    ]
    ++ lib.optionals (blas-ilp64.passthru.implementation == "mkl") [
      "-DMKLROOT=${blas-ilp64.passthru.provider}"
      "-DLINALG=MKL"
    ]
    ++ lib.optionals enableMpi [
      "-DGA=ON"
      "-DMPI=ON"
    ];

  preConfigure = lib.optionalString enableMpi ''
        ${lib.strings.cmakeBool "BUILD_STATIC_LIBS" stdenv.hostPlatform.isStatic}
        ${lib.strings.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic)}
        "-DLINALG=Manual"
        "-DLINALG_LIBRARIES=-lblas -llapack"
        ${lib.strings.cmakeBool "DGA" enableMpi}
        ${lib.strings.cmakeBool "MPI" enableMpi}
      )
    ''
    + lib.optionalString enableMpi ''
      export GAROOT=${globalarrays};
    '';

  postConfigure = ''
  # The Makefile will install pymolcas during the build grrr.
  postConfigure = ''
    mkdir -p $out/bin
    export PATH=$PATH:$out/bin
  '';
@@ -158,8 +162,8 @@ stdenv.mkDerivation rec {
  # removed by autopatchelf
  noAuditTmpdir = true;

  postFixup = ''
  # Wrong store path in shebang (bare Python, no Python pkgs), force manual re-patching
  postFixup = ''
    for exe in $(find $out/bin/ -type f -name "*.py"); do
      sed -i "1s:.*:#!${python}/bin/python:" "$exe"
    done
+55 −0
Original line number Diff line number Diff line
@@ -45,3 +45,58 @@ index 5fd1ef207..8d2957c6e 100644
                        SOURCE_SUBDIR dmrg
                        CMAKE_ARGS ${EP_CMAKE_ARGS}
                        CMAKE_CACHE_ARGS ${EP_CMAKE_CACHE_ARGS}
diff --git a/cmake/custom/qcmaquis.cmake b/cmake/custom/qcmaquis.cmake
index 5fd1ef207..4291ec3d7 100644
--- a/cmake/custom/qcmaquis.cmake
+++ b/cmake/custom/qcmaquis.cmake
@@ -94,47 +94,9 @@ if (NOT MAQUIS_DMRG_FOUND) # Does the opposite work?
     )
   endif (BOOST_ROOT)

-  if (LINALG STREQUAL "Manual")
-    target_files (LINALG_LIBRARIES_FILES ${LINALG_LIBRARIES})
-    list (APPEND LINALG_LIBRARIES_FILES ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
-    string (REPLACE ";" '\' LINALG_LIBRARIES_FILES "${LINALG_LIBRARIES_FILES}")
-    list (APPEND QCMaquisCMakeArgs
-          "-DBLAS_LAPACK_SELECTOR=manual"
-          "-DMAQUISLapack_LIBRARIES=${LINALG_LIBRARIES_FILES}"
-    )
-  elseif (LINALG STREQUAL "MKL")
-    list (APPEND QCMaquisCMakeArgs
-          "-DBLAS_LAPACK_SELECTOR=mkl_sequential"
-    )
-  elseif (LINALG STREQUAL "OpenBLAS")
-    list (APPEND QCMaquisCMakeArgs
-          "-DBLAS_LAPACK_SELECTOR=openblas"
-          "-DOPENBLASROOT=${OPENBLASROOT}"
-    )
-  elseif (LINALG STREQUAL "Accelerate")
-    list (APPEND QCMaquisCMakeArgs
-          "-DBLAS_LAPACK_SELECTOR:STRING=veclib"
-    )
-  elseif (LINALG STREQUAL "Internal")
-
-    # To link QCMaquis with Fortran static libraries, we
-    # need to add -lgfortran for gfortran
-    # It seems that ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}
-    # is not suited for this because it contains also other unnecessary libraries
-
-    # for some reason, the list does not work if the generator expression -lgfortran is not first
-    # but for correct linking it needs to be last AND with a prepended "-l"
-    if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
-      set (Fortran_RUNTIME_LIBRARY "gfortran")
-    endif ()
-
-    list (APPEND QCMaquisCMakeArgs
-          "-DBLAS_LAPACK_SELECTOR=manual"
-          "-DMAQUISLapack_LIBRARIES=$<$<BOOL:Fortran_RUNTIME_LIBRARY>:${Fortran_RUNTIME_LIBRARY}\ >$<TARGET_FILE:blas>\ $<TARGET_FILE:lapack>\ $<TARGET_FILE:blas>\ -l$<$<BOOL:Fortran_RUNTIME_LIBRARY>:${Fortran_RUNTIME_LIBRARY}>"
-    )
-  else ()
-    message (FATAL_ERROR "LINALG=${LINALG} is not supported by QCMaquis")
-  endif ()
+  list (APPEND QCMaquisCMakeArgs
+        "-DBLAS_LAPACK_SELECTOR=auto"
+  )

   # Enabling source changes to keep ExternalProject happy
   set (CMAKE_DISABLE_SOURCE_CHANGES OFF