Created
October 19, 2022 16:28
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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