Hello,
i want to run a for loop
in parallel but using Threads.threads
just made the Programm slower so i wanted to try @distributed
module MyModule
export start, loop_inner, rec
function start()
return rec(...)
end
@inline function loop_inner(...)
...
end
function rec(...)
...
results = zeros(N)
@sync @distributed for idx in 1::N
results[idx] = MyModule.loop_inner(...)
end
return sum(results)
...
end
When i just use@distributed
without @sync
in front of it - im getting no UndefVarError's
but sum(results)
will always be 0
. When i try to use @sync @distributed
im getting:
ERROR: LoadError: TaskFailedException:
On worker 2:
UndefVarError: MyModule not defined
My Main looks something like this:
using Distributed
cwd = pwd()
@Distributed.everywhere push!(LOAD_PATH,"pwd")
@Distributed.everywhere include("MyModule.jl")
@Distributed.everywhere using .MyModule
workers = Threads.nthreads() # = 8
addprocs(workers,
#max_parallel = 8,
restrict=true,
enable_threaded_blas=true,
exeflags=`--optimize=3 --inline=yes --check-bounds=no --math-mode=fast`,
topology=:master_worker)
LangfordParallel.start()
$JULIA_NUM_THREADS=8 julia -L MyModule.jl main.jl -p=8
Code: https://github.com/masterholdy/julia-threading-question