PackagingDrafts/MPI

Introduction
Message Passing Interface (MPI) is an API for parallelization of programs across multiple nodes and has been around since 1994. MPI can also be used for parallelization on SMP machines and is considered very efficient in it too (close to 100% scaling on parallelizable code as compared to ~80% commonly obtained with threads due to unoptimal memory allocation on NUMA machines). Before MPI, about every manufacturer of supercomputers had their own programming language for writing programs; MPI made porting software easy.

There are many MPI implementations available, such as LAM-MPI (in Fedora, obsoleted by Open MPI), Open MPI (the default MPI compiler in Fedora and the MPI compiler used in RHEL), MPICH (Not yet in Fedora), MPICH2 (in Fedora) and MVAPICH1 and MVAPICH2 (are in RHEL but not yet in Fedora).

As some MPI libraries work better on some hardware than others, and some software works best with some MPI library, the selection of the library used must be done in user level, on a session specific basis. Also, people doing high performance computing may want to use more efficient compilers than the default one in Fedora (gcc), so one must be able to have many versions of the MPI compiler each compiled with a different compiler installed at the same time. This must be taken into account when writing spec files.

Packaging of MPI compilers
The MPI compiler RPMs MUST be possible to build with other compilers as well and support simultaneous installation of versions compiled with different compilers (e.g. in addition to a version compiled with  a version compiled with   must be possible to install and use simultaneously as gfortran does not fully support Fortran 77). To do this, the files of MPI compilers MUST be installed in the following directories: Here  is null when compiled with the normal   combination, but would be e.g.   for.

As include files and manual pages are bound to overlap between different MPI implementations, they MUST also placed outside normal directories. It is possible that some man pages or include files (either those of the MPI compiler itself or of some MPI software installed in the compiler's directory) are architecture specific (e.g. a definition on a 32-bit arch differs from that on a 64-bit arch), the directories that MUST be used are as follows:

Architecture and compiler independent parts (except headers which go into  ) MUST be placed in a   subpackage that is   on >= Fedora 11.

The MPI compiler's spec file MUST support the use of the following variables to compile with other compilers %global opt_cc gcc %global opt_cxx g++ %global opt_f77 gfortran %global opt_fc gfortran
 * 1) We only compile with gcc, but other people may want other compilers.
 * 2) Set the compiler here.
 * 1) Optional CFLAGS to use with the specific compiler...gcc doesn't need any,
 * 2) so uncomment and define to use
 * 3) global opt_cflags
 * 1) global opt_cxxflags
 * 1) global opt_fflags
 * 1) global opt_fcflags


 * 1) Optional name suffix to use...we leave it off when compiling with gcc, but
 * 2) for other compiled versions to install side by side, it will need a
 * 3) suffix in order to keep the names from conflicting.
 * 4) global cc_name_suffix -gcc

The runtime of MPI compilers (mpirun, the libraries, the manuals etc) MUST be packaged into %{name}, and the development headers and libraries into %{name}-devel.

As the compiler is installed outside, one needs to load the relevant variables before being able to use the compiler or run MPI programs. This is done using environment modules.

The module file MUST prepend the MPI bindir  into the users PATH, set LD_LIBRARY_PATH to   and PYTHONPATH to. The module file MUST also set some helper variables (primarily for use in spec files): As these directories may be used by software using the MPI stack, the MPI runtime package MUST own all of them.

MUST: By default, NO files are placed in. If the packager wishes to provide alternatives support, it MUST be placed in a subpackage along with the ld.so.conf.d file so that alternatives support does not need to be installed if not wished for.

MUST: If the maintainer wishes for the environment module to load automatically by use of a scriptlet in /etc/profile.d or by some other mechanism, this MUST be done in a subpackage.

The MPI compiler package MUST provide an RPM macro that makes loading and unloading the support easy in spec files, e.g. by placing the following in %_openmpi_load \ . /etc/profile.d/modules.sh; \ module load openmpi-%{_arch}; \ export CFLAGS="$CFLAGS %{optflags}"; %_openmpi_unload \ . /etc/profile.d/modules.sh; \ module unload openmpi-%{_arch}; loading and unloading the compiler in spec files is as easy as  and.

If the environment module sets compiler flags such as  (thus overriding the ones exported in , the RPM macro MUST make them use the Fedora optimization flags   once again (as in the example above in which the openmpi-%{_arch} module sets CFLAGS).

Packaging of MPI software
Software that supports MPI MUST be packaged also in serial mode [i.e. no MPI], if it is supported by upstream. (for instance: ).

If possible, the packager MUST package versions for each MPI compiler in Fedora (e.g. if something can only be built with mpich2 and mvapich2, then lam and openmpi packages do not need to be made).

MPI implementation specific files MUST be installed in the directories used by the used MPI compiler (,  and so on).

The binaries MUST be suffixed with  (e.g. _openmpi for Open MPI, _mpich2 for MPICH2 and _lam for LAM/MPI). This is for two reasons: the serial version of the program can still be run when an MPI module is loaded and the user is always aware of the version s/he is running. This does not need to hurt the use of shell scripts:
 * 1) Which MPI implementation do we use?

