Skip to content

Instantly share code, notes, and snippets.

@brenhinkeller
Created October 19, 2022 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brenhinkeller/538502bc47dcb29fc7becfff70ff06d4 to your computer and use it in GitHub Desktop.
Save brenhinkeller/538502bc47dcb29fc7becfff70ff06d4 to your computer and use it in GitHub Desktop.
Natively compile and run parallel Hello World with MPICH_jll MPI in Julia!
using StaticCompiler, StaticTools, StaticMPI, MPICH_jll
function mpihello(argc, argv)
MPI_Init(argc, argv)
comm = MPI_COMM_WORLD
world_size, world_rank = MPI_Comm_size(comm), MPI_Comm_rank(comm)
printf((c"Hello from ", world_rank, c" of ", world_size, c" processors!\n"))
MPI_Finalize()
end
# Compile
mpilib = joinpath(MPICH_jll.PATH[], "..", "lib")
path = compile_executable(mpihello, (Int, Ptr{Ptr{UInt8}}), "./";
cflags=`-lmpi -L/$mpilib`
# -lmpi instructs compiler to link against libmpi.so / libmpi.dylib
# -L/$mpilib provides path where to find that libmpi
)
# Run
mpiexec = joinpath(MPICH_jll.PATH[], "mpiexec")
run(`$mpiexec -np 8 $path`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment