Maintaining structures across workers

I created a struct params to be used across different workers as -

@everywhere params = parameters(Int64[], ...)

I initialise params.mapping_ping as

params.mapping_ping = rand(1:params.q_datacenters, dimensions.num_func_K)
println("init length of params.mapping_ping = ", length(params.mapping_ping))

#output- init length of params.mapping_ping = 100

However, when I run local task = @spawnat :any custom_prox(..) which calls

@everywhere function ProximalOperators.prox!(y, f::HingeDot, x, gamma)
    println("length of params.mapping_ping is ", length(params.mapping_ping))
    datacenter_index = params.mapping_ping[f.k]

I get the output
From worker 3: length of params.mapping_ping is 0.
Why is the length zero here and how can I fix it. I am newer to Julia and I tried reading the documentation but I didn’t know where to begin searching for this issue.

Each process has its own params. You are updating the params only in the master process.

Try adding @everywhere to the code setting mapping_ping.

https://docs.julialang.org/en/v1/stdlib/Distributed/#Distributed.@everywhere

Execute an expression under Main on all procs .