Configuration
There are multiple MPI implementations:
julia> using MPI
julia> MPI.versioninfo()
MPIPreferences:
binary: MPICH_jll
abi: MPICH
Package versions
MPI.jl: 0.20.22
MPIPreferences.jl: 0.1.11
MPICH_jll: 4.3.0+1
Library information:
libmpi: /home/vchuravy/.julia/artifacts/05d8c79b270470018e9de8dd24ddb6d7954aff9d/lib/libmpi.so
libmpi dlpath: /home/vchuravy/.julia/artifacts/05d8c79b270470018e9de8dd24ddb6d7954aff9d/lib/libmpi.so
MPI version: 4.1.0
Library version:
MPICH Version: 4.3.0
MPICH Release date: Mon Feb 3 09:09:47 AM CST 2025
MPICH ABI: 17:0:5
MPICH Device: ch3:nemesis
MPICH configure: –build=x86_64-linux-musl –disable-dependency-tracking –disable-doc –enable-fast=ndebug,O3 –enable-static=no –host=x86_64-linux-gnu –prefix=/workspace/destdir –with-device=ch3 –with-hwloc=/workspace/destdir
MPICH CC: cc -DNDEBUG -DNVALGRIND -O3
MPICH CXX: c++ -DNDEBUG -DNVALGRIND -O3
MPICH F77: gfortran -O3
MPICH FC: gfortran -O3
MPICH features:
On Unix, MPI.jl will install and use MPICH through the MPICH_jll package.
MPIPreferences
To switch which MPI implementation MPI.jl uses you can use the package MPIPreferences.jl.
For more information see: https://juliaparallel.org/MPI.jl/stable/configuration/
When executing on a cluster you will likely need to configure MPI.jl to use the system provided MPI.
Installing mpiexecjl
julia> using MPI
julia> MPI.install_mpiexecjl()
By default, it will install to ~/.julia/bin, but you can also choose to install it somewhere else.
As an example, to install it in the current working directory:
julia> using MPI
julia> MPI.install_mpiexecjl(destdir=".")
After installing it, you can use it to launch several Julia processes under MPI:
mpiexecjl --project=/path/to/project -n 4 julia script.jl
# or
./mpiexecjl --project=/path/to/project -n 4 julia script.jl
Exercises
MPI.jl has a series of examples:
To get started, copy the “Hello world” example into 01-hello.jl and run it with four processes:
mpiexecjl --project=. -n 4 julia 01-hello.jl
You should see one line per rank, printed in a non-deterministic order — just like the @mpi hello-world from the lecture:
Hello world, I have rank 0 out of 4 processors
Hello world, I have rank 2 out of 4 processors
Hello world, I have rank 1 out of 4 processors
Hello world, I have rank 3 out of 4 processors
Diffusion
In exercise 7 we looked at a diffusion kernel. Instead of implementing this on the GPU you can also implement it with MPI.
Note
The “hard” part is the handling of the boundary conditions and ghost cells. So focus on that in the beginning. How are you going to split the computational domain? Who needs to talk to whom?
To check correctness, gather the distributed result back onto a single rank (with MPI.Gather) and compare it against the single-process version from exercise 7. Running with one rank (-n 1) should reproduce the serial result exactly, and the answer should not change as you increase the number of ranks.