# IT4Innovations
# LK 2024

name = 'OpenMPI'
version = '5.0.2'
versionsuffix = '-rocm'

homepage = 'https://www.open-mpi.org/'
description = """The Open MPI Project is an open source MPI-3 implementation."""

toolchain = {'name': 'NVHPC', 'version': '23.11'}

source_urls = ['https://www.open-mpi.org/software/ompi/v%(version_major_minor)s/downloads']
sources = [SOURCELOWER_TAR_BZ2]
checksums = [
    'ee46ad8eeee2c3ff70772160bff877cbf38c330a0bc3b3ddc811648b3396698f',
]

builddependencies = [
    ('pkgconf', '1.9.3'),
    ('Perl', '5.36.0'),
    ('Autotools', '20220317'),
]

dependencies = [
    ('zlib', '1.2.12'),
    ('hwloc', '2.8.0'),
    ('libevent', '2.1.12'),
    ('UCX', '1.15.0', '-rocm'),
    ('libfabric', '1.16.1'),
    ('PMIx', '4.2.6'),
    ('UCX-ROCM', '1.15.0', '-rocm'),
]

configopts = ' -with-rocm=/opt/rocm '
configopts += ' CC=pgcc CXX=pgc++ FC=pgfortran'
configopts += ' CXXFLAGS="-fPIC"'

# IT4I-specific settings

#configopts += '--enable-shared '
configopts += ' --enable-mpi-thread-multiple'
configopts += ' --with-verbs'
configopts += ' --enable-mpirun-prefix-by-default'
configopts += ' --with-hwloc=$EBROOTHWLOC'  # hwloc support
configopts += ' --with-slurm' # Enable slurm
configopts += ' --with-ucx=$EBROOTUCX'
configopts += ' --with-knem=/opt/knem-1.1.4.90mlnx3'

osdependencies = [('libibverbs-dev', 'libibverbs-devel', 'rdma-core-devel')]

postinstallcmds = [
    'echo "# By default, for Open MPI 4.0 and later, infiniband ports on a device are not used by default." >> %(installdir)s/etc/openmpi-mca-params.conf',
    'echo "btl_openib_allow_ib = true" >> %(installdir)s/etc/openmpi-mca-params.conf',
]

local_libs = ["mpi_mpifh", "mpi", "ompitrace", "open-pal", "open-rte"]
sanity_check_paths = {
    'files': [
        "bin/%s" %
        binfile for binfile in [
            "ompi_info", "opal_wrapper", "orterun"]] + [
                "lib/lib%s.%s" %
                (libfile, SHLIB_EXT) for libfile in local_libs] + [
                    "include/%s.h" %
                    x for x in [
                        "mpi-ext", "mpif-config", "mpif", "mpi", "mpi_portable_platform"]], 'dirs': [], }

moduleclass = 'mpi'
