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