Julia: Nested PMAP calls do not work

Created on 11 Jun 2019  Â·  4Comments  Â·  Source: JuliaLang/julia

Hello,
the following code with has nested pmap functions, it hangs even if I execute it with 1 single process addprocs(1).

using Distributed
@everywhere function inner_process(task_id)
    task_id^2
end

@everywhere function outer_process(job_id)
    inner_task  = collect(1:2)
    pmap(inner_process, inner_task)
end

function do_job(jobs_list) 
    pmap(outer_process, jobs_list)
end

jobs_list = collect(1:10)
do_job(jobs_list)

This is the version I am using

julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
export JULIA_NUM_THREADS = 4
JULIA_DEPOT_PATH = C:Program FilesReSolver.DistributedJuliadepot
JULIA_EDITOR = C:UsersAppDataLocalatomatom.exe
JULIA_NUM_THREADS = 4
JULIA_PKGDIR = C:Program FilesReSolver.DistributedJuliapackages

Am I maybe misunderstanding the feature or is this an expected behavior?

Most helpful comment

I guess this is expected behavior, since the outer pmap already employs (by default) all workers, so there are no ones left to distribute to. Check the ?pmap docstring. However, when you specify which workers to use, everything works fine even with nested pmaps:

using Distributed
addprocs() # this yields workers 2:5 on my machine
@everywhere function inner_process(task_id)
    task_id^2
end

@everywhere function outer_process(job_id)
    inner_task  = collect(1:2)
    pmap(inner_process, WorkerPool([4, 5]), inner_task)
end

function do_job(jobs_list) 
    pmap(outer_process, WorkerPool([2, 3]), jobs_list)
end

jobs_list = collect(1:10)
do_job(jobs_list)

returns the same result as running your original code on a single worker process.

All 4 comments

Note that this code executes correctly if no worker processes are added, i.e. one does not run addprocs and just uses the master process.

I guess this is expected behavior, since the outer pmap already employs (by default) all workers, so there are no ones left to distribute to. Check the ?pmap docstring. However, when you specify which workers to use, everything works fine even with nested pmaps:

using Distributed
addprocs() # this yields workers 2:5 on my machine
@everywhere function inner_process(task_id)
    task_id^2
end

@everywhere function outer_process(job_id)
    inner_task  = collect(1:2)
    pmap(inner_process, WorkerPool([4, 5]), inner_task)
end

function do_job(jobs_list) 
    pmap(outer_process, WorkerPool([2, 3]), jobs_list)
end

jobs_list = collect(1:10)
do_job(jobs_list)

returns the same result as running your original code on a single worker process.

This example also works for me if using a workerpool containing all processes, _including the master process_. The default worker pool for pmap doesn't contain process 1 it seems.

using Distributed
addprocs() # this yields workers 2:5 on my machine
@everywhere function inner_process(task_id)
    task_id^2
end

@everywhere function outer_process(job_id)
    inner_task  = collect(1:2)
    pmap(inner_process, WorkerPool(procs()), inner_task)
end

function do_job(jobs_list) 
    pmap(outer_process, WorkerPool(procs()), jobs_list)
end

jobs_list = collect(1:10)
do_job(jobs_list)

@alandion. It also works if a worker pool containing all workers excluding the master process is created. It seems the trick is to create a worker pool when nesting??. (unlike the example given by @dkarrasch example here am sharing all workers)

using Distributed
addprocs() # this yields workers 2:5 on my machine
@everywhere function inner_process(task_id)
    task_id^2
end

@everywhere function outer_process(job_id)
    inner_task  = collect(1:2)
    pmap(inner_process, WorkerPool(workers()), inner_task)
end

function do_job(jobs_list) 
    pmap(outer_process, WorkerPool(workers()), jobs_list)
end

jobs_list = collect(1:10)
do_job(jobs_list)

For me it only hangs when an explicit WorkerPool or CachingPool isn't passed as an argument.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  Â·  3Comments

omus picture omus  Â·  3Comments

TotalVerb picture TotalVerb  Â·  3Comments

manor picture manor  Â·  3Comments

iamed2 picture iamed2  Â·  3Comments