lol
1{ lib, stdenv, fetchurl, removeReferencesTo, gfortran, perl, libnl
2, rdma-core, zlib, numactl, libevent, hwloc, targetPackages, symlinkJoin
3, libpsm2, libfabric, pmix, ucx, ucc, makeWrapper
4, config
5# Enable CUDA support
6, cudaSupport ? config.cudaSupport, cudaPackages
7
8# Enable the Sun Grid Engine bindings
9, enableSGE ? false
10
11# Pass PATH/LD_LIBRARY_PATH to point to current mpirun by default
12, enablePrefix ? false
13
14# Enable libfabric support (necessary for Omnipath networks) on x86_64 linux
15, fabricSupport ? stdenv.isLinux && stdenv.isx86_64
16
17# Enable Fortran support
18, fortranSupport ? true
19}:
20
21stdenv.mkDerivation rec {
22 pname = "openmpi";
23 version = "4.1.6";
24
25 src = with lib.versions; fetchurl {
26 url = "https://www.open-mpi.org/software/ompi/v${major version}.${minor version}/downloads/${pname}-${version}.tar.bz2";
27 sha256 = "sha256-90CZRIVRbetjtTEa8SLCZRefUyig2FelZ7hdsAsR5BU=";
28 };
29
30 postPatch = ''
31 patchShebangs ./
32
33 # Ensure build is reproducible
34 ts=`date -d @$SOURCE_DATE_EPOCH`
35 sed -i 's/OPAL_CONFIGURE_USER=.*/OPAL_CONFIGURE_USER="nixbld"/' configure
36 sed -i 's/OPAL_CONFIGURE_HOST=.*/OPAL_CONFIGURE_HOST="localhost"/' configure
37 sed -i "s/OPAL_CONFIGURE_DATE=.*/OPAL_CONFIGURE_DATE=\"$ts\"/" configure
38 find -name "Makefile.in" -exec sed -i "s/\`date\`/$ts/" \{} \;
39 '';
40
41 outputs = [ "out" "man" "dev" ];
42
43 buildInputs = [ zlib ]
44 ++ lib.optionals stdenv.isLinux [ libnl numactl pmix ucx ucc ]
45 ++ lib.optionals cudaSupport [ cudaPackages.cuda_cudart ]
46 ++ [ libevent hwloc ]
47 ++ lib.optional (stdenv.isLinux || stdenv.isFreeBSD) rdma-core
48 ++ lib.optionals fabricSupport [ libpsm2 libfabric ];
49
50 nativeBuildInputs = [ perl removeReferencesTo makeWrapper ]
51 ++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ]
52 ++ lib.optionals fortranSupport [ gfortran ];
53
54 configureFlags = lib.optional (!cudaSupport) "--disable-mca-dso"
55 ++ lib.optional (!fortranSupport) "--disable-mpi-fortran"
56 ++ lib.optionals stdenv.isLinux [
57 "--with-libnl=${lib.getDev libnl}"
58 "--with-pmix=${lib.getDev pmix}"
59 "--with-pmix-libdir=${pmix}/lib"
60 "--enable-mpi-cxx"
61 ] ++ lib.optional enableSGE "--with-sge"
62 ++ lib.optional enablePrefix "--enable-mpirun-prefix-by-default"
63 # TODO: add UCX support, which is recommended to use with cuda for the most robust OpenMPI build
64 # https://github.com/openucx/ucx
65 # https://www.open-mpi.org/faq/?category=buildcuda
66 ++ lib.optionals cudaSupport [ "--with-cuda=${cudaPackages.cuda_cudart}" "--enable-dlopen" ]
67 ++ lib.optionals fabricSupport [ "--with-psm2=${lib.getDev libpsm2}" "--with-libfabric=${lib.getDev libfabric}" ]
68 ;
69
70 enableParallelBuilding = true;
71
72 postInstall = ''
73 find $out/lib/ -name "*.la" -exec rm -f \{} \;
74
75 for f in mpi shmem osh; do
76 for i in f77 f90 CC c++ cxx cc fort; do
77 moveToOutput "bin/$f$i" "''${!outputDev}"
78 echo "move $fi$i"
79 moveToOutput "share/openmpi/$f$i-wrapper-data.txt" "''${!outputDev}"
80 done
81 done
82
83 for i in ortecc orte-info ompi_info oshmem_info opal_wrapper; do
84 moveToOutput "bin/$i" "''${!outputDev}"
85 done
86
87 moveToOutput "share/openmpi/ortecc-wrapper-data.txt" "''${!outputDev}"
88 '';
89
90 postFixup = ''
91 remove-references-to -t $dev $(readlink -f $out/lib/libopen-pal${stdenv.hostPlatform.extensions.sharedLibrary})
92 remove-references-to -t $man $(readlink -f $out/lib/libopen-pal${stdenv.hostPlatform.extensions.sharedLibrary})
93
94 # The path to the wrapper is hard coded in libopen-pal.so, which we just cleared.
95 wrapProgram $dev/bin/opal_wrapper \
96 --set OPAL_INCLUDEDIR $dev/include \
97 --set OPAL_PKGDATADIR $dev/share/openmpi
98
99 # default compilers should be indentical to the
100 # compilers at build time
101
102 echo "$dev/share/openmpi/mpicc-wrapper-data.txt"
103 sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc:' \
104 $dev/share/openmpi/mpicc-wrapper-data.txt
105
106 echo "$dev/share/openmpi/ortecc-wrapper-data.txt"
107 sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc:' \
108 $dev/share/openmpi/ortecc-wrapper-data.txt
109
110 echo "$dev/share/openmpi/mpic++-wrapper-data.txt"
111 sed -i 's:compiler=.*:compiler=${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}c++:' \
112 $dev/share/openmpi/mpic++-wrapper-data.txt
113 '' + lib.optionalString fortranSupport ''
114
115 echo "$dev/share/openmpi/mpifort-wrapper-data.txt"
116 sed -i 's:compiler=.*:compiler=${gfortran}/bin/${gfortran.targetPrefix}gfortran:' \
117 $dev/share/openmpi/mpifort-wrapper-data.txt
118
119 '';
120
121 doCheck = true;
122
123 passthru = {
124 inherit cudaSupport;
125 cudatoolkit = cudaPackages.cudatoolkit; # For backward compatibility only
126 };
127
128 meta = with lib; {
129 homepage = "https://www.open-mpi.org/";
130 description = "Open source MPI-3 implementation";
131 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.";
132 maintainers = with maintainers; [ markuskowa ];
133 license = licenses.bsd3;
134 platforms = platforms.unix;
135 };
136}