
Bootstrap: docker
From: ubuntu:xenial
Include: apt-add-repository


%post
        sed -i 's/main/main restricted universe/g' /etc/apt/sources.list
        apt-get update
        apt-get install -y bash git wget build-essential gcc time libc6-dev libgcc-5-dev python libevent-2* libevent-dev autoconf libtool flex
        apt-get install -y dkms infiniband-diags libibverbs* ibacm librdmacm* libmlx4* libmlx5* mstflint libibcm.* libibmad.* libibumad* opensm srptools libmlx4-dev librdmacm-dev rdmacm-utils ibverbs-utils perftest vlan ibutils

        ####################
        ##Install HWLoc
        ####################
        cd /tmp
        wget https://github.com/open-mpi/hwloc/archive/hwloc-1.11.7.tar.gz -O hwloc-1.11.7.tar.gz
        tar xzvf hwloc-1.11.7.tar.gz
        cd hwloc-hwloc-1.11.7
        ./autogen.sh
        ./configure --prefix=/usr
        make install

        ####################
        ##Install PMIx
        ####################
        PMIX_MAJOR_VERSION=1
        PMIX_MINOR_VERSION=2
        PMIX_PATCH_VERSION=2
        PMIX_VERSION=$PMIX_MAJOR_VERSION.$PMIX_MINOR_VERSION.$PMIX_PATCH_VERSION
        cd /tmp
        wget https://github.com/pmix/pmix/releases/download/v$PMIX_VERSION/pmix-$PMIX_VERSION.tar.gz -O pmix-$PMIX_VERSION.tar.gz
        tar xzvf pmix-$PMIX_VERSION.tar.gz
        cd pmix-$PMIX_VERSION
        ./configure --with-hwloc=/usr --with-platform=optimized --with-libevent=/usr --with-devel-headers --prefix=/usr
        make install


        ####################
        ##Install OpenMPI 2.X
        ## Las version 2.1.x  deben tener el siguiente flag de configuración "--disable-pmix-dstore"
        ####################
        OMPI_MAJOR_VERSION=2
        OMPI_MINOR_VERSION=0
        OMPI_PATCH_VERSION=1
        OMPI_VERSION=$OMPI_MAJOR_VERSION.$OMPI_MINOR_VERSION.$OMPI_PATCH_VERSION
        cd /tmp
        wget https://www.open-mpi.org/software/ompi/v$OMPI_MAJOR_VERSION.$OMPI_MINOR_VERSION/downloads/openmpi-$OMPI_VERSION.tar.gz -O openmpi-$OMPI_VERSION.tar.gz
        tar -xzf openmpi-$OMPI_VERSION.tar.gz
        mkdir -p /tmp/openmpi-$OMPI_VERSION/build
        cd /tmp/openmpi-$OMPI_VERSION/build
        ../configure --enable-shared --enable-mpi-thread-multiple --with-verbs --enable-mpirun-prefix-by-default --with-hwloc=/usr --with-libevent=/usr --disable-dlopen --with-pmix=/usr --prefix=/usr 
        make all install
        export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
        cd /tmp


#        ####################
#        ##Install OpenMPI 3.X
#        ####################
#        OMPI_MAJOR_VERSION=3
#        OMPI_MINOR_VERSION=0
#        OMPI_PATCH_VERSION=0
#        OMPI_VERSION=$OMPI_MAJOR_VERSION.$OMPI_MINOR_VERSION.$OMPI_PATCH_VERSION
#        OMPI_RC=3
#        cd /tmp
#        wget https://github.com/open-mpi/ompi/archive/v3.0.0rc3.tar.gz
#        tar xzvf v3.0.0rc3.tar.gz
#        mkdir -p /tmp/ompi-3.0.0rc3/build
#        cd /tmp/ompi-3.0.0rc3
#        ./autogen.pl
#        cd /tmp/ompi-3.0.0rc3/build
#        ../configure --enable-shared --enable-mpi-thread-multiple --with-verbs --enable-mpirun-prefix-by-default --with-hwloc=/usr --with-libevent=/usr --disable-dlopen --with-pmix=/usr --disable-pmix-dstore --prefix=/usr
#        make all install
#        export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH


        ####################
        ## Install ring
        ####################
        wget https://raw.githubusercontent.com/open-mpi/ompi/master/examples/ring_c.c
        mpicc ring_c.c -o /usr/bin/ring

        mkdir -p /scratch
        mkdir -p /opt/cesga


