# Generate Random Symmetric Matrices with pmap

**URL:** https://discourse.julialang.org/t/generate-random-symmetric-matrices-with-pmap/24706
**Category:** General Usage
**Tags:** pmap
**Created:** [May 28, 2019, 7:18pm UTC](https://discourse.julialang.org/t/generate-random-symmetric-matrices-with-pmap/24706 "2019-05-28T19:18:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![VincentTam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vincenttam/32/8358_2.png) [@VincentTam](https://discourse.julialang.org/u/VincentTam)
#### Post date: [May 28, 2019, 7:18pm UTC](https://discourse.julialang.org/t/generate-random-symmetric-matrices-with-pmap/24706/1 "2019-05-28T19:18:55Z")

</div>

I would like to call `Symmetric()` inside an `@everywhere function`, and use `pmap` to generate an array of `Symmetric` matrices, which are half of the `sizeof` normal ones, but I received an `UndefVarError`.

```julia
using LinearAlgebra, Distributed
addprocs(Sys.CPU_THREADS - 1)
@everywhere function G_parallel(d)
  return Symmetric([i == j ? randn()/d : randn()/(2*d) for i in 1:d, j in 1:d])
end
pmap( _ -> G_parallel(2), 1:10000)

```

Here’s the error received.

```julia
On worker 4:
UndefVarError: Symmetric not defined
G_parallel at ./In[5]:2
#9 at ./In[6]:1
#112 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Distributed/src/process_messages.jl:269
run_work_thunk at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Distributed/src/process_messages.jl:56
macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Distributed/src/process_messages.jl:269 [inlined]
#111 at ./task.jl:259

Stacktrace:
 [1] (::getfield(Base, Symbol("##696#698")))(::Task) at ./asyncmap.jl:178
 [2] foreach(::getfield(Base, Symbol("##696#698")), ::Array{Any,1}) at ./abstractarray.jl:1866
 [3] maptwice(::Function, ::Channel{Any}, ::Array{Any,1}, ::UnitRange{Int64}) at ./asyncmap.jl:178
 [4] #async_usemap#681 at ./asyncmap.jl:154 [inlined]
 [5] #async_usemap at ./none:0 [inlined]
 [6] #asyncmap#680 at ./asyncmap.jl:81 [inlined]
 [7] #asyncmap at ./none:0 [inlined]
 [8] #pmap#213(::Bool, ::Int64, ::Nothing, ::Array{Any,1}, ::Nothing, ::Function, ::Function, ::WorkerPool, ::UnitRange{Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Distributed/src/pmap.jl:126
 [9] pmap(::Function, ::WorkerPool, ::UnitRange{Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Distributed/src/pmap.jl:101
 [10] #pmap#223(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::UnitRange{Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Distributed/src/pmap.jl:156
 [11] pmap(::Function, ::UnitRange{Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Distributed/src/pmap.jl:156
 [12] top-level scope at In[6]:1

```

---

<div class="post-metadata">

### Author: ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)
#### Post date: [May 28, 2019, 7:33pm UTC](https://discourse.julialang.org/t/generate-random-symmetric-matrices-with-pmap/24706/2 "2019-05-28T19:33:05Z")

</div>

Try putting „@everywhere“ in front of the using statement for all workers to load LinearAlgebra. The addprocs call should happen before that

---

<div class="post-metadata">

### Author: ![VincentTam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vincenttam/32/8358_2.png) [@VincentTam](https://discourse.julialang.org/u/VincentTam)
#### Post date: [May 28, 2019, 7:39pm UTC](https://discourse.julialang.org/t/generate-random-symmetric-matrices-with-pmap/24706/3 "2019-05-28T19:39:02Z")

</div>

Thanks for answer!
