Skip to content

Commit c4b6b42

Browse files
committed
adding defiant2 mpi example
1 parent fa2a255 commit c4b6b42

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

defiant/mpiexample/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# MPI Example
2+
3+
This example shows how to install MPICH 4.1.2 in a container derived from a CUDA 12.6 container released by Nvidia.
4+
5+
Build the images by running
6+
7+
```
8+
./build.sh
9+
```
10+
11+
Submit the batch script
12+
13+
```
14+
sbatch submit.sl
15+
```
16+

defiant/mpiexample/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
apptainer build rocky9opensusempich412nvidia2411.sif rocky9opensusempich412nvidia2411.def
4+
apptainer build mpiexample.sif mpiexample.def

defiant/mpiexample/mpiexample.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
#include <mpi.h>
3+
4+
int main (int argc, char *argv[])
5+
{
6+
int rank, size;
7+
MPI_Comm comm;
8+
9+
comm = MPI_COMM_WORLD;
10+
MPI_Init (&argc, &argv);
11+
MPI_Comm_rank (comm, &rank);
12+
MPI_Comm_size (comm, &size);
13+
14+
printf("Hello from rank %d\n", rank);
15+
16+
MPI_Barrier(comm);
17+
MPI_Finalize();
18+
}
19+

defiant/mpiexample/mpiexample.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Bootstrap: localimage
2+
From: rocky9opensusempich412nvidia2411.sif
3+
4+
%files
5+
mpiexample.c /app/mpiexample.c
6+
7+
8+
%post
9+
cd /app && mpicc -o mpiexample mpiexample.c
10+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Bootstrap: docker
2+
From: nvcr.io/nvidia/nvhpc:24.11-devel-cuda12.6-rockylinux9
3+
4+
%environment
5+
# Point to MPICH binaries, libraries man pages
6+
export MPICH_DIR=/opt/mpich
7+
export PATH="$MPICH_DIR/bin:$PATH"
8+
export LD_LIBRARY_PATH="$MPICH_DIR/lib:$LD_LIBRARY_PATH"
9+
export MANPATH=$MPICH_DIR/share/man:$MANPATH
10+
11+
%post
12+
13+
14+
# Information about the version of MPICH to use
15+
export MPICH_VERSION=4.1.2
16+
export MPICH_URL="http://www.mpich.org/static/downloads/$MPICH_VERSION/mpich-$MPICH_VERSION.tar.gz"
17+
export MPICH_DIR=/opt/mpich
18+
19+
echo "Installing MPICH..."
20+
rm -rf /tmp/mpich
21+
mkdir -p /tmp/mpich
22+
mkdir -p /opt
23+
# Download
24+
cd /tmp/mpich && wget -O mpich-$MPICH_VERSION.tar.gz $MPICH_URL && tar --no-same-owner -xzf mpich-$MPICH_VERSION.tar.gz
25+
# Compile and install
26+
export FFLAGS=-fallow-argument-mismatch
27+
28+
cd /tmp/mpich/mpich-$MPICH_VERSION
29+
#patch -p1 < /my_change.patch
30+
#./autogen.sh
31+
./configure --with-device=ch4:ucx --prefix=$MPICH_DIR && make install
32+
rm -rf /tmp/mpich
33+
34+

defiant/mpiexample/submit.sl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
#SBATCH -t00:10:00
3+
#SBATCH -A stf007
4+
#SBATCH -p batch-cpu
5+
#SBATCH -N2
6+
#SBATCH -J mpiexample
7+
#SBATCH -o logs/%x_%j.out
8+
#SBATCH -e logs/%x_%j.out
9+
10+
module reset
11+
module load cray-mpich-ucx-abi
12+
13+
export MPICH_SMP_SINGLE_COPY_MODE=NONE
14+
export APPTAINERENV_LD_LIBRARY_PATH="/opt/cray/pe/mpich/8.1.32/ucx/crayclang/18.0/lib-abi-mpich:/opt/cray/pe/mpich/8.1.32/gtl/lib:$CRAY_LD_LIBRARY_PATH:$LD_LIBRARY_PATH:/opt/cray/pe/lib64:/usr/lib64/libibverbs:/opt/cray/pals/1.6/lib:/usr/lib64/ucx"
15+
export APPTAINER_CONTAINLIBS="/usr/lib64/libjansson.so.4,/usr/lib64/libdrm.so.2,/lib64/libtinfo.so.6,/usr/lib64/libnl-3.so.200,/usr/lib64/librdmacm.so.1,/usr/lib64/libibverbs.so.1,/usr/lib64/libibverbs/libmlx5-rdmav57.so,/lib64/libucs.so.0,/lib64/libucp.so.0,/lib64/libuct.so.0,/lib64/libucm.so.0"
16+
export APPTAINER_BIND=/usr/share/libdrm,/var/spool/slurm,/opt/cray,/opt/mellanox,/etc/libibverbs.d,/usr/lib64/ucx,${PWD}
17+
18+
19+
export CONTAINER=../containers/mpiexample.sif
20+
21+
srun --unbuffered -N2 -n4 --tasks-per-node 2 apptainer exec --fakeroot --workdir `pwd` $CONTAINER /app/mpiexample

0 commit comments

Comments
 (0)