From Fedora Project Wiki

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 {gcc,g++,gfortran} a version compiled with {gcc34,g++34,g77} 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:

File type Placement
Binaries %{_libdir}/%{name}%{?_cc_name_suffix}/bin
Libraries %{_libdir}/%{name}%{?_cc_name_suffix}/lib
Fortran modules %{_fmoddir}/%{name}%{?_cc_name_suffix}/
Architecture specific Python modules %{python2_sitearch}/%{name}%{?_cc_name_suffix}/


Config files %{_sysconfdir}/%{name}-%{_arch}%{?_cc_name_suffix}/

Here %{?_cc_name_suffix} is null when compiled with the normal {gcc,g++,gfortran} combination, but would be e.g. -gcc34 for {gcc34,g++34,g77}.

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:

File type Placement
Man pages %{_mandir}/%{name}-%{_arch}%{?_cc_name_suffix}/
Include files %{_includedir}/%{name}-%{_arch}%{?_cc_name_suffix}/

Architecture and compiler (%{?_cc_name_suffix}) independent parts (except headers which go into -devel) MUST be placed in a -common subpackage that is BuildArch: noarch.

The MPI compiler's spec file MUST support the use of the following variables to compile with other compilers

# We only compile with gcc, but other people may want other compilers.
# Set the compiler here.
%global opt_cc gcc
# Optional CFLAGS to use with the specific compiler...gcc doesn't need any,
# so uncomment and define to use
#global opt_cflags
%global opt_cxx g++
#global opt_cxxflags
%global opt_f77 gfortran
#global opt_fflags
%global opt_fc gfortran
#global opt_fcflags

# Optional name suffix to use...we leave it off when compiling with gcc, but
# for other compiled versions to install side by side, it will need a
# suffix in order to keep the names from conflicting.
#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 PATH, 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 be installed under %{_sysconfdir}/modulefiles/mpi/. This allows as user with only one mpi implementation installed to load the module with:

module load mpi

The module file MUST have the line:

conflict mpi

to prevent concurrent loading of multiple mpi modules.

The module file MUST prepend the MPI bindir %{_bindir}/%{name}-%{_arch}%{?_opt_cc_suffix} into the users PATH, set LD_LIBRARY_PATH to %{_libdir}/%{name}%{?_opt_cc_suffix}/. The module file MUST also set some helper variables (primarily for use in spec files):

Variable Value Explanation
MPI_BIN %{_libdir}/%{name}%{?_opt_cc_suffix}/bin Binaries compiled against the MPI stack
MPI_SYSCONFIG %{_sysconfdir}/%{name}-%{_arch}%{?opt_cc_suffix}/ MPI stack specific configuration files
MPI_FORTRAN_MOD_DIR %{_fmoddir}/%{name}%{?_opt_cc_suffix}/ MPI stack specific Fortran module directory
MPI_INCLUDE %{_includedir}/%{name}-%{_arch}%{?_opt_cc_suffix}/ MPI stack specific headers
MPI_LIB %{_libdir}/%{name}%{?_opt_cc_suffix}/lib Libraries compiled against the MPI stack
MPI_MAN %{_mandir}/%{name}-%{_arch}%{?_opt_cc_suffix}/ MPI stack specific man pages
%{python2_sitearch}/%{name}%{?_cc_name_suffix}/ MPI stack specific Python 2 modules

%{python3_sitearch}/%{name}%{?_cc_name_suffix}/ MPI stack specific Python 3 modules
MPI_COMPILER %{name}-%{_arch}%{?_cc_name_suffix} Name of compiler package, for use in e.g. spec files
MPI_SUFFIX %{?_cc_name_suffix}_%{name} The suffix used for programs compiled against the MPI stack

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 /etc/ If the packager wishes to provide alternatives support, it MUST be placed in a subpackage along with the 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.

MUST: 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 /etc/rpm/macros.openmpi

%_openmpi_load \
 . /etc/profile.d/; \
 module load mpi/openmpi-%{_arch}; \
 export CFLAGS="$CFLAGS %{optflags}";
%_openmpi_unload \
 . /etc/profile.d/; \
 module unload mpi/openmpi-%{_arch};

loading and unloading the compiler in spec files is as easy as %{_openmpi_load} and %{_openmpi_unload}.

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

Automatic setting of the module loading path in python interpreters is down using a .pth file placed in one of the directories normally searched for modules (%{python2_sitearch}/, %{python3_sitearch}/). Those .pth files should append the directory specified with $MPI_PYTHON2_SITEARCH or $MPI_PYTHON3_SITEARCH environment variable, depending on the interpreter version, to sys.path, and do nothing if those variables are unset. Module files MUST NOT set PYTHONPATH directly, since it cannot be set for both Python versions at the same time.