# Error calling remotecall\_fetch from module

**URL:** <https://discourse.julialang.org/t/error-calling-remotecall-fetch-from-module/1029>\
**Category:** General Usage\
**Created:** [December 18, 2016, 9:11pm UTC](https://discourse.julialang.org/t/error-calling-remotecall-fetch-from-module/1029 "2016-12-18T21:11:28Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [December 18, 2016, 9:11pm UTC](https://discourse.julialang.org/t/error-calling-remotecall-fetch-from-module/1029/1 "2016-12-18T21:11:28Z")

</div>

I had similar code working on v0.4, but now fails on v0.5

```julia
module TestModule
    export test1, test2, test3
    test1(id) = remotecall_fetch(myid, id)
    test2(id) = remotecall_fetch(()->VERSION, id)
    test3(id) = remotecall_fetch(eval, id, :(Sys.CPU_CORES))
end

using TestModule
addprocs(2)

test1(2) # works
test2(2) # error
test3(2) # error

```

And here’s the output:

```julia
julia> test1(2)
2

julia> test2(2)
ERROR: On worker 2:
UndefVarError: TestModule not defined
 in deserialize at .\serialize.jl:602
 in handle_deserialize at .\serialize.jl:581
 in deserialize at .\serialize.jl:541
 in deserialize_datatype at .\serialize.jl:822
 in handle_deserialize at .\serialize.jl:571
 in deserialize_msg at .\multi.jl:120
 in message_handler_loop at .\multi.jl:1317
 in process_tcp_streams at .\multi.jl:1276
 in #620 at .\event.jl:68
 in #remotecall_fetch#608(::Array{Any,1}, ::Function, ::Function, ::Base.Worker) at .\multi.jl:1070
 in remotecall_fetch(::Function, ::Base.Worker) at .\multi.jl:1062
 in #remotecall_fetch#611(::Array{Any,1}, ::Function, ::Function, ::Int64) at .\multi.jl:1080
 in test2(::Int64) at .\REPL[1]:4

julia> test3(2)
ERROR: On worker 2:
UndefVarError: ##1#2 not defined
 in deserialize_datatype at .\serialize.jl:823
 in handle_deserialize at .\serialize.jl:571
 in deserialize_msg at .\multi.jl:120
 in message_handler_loop at .\multi.jl:1317
 in process_tcp_streams at .\multi.jl:1276
 in #620 at .\event.jl:68
 in #remotecall_fetch#608(::Array{Any,1}, ::Function, ::Function, ::Base.Worker) at .\multi.jl:1070
 in remotecall_fetch(::Function, ::Base.Worker) at .\multi.jl:1062
 in #remotecall_fetch#611(::Array{Any,1}, ::Function, ::Function, ::Int64) at .\multi.jl:1080
 in test3(::Int64) at .\REPL[1]:5

```

Why is it failing?

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [December 20, 2016, 12:18am UTC](https://discourse.julialang.org/t/error-calling-remotecall-fetch-from-module/1029/2 "2016-12-20T00:18:13Z")

</div>

The example code gives the same error on 0.4, for the same reason: the code must be loaded on remote workers. A simple fix is:

```julia
@everywhere module TestModule
...
end

```

(note: run `@everywhere` _after_ `addprocs`!)

Please see [the manual](http://docs.julialang.org/en/release-0.5/manual/parallel-computing/) for more options and examples.

---

<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:** [December 20, 2016, 2:20am UTC](https://discourse.julialang.org/t/error-calling-remotecall-fetch-from-module/1029/3 "2016-12-20T02:20:29Z")

</div>

Yes, it does give same error on 0.4. I apologise I should have checked first.  
In trying to create a minimal working example I’ve obviously removed something relevant.

I have seen `@everywhere using Module` but for some reason I didn’t need this in my case (on v0.4)  
But I did have `using Module` after `addprocs()`  
Another difference was that Module was defined in a file in LOAD\_PATH.

So I’m a bit confused about why it worked on v0.4. I’ll do some more investigating.

To help my understanding, in the example above, why does TestModule need to be loaded on remote workers?  
It seems there isn’t anything in TestModule required on remote workers.

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [December 20, 2016, 2:34am UTC](https://discourse.julialang.org/t/error-calling-remotecall-fetch-from-module/1029/4 "2016-12-20T02:34:31Z")

</div>

> [@greg\_plowman](#):
>
> To help my understanding, in the example above, why does TestModule need to be loaded on remote workers?It seems there isn’t anything in TestModule required on remote workers.

Anonymous functions are still referenced by enclosing module – look at `@code_lowered test2(2)`. Likewise for the 3rd one: `eval` == `TestModule.eval`.

---

<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:** [December 20, 2016, 3:05am UTC](https://discourse.julialang.org/t/error-calling-remotecall-fetch-from-module/1029/5 "2016-12-20T03:05:57Z")

</div>

Thanks! This is very helpful.

For the above, I can do the following using `Core.eval` and everything works without requiring TestModule on workers.

```julia
module TestModule
    export test1, test2, test3
    test1(id) = remotecall_fetch(myid, id)
    test2(id) = remotecall_fetch(Core.eval, id, :VERSION)
    test3(id) = remotecall_fetch(Core.eval, id, Sys, :CPU_CORES)
end

using TestModule
addprocs(2)

test1(2)
test2(2)
test3(2)

```
