Using @code_warntype
on pmap
, this is reported as type unstable, is this true ? Is there a way to make it type stable ?
julia> using Distributed, BenchmarkTools
julia> a = rand(1:35,100) # Int64[100]
julia> addprocs(3)
julia> @everywhere function f(n)
if n == 0 return 0 end
if n == 1 return 1 end
return f(n-1) + f(n-2)
end
julia> @benchmark results = map(f,a) # serialised: median time: 371 ms
julia> @benchmark results = pmap(f,a) # parallelised: median time: 157 ms
julia> map(f,a) # Int64[100]
julia> pmap(f,a) # Int64[100]
julia> @code_warntype map(f,a)
Body::Array{Int64,1}
1 β %1 = %new(Base.Generator{Array{Int64,1},typeof(f)}, f, A)::Base.Generator{Array{Int64,1},typeof(f)}
β %2 = invoke Base._collect(_3::Array{Int64,1}, %1::Base.Generator{Array{Int64,1},typeof(f)}, $(QuoteNode(Base.EltypeUnknown()))::Base.EltypeUnknown, $(QuoteNode(Base.HasShape{1}()))::Base.HasShape{1})::Array{Int64,1}
βββ return %2
julia> @code_warntype pmap(f,a)
Body::Any
1 β %1 = invoke Distributed.default_worker_pool()::Union{Nothing, WorkerPool}
β %2 = Distributed.pmap::typeof(pmap)
β %3 = (isa)(%1, WorkerPool)::Bool
βββ goto #3 if not %3
2 β %5 = Ο (%1, WorkerPool)
β %6 = invoke %2(_2::Function, %5::WorkerPool, _3::Array{Int64,1})::Any
βββ goto #6
3 β %8 = (isa)(%1, Nothing)::Bool
βββ goto #5 if not %8
4 β %10 = invoke Distributed.:(#pmap#226)($(QuoteNode(Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}()))::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, Distributed.pmap::Function, f::Function, nothing::Nothing, _3::Array{Int64,1})::Any
βββ goto #6
5 β (Core.throw)(ErrorException("fatal error in type inference (type bound)"))
βββ $(Expr(:unreachable))
6 β %14 = Ο (#2 => %6, #4 => %10)::Any
βββ goto #7
7 β return %14