# How to debug "Local instance of remote reference not found"?

**URL:** <https://discourse.julialang.org/t/how-to-debug-local-instance-of-remote-reference-not-found/57359>\
**Category:** New to Julia\
**Tags:** question, distributed\
**Created:** [March 17, 2021, 4:29am UTC](https://discourse.julialang.org/t/how-to-debug-local-instance-of-remote-reference-not-found/57359 "2021-03-17T04:29:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Post date:** [March 17, 2021, 4:29am UTC](https://discourse.julialang.org/t/how-to-debug-local-instance-of-remote-reference-not-found/57359/1 "2021-03-17T04:29:47Z")

</div>

I tried to make a self-contained MWE but can’t replicate the error.

For some reason it doesn’t like the `@sync`:

```julia
    @sync @distributed for d in 1:ndocs
        thetaLoop!(Theta,Achain,J,d,n_burn,Alpha,verbose,nchains,startiter,niter,k)
    end

```

`thetaLoop!` refers to:

```julia
function getAllTheta(Achain,J,Alpha,startiter,niter,nchains,k;verbose=false)
    n_burn = niter-startiter-1
    ndocs = size(J)[2]
    Theta = SharedArray(zeros(n_burn,k,nchains,ndocs))
    @sync @distributed for d in 1:ndocs
        thetaLoop!(Theta,Achain,J,d,n_burn,Alpha,verbose,nchains,startiter,niter,k)
    end
    Array(Theta)
end

function thetaLoop!(Theta,Achain,J,d,n_burn,Alpha,verbose,nchains,startiter,niter,k)
    for j in 1:nchains
        for i in 1:n_burn    
            verbose ? println(myid(),": doc $d, iter $i") : nothing
            nji = getZ(Achain[startiter:niter,:,:][i,:,j],k)*J
            Theta[i,:,j,d] .= vec((nji[:,d] .+ Alpha) ./ sum(nji[:,d] .+ Alpha))
        end
    end
end

```

Error:

```julia
ERROR: LoadError: TaskFailedException:
On worker 2:
Local instance of remote reference not found
channel_from_id at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Distributed/src/remotecall.jl:164
init_loc_flds at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/SharedArrays/src/SharedArrays.jl:426
deserialize at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/SharedArrays/src/SharedArrays.jl:483
handle_deserialize at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:842
deserialize at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:1350
handle_deserialize at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:837
deserialize at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:1350
handle_deserialize at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:837
deserialize at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Serialization/src/Serialization.jl:773 [inlined]
deserialize_msg at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Distributed/src/messages.jl:99
#invokelatest#1 at ./essentials.jl:710 [inlined]
invokelatest at ./essentials.jl:709 [inlined]
message_handler_loop at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Distributed/src/process_messages.jl:185
process_tcp_streams at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Distributed/src/process_messages.jl:142
#99 at ./task.jl:356

```
