
Bootstrap: docker
From: ubuntu:24.04

%files
    mpitest.c /opt/mpitest/
    ../../../../etc/docker/requirements.openmpi-x86_64 /opt
    ../../../../etc/docker/requirements.system /opt

%environment
    export PATH="/opt/ompi/bin:${PATH}"
    export LD_LIBRARY_PATH="/opt/ompi/lib:${LD_LIBRARY_PATH}"
    export MPI_BUFFER_SIZE="20000000"
    export MPI_ARCH_PATH="/opt/ompi"
    export OMPI_MCA_pml="ucx"
    export OMPI_MCA_btl="^vader,tcp,openib,uct"

%post
    export UCX_VERSION="1.18.1"
    export OMPI_VERSION="4.0.4"
    apt-get update
    xargs apt-get install -qy --fix-missing --no-install-recommends < "/opt/requirements.openmpi-$(uname -m)"
    UCX_URL="https://github.com/openucx/ucx/releases/download/v${UCX_VERSION}/ucx-${UCX_VERSION}.tar.gz"
    OMPI_MAJOR_VERSION=$(echo ${OMPI_VERSION} | cut -d. -f1,2)
    OMPI_URL="https://download.open-mpi.org/release/open-mpi/v${OMPI_MAJOR_VERSION}/openmpi-${OMPI_VERSION}.tar.bz2"
    mkdir -p build
    cd build
    curl -s -OL "${UCX_URL}"
    curl -s -OL "${OMPI_URL}"
    tar -xzf "ucx-${UCX_VERSION}.tar.gz"
    tar -xjf "openmpi-${OMPI_VERSION}.tar.bz2"
    cd "ucx-${UCX_VERSION}"
    mkdir build
    cd build
    ../contrib/configure-release \
        --prefix=/opt/ucx \
        --with-verbs
    make -j
    make install
    cd "../../openmpi-${OMPI_VERSION}"
    ./configure \
        --prefix=/opt/ompi \
        --with-ucx=/opt/ucx \
        --enable-mpirun-prefix-by-default \
        --with-pmi
    make -j install
    cd ../..
    ln -s /opt/ompi/lib /opt/ompi/lib64
    rm -rf build /var/lib/apt/lists/*

    # MPI Compile Test
    cd /opt/mpitest && /opt/ompi/bin/mpicc -o mpitest mpitest.c