Running hybrid MPI+GPU jobs in a Apptainer/Singularity Container

Hi,

Does anyone know how to launch hybrid MPI+GPU jobs using Apptainer (version 1.0.2) formerly known as Singularity? I am trying to use the following approach:

mpirun -n 2 apptainer exec -C --nv -B $PWD:/host_pwd sboxGpuLammps-cu-11-0 /lammps/build/./lmp -k on g 1 -sf kk -pk kokkos -in /host_pwd/in.lj.txt >> log.lammps

However, when I run the job it runs two replica jobs (1mpi-proc + GPU) instead of one job with (2 mpi-procs + 1 GPU). I would much appreciate any ideas on how this can be resolved.

With just one mpi-proc+GPU the output is as expected.

Container build info:
I have built the container by using a sandbox approach and the definition file (…/lammps_dir/tools/singularity/ubuntu18_gpu.def) that come with lammps. After the creation of the sandbox I installed LAMMPS within the container.

LAMMPS info:
I am using LAMMPS (29 Sep 2021 - Update 3) with openmpi 4.0.6.
Cuda version is 11.0.3.
Nvidia-Driver version is 450.119.03
GPU device: Nvidia RTX 2080 Ti TURING 7.5 architecture

Thanks very much for your time and help…

Warm regards,
Vaibhav.

This behavior would be consistent with having a different MPI library in the host system than inside the container.

Most current MPI libraries - and that includes OpenMPI - communicate the node rank and MPI cluster topology via environment variables that are specific to its mpirun command.

For example the command line mpirun -np 4 singularity exec ubuntu22.04.sif ./build-ubuntu22/lmp -in in.dummy which is run on a Fedora 34 host to launch LAMMPS in an Ubuntu 22.04LTS container
produces this output with mpirun from MPICH:

LAMMPS (24 Mar 2022)
  using 1 OpenMP thread(s) per MPI task
Created orthogonal box = (0 0 0) to (1 1 1)
  1 by 1 by 1 MPI processor grid
Total wall time: 0:00:00
LAMMPS (24 Mar 2022)
  using 1 OpenMP thread(s) per MPI task
Created orthogonal box = (0 0 0) to (1 1 1)
  1 by 1 by 1 MPI processor grid
Total wall time: 0:00:00
LAMMPS (24 Mar 2022)
  using 1 OpenMP thread(s) per MPI task
Created orthogonal box = (0 0 0) to (1 1 1)
  1 by 1 by 1 MPI processor grid
Total wall time: 0:00:00
LAMMPS (24 Mar 2022)
  using 1 OpenMP thread(s) per MPI task
Created orthogonal box = (0 0 0) to (1 1 1)
  1 by 1 by 1 MPI processor grid
Total wall time: 0:00:00

And this output with mpirun from OpenMPI:

LAMMPS (24 Mar 2022)
  using 1 OpenMP thread(s) per MPI task
Created orthogonal box = (0 0 0) to (1 1 1)
  1 by 2 by 2 MPI processor grid
Total wall time: 0:00:00
1 Like

Thanks a lot…Axel. :slight_smile:

It is indeed the case.
I have openmpi v2.1.1 installed within the container and version v4.0.6 outside the container.

I will try with a matching version inside the container.
Thanks once again.

Warm regards,
Vaibhav.

Just a quick feedback on how I resolved the problem so that it helps other people looking at this thread.
I went back and matched the openmpi versions both inside the container and the host to openmpi-4.0.6. However, this still did not resolve the problem.

Then, quite by chance, as I was looking at this page:

I noticed that I had a -C flag with the Apptainer command in the mpirun command to launch the job
mpirun -n 2 apptainer exec -C --nv -B $PWD:/host_pwd sboxGpuLammps-cu-11-0 /lammps/build/./lmp -k on g 1 -sf kk -pk kokkos -in /host_pwd/in.lj.txt >> log.lammps

This was one of the key culprits and once I removed this unnecessary flag I got the expected behavior. It is better to use the following command to launch the job:
mpirun -n 2 apptainer run --nv -B $PWD:/host_pwd –pwd /host_pwd mpi4Lammps.sif /lammps/build/lmp -k on g 1 -sf kk -pk kokkos -in /host_pwd/in.lj.txt
The command option in bold is very useful/required to direct the output to a directory of your choice.

Other useful notes regarding the definition files that come with Lammps in …/lammps/tools/singularity/ubuntu18.04_*.def:
The libvtk6-dev, libnetcdf and libpnetcdf libraries when installed from the ubuntu-18.04 repo also install mpi-default-bin and mpi-default-dev that are openmpi-2.1.1 despite removing the explicit install commands for the mpi-stuff. So, I opted to exclude the VTK and the NETCDF packages from the install. To install these packages as well, one would likely need to install the libvtk6-dev, libnetcdf and libpnetcdf libraries from source rather than the ubuntu-18.04 repo after the installation of the mpi-package of choice. Of course, all of this applies only if the mpi-version on host is different from the default openmpi-2.1.1 installed from the Ubuntu-18.04 repo.

Also, the newer releases of LAMMPS require cmake-3.16 or higher for the installation of the Kokkos package while the definition files pull cmake-3.10 from the ubuntu-repos. To get around this one needs to install a higher >3.16 cmake version from the tar-file as in:

###########################################################################
# CMAKE
###########################################################################
cd /
wget https://cmake.org/files/v3.23/cmake-3.23.2.tar.gz
tar -xvf cmake-3.23.2.tar.gz
cd cmake-3.23.2
./bootstrap && make -j 16 && make install

apt-get update

###########################################################################

However, if one removes the installation of the libvtk6-dev, libnetcdf and libpnetcdf from the *.def file then one needs to install the open-ssl and libssl-dev libraries additionally to complete the installation for CMake-3.23.2.

The public key (7fa2af80.pub) for the cuda-repos in the definition files is old and needs to be replaced with a newer one (3bf863cc.pub):
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
add-apt-repository “deb Index of /compute/cuda/repos/ubuntu1804/x86_64 /”
apt-get update

The same applies to the Radeon Open Compute repo as well. Here it appears that the online location of the gpg-key has changed. The updated one that I used is:
curl -sL http://repo.radeon.com/rocm/rocm.gpg.key | apt-key add -
printf “deb [arch=amd64] Index of /rocm/apt/4.3/ xenial main” > /etc/apt/sources.list.d/rocm.list

1 Like

Thanks for the detailed follow up.
Since there are multiple moving targets here, the singularity definitions are always at a high risk of being outdated. Especially for GPU related software.

I think, I must say THANK YOU for all your help and inputs… :slight_smile:
I am deeply appreciative of the efforts that the LAMMPS Developers make to keep this juggernaut rolling at the cutting edge of HPC.

Warm regards,
Vaibhav.