# How to declare sharedarray in local scope

**URL:** <https://discourse.julialang.org/t/how-to-declare-sharedarray-in-local-scope/112683>\
**Category:** General Usage\
**Tags:** sharedarrays\
**Created:** [April 8, 2024, 1:49pm UTC](https://discourse.julialang.org/t/how-to-declare-sharedarray-in-local-scope/112683 "2024-04-08T13:49:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TongTongYee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tongtongyee/32/207244_2.png) [@TongTongYee](https://discourse.julialang.org/u/TongTongYee)\
**Post date:** [April 8, 2024, 1:49pm UTC](https://discourse.julialang.org/t/how-to-declare-sharedarray-in-local-scope/112683/1 "2024-04-08T13:49:34Z")

</div>

Hi!

I want to use sharedArray without data movement.

So I write the following code.

```julia
using Distributed
addprocs(1)
A = SharedArray{ComplexF64,1}(fill(1,(10)));
@everywhere 2 A

```

But this code makes the error,

```julia
ERROR: On worker 2:
UndefVarError: `A` not defined

```

In a global scope, I have solution.

```julia
using Distributed
addprocs(1)
A = SharedArray{ComplexF64,1}(fill(1,(10)));
@spawnat(2,A)
@everywhere 2 A

```

This code don’t make an error.

But my problem is in local scope.

For example,

```julia
function ex2()
    A = SharedArray{ComplexF64,1}(fill(1,(10)));
    for w in workers()
        fetch(@spawnat(w,A))
    end
    remotecall_fetch(x->x,2,A)
    @everywhere 2 println(Base.@locals)
    @everywhere 2 A
    return 
end

```

This code makes the error,

```julia
ERROR: On worker 2:
UndefVarError: `A` not defined

```

I have no solution in local scope.
