# Correct calling order for modules and pmap?

**URL:** https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824
**Category:** General Usage
**Created:** [March 19, 2018, 9:05pm UTC](https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824 "2018-03-19T21:05:24Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)
#### Post date: [March 19, 2018, 9:05pm UTC](https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824/1 "2018-03-19T21:05:24Z")

</div>

I have a module , `my_module.jl`, which includes functions that I would like to use with `pmap`. Currently, I have tried to execute this like:

```julia
addprocs(4)
include("my_module.jl")

@everywhere function pmap_f(x)
    return my_module.g(x)^2
end

xvals = [[x] for x in linspace(0,1)];

gvals = pmap(pmap_f, xvals)

rmprocs(workers())

```

But this just ends up generating an error that my\_module not found in the current path. Can someone offer some guidance about the correct way to set up such a script?

---

<div class="post-metadata">

### Author: ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)
#### Post date: [March 19, 2018, 9:14pm UTC](https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824/2 "2018-03-19T21:14:46Z")

</div>

Should not it be `@everywhere include...`?

Maybe add  
`@everywhere cd("path to my file")`

---

<div class="post-metadata">

### Author: ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)
#### Post date: [March 19, 2018, 9:30pm UTC](https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824/3 "2018-03-19T21:30:33Z")

</div>

I tried the callling sequence:

```julia
@everywhere cd("/Users/me/path_to_module/")
@everywhere include("my_module.jl")

```

and this ends up generating:

```julia
On worker 7:
UndefVarError: my_module not defined

```

---

<div class="post-metadata">

### Author: ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)
#### Post date: [March 19, 2018, 9:50pm UTC](https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824/4 "2018-03-19T21:50:00Z")

</div>

This is the error returned by the two above line? It works in serial?  
And `@everywhere include("/Users/me/path_to_module/my_module.jl")`?

---

<div class="post-metadata">

### Author: ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)
#### Post date: [March 20, 2018, 2:31am UTC](https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824/5 "2018-03-20T02:31:33Z")

</div>

Putting the fully qualified path in the `@everywhere include` command resolves this.

---

<div class="post-metadata">

### Author: ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)
#### Post date: [March 20, 2018, 2:47am UTC](https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824/6 "2018-03-20T02:47:33Z")

</div>

Is there a cleaner way to do this, without having to identify, beforehand, exactly where I am in the filesystem when calling the `include`?

---

<div class="post-metadata">

### Author: ![pasha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pasha/32/3319_2.png) [@pasha](https://discourse.julialang.org/u/pasha)
#### Post date: [March 20, 2018, 3:04am UTC](https://discourse.julialang.org/t/correct-calling-order-for-modules-and-pmap/9824/7 "2018-03-20T03:04:11Z")

</div>

I make all of my projects into a custom module, and softlink (`ln -s` in linux) the development directory into `~/.julia/v0.6` so it shows up as a directory alongside the packages that I’ve loaded from the official sources. Then for parallel I just need to `@everywhere using MyModule` .

There are subtle differences between `using` and `include`, and usually my needs are met with `using`. The other big benefit with `using` is that `Revise.jl` will keep it up to date, at least in the main worker.
