Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The MPI.jl package provides the Julia interface to the Message Passing Interface (MPI).

Table of Contents
minLevel1
maxLevel6
outlinefalse
typelist
printablefalse

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)

Of you want to avoid using a system MPI but instead use an MPI variant provided by Julia as an artifact (JLL), you have to run the following.

Code Block
languagejulia
using MPIPreferences
MPIPreferences.use_jll_binary()

A simple MPI example

Code Block
languagejulia
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()