# How am I supposed to use pmap?

**URL:** <https://discourse.julialang.org/t/how-am-i-supposed-to-use-pmap/3943>\
**Category:** General Usage\
**Created:** [May 26, 2017, 7:22pm UTC](https://discourse.julialang.org/t/how-am-i-supposed-to-use-pmap/3943 "2017-05-26T19:22:11Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [June 3, 2017, 4:58am UTC](https://discourse.julialang.org/t/how-am-i-supposed-to-use-pmap/3943/12 "2017-06-03T04:58:56Z")

</div>

Do you have a minimal example?

I typically use this approach:

1. Put everything you need distributed to workers into a Module.
2. Save Module to filesystem
3. Ensure path to Module is in `LOAD_PATH`
4. `addprocs()`
5. `using Module`

Notes:

- It is important to `addprocs` _before_ `using Module`
- You shouldn’t need `@everywhere`
- You shouldn’t get warnings about replacing module.

Here’s an example:

```julia
module ModuleA
    export testA
    function testA(x)
        println(x, " -> ", x*x)
        return x*x
    end
end

```

Save this to file `ModuleA.jl` (or `ModuleA/src/ModuleA.jl`)

Now run this:

```julia
addprocs()

# ensure module is in LOAD_PATH
# in this example, module A was saved to working directory (but can be any directory)
thisDir = dirname(@ __FILE__ ())
any(path -> path == thisDir, LOAD_PATH) || push!(LOAD_PATH, thisDir)

using ModuleA

pmap(testA, 1:10)

```

And here’s the output:

```julia
Julia-0.5.2> include("loading_pmap.jl")
        From worker 2: 1 -> 1
        From worker 3: 4 -> 16
        From worker 5: 2 -> 4
        From worker 4: 3 -> 9
        From worker 2: 5 -> 25
        From worker 5: 6 -> 36
        From worker 4: 7 -> 49
        From worker 3: 8 -> 64
        From worker 2: 9 -> 81
        From worker 4: 10 -> 100
10-element Array{Any,1}:
   1
   4
   9
  16
  25
  36
  49
  64
  81
 100

```

---

_[View the full topic](https://discourse.julialang.org/t/how-am-i-supposed-to-use-pmap/3943)._
