# Error when I use the function distribute(array) from the libray DistributedArrays

**URL:** <https://discourse.julialang.org/t/error-when-i-use-the-function-distribute-array-from-the-libray-distributedarrays/16015>\
**Category:** Julia at Scale\
**Tags:** array, distributed\
**Created:** [October 8, 2018, 10:38am UTC](https://discourse.julialang.org/t/error-when-i-use-the-function-distribute-array-from-the-libray-distributedarrays/16015 "2018-10-08T10:38:11Z")\
**Posts on this page:** 4\
**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 8, 2018, 10:38am UTC](https://discourse.julialang.org/t/error-when-i-use-the-function-distribute-array-from-the-libray-distributedarrays/16015/1 "2018-10-08T10:38:12Z")

</div>

When I create an array and after I use the distribute() function from the Distributed Arrays library, I get this error:

ERROR: On worker 2:  
KeyError: key DistributedArrays [aaf54ef3-cdf8-58ed-94cc-d582ad619b94] not found  
getindex at .\dict.jl:478 [inlined]  
root\_module at .\loading.jl:892 [inlined]  
deserialize\_module at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Serialization\src\Serialization.jl:831  
handle\_deserialize at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Serialization\src\Serialization.jl:764  
deserialize at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Serialization\src\Serialization.jl:703  
deserialize\_datatype at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Serialization\src\Serialization.jl:1050  
handle\_deserialize at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Serialization\src\Serialization.jl:743  
deserialize at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Serialization\src\Serialization.jl:703  
handle\_deserialize at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Serialization\src\Serialization.jl:750  
deserialize\_msg at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Serialization\src\Serialization.jl:703  
#invokelatest#1 at .\essentials.jl:686 [inlined]  
invokelatest at .\essentials.jl:685 [inlined]  
message\_handler\_loop at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\process\_messages.jl:160  
process\_tcp\_streams at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.0\Distributed\src\process\_messages.jl:117  
#105 at .\task.jl:259  
#remotecall\_fetch#149(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Distributed.Worker, ::Function, ::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:379  
remotecall\_fetch(::Function, ::Distributed.Worker, ::Function, ::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:371  
#remotecall\_fetch#152(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Int64, ::Function, ::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:392  
remotecall\_fetch(::Function, ::Int64, ::Function, ::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:392  
macro expansion at C:\Users\Daniele.julia\packages\DistributedArrays\XV7NS\src\darray.jl:87 [inlined]  
(::getfield(DistributedArrays, Symbol(“##1#2”)){Tuple{Int64,Int64},getfield(DistributedArrays, Symbol(“##63#65”)){DistributedArrays.DestinationSerializer},Tuple{Int64,Int64},Array{Int64,2},Array{Tuple{UnitRange{Int64},UnitRange{Int64}},2},Array{Array{Int64,1},1},Channel{Any}})() at .\task.jl:259

…and 3 more exception(s).

Stacktrace:  
[1] sync\_end(::Array{Any,1}) at .\task.jl:226  
[2] macro expansion at C:\Users\Daniele.julia\packages\DistributedArrays\XV7NS\src\darray.jl:83 [inlined]  
[3] macro expansion at .\task.jl:244 [inlined]  
[4] DArray(::Tuple{Int64,Int64}, ::Function, ::Tuple{Int64,Int64}, ::Array{Int64,2}, ::Array{Tuple{UnitRange{Int64},UnitRange{Int64}},2}, ::Array{Array{Int64,1},1}) at C:\Users\Daniele.julia\packages\DistributedArrays\XV7NS\src\darray.jl:82  
[5] DArray(::Function, ::Tuple{Int64,Int64}, ::Array{Int64,1}, ::Array{Int64,1}) at C:\Users\Daniele.julia\packages\DistributedArrays\XV7NS\src\darray.jl:169  
[6] #distribute#61(::Array{Int64,1}, ::Array{Int64,1}, ::Function, ::Array{Int64,2}) at C:\Users\Daniele.julia\packages\DistributedArrays\XV7NS\src\darray.jl:501  
[7] distribute(::Array{Int64,2}) at C:\Users\Daniele.julia\packages\DistributedArrays\XV7NS\src\darray.jl:494  
[8] top-level scope at none:0

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [February 16, 2019, 1:03am UTC](https://discourse.julialang.org/t/error-when-i-use-the-function-distribute-array-from-the-libray-distributedarrays/16015/2 "2019-02-16T01:03:19Z")

</div>

I’m facing a similar issue. Any idea?

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [February 16, 2019, 2:57am UTC](https://discourse.julialang.org/t/error-when-i-use-the-function-distribute-array-from-the-libray-distributedarrays/16015/3 "2019-02-16T02:57:34Z")

</div>

The issue happens when I add child processes from a function within a module. The child processes do not see the module itself but I couldn’t use the `using` statement either because it’s inside a function. Moving to the `addprocs` call out to a script avoids this problem. I’m wondering however if there’s a better way to do this though…

---

<div class="post-metadata">

**Author:** ![jsbryan4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsbryan4/32/34173_2.png) [@jsbryan4](https://discourse.julialang.org/u/jsbryan4)\
**Post date:** [April 7, 2022, 9:57pm UTC](https://discourse.julialang.org/t/error-when-i-use-the-function-distribute-array-from-the-libray-distributedarrays/16015/4 "2022-04-07T21:57:05Z")

</div>

According to [this post](https://discourse.julialang.org/t/distributed-computing-not-found-package-error/34851) the issue is that the processes are likely added after the “@everywhere using …” commands. I found that by reorganizing my import statements I could make this error go away. Specifically make sure you addprocs first like

```julia
using Distributed
addprocs(4)
@everywhere using DistributedArrays
import("myfile.jl")

```
