# Julia 0.6 parallelization of modules and functions

**URL:** https://discourse.julialang.org/t/julia-0-6-parallelization-of-modules-and-functions/19952
**Category:** Julia at Scale
**Created:** [January 23, 2019, 12:25am UTC](https://discourse.julialang.org/t/julia-0-6-parallelization-of-modules-and-functions/19952 "2019-01-23T00:25:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![wonderboy3489](https://avatars.discourse-cdn.com/v4/letter/w/e8c25b/32.png) [@wonderboy3489](https://discourse.julialang.org/u/wonderboy3489)
#### Post date: [January 23, 2019, 12:25am UTC](https://discourse.julialang.org/t/julia-0-6-parallelization-of-modules-and-functions/19952/1 "2019-01-23T00:25:12Z")

</div>

Hi all,

I’m trying to modify some example code from the documentation and am running into an error. Here’s my module that I’m trying to create:

```julia
@everywhere module parallel_test

using Base.Distributed
@everywhere using Base.SharedArray
@everywhere import Distributions

@everywhere advection_shared_chunk!(q, u, z) =
   advection_chunk!(q, u, z, myrange(q)..., 1:size(q,3)-1)

function advection_shared!(q, u, z)
   @sync begin
       for p in procs(q)
           @async remotecall_wait(advection_shared_chunk!, p, q, u, z)
       end
   end
   q
end;

@everywhere function advection_chunk!(q, u, z, irange, jrange, trange)
   @show (irange, jrange, trange) # display so we can see what's happening
   for t in trange, j in jrange, i in irange
       q[i,j,t+1] = q[i,j,t] + u[i,j,t] + z[i] - Distributions.cdf(Distributions.TDist(10), 34)
   end
   q
end

@everywhere function myrange(q::SharedArray)
   idx = indexpids(q)
   if idx == 0 # This worker is not assigned a piece
       return 1:0, 1:0
   end
   nchunks = length(procs(q))
   splits = [round(Int, s) for s in linspace(0,size(q,2),nchunks+1)]
   1:size(q,1), splits[idx]+1:splits[idx+1]
end

function test_function(q, u, z)

	advection_shared!(q,u,z);
end

end

```

Then, from the terminal (after loading with julia -p 4):

```julia
 q = SharedArray{Float64,3}((500,500,500));
 u = SharedArray{Float64,3}((500,500,500));
 z = rand(500,1)
parallel_test.test_function(q, u, z)

```

I’m running into this error:

```julia
**ERROR:** UndefVarError: advection_shared_chunk! not defined

(::parallel_test.##9#10{SharedArray{Float64,3},SharedArray{Float64,3},Array{Float64,2}})() at ./task.jl:335

...and 3 more exception(s).

Stacktrace:

[1] **sync_end()** at **./task.jl:287**

[2] **macro expansion** at **./task.jl:303** [inlined]

[3] **advection_shared!(** ::SharedArray{Float64,3}, ::SharedArray{Float64,3}, ::Array{Float64,2} **)** at **/Users/james.nance/Documents/1225/parallel_test.jl:9**

[4] **test_function(** ::SharedArray{Float64,3}, ::SharedArray{Float64,3}, ::Array{Float64,2} **)** at **/Users/james.nance/Documents/1225/parallel_test.jl:40**

```

Any idea what’s going on?

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [January 23, 2019, 3:27am UTC](https://discourse.julialang.org/t/julia-0-6-parallelization-of-modules-and-functions/19952/2 "2019-01-23T03:27:24Z")

</div>

Would you mind fixing the quoting of you code by changing the ‘…’ to ‘```’ please? It’ll make your code much easier for others to read and comprehend.

I’m thinking that you might have too many `@everywhere` calls here, since you have one already at the module level (which I suppose should cover everything contained within it). Maybe try removing all but that one?

Importantly, how are you launching your processes? Are you using a flag from the shell, or doing `addprocs` earlier before you run your actual code?

---

<div class="post-metadata">

### Author: ![wonderboy3489](https://avatars.discourse-cdn.com/v4/letter/w/e8c25b/32.png) [@wonderboy3489](https://discourse.julialang.org/u/wonderboy3489)
#### Post date: [January 23, 2019, 4:00pm UTC](https://discourse.julialang.org/t/julia-0-6-parallelization-of-modules-and-functions/19952/3 "2019-01-23T16:00:13Z")

</div>

Thanks, @jpsamaroo, I’m very new to this site and didn’t know how to do that. Looks much nicer now!

And removing all but the first @everywhere did the trick. I’m starting Julia with 4 processes and then running the code.
