Is there something in place to support parallel IO? I’m currently thinking in the context of MPI, where it is nice to have functionality such as only printing on the first rank or prefixing lines with the process rank. Or more challenging, make sure output from different ranks is neatly separated on separate lines.
Maybe this post will help–
Actually, I’m mostly interested in printing to the console. I found I can do it for
println as follows:
immutable RankedIO <: Base.IO wrapped_stream::Base.IO print_rank::Int own_rank::Int end function Base.println(io::RankedIO, xs...) if io.print_rank == io.own_rank Base.println(io.wrapped_stream, xs...) end end
This can then be used as follows:
const io = RankedIO(STDOUT, 0, myrank) println(io, "this will only print on process rank 0")
I have a strong feeling there is a much better way to achieve this, however. I noticed for instance there is an
IOContext, maybe that is the way to go? Also, is there a way to avoid passing around the
io object all the time? And finally, this works only for
println, so maybe there is a more basic method to override?
If you want to suppress printing on processes that are not rank 0, how about using
redirect_stdout to redirect
STDOUT to either a file or
/dev/null on all nodes that are not rank 0.
I like the idea, but what do I pass, exactly? This doesn’t work:
DevNull is not quite
/dev/null but the folowwing should work
Thanks, that works. It’s a shame it’s not cross-platform, but that’s not really a concern for me at this time.