Bootstrap: docker
From: rockylinux:9

%arguments
    OMPI_VER=5.0.3

%environment
    # Point to OMPI binaries, libraries, man pages
    export OMPI_DIR=/opt/ompi
    export PATH="$OMPI_DIR/bin:$PATH"
    export LD_LIBRARY_PATH="$OMPI_DIR/lib:$LD_LIBRARY_PATH"
    export MANPATH="$OMPI_DIR/share/man:$MANPATH"

%post
     echo "Installing required packages..."
    # configure package manager to work non-interactive and speed up package download
    printf '%s\n' 'assumeyes=true' 'max_parallel_downloads=15' >> /etc/dnf/dnf.conf
    # update package information
    dnf update
    # install compilers and build environments
    dnf group install "Development Tools"
    # install wget to download sources via HTTP
    dnf install wget
    # Clean up andy cached information, build files, etc.
    dnf clean all

    echo "Installing Open MPI"
    export OMPI_DIR=/opt/ompi
    export OMPI_VERSION={{ OMPI_VER }}
    export OMPI_URL="https://download.open-mpi.org/release/open-mpi/v${OMPI_VERSION:0:3}/openmpi-$OMPI_VERSION.tar.bz2"
    mkdir -p /tmp/ompi
    mkdir -p /opt
    # Download and extract Open-MPI tarball
    cd /tmp/ompi && wget -O openmpi-$OMPI_VERSION.tar.bz2 $OMPI_URL && tar -xjf openmpi-$OMPI_VERSION.tar.bz2
    # Compile and install; default configure sill suffice as we plan to use the Open-MPI installed on the host
    cd /tmp/ompi/openmpi-$OMPI_VERSION && ./configure --prefix=$OMPI_DIR
    # Build in parallel
    make -j8 install

    # Install Python3 and pip
    dnf install python3 python3-pip
    
    # Install amdahl via pip
    python3 -m pip install amdahl

%runscript
   # Default action that calls MPI with outside arguments
   exec mpiexec "$@" /usr/local/bin/amdahl
