Skip to content
Snippets Groups Projects
Verified Commit d2faec26 authored by Darren Reed's avatar Darren Reed Committed by GitLab UZH
Browse files

Update container_info.md fix to bind .def and instructions to install openmpi on a vm

parent 682b6083
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,37 @@ Guide to the singularity definition file, for building your own custom singulari
Containers using (MPI)[https://docs.sylabs.io/guides/3.5/user-guide/mpi.html] parallelism (Message Passing Interface) can be more complicated, and there are multiple ways to configure singularity plus MPI.
Here is an example using the **bind** approach. A definition file could look like this. It assumes that you have already compiled and built the executable mpi_hello_world from mpi_hello_world.c, borrowed from (here)[https://github.com/mpitutorial/mpitutorial/tree/gh-pages/tutorials/mpi-hello-world]:
Here is an example using the **bind** approach. It assumes that you have already compiled and built the executable mpi_hello_world from mpi_hello_world.c, borrowed from (here)[https://github.com/mpitutorial/mpitutorial/tree/gh-pages/tutorials/mpi-hello-world].
Starting from a Singularity ubuntu 20.04 ScienceCloud instance, the instance can be setup with a version of Open MPI that matches the `openmpi/4.1.3` module on ScienceCluster with the following sequence of commands:
```
## Commands to run from a ScienceCloud instance to install OpenMPI version 4.1.3
sudo apt-get install wget gcc bash g++ make libsysfs2 libsysfs-dev libevent-dev libpmix-dev -y
sudo apt-get install mpi-default-dev -y
make
export OMPI_DIR=/opt/ompi
export OMPI_VERSION=4.1.3
export OMPI_URL="https://download.open-mpi.org/release/open-mpi/v4.1/openmpi-$OMPI_VERSION.tar.bz2"
mkdir -p /tmp/ompi
mkdir -p /opt
cd /tmp/ompi
sudo wget -O openmpi-$OMPI_VERSION.tar.bz2 $OMPI_URL
tar -xjf openmpi-$OMPI_VERSION.tar.bz2
cd /tmp/ompi/openmpi-$OMPI_VERSION
sudo ./configure --enable-orterun-prefix-by-default --with-pmix=/usr/lib/x86_64-linux-gnu/pmix/ --prefix=$OMPI_DIR
sudo make install
export PATH=$OMPI_DIR/bin:$PATH
export LD_LIBRARY_PATH=$OMPI_DIR/lib:$LD_LIBRARY_PATH
export MANPATH=$OMPI_DIR/share/man:$MANPATH
```
Then compile compile mpi_hello_world by copying `mpi_hello_world.c` and `makefile` from the above repository to your home on the virtual machine.
Then cd to your home, and
`make`
to compile and create the file `mpi_hello_world` (if all went well).
This is an example "bind" definition file ("mpi_hello_world_bind.def"):
```
Bootstrap: docker
From: ubuntu:20.04
......@@ -42,7 +72,8 @@ From: ubuntu:20.04
%environment
export MPI_DIR="/apps/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.3.0/openmpi-4.1.3-hxw6m2yyxelnba6ruvojic4oohxsbdl7"
export MPI_DIR="/apps/opt/spack/linux-ubuntu20.04-x86_64/gcc-9.3.0/openmpi-4.1.3-efaqdqjshm5pznecwekvbmt42qbwhinl"
### MPI_DIR must match the cluster MPI install path exactly
## ScienceCluster openmpi bind paths
export PATH="$MPI_DIR/bin:$PATH"
export LD_LIBRARY_PATH="$MPI_DIR/lib:$LD_LIBRARY_PATH"
......@@ -58,7 +89,7 @@ From: ubuntu:20.04
In this mode, the application in the container calls the MPI library on the host (ScienceCluster) for communication between tasks. On a ScienceCloud instance, the container image can be built as:
`sudo singularity build mpi_hello_world_bind.sif recipe.def`
`sudo singularity build mpi_hello_world_bind.sif mpi_hello_world_bind.def`
A slurm script, which you would submit with `sbatch`, to run this container using 4 MPI tasks on a single node could look like this:
......@@ -79,14 +110,16 @@ module load singularityce
echo 'start'
srun --exclusive --ntasks=4 --cpus-per-task=1 --nodes=1 --mem 3000M singularity exec --bind "$MPI_DIR" --bind /apps ./mpi_hello_world /opt/bin/mpi_hello_world
srun --exclusive --ntasks=4 --cpus-per-task=1 --nodes=1 --mem 3000M singularity exec --bind "$MPI_DIR" --bind /apps ./mpi_hello_world_bind.sif /opt/bin/mpi_hello_world
echo 'finished'
```
Does the above example work? If not, how would you debug it?
Does the above example work? If not, how would you debug it?
The trade-off in the above "bind" MPI container example is that while the container is relatively lightweight because it does not have MPI installed within it, some work is needed to create the MPI environment to compile the MPI executable that will be copied into the container.
***
For the same example, using a **hybrid** approach, here is a definition file. The important changes are than openmpi is downloaded and built within the post section of the .def file, and then the environment sets the OMPI variables to use the openmpi version within the container:
For the same example, using a **hybrid** approach, here is a definition file. The important changes are than openmpi is downloaded and built within the post section of the .def file, and then the environment sets the OMPI variables to use the openmpi version within the container (mpi_hello_world_hybrid.def):
```
Bootstrap: docker
From: ubuntu:20.04
......@@ -149,7 +182,7 @@ echo 'start'
### Specifying --mem 2999M would work, but safest approach is not to respecify the
### slurm resources in the srun command (by default srun has available the full job resources):
srun singularity exec ./hybrid.sif /opt/mpi_hello_world
srun singularity exec ./mpi_hello_world_hybrid.sif /opt/mpi_hello_world
echo 'finished'
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment