Skip to content
Snippets Groups Projects
Commit 0e3801d8 authored by Guilherme Calandrini's avatar Guilherme Calandrini
Browse files

added example of openmpi with singularity

parent bf86f64f
No related branches found
No related tags found
1 merge request!786Draft: added example of openmpi with singularity
This commit is part of merge request !786. Comments created here will be created in the context of that merge request.
...@@ -58,6 +58,90 @@ EOF ...@@ -58,6 +58,90 @@ EOF
./hello ./hello
``` ```
### OpenMPI
Definition file:
```code
Bootstrap: docker
From: ubuntu:latest
%files
mpitest.c /opt
%environment
export OMPI_DIR=/opt/ompi
export SINGULARITY_OMPI_DIR=$OMPI_DIR
export SINGULARITYENV_APPEND_PATH=$OMPI_DIR/bin
export SINGULAIRTYENV_APPEND_LD_LIBRARY_PATH=$OMPI_DIR/lib
%post
echo "Installing required packages..."
apt-get update && apt-get install -y wget git bash gcc gfortran g++ make file
echo "Installing Open MPI"
export OMPI_DIR=/opt/ompi
export OMPI_VERSION=4.0.1
export OMPI_URL="https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-$OMPI_VERSION.tar.bz2"
mkdir -p /tmp/ompi
mkdir -p /opt
# Download
cd /tmp/ompi && wget -O openmpi-$OMPI_VERSION.tar.bz2 $OMPI_URL && tar -xjf openmpi-$OMPI_VERSION.tar.bz2
# Compile and install
cd /tmp/ompi/openmpi-$OMPI_VERSION && ./configure --prefix=$OMPI_DIR && make install
# Set env variables so we can compile our application
export PATH=$OMPI_DIR/bin:$PATH
export LD_LIBRARY_PATH=$OMPI_DIR/lib:$LD_LIBRARY_PATH
export MANPATH=$OMPI_DIR/share/man:$MANPATH
echo "Compiling the MPI application..."
cd /opt && mpicc -o mpitest mpitest.c
```
```code
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv) {
int rc;
int size;
int myrank, len;
char name[MPI_MAX_PROCESSOR_NAME];
MPI_Init (&argc, &argv);
MPI_Comm_size (MPI_COMM_WORLD, &size);
MPI_Comm_rank (MPI_COMM_WORLD, &myrank);
MPI_Get_processor_name(name, &len);
fprintf (stdout, "Hello, I am rank %d/%d, at %s\n", myrank, size, name);
MPI_Finalize();
return EXIT_SUCCESS;
exit_with_error:
MPI_Finalize();
return EXIT_FAILURE;
}
```
At your computer:
```console
sudo singularity build ubuntu_omp.sif ubuntu_omp.def
```
At ZIH systems:
```console
marie@login$ export PMIX_MCA_gds=hash
marie@login$ srun -n 2 --time 00:10:00 singularity exec ubuntu_omp.sif /opt/mpitest
```
### CUDA + CuDNN + OpenMPI ### CUDA + CuDNN + OpenMPI
* Chosen CUDA version depends on installed driver of host * Chosen CUDA version depends on installed driver of host
......
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