I did not have much success using Threads.@threads
to accelerate code execution. The code would sometimes run marginally faster and sometimes even slower.
So now I am trying packages like ParallelUtilities
that use the Distributed
package. But I have not even managed to get the code to run. This example is extracted from the documentation for ParallelUtilities
and it generates a TaskFailedException
. Any hints on what is going wrong?
using Distributed
using ParallelUtilities
addprocs(2)
@everywhere f(x) = ones(10_000, 1_000);
A = @time @distributed (+) for i=1:nworkers()
f(i)
end;
1.931315 seconds (1.51 M allocations: 310.286 MiB, 3.94% gc time, 42.46% compilation time)
B = @time pmapreduce(f, +, 1:nworkers());
ERROR: TaskFailedException
nested task error: On worker 2:
KeyError: key ParallelUtilities [fad6cfc8-4f83-11e9-06cc-151124046ad0] not found
Stacktrace:
[1] getindex
@ .\dict.jl:481 [inlined]
[2] root_module
@ .\loading.jl:1056 [inlined]
[3] deserialize_module
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Serialization\src\Serialization.jl:981
[4] handle_deserialize
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Serialization\src\Serialization.jl:883
[5] deserialize
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Serialization\src\Serialization.jl:801
[6] deserialize_datatype
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Serialization\src\Serialization.jl:1331
[7] handle_deserialize
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Serialization\src\Serialization.jl:854
[8] deserialize
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Serialization\src\Serialization.jl:801
[9] handle_deserialize
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Serialization\src\Serialization.jl:861
[10] deserialize
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Serialization\src\Serialization.jl:801 [inlined]
[11] deserialize_msg
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Distributed\src\messages.jl:87
[12] #invokelatest#2
@ .\essentials.jl:716 [inlined]
[13] invokelatest
@ .\essentials.jl:714 [inlined]
[14] message_handler_loop
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Distributed\src\process_messages.jl:169
[15] process_tcp_streams
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Distributed\src\process_messages.jl:126
[16] #99
@ .\task.jl:423
Stacktrace:
[1] remotecall_fetch(::Function, ::Distributed.Worker; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Distributed C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Distributed\src\remotecall.jl:452
[2] remotecall_fetch
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Distributed\src\remotecall.jl:444 [inlined]
[3] #remotecall_fetch#158
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Distributed\src\remotecall.jl:479 [inlined]
[4] remotecall_fetch
@ C:\Users\fsald\AppData\Local\Programs\Julia-1.7.0\share\julia\stdlib\v1.7\Distributed\src\remotecall.jl:479 [inlined]
[5] (::ParallelUtilities.ClusterQueryUtils.var"#1#3"{Vector{String}, Int64, Int64})()
@ ParallelUtilities.ClusterQueryUtils .\task.jl:423
...and 1 more exception.
Stacktrace:
[1] sync_end(c::Channel{Any})
@ Base .\task.jl:381
[2] macro expansion
@ .\task.jl:400 [inlined]
[3] hostnames(procs::Vector{Int64})
@ ParallelUtilities.ClusterQueryUtils C:\Users\fsald\.julia\packages\ParallelUtilities\1gSmb\src\clusterquery.jl:25
[4] procs_node
@ C:\Users\fsald\.julia\packages\ParallelUtilities\1gSmb\src\clusterquery.jl:51 [inlined]
[5] chooseworkers
@ C:\Users\fsald\.julia\packages\ParallelUtilities\1gSmb\src\clusterquery.jl:91 [inlined]
[6] maybetrimmedworkerpool
@ C:\Users\fsald\.julia\packages\ParallelUtilities\1gSmb\src\clusterquery.jl:115 [inlined]
[7] pmapreduce(f::Function, op::Function, iterators::UnitRange{Int64}; reducekw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ParallelUtilities C:\Users\fsald\.julia\packages\ParallelUtilities\1gSmb\src\mapreduce.jl:285
[8] pmapreduce
@ C:\Users\fsald\.julia\packages\ParallelUtilities\1gSmb\src\mapreduce.jl:284 [inlined]
[9] top-level scope
@ .\timing.jl:220 [inlined]
[10] top-level scope
@ .\REPL[9]:0