The MPI.jl package provides the Julia interface to the Message Passing Interface (MPI).
OpenMPI via JuliaHPC
(recommended)
...
NOTE: To avoid conflicts, we recommend to use the Julia
module (i.e. module load lang Julia
) instead of the JuliaHPC
module when using an arbitrary system MPI.
Using Julia MPI artifacts (JLLs)
Code Block |
---|
using MPIPreferences
MPIPreferences.use_jll_binary() |
A simple MPI example
Code Block |
---|
|
using MPI
MPI.Init()
const MAX_LEN = 100
comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
com_size = MPI.Comm_size(comm)
msg = "Greetings from process $(rank) of $(com_size)!"
msg_buf = collect(msg) # String -> Vector{Char}
if rank != 0
# Every worker sends a message (blocking)
MPI.Send(msg_buf, comm; dest=0)
else
println(msg)
# Master receives and prints the messages one-by-one (blocking)
for r in 1:com_size-1
# blocking receive
MPI.Recv!(msg_buf, comm; source=r)
println(join(msg_buf))
end
end
MPI.Finalize() |