# Distributed computing using mutable struct

**URL:** <https://discourse.julialang.org/t/distributed-computing-using-mutable-struct/66029>\
**Category:** General Usage\
**Tags:** question, distributed\
**Created:** [August 8, 2021, 4:35pm UTC](https://discourse.julialang.org/t/distributed-computing-using-mutable-struct/66029 "2021-08-08T16:35:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmurga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmurga/32/15944_2.png) [@jmurga](https://discourse.julialang.org/u/jmurga)\
**Post date:** [August 8, 2021, 4:35pm UTC](https://discourse.julialang.org/t/distributed-computing-using-mutable-struct/66029/1 "2021-08-08T16:35:21Z")

</div>

Hi everyone,

I am developing a bioinformatics package to estimate protein adaptation rate using analytical theory followed by an Approximate Bayesian Computation.

I have used a mutable struct to change some mutational features independently and output _N_ independent estimations, which I used to perform ABC. Since _N_ is nearly `10^6` I have explored distributed computing to perform such _N_ independent estimation.

The problem is that I am performing the distributed computing using several copies of the mutable struct, which finally changes any value inside the function which performs the whole estimation.

Here I summed up the code which makes the estimation.

```julia
# param is the mutable struct
# N is the number of models to solve
# nTot, nLow, ngh, ngl, ngamNeg, afac, θ, ρ, are the arrays containing the values to solve the model

fac = rand(-2:0.05:2,N)
afac = @. 0.184*(2^fac)
nTot = rand(0.1:0.01:0.9,N)
lfac = rand(0.0:0.05:0.9,N)
nLow = @. nTot * lfac
ngh = rand(repeat(gH,N),N);
ngamNeg = rand(repeat(gamNeg,N),N);
θ = fill(theta,N)
ρ = fill(rho,N)

nParam = [param for i in 1:N];

# iterRates change param values nTot, nLow, ngh, ngl, ngamNeg, afac, θ, ρ values before performing the estimation
Distributed.pmap(iterRates, nParam, nBinom, nTot, nLow, ngh, ngl, ngamNeg, afac, θ, ρ);

```

I have never programmed using distributed computing before, but I am sure this is not the proper way to program it. Is there any other way to properly distribute my mutable struct and solve my model _N_ times?

Thanks in advance!

Jesús
