gnu: Use PACKAGE/INHERIT in more places.
[jackhill/guix/guix.git] / gnu / packages / mpi.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2018, 2019 Eric Bavier <bavier@member.fsf.org>
3 ;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2014 Ian Denhardt <ian@zenhack.net>
5 ;;; Copyright © 2016 Andreas Enge <andreas@enge.fr>
6 ;;; Copyright © 2017 Dave Love <fx@gnu.org>
7 ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
8 ;;; Copyright © 2018, 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
9 ;;; Copyright © 2018 Paul Garlick <pgarlick@tourbillion-technology.com>
10 ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
11 ;;;
12 ;;; This file is part of GNU Guix.
13 ;;;
14 ;;; GNU Guix is free software; you can redistribute it and/or modify it
15 ;;; under the terms of the GNU General Public License as published by
16 ;;; the Free Software Foundation; either version 3 of the License, or (at
17 ;;; your option) any later version.
18 ;;;
19 ;;; GNU Guix is distributed in the hope that it will be useful, but
20 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;; GNU General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
27 (define-module (gnu packages mpi)
28 #:use-module (guix packages)
29 #:use-module ((guix licenses) #:prefix license:)
30 #:use-module (guix download)
31 #:use-module (guix utils)
32 #:use-module (guix deprecation)
33 #:use-module (guix build-system gnu)
34 #:use-module (guix build-system python)
35 #:use-module (gnu packages)
36 #:use-module (gnu packages base)
37 #:use-module (gnu packages compression)
38 #:use-module (gnu packages fabric-management)
39 #:use-module (gnu packages gcc)
40 #:use-module (gnu packages java)
41 #:use-module (gnu packages libevent)
42 #:use-module (gnu packages linux)
43 #:use-module (gnu packages pciutils)
44 #:use-module (gnu packages xorg)
45 #:use-module (gnu packages gtk)
46 #:use-module (gnu packages xml)
47 #:use-module (gnu packages perl)
48 #:use-module (gnu packages ncurses)
49 #:use-module (gnu packages parallel)
50 #:use-module (gnu packages pkg-config)
51 #:use-module (gnu packages valgrind)
52 #:use-module (srfi srfi-1)
53 #:use-module (ice-9 match))
54
55 (define-public hwloc-1
56 ;; Note: For now we keep 1.x as the default because many packages have yet
57 ;; to migrate to 2.0.
58 (package
59 (name "hwloc")
60 (version "1.11.12")
61 (source (origin
62 (method url-fetch)
63 (uri (string-append "https://www.open-mpi.org/software/hwloc/v"
64 (version-major+minor version)
65 "/downloads/hwloc-" version ".tar.bz2"))
66 (sha256
67 (base32
68 "0za1b9lvrm3rhn0lrxja5f64r0aq1qs4m0pxn1ji2mbi8ndppyyx"))))
69 (build-system gnu-build-system)
70 (outputs '("out" ;'lstopo' & co., depends on Cairo, libx11, etc.
71 "lib" ;small closure
72 "doc" ;400+ section 3 man pages
73 "debug"))
74 (inputs
75 `(("libx11" ,libx11)
76 ("cairo" ,cairo)
77 ("ncurses" ,ncurses)
78 ("expat" ,expat)
79 ,@(if (not (string-prefix? "armhf"
80 (or (%current-target-system)
81 (%current-system))))
82 `(("numactl" ,numactl))
83 '())))
84 (propagated-inputs
85 ;; hwloc.pc lists it in 'Requires.private'.
86 `(("libpciaccess" ,libpciaccess)))
87 (native-inputs
88 `(("pkg-config" ,pkg-config)))
89 (arguments
90 `(#:configure-flags '("--localstatedir=/var")
91 #:phases
92 (modify-phases %standard-phases
93 (add-before 'check 'skip-linux-libnuma-test
94 (lambda _
95 ;; Arrange to skip 'tests/linux-libnuma', which fails on some
96 ;; machines: <https://github.com/open-mpi/hwloc/issues/213>.
97 (substitute* "tests/linux-libnuma.c"
98 (("numa_available\\(\\)")
99 "-1"))
100 #t))
101 (add-after 'install 'refine-libnuma
102 ;; Give -L arguments for libraries to avoid propagation
103 (lambda* (#:key inputs outputs #:allow-other-keys)
104 (let ((out (assoc-ref outputs "lib"))
105 (numa (assoc-ref inputs "numactl")))
106 (substitute* (map (lambda (f) (string-append out "/" f))
107 '("lib/pkgconfig/hwloc.pc" "lib/libhwloc.la"))
108 (("-lnuma" lib)
109 (string-append "-L" numa "/lib " lib))))))
110 (add-after 'install 'avoid-circular-references
111 (lambda* (#:key outputs #:allow-other-keys)
112 (let ((lib (assoc-ref outputs "lib")))
113 ;; Suppress the 'prefix=' and 'exec_prefix=' lines so that the
114 ;; "lib" output doesn't refer to "out".
115 (substitute* (string-append lib "/lib/pkgconfig/hwloc.pc")
116 (("^.*prefix=.*$")
117 ""))
118 #t)))
119 (add-after 'install 'move-man3-pages
120 (lambda* (#:key outputs #:allow-other-keys)
121 ;; Move section 3 man pages to the "doc" output.
122 (let ((out (assoc-ref outputs "out"))
123 (doc (assoc-ref outputs "doc")))
124 (copy-recursively (string-append out "/share/man/man3")
125 (string-append doc "/share/man/man3"))
126 (delete-file-recursively (string-append out "/share/man/man3"))
127 #t))))))
128 (home-page "https://www.open-mpi.org/projects/hwloc/")
129 (synopsis "Abstraction of hardware architectures")
130 (description
131 "hwloc provides a portable abstraction (across OS,
132 versions, architectures, ...) of the hierarchical topology of modern
133 architectures, including NUMA memory nodes, sockets, shared caches, cores and
134 simultaneous multithreading. It also gathers various attributes such as cache
135 and memory information. It primarily aims at helping high-performance
136 computing applications with gathering information about the hardware so as to
137 exploit it accordingly and efficiently.
138
139 hwloc may display the topology in multiple convenient formats. It also offers
140 a powerful programming interface to gather information about the hardware,
141 bind processes, and much more.")
142 (license license:bsd-3)))
143
144 (define-public hwloc-2
145 ;; Note: 2.x isn't the default yet, see above.
146 (package
147 (inherit hwloc-1)
148 (version "2.4.1")
149 (source (origin
150 (method url-fetch)
151 (uri (string-append "https://download.open-mpi.org/release/hwloc/v"
152 (version-major+minor version)
153 "/hwloc-" version ".tar.bz2"))
154 (sha256
155 (base32
156 "0qyywmyns2jf3is3axrwmffvdd7ji7liy5axp650q4i6kzk2291r"))))
157
158 ;; libnuma is no longer needed.
159 (inputs (alist-delete "numactl" (package-inputs hwloc-1)))
160 (arguments
161 (substitute-keyword-arguments (package-arguments hwloc-1)
162 ((#:phases phases)
163 `(modify-phases ,phases
164 (replace 'skip-linux-libnuma-test
165 (lambda _
166 ;; Arrange to skip 'tests/hwloc/linux-libnuma', which fails on
167 ;; some machines: <https://github.com/open-mpi/hwloc/issues/213>.
168 (substitute* "tests/hwloc/linux-libnuma.c"
169 (("numa_available\\(\\)")
170 "-1"))
171 #t))
172 (add-before 'check 'skip-test-that-fails-on-qemu
173 (lambda _
174 ;; Skip test that fails on emulated hardware due to QEMU bug:
175 ;; <https://bugs.gnu.org/40342>.
176 (substitute* "tests/hwloc/hwloc_get_last_cpu_location.c"
177 (("hwloc_topology_init" all)
178 (string-append "exit (77);\n" all)))
179 #t))))))))
180
181 (define-deprecated hwloc-2.0 hwloc-2)
182
183 (define-public hwloc
184 ;; The latest stable series of hwloc.
185 hwloc-2)
186
187 (define-public openmpi
188 (package
189 (name "openmpi")
190 (version "4.0.5")
191 (source
192 (origin
193 (method url-fetch)
194 (uri (string-append "https://www.open-mpi.org/software/ompi/v"
195 (version-major+minor version)
196 "/downloads/openmpi-" version ".tar.bz2"))
197 (sha256
198 (base32 "02f0r9d3xgs08svkmj8v7lzviyxqnkk4yd3z0wql550xnriki3y5"))
199 (patches (search-patches "openmpi-mtl-priorities.patch"))))
200 (build-system gnu-build-system)
201 (inputs
202 `(("hwloc" ,hwloc-2 "lib")
203 ("gfortran" ,gfortran)
204 ("libfabric" ,libfabric)
205 ("libevent" ,libevent)
206 ("opensm" ,opensm)
207 ,@(if (and (not (%current-target-system))
208 (member (%current-system) (package-supported-systems psm)))
209 `(("psm" ,psm))
210 '())
211 ,@(if (and (not (%current-target-system))
212 (member (%current-system) (package-supported-systems psm2)))
213 `(("psm2" ,psm2))
214 '())
215 ,@(if (and (not (%current-target-system))
216 (member (%current-system) (package-supported-systems ucx)))
217 `(("ucx" ,ucx))
218 '())
219 ("rdma-core" ,rdma-core)
220 ("valgrind" ,valgrind)
221 ("slurm" ,slurm))) ;for PMI support (launching via "srun")
222 (native-inputs
223 `(("pkg-config" ,pkg-config)
224 ("perl" ,perl)))
225 (outputs '("out" "debug"))
226 (arguments
227 `(#:configure-flags `("--enable-mpi-ext=affinity" ;cr doesn't work
228 "--enable-memchecker"
229 "--with-sge"
230 "--with-valgrind"
231 "--with-hwloc=external"
232 "--with-libevent"
233
234 ;; Help 'orterun' and 'mpirun' find their tools
235 ;; under $prefix by default.
236 "--enable-mpirun-prefix-by-default"
237
238 ;; InfiniBand support
239 "--enable-openib-control-hdr-padding"
240 "--enable-openib-dynamic-sl"
241 "--enable-openib-udcm"
242 "--enable-openib-rdmacm"
243 "--enable-openib-rdmacm-ibaddr"
244
245 ;; Enable support for SLURM's Process Manager
246 ;; Interface (PMI).
247 ,(string-append "--with-pmi="
248 (assoc-ref %build-inputs "slurm")))
249 #:phases (modify-phases %standard-phases
250 ;; opensm is needed for InfiniBand support.
251 (add-after 'unpack 'find-opensm-headers
252 (lambda* (#:key inputs #:allow-other-keys)
253 (setenv "C_INCLUDE_PATH"
254 (string-append (assoc-ref inputs "opensm")
255 "/include/infiniband"))
256 (setenv "CPLUS_INCLUDE_PATH"
257 (string-append (assoc-ref inputs "opensm")
258 "/include/infiniband"))
259 #t))
260 (add-before 'build 'remove-absolute
261 (lambda _
262 ;; Remove compiler absolute file names (OPAL_FC_ABSOLUTE
263 ;; etc.) to reduce the closure size. See
264 ;; <https://lists.gnu.org/archive/html/guix-devel/2017-07/msg00388.html>
265 ;; and
266 ;; <https://www.mail-archive.com/users@lists.open-mpi.org//msg31397.html>.
267 (substitute* '("orte/tools/orte-info/param.c"
268 "oshmem/tools/oshmem_info/param.c"
269 "ompi/tools/ompi_info/param.c")
270 (("_ABSOLUTE") ""))
271 ;; Avoid valgrind (which pulls in gdb etc.).
272 (substitute*
273 '("./ompi/mca/io/romio321/src/io_romio321_component.c")
274 (("MCA_io_romio321_COMPLETE_CONFIGURE_FLAGS")
275 "\"[elided to reduce closure]\""))
276 #t))
277 (add-before 'build 'scrub-timestamps ;reproducibility
278 (lambda _
279 (substitute* '("ompi/tools/ompi_info/param.c"
280 "orte/tools/orte-info/param.c"
281 "oshmem/tools/oshmem_info/param.c")
282 ((".*(Built|Configured) on.*") ""))
283 #t))
284 (add-after 'install 'remove-logs ;reproducibility
285 (lambda* (#:key outputs #:allow-other-keys)
286 (let ((out (assoc-ref outputs "out")))
287 (for-each delete-file (find-files out "config.log"))
288 #t))))))
289 (home-page "https://www.open-mpi.org")
290 (synopsis "MPI-3 implementation")
291 (description
292 "The Open MPI Project is an MPI-3 implementation that is developed and
293 maintained by a consortium of academic, research, and industry partners. Open
294 MPI is therefore able to combine the expertise, technologies, and resources
295 from all across the High Performance Computing community in order to build the
296 best MPI library available. Open MPI offers advantages for system and
297 software vendors, application developers and computer science researchers.")
298 ;; See file://LICENSE
299 (license license:bsd-2)))
300
301 ;; TODO: javadoc files contain timestamps.
302 (define-public java-openmpi
303 (package/inherit openmpi
304 (name "java-openmpi")
305 (inputs
306 `(("openmpi" ,openmpi)
307 ,@(package-inputs openmpi)))
308 (native-inputs
309 `(("jdk" ,openjdk11 "jdk")
310 ("zip" ,(@ (gnu packages compression) zip))
311 ,@(package-native-inputs openmpi)))
312 (outputs '("out"))
313 (arguments
314 `(#:modules ((guix build gnu-build-system)
315 ((guix build ant-build-system) #:prefix ant:)
316 (guix build utils))
317 #:imported-modules ((guix build ant-build-system)
318 (guix build syscalls)
319 ,@%gnu-build-system-modules)
320 ,@(substitute-keyword-arguments (package-arguments openmpi)
321 ((#:configure-flags flags)
322 `(cons "--enable-mpi-java" ,flags))
323 ((#:make-flags flags ''())
324 `(append '("-C" "ompi/mpi/java")
325 ,flags))
326 ((#:phases phases)
327 `(modify-phases ,phases
328 ;; We could provide the location of the JDK in the configure
329 ;; flags, but since the configure flags are embedded in the
330 ;; info binaries that would leave a reference to the JDK in
331 ;; the "out" output. To avoid this we set JAVA_HOME.
332 (add-after 'unpack 'set-JAVA_HOME
333 (lambda* (#:key inputs #:allow-other-keys)
334 (setenv "JAVA_HOME" (assoc-ref inputs "jdk"))
335 #t))
336 (add-after 'unpack 'link-with-existing-mpi-libraries
337 (lambda* (#:key inputs #:allow-other-keys)
338 (substitute* "ompi/mpi/java/c/Makefile.in"
339 (("\\$\\(top_builddir\\)/ompi/lib@OMPI_LIBMPI_NAME@.la")
340 (string-append (assoc-ref inputs "openmpi") "/lib/libmpi.la")))
341 #t))
342 (add-after 'install 'strip-jar-timestamps
343 (assoc-ref ant:%standard-phases 'strip-jar-timestamps)))))))
344 (synopsis "Java bindings for MPI")))
345
346 (define-public openmpi-thread-multiple
347 (package/inherit openmpi
348 (name "openmpi-thread-multiple")
349 (arguments
350 (substitute-keyword-arguments (package-arguments openmpi)
351 ((#:configure-flags flags)
352 `(cons "--enable-mpi-thread-multiple" ,flags))))
353 (description " This version of Open@tie{}MPI has an implementation of
354 @code{MPI_Init_thread} that provides @code{MPI_THREAD_MULTIPLE}. This won't
355 work correctly with all transports (such as @code{openib}), and the
356 performance is generally worse than the vanilla @code{openmpi} package, which
357 only provides @code{MPI_THREAD_FUNNELED}.")))
358
359 ;;; Build phase to be used for packages that execute MPI code.
360 (define-public %openmpi-setup
361 '(lambda _
362 ;; By default, running the test suite would fail because 'ssh' could not
363 ;; be found in $PATH. Define this variable to placate Open MPI without
364 ;; adding a dependency on OpenSSH (the agent isn't used anyway.)
365 (setenv "OMPI_MCA_plm_rsh_agent" (which "false"))
366 ;; Allow oversubscription in case there are less physical cores available
367 ;; in the build environment than the package wants while testing.
368 (setenv "OMPI_MCA_rmaps_base_mapping_policy" "core:OVERSUBSCRIBE")
369
370 ;; UCX sometimes outputs uninteresting warnings such as:
371 ;;
372 ;; mpool.c:38 UCX WARN object 0x7ffff44fffc0 was not returned to mpool ucp_am_bufs
373 ;;
374 ;; These in turn leads to failures of test suites that capture and
375 ;; compare stdout, such as that of 'hdf5-parallel-openmpi'. Thus, tell
376 ;; UCX to not emit those warnings.
377 (setenv "UCX_LOG_LEVEL" "error")
378 #t))
379
380 (define-public python-mpi4py
381 (package
382 (name "python-mpi4py")
383 (version "3.0.3")
384 (source
385 (origin
386 (method url-fetch)
387 (uri (pypi-uri "mpi4py" version))
388 (sha256
389 (base32 "07ssbhssv27rrjx1c5vd3vsr31vay5d8xcf4zh9yblcyidn72b81"))))
390 (build-system python-build-system)
391 (arguments
392 `(#:phases
393 (modify-phases %standard-phases
394 (add-after 'build 'mpi-setup
395 ,%openmpi-setup)
396 (add-before 'check 'pre-check
397 (lambda _
398 ;; Skip BaseTestSpawn class (causes error 'ompi_dpm_dyn_init()
399 ;; failed --> Returned "Unreachable"' in chroot environment).
400 (substitute* "test/test_spawn.py"
401 (("unittest.skipMPI\\('openmpi\\(<3.0.0\\)'\\)")
402 "unittest.skipMPI('openmpi')"))
403 #t)))))
404 (inputs
405 `(("openmpi" ,openmpi)))
406 (home-page "https://bitbucket.org/mpi4py/mpi4py/")
407 (synopsis "Python bindings for the Message Passing Interface standard")
408 (description "MPI for Python (mpi4py) provides bindings of the Message
409 Passing Interface (MPI) standard for the Python programming language, allowing
410 any Python program to exploit multiple processors.
411
412 mpi4py is constructed on top of the MPI-1/MPI-2 specification and provides an
413 object oriented interface which closely follows MPI-2 C++ bindings. It
414 supports point-to-point and collective communications of any picklable Python
415 object as well as optimized communications of Python objects (such as NumPy
416 arrays) that expose a buffer interface.")
417 (license license:bsd-3)))
418
419 (define-public mpich
420 (package
421 (name "mpich")
422 (version "3.3.2")
423 (source (origin
424 (method url-fetch)
425 (uri (string-append "http://www.mpich.org/static/downloads/"
426 version "/mpich-" version ".tar.gz"))
427 (sha256
428 (base32
429 "1farz5zfx4cd0c3a0wb9pgfypzw0xxql1j1294z1sxslga1ziyjb"))))
430 (build-system gnu-build-system)
431 (inputs
432 `(("zlib" ,zlib)
433 ("hwloc" ,hwloc-2 "lib")
434 ("slurm" ,slurm)
435 ,@(if (and (not (%current-target-system))
436 (member (%current-system) (package-supported-systems ucx)))
437 `(("ucx" ,ucx))
438 '())))
439 (native-inputs
440 `(("perl" ,perl)
441 ("which" ,which)
442 ("gfortran" ,gfortran)))
443 (outputs '("out" "debug"))
444 (arguments
445 `(#:configure-flags
446 (list "--disable-silent-rules" ;let's see what's happening
447 "--enable-debuginfo"
448
449 ;; Default to "ch4", as will be the case in 3.4. It also works
450 ;; around issues when running test suites of packages that use
451 ;; MPICH: <https://issues.guix.gnu.org/39588#15>.
452 "--with-device=ch4:ucx" ; --with-device=ch4:ofi segfaults in tests
453
454 (string-append "--with-hwloc-prefix="
455 (assoc-ref %build-inputs "hwloc"))
456
457 ,@(if (assoc "ucx" (package-inputs this-package))
458 `((string-append "--with-ucx="
459 (assoc-ref %build-inputs "ucx")))
460 '()))
461
462 #:phases (modify-phases %standard-phases
463 (add-after 'unpack 'patch-sources
464 (lambda _
465 (substitute* "./maint/gen_subcfg_m4"
466 (("/usr/bin/env") (which "env")))
467 (substitute* "src/glue/romio/all_romio_symbols"
468 (("/usr/bin/env") (which "env")))
469 (substitute* (find-files "." "buildiface")
470 (("/usr/bin/env") (which "env")))
471 (substitute* "maint/extracterrmsgs"
472 (("/usr/bin/env") (which "env")))
473 (substitute* (find-files "." "f77tof90")
474 (("/usr/bin/env") (which "env")))
475 (substitute* (find-files "." "\\.sh$")
476 (("/bin/sh") (which "sh")))
477 #t))
478 (add-before 'configure 'fix-makefile
479 (lambda _
480 ;; Remove "@hwloclib@" from 'pmpi_convenience_libs'.
481 ;; This fixes "No rule to make target '-lhwloc', needed
482 ;; by 'lib/libmpi.la'".
483 (substitute* "Makefile.in"
484 (("^pmpi_convenience_libs = (.*) @hwloclib@ (.*)$" _
485 before after)
486 (string-append "pmpi_convenience_libs = "
487 before " " after)))
488 #t)))))
489 (home-page "https://www.mpich.org/")
490 (synopsis "Implementation of the Message Passing Interface (MPI)")
491 (description
492 "MPICH is a high-performance and portable implementation of the Message
493 Passing Interface (MPI) standard (MPI-1, MPI-2 and MPI-3). MPICH provides an
494 MPI implementation that efficiently supports different computation and
495 communication platforms including commodity clusters, high-speed networks (10
496 Gigabit Ethernet, InfiniBand, Myrinet, Quadrics), and proprietary high-end
497 computing systems (Blue Gene, Cray). It enables research in MPI through a
498 modular framework for other derived implementations.")
499 (license license:bsd-2)))