module load mpich2-i386
 * 1) module load lam-i386
 * 2) module load openmpi-i386

foo -preprocess < foo.in mpirun -np 4 foo${MPI_SUFFIX} mpirun -np 4 bar${MPI_SUFFIX} -process bar -collect
 * 1) Run preprocessor
 * 1) Run calculation
 * 1) Run some processing
 * 1) Collect results

The MPI enabled bits MUST be placed in a subpackage with the suffix denoting the MPI compiler used (for instance:  for Open MPI [the traditional MPI compiler in Fedora] or   for MPICH2). For directory ownership and to guarantee the pickup of the correct MPI runtime, the MPI subpackages MUST require the correct MPI compiler's runtime package.

Each MPI build of shared libraries SHOULD have a separate -libs subpackage for the libraries (e.g. foo-mpich2-libs). As in the case of MPI compilers, library configuration (in ) MUST NOT be made.

In case the headers are the same regardless of the compilation method and architecture (e.g. 32-bit serial, 64-bit Open MPI, MPICH2), they MUST be split into a separate  subpackage (e.g. 'foo-headers'). Fortran modules are architecture specific and as such are placed in the (MPI implementation specific)  package (foo-devel for the serial version and foo-openmpi-devel for the Open MPI version).

Each MPI build MUST have a separate -devel subpackage (e.g. foo-mpich2-devel) that includes the development libraries and  if such a package exists. The goal is to be able to install and develop using e.g. 'foo-mpi-devel' without needing to install e.g. mpich2 and lam or the serial version of the package.

Files must be shared between packages as much as possible. Compiler independent parts, such as data files in  and man files MUST be put into a   subpackage that is required by all of the binary packages (the serial package and all of the MPI packages).

A sample spec file
%global dconfigure %(printf %%s '%configure' | sed 's!\./configure!../configure!g')
 * 1) Define a macro for calling ../configure instead of ./configure

Name: foo Requires: %{name}-common = %{version}-%{release}

%package common

%package lam BuildRequires: lam-devel Requires: lam Requires: %{name}-common = %{version}-%{release}
 * 1) Require explicitly for dir ownership and to guarantee the pickup of the right runtime

%package mpi BuildRequires: openmpi-devel Requires: openmpi Requires: %{name}-common = %{version}-%{release}
 * 1) Require explicitly for dir ownership and to guarantee the pickup of the right runtime

%package mpich2 BuildRequires: mpich2-devel Requires: mpich2 Requires: %{name}-common = %{version}-%{release}
 * 1) Require explicitly for dir ownership and to guarantee the pickup of the right runtime

%build
 * 1) Have to do off-root builds to be able to build many versions at once

%define dobuild \ mkdir $MPI_COMPILER; \ cd $MPI_COMPILER; \ %dconfigure --program-suffix=$MPI_SUFFIX ;\ make %{?_smp_mflags} ; \ cd ..
 * 1) To avoid replicated code define a build macro

MPI_COMPILER=serial MPI_SUFFIX= %dobuild
 * 1) Build serial version, dummy arguments

export CC=mpicc export CXX=mpicxx export FC=mpif90 export F77=mpif77
 * 1) Build parallel versions: set compiler variables to MPI wrappers

%{_lam_load} %dobuild %{_lam_unload}
 * 1) Build LAM version

%{_openmpi_load} %dobuild %{_openmpi_unload}
 * 1) Build OpenMPI version

%{_mpich2_load} %dobuild %{_mpich2_unload}
 * 1) Build mpich2 version

%install make -C serial install DESTDIR=%{buildroot} INSTALL="install -p" CPPROG="cp -p"
 * 1) Install serial version

%{_lam_load} make -C $MPI_COMPILER install DESTDIR=%{buildroot} INSTALL="install -p" CPPROG="cp -p" %{_lam_unload}
 * 1) Install LAM version

%{_openmpi_load} make -C $MPI_COMPILER install DESTDIR=%{buildroot} INSTALL="install -p" CPPROG="cp -p" %{_openmpi_unload}
 * 1) Install OpenMPI version

%{_mpich2_load} make -C $MPI_COMPILER install DESTDIR=%{buildroot} INSTALL="install -p" CPPROG="cp -p" %{_mpich2_unload}
 * 1) Install MPICH2 version

%files # All the serial (normal) binaries

%files common # All files shared between the serial and different MPI versions

%files lam # All lam linked files

%files openmpi # All openmpi linked files

%files mpich2 # All mpich2 linked files