# Error when I run for the first time my parallel code

**URL:** https://discourse.julialang.org/t/error-when-i-run-for-the-first-time-my-parallel-code/16435
**Category:** Julia at Scale
**Created:** [October 17, 2018, 10:57am UTC](https://discourse.julialang.org/t/error-when-i-run-for-the-first-time-my-parallel-code/16435 "2018-10-17T10:57:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dsHitman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dshitman/32/5465_2.png) [@dsHitman](https://discourse.julialang.org/u/dsHitman)
#### Post date: [October 17, 2018, 10:57am UTC](https://discourse.julialang.org/t/error-when-i-run-for-the-first-time-my-parallel-code/16435/1 "2018-10-17T10:57:59Z")

</div>

Hi, when I run for the first time my parallel code the REPL give me this error

`ERROR: LoadError: On worker 2:  
UndefVarError: SharedArray not defined  
top-level scope at none:0  
eval at .\boot.jl:319  
#116 at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\process\_messages.jl:276  
run\_work\_thunk at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\process\_messages.jl:56  
run\_work\_thunk at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\process\_messages.jl:65  
#102 at .\task.jl:259  
#remotecall\_wait#154(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Distributed.Worker, ::Module, ::Vararg{Any,N} where N) at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:407  
remotecall\_wait(::Function, ::Distributed.Worker, ::Module, ::Vararg{Any,N} where N) at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:398  
#remotecall\_wait#157(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Int64, ::Module, ::Vararg{Any,N} where N) at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:419  
remotecall\_wait(::Function, ::Int64, ::Module, ::Vararg{Any,N} where N) at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:419  
(::getfield(Distributed, Symbol(“##163#165”)){Module,Expr})() at .\task.jl:259

…and 6 more exception(s).

Stacktrace:  
[1] sync\_end(::Array{Any,1}) at .\task.jl:226  
[2] remotecall\_eval(::Module, ::Array{Int64,1}, ::Expr) at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\macros.jl:207  
[3] top-level scope at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\macros.jl:190  
[4] include at .\boot.jl:317 [inlined]  
[5] include\_relative(::Module, ::String) at .\loading.jl:1038  
[6] include(::Module, ::String) at .\sysimg.jl:29  
[7] include(::String) at .\client.jl:388  
[8] top-level scope at none:0`

But I use the macro @everywhere with using SharedArrays, in fact, when I run the same code again, after this ERROR, it works normally. Is there a way to avoid this ERROR the first time that I run my code?

---

<div class="post-metadata">

### Author: ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)
#### Post date: [October 25, 2018, 7:32pm UTC](https://discourse.julialang.org/t/error-when-i-run-for-the-first-time-my-parallel-code/16435/2 "2018-10-25T19:32:35Z")

</div>

Could you post a minimal working example to illustrate how you’re getting this error? The following works for me on 0.7

```julia
julia> using Distributed

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

julia> @everywhere using SharedArrays

julia> A = SharedArray{Float64}((4,4,4),pids=[2;3;4])
4×4×4 SharedArray{Float64,3}:
[:, :, 1] =
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0

[:, :, 2] =
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0

[:, :, 3] =
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0

[:, :, 4] =
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0

julia> B = remotecall_fetch(localindices,3,A)
22:42

```
