Here's a surprising result:
julia> tic(); nheads = @parallel (+) for i=1:200000000
randbit()
end; toc()
elapsed time: 48.244946002960205 seconds
48.244946002960205
This was with a single processor. On my laptop, starting with julia -p 2 approximately halves this time.
Then I copied the "count_heads" example from the manual, with the exception that I added an "Int" qualifier to c:
function count_heads(n)
c::Int = 0
for i = 1:n
c += randbit()
end
c
end
julia> load("countheads.jl")
julia> tic(); n = count_heads(200000000); toc()
elapsed time: 2.662583112716675 seconds
2.662583112716675
Without the ::Int qualifier, I get this:
julia> tic(); n = count_heads(200000000); toc()
elapsed time: 11.013921022415161 seconds
11.013921022415161
which is still much faster than parallel for. I notice that the result of both parallel for and the version without the ::Int return their results as a Uint32.
Here's a surprising result:
julia> tic(); nheads = @parallel (+) for i=1:200000000
randbit()
end; toc()
elapsed time: 48.244946002960205 seconds
48.244946002960205
This was with a single processor. On my laptop, starting with julia -p 2 approximately halves this time.
Then I copied the "count_heads" example from the manual, with the exception that I added an "Int" qualifier to c:
function count_heads(n)
c::Int = 0
for i = 1:n
c += randbit()
end
c
end
julia> load("countheads.jl")
julia> tic(); n = count_heads(200000000); toc()
elapsed time: 2.662583112716675 seconds
2.662583112716675
Without the ::Int qualifier, I get this:
julia> tic(); n = count_heads(200000000); toc()
elapsed time: 11.013921022415161 seconds
11.013921022415161
which is still much faster than parallel for. I notice that the result of both parallel for and the version without the ::Int return their results as a Uint32.