1 { lib, stdenv, fetchurl, gfortran, perl, libnl
2 , rdma-core, zlib, numactl, libevent, hwloc, targetPackages, symlinkJoin
3 , libpsm2, libfabric, pmix, ucx
6 , cudaSupport ? false, cudatoolkit ? null
8 # Enable the Sun Grid Engine bindings
11 # Pass PATH/LD_LIBRARY_PATH to point to current mpirun by default
12 , enablePrefix ? false
14 # Enable libfabric support (necessary for Omnipath networks) on x86_64 linux
15 , fabricSupport ? stdenv.isLinux && stdenv.isx86_64
17 # Enable Fortran support
18 , fortranSupport ? true
21 assert !cudaSupport || cudatoolkit != null;
24 cudatoolkit_joined = symlinkJoin {
25 name = "${cudatoolkit.name}-unsplit";
26 paths = [ cudatoolkit.out cudatoolkit.lib ];
28 in stdenv.mkDerivation rec {
32 src = with lib.versions; fetchurl {
33 url = "https://www.open-mpi.org/software/ompi/v${major version}.${minor version}/downloads/${pname}-${version}.tar.bz2";
34 sha256 = "03ckngrff1cl0l81vfvrfhp99rbgk7s0633kr1l468yibwbjx4cj";
40 # Ensure build is reproducible
41 ts=`date -d @$SOURCE_DATE_EPOCH`
42 sed -i 's/OPAL_CONFIGURE_USER=.*/OPAL_CONFIGURE_USER="nixbld"/' configure
43 sed -i 's/OPAL_CONFIGURE_HOST=.*/OPAL_CONFIGURE_HOST="localhost"/' configure
44 sed -i "s/OPAL_CONFIGURE_DATE=.*/OPAL_CONFIGURE_DATE=\"$ts\"/" configure
45 find -name "Makefile.in" -exec sed -i "s/\`date\`/$ts/" \{} \;
48 buildInputs = [ zlib ]
49 ++ lib.optionals stdenv.isLinux [ libnl numactl pmix ucx ]
50 ++ lib.optionals cudaSupport [ cudatoolkit ]
52 ++ lib.optional (stdenv.isLinux || stdenv.isFreeBSD) rdma-core
53 ++ lib.optionals fabricSupport [ libpsm2 libfabric ];
55 nativeBuildInputs = [ perl ]
56 ++ lib.optionals fortranSupport [ gfortran ];
58 configureFlags = lib.optional (!cudaSupport) "--disable-mca-dso"
59 ++ lib.optional (!fortranSupport) "--disable-mpi-fortran"
60 ++ lib.optionals stdenv.isLinux [
61 "--with-libnl=${libnl.dev}"
63 "--with-pmix-libdir=${pmix}/lib"
65 ] ++ lib.optional enableSGE "--with-sge"
66 ++ lib.optional enablePrefix "--enable-mpirun-prefix-by-default"
67 # TODO: add UCX support, which is recommended to use with cuda for the most robust OpenMPI build
68 # https://github.com/openucx/ucx
69 # https://www.open-mpi.org/faq/?category=buildcuda
70 ++ lib.optionals cudaSupport [ "--with-cuda=${cudatoolkit_joined}" "--enable-dlopen" ]
71 ++ lib.optionals fabricSupport [ "--with-psm2=${libpsm2}" "--with-libfabric=${libfabric}" ]
74 enableParallelBuilding = true;
81 # default compilers should be indentical to the
82 # compilers at build time
84 sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc:' \
85 $out/share/openmpi/mpicc-wrapper-data.txt
87 sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc:' \
88 $out/share/openmpi/ortecc-wrapper-data.txt
90 sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}c++:' \
91 $out/share/openmpi/mpic++-wrapper-data.txt
92 '' + lib.optionalString fortranSupport ''
94 sed -i 's:compiler=.*:compiler=${gfortran}/bin/${gfortran.targetPrefix}gfortran:' \
95 $out/share/openmpi/mpifort-wrapper-data.txt
101 inherit cudaSupport cudatoolkit;
105 homepage = "https://www.open-mpi.org/";
106 description = "Open source MPI-3 implementation";
107 longDescription = "The Open MPI Project is an open source MPI-3 implementation that is developed and maintained by a consortium of academic, research, and industry partners. Open MPI is therefore able to combine the expertise, technologies, and resources from all across the High Performance Computing community in order to build the best MPI library available. Open MPI offers advantages for system and software vendors, application developers and computer science researchers.";
108 maintainers = with maintainers; [ markuskowa ];
109 license = licenses.bsd3;
110 platforms = platforms.unix;