Skip to content

Commit 7814422

Browse files
committed
openmolcas: fix blas/lapack usage and qcmaquis builds
1 parent d1a19f5 commit 7814422

File tree

4 files changed

+130
-61
lines changed

4 files changed

+130
-61
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/src/gctime.c b/src/gctime.c
2+
index 34fcb6f..832459c 100644
3+
--- a/src/gctime.c
4+
+++ b/src/gctime.c
5+
@@ -1,14 +1,15 @@
6+
+#include <string.h>
7+
typedef long f77_int; /* Fortran integer type */
8+
typedef char * f77_char; /* Fortran character argument */
9+
#define CH_F2C(X) ((char *) (X)) /* How to get char ptr from F77 argument */
10+
-gctime (fstr, lstr) f77_char *fstr; int lstr; {
11+
+int gctime (fstr, lstr) f77_char *fstr; int lstr; {
12+
long time(), t;
13+
char *ctime();
14+
t = time ( (long *) 0);
15+
strcpy(CH_F2C(fstr),ctime(&t));
16+
return (0);
17+
}
18+
-gctime_(fstr, lstr) f77_char *fstr; int lstr; {
19+
+int gctime_(fstr, lstr) f77_char *fstr; int lstr; {
20+
long time(), t;
21+
char *ctime();
22+
t = time ( (long *) 0);

pkgs/by-name/op/openmolcas/openblasPath.patch

Lines changed: 0 additions & 12 deletions
This file was deleted.

pkgs/by-name/op/openmolcas/package.nix

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
gfortran,
88
perl,
99
blas-ilp64,
10+
lapack-ilp64,
1011
hdf5-cpp,
1112
python3,
1213
texliveMinimal,
@@ -16,7 +17,7 @@
1617
gsl,
1718
boost,
1819
autoPatchelfHook,
19-
enableQcmaquis ? false,
20+
enableQcmaquis ? true,
2021
# Note that the CASPT2 module is broken with MPI
2122
# See https://gitlab.com/Molcas/OpenMolcas/-/issues/169
2223
enableMpi ? false,
@@ -25,11 +26,7 @@
2526
}:
2627

2728
assert blas-ilp64.isILP64;
28-
assert lib.elem blas-ilp64.passthru.implementation [
29-
"openblas"
30-
"mkl"
31-
];
32-
assert enableQcmaquis -> lib.elem blas-ilp64.passthru.implementation "mkl";
29+
assert lapack-ilp64.isILP64;
3330

3431
let
3532
python = python3.withPackages (
@@ -46,11 +43,27 @@ let
4643
rev = "release-3.1.4"; # Must match tag in cmake/custom/qcmaquis.cmake
4744
hash = "sha256-vhC5k+91IPFxdCi5oYt1NtF9W08RxonJjPpA0ls4I+o=";
4845
};
49-
nevtp2Src = fetchFromGitHub {
50-
owner = "qcscine";
51-
repo = "nevpt2";
52-
rev = "e1484fd"; # Must match tag in cmake/custom/nevpt2.cmake
53-
hash = "sha256-Vl+FhwhJBbD/7U2CwsYE9BClSQYLJ8DKXV9EXxQUmz0=";
46+
47+
# NEVPT2 sources must be patched to be valid C code in gctime.c
48+
nevpt2Src = stdenv.mkDerivation {
49+
pname = "nevpt2-src";
50+
version = "unstable";
51+
phases = [
52+
"unpackPhase"
53+
"patchPhase"
54+
"installPhase"
55+
];
56+
src = fetchFromGitHub {
57+
owner = "qcscine";
58+
repo = "nevpt2";
59+
rev = "e1484fd"; # Must match tag in cmake/custom/nevpt2.cmake
60+
hash = "sha256-Vl+FhwhJBbD/7U2CwsYE9BClSQYLJ8DKXV9EXxQUmz0=";
61+
};
62+
patches = [ ./nevpt2.patch ];
63+
installPhase = ''
64+
mkdir $out
65+
cp -r * $out/.
66+
'';
5467
};
5568

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

6881
patches = [
69-
# Required to handle openblas multiple outputs
70-
./openblasPath.patch
71-
72-
# Required for a local QCMaquis build
82+
# Required for a local QCMaquis build. Also sanitises QCMaquis BLAS/LAPACK handling
7383
./qcmaquis.patch
7484
];
7585

@@ -83,7 +93,7 @@ stdenv.mkDerivation rec {
8393
--subst-var-by "qcmaquis_src_url" "file://${qcmaquisSrc}"
8494
8595
substituteInPlace cmake/custom/nevpt2.cmake \
86-
--subst-var-by "nevpt2_src_url" "file://${nevtp2Src}"
96+
--subst-var-by "nevpt2_src_url" "file://${nevpt2Src}"
8797
'';
8898

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

98108
buildInputs =
99109
[
100-
blas-ilp64.passthru.provider
101110
hdf5-cpp
102111
python
103112
armadillo
104113
libxc
105114
gsl.dev
106115
boost
116+
blas-ilp64
117+
lapack-ilp64
107118
]
108119
++ lib.optionals enableMpi [
109120
mpi
@@ -112,38 +123,31 @@ stdenv.mkDerivation rec {
112123

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

115-
cmakeFlags =
116-
[
117-
"-DOPENMP=ON"
118-
"-DTOOLS=ON"
119-
"-DHDF5=ON"
120-
"-DFDE=ON"
121-
"-DEXTERNAL_LIBXC=${lib.getDev libxc}"
122-
(lib.strings.cmakeBool "DMRG" enableQcmaquis)
123-
(lib.strings.cmakeBool "NEVPT2" enableQcmaquis)
124-
"-DCMAKE_SKIP_BUILD_RPATH=ON"
125-
(lib.strings.cmakeBool "BUILD_STATIC_LIBS" stdenv.hostPlatform.isStatic)
126-
(lib.strings.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic))
127-
]
128-
++ lib.optionals (blas-ilp64.passthru.implementation == "openblas") [
129-
"-DOPENBLASROOT=${blas-ilp64.passthru.provider.dev}"
130-
"-DLINALG=OpenBLAS"
131-
]
132-
++ lib.optionals (blas-ilp64.passthru.implementation == "mkl") [
133-
"-DMKLROOT=${blas-ilp64.passthru.provider}"
134-
"-DLINALG=MKL"
135-
]
136-
++ lib.optionals enableMpi [
137-
"-DGA=ON"
138-
"-DMPI=ON"
139-
];
140-
141-
preConfigure = lib.optionalString enableMpi ''
142-
export GAROOT=${globalarrays};
143-
'';
144-
126+
preConfigure =
127+
''
128+
cmakeFlagsArray+=(
129+
"-DOPENMP=ON"
130+
"-DTOOLS=ON"
131+
"-DHDF5=ON"
132+
"-DFDE=ON"
133+
"-DEXTERNAL_LIBXC=${lib.getDev libxc}"
134+
${lib.strings.cmakeBool "DMRG" enableQcmaquis}
135+
${lib.strings.cmakeBool "NEVPT2" enableQcmaquis}
136+
"-DCMAKE_SKIP_BUILD_RPATH=ON"
137+
${lib.strings.cmakeBool "BUILD_STATIC_LIBS" stdenv.hostPlatform.isStatic}
138+
${lib.strings.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic)}
139+
"-DLINALG=Manual"
140+
"-DLINALG_LIBRARIES=-lblas -llapack"
141+
${lib.strings.cmakeBool "DGA" enableMpi}
142+
${lib.strings.cmakeBool "MPI" enableMpi}
143+
)
144+
''
145+
+ lib.optionalString enableMpi ''
146+
export GAROOT=${globalarrays};
147+
'';
148+
149+
# The Makefile will install pymolcas during the build grrr.
145150
postConfigure = ''
146-
# The Makefile will install pymolcas during the build grrr.
147151
mkdir -p $out/bin
148152
export PATH=$PATH:$out/bin
149153
'';
@@ -158,8 +162,8 @@ stdenv.mkDerivation rec {
158162
# removed by autopatchelf
159163
noAuditTmpdir = true;
160164

165+
# Wrong store path in shebang (bare Python, no Python pkgs), force manual re-patching
161166
postFixup = ''
162-
# Wrong store path in shebang (bare Python, no Python pkgs), force manual re-patching
163167
for exe in $(find $out/bin/ -type f -name "*.py"); do
164168
sed -i "1s:.*:#!${python}/bin/python:" "$exe"
165169
done

pkgs/by-name/op/openmolcas/qcmaquis.patch

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,58 @@ index 5fd1ef207..8d2957c6e 100644
4545
SOURCE_SUBDIR dmrg
4646
CMAKE_ARGS ${EP_CMAKE_ARGS}
4747
CMAKE_CACHE_ARGS ${EP_CMAKE_CACHE_ARGS}
48+
diff --git a/cmake/custom/qcmaquis.cmake b/cmake/custom/qcmaquis.cmake
49+
index 5fd1ef207..4291ec3d7 100644
50+
--- a/cmake/custom/qcmaquis.cmake
51+
+++ b/cmake/custom/qcmaquis.cmake
52+
@@ -94,47 +94,9 @@ if (NOT MAQUIS_DMRG_FOUND) # Does the opposite work?
53+
)
54+
endif (BOOST_ROOT)
55+
56+
- if (LINALG STREQUAL "Manual")
57+
- target_files (LINALG_LIBRARIES_FILES ${LINALG_LIBRARIES})
58+
- list (APPEND LINALG_LIBRARIES_FILES ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
59+
- string (REPLACE ";" '\' LINALG_LIBRARIES_FILES "${LINALG_LIBRARIES_FILES}")
60+
- list (APPEND QCMaquisCMakeArgs
61+
- "-DBLAS_LAPACK_SELECTOR=manual"
62+
- "-DMAQUISLapack_LIBRARIES=${LINALG_LIBRARIES_FILES}"
63+
- )
64+
- elseif (LINALG STREQUAL "MKL")
65+
- list (APPEND QCMaquisCMakeArgs
66+
- "-DBLAS_LAPACK_SELECTOR=mkl_sequential"
67+
- )
68+
- elseif (LINALG STREQUAL "OpenBLAS")
69+
- list (APPEND QCMaquisCMakeArgs
70+
- "-DBLAS_LAPACK_SELECTOR=openblas"
71+
- "-DOPENBLASROOT=${OPENBLASROOT}"
72+
- )
73+
- elseif (LINALG STREQUAL "Accelerate")
74+
- list (APPEND QCMaquisCMakeArgs
75+
- "-DBLAS_LAPACK_SELECTOR:STRING=veclib"
76+
- )
77+
- elseif (LINALG STREQUAL "Internal")
78+
-
79+
- # To link QCMaquis with Fortran static libraries, we
80+
- # need to add -lgfortran for gfortran
81+
- # It seems that ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}
82+
- # is not suited for this because it contains also other unnecessary libraries
83+
-
84+
- # for some reason, the list does not work if the generator expression -lgfortran is not first
85+
- # but for correct linking it needs to be last AND with a prepended "-l"
86+
- if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
87+
- set (Fortran_RUNTIME_LIBRARY "gfortran")
88+
- endif ()
89+
-
90+
- list (APPEND QCMaquisCMakeArgs
91+
- "-DBLAS_LAPACK_SELECTOR=manual"
92+
- "-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}>"
93+
- )
94+
- else ()
95+
- message (FATAL_ERROR "LINALG=${LINALG} is not supported by QCMaquis")
96+
- endif ()
97+
+ list (APPEND QCMaquisCMakeArgs
98+
+ "-DBLAS_LAPACK_SELECTOR=auto"
99+
+ )
100+
101+
# Enabling source changes to keep ExternalProject happy
102+
set (CMAKE_DISABLE_SOURCE_CHANGES OFF

0 commit comments

Comments
 (0)