# (Parallel) Using pmap within modules

**URL:** <https://discourse.julialang.org/t/parallel-using-pmap-within-modules/2088>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 13, 2017, 5:10pm UTC](https://discourse.julialang.org/t/parallel-using-pmap-within-modules/2088 "2017-02-13T17:10:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stustd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stustd/32/21430_2.png) [@stustd](https://discourse.julialang.org/u/stustd)\
**Post date:** [February 13, 2017, 5:10pm UTC](https://discourse.julialang.org/t/parallel-using-pmap-within-modules/2088/1 "2017-02-13T17:10:47Z")

</div>

I cannot figure out how to use `pmap` from within a module. For instance the following code works:

```julia
@everywhere module Work
  w(i) = myid()
end

module Sub

using Work

function go()
  p = pmap(Work.w, 1:10 )
  println(p)
end

go()

end

```

Scoping the the same code within a Top module, i.e.

```julia
module Top

@everywhere module Work
  w(i) = myid()
end

module Sub

using Work

function go()
  p = pmap(Work.w, 1:10 )
  println(p)
end

go()

end

end

```

errors with:

LoadError: On worker 2:  
UndefVarError: Top not defined  
in deserialize at ./serialize.jl:602  
…

I’m using a deeply nested module hierarchy. In summary: I cannot see how to use the parallel functionality at any module level lower than the top level. Advice much appreciated!

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [February 13, 2017, 11:19pm UTC](https://discourse.julialang.org/t/parallel-using-pmap-within-modules/2088/2 "2017-02-13T23:19:11Z")

</div>

Not that I have an answer to your question, but this behavior is fixed on the current 0.6-dev:

```julia
julia> addprocs(3)
3-element Array{Int64,1}:
 2
 3
 4

julia> module Top

       @everywhere module Work
         w(i) = myid()
       end

       module Sub

       using Work

       function go()
         p = pmap(Work.w, 1:10 )
         println(p)
       end

       go()

       end

       end
[2, 3, 4, 2, 2, 2, 2, 2, 2, 2]
Top

julia> Top.Sub.go()
[2, 3, 4, 2, 3, 4, 2, 3, 4, 2]

```

---

<div class="post-metadata">

**Author:** ![stustd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stustd/32/21430_2.png) [@stustd](https://discourse.julialang.org/u/stustd)\
**Post date:** [February 13, 2017, 11:34pm UTC](https://discourse.julialang.org/t/parallel-using-pmap-within-modules/2088/3 "2017-02-13T23:34:51Z")

</div>

@dfdx Confirmed, seems to be an 0.5.0 issue. Thanks!

---

<div class="post-metadata">

**Author:** ![amit.murthy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amit.murthy/32/47_2.png) [@amit.murthy](https://discourse.julialang.org/u/amit.murthy)\
**Post date:** [February 15, 2017, 4:56am UTC](https://discourse.julialang.org/t/parallel-using-pmap-within-modules/2088/4 "2017-02-15T04:56:25Z")

</div>

The `@everywhere` will define `Work` as a top-level module on all processes (can be confirmed with `whos()` and `remote_do(whos, 2)`).
