Hi all. I’m learning how to use MPI with Julia, specifically the MPI.jl package.
I’m trying to understand how to print on external temporary files, and I can’t make it work.
This is my current minimal non-working example script, called mpi_test.jl:
using MPI
MPI.Init()
let
comm = MPI.COMM_WORLD
prank = MPI.Comm_rank(comm)
io_file, _ = mktemp()
io_file = MPI.bcast(io_file, comm)
f = MPI.File.open(comm, io_file; write=true)
MPI.File.write(f, "$prank: hello!")
io_files = MPI.gather(io_file, comm)
prank == 0 && for p in 0:MPI.Comm_size(comm)-1
println(p, ": ", io_files[p+1])
end
end
which I run with mpiexecjl -np 4 julia --project mpi_test.jl.
The output is
If I write to an ordinary file, say io_file = "test.txt" instead of using mktemp(), the file is correctly created in the working directory and contains the given string.
With mktemp() instead, no file is created at all in the /tmp folder.
Well, I’m just dumb, I found out why this happens, and it has nothing to do with MPI: the temporary files were deleted by Julia when the script ended because I didn’t supply the cleanup=false argument to mktemp().