Thanks for your reply.

In my view it is natural, that the order of the "output" (print statements) 
> is intermingled, as the code runs in parallel.


Yes, I agree. But I'd like to make sure we're talking about the same level 
of intermingledness (is this a new word?)
Firstly I don't really understand parallel processing, output streams, 
switching etc.
But when I first starting using Julia for parallel sims (Julia v0.3) I was 
initially surprised that output from each worker was NOT intermingled, in 
the sense that each print statement from a worker was delivered to the 
master process console "atomically". i.e. there were discreet lines on the 
console each wholly from a single worker.
Sure, the order of the lines depended on the speed of the processor, the 
amount of work to do etc.
After a while, I just assumed this was either magic, or there was some kind 
of queuing system with locking or similar.
In any case, I didn't really think about it until I started using Julia 
v0.4 where output lines are sometimes not discrete and sometimes delayed.

Here's an example of output:
 
     ...
     From worker 3:  Completed random trial 69
     From worker 3:  Starting random trial 86 with 1000000 games
     From worker 5:  Starting random trial 87 with 1000000 games
     From worker 2:  Completed random trial 70
     From worker 2:  Starting random trial 88 with 1000000 games
     From worker 27: Starting random trial 89 with 1000000 games
     From worker 21: Completed random trial  From worker 22: Starting 
random trial 90 with 1000000 games
     From worker 23: Starting random trial 93 with 1000000 games
     From worker 21: 81
     From worker 19: Starting random trial 91 with 1000000 games
     From worker 14: Starting random trial 96 with 1000000 games
     From worker 4:  Completed random trial 82
     From worker 4:  Starting random trial 98 with 1000000 games
     From worker 24: Completed random trial  From worker 26: Completed 
random trial 76
     From worker 25: Completed random trial 80
     From worker 24: 85
     From worker 22: Completed random trial 90
     From worker 3:  Completed random trial 86
     From worker 8:  Completed random trial  From worker 9:  Starting 
random trial 94 with 1000000 games
     From worker 8:  78
     From worker 3:  Starting random trial 99 with 1000000 games
     From worker 27: Completed random trial  From worker 29: Starting 
random trial 92 with 1000000 games
     From worker 28: Starting random trial 95 with 1000000 games
     From worker 27: 89
     From worker 2:  Completed random trial 88
     From worker 2:  Starting random trial 100 with 1000000 games
     From worker 23: Completed random trial 93
     From worker 29: Completed random trial 92
     From worker 28: Completed random trial 95
     From worker 14: Completed random trial  From worker 16: Completed 
random trial 72
     From worker 15: Completed random trial 75
     From worker 20: Completed random trial 79
     From worker 17: Completed random trial 83
     From worker 18: Completed random trial 84
     From worker 19: Completed random trial 91
     From worker 14: 96
     From worker 4:  Completed random trial 98
     From worker 9:  Completed random trial 94
     From worker 3:  Completed random trial 99
     From worker 10: Completed random trial  From worker 11: Completed 
random trial 65
     From worker 12: Completed random trial 66
     From worker 13: Completed random trial 71
     From worker 10: 77      From worker 11: Starting random trial 97 with 
1000000 games
     From worker 10:
     From worker 2:  Completed random trial 100
     From worker 5:  Completed random trial  From worker 6:  Completed 
random trial 73
     From worker 7:  Completed random trial 74
     From worker 5:  87
     From worker 11: Completed random trial 97


Again I have no idea how these thing work, but here's code from Julia v0.3 
(multi.jl) 

     if isa(stream, AsyncStream)
        let wrker = w
            # redirect console output from workers to the client's stdout:
            @async begin
                while !eof(stream)
                    line = readline(stream)
                    print("\tFrom worker $(wrker.id):\t$line")
                end
            end
        end
    end


And equivalent code from Julia v0.4:

function redirect_worker_output(ident, stream)
    @schedule while !eof(stream)
        line = readline(stream)
        if startswith(line, "\tFrom worker ")
            # STDOUT's of "additional" workers started from an initial 
worker on a host are not available
            # on the master directly - they are routed via the initial 
worker's STDOUT.
            print(line)
        else
            print("\tFrom worker $(ident):\t$line")
        end
    end
end


It seems we've gone from @async to @schedule.
Would this make a difference?

Reply via email to