# How to distribute arrays part of struct with MPI (MPI.jl)

**URL:** https://discourse.julialang.org/t/how-to-distribute-arrays-part-of-struct-with-mpi-mpi-jl/87305
**Category:** Julia at Scale
**Tags:** question, mpi
**Created:** [September 15, 2022, 8:30am UTC](https://discourse.julialang.org/t/how-to-distribute-arrays-part-of-struct-with-mpi-mpi-jl/87305 "2022-09-15T08:30:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![verseve](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/verseve/32/22231_2.png) [@verseve](https://discourse.julialang.org/u/verseve)
#### Post date: [September 15, 2022, 8:30am UTC](https://discourse.julialang.org/t/how-to-distribute-arrays-part-of-struct-with-mpi-mpi-jl/87305/1 "2022-09-15T08:30:32Z")

</div>

I am wondering what the best approach is to distribute arrays that are part of a struct with MPI.

Example of such a struct (partly):

```julia
@get_units @with_kw struct SBM{T,N,M}
    Δt::T | "s"
    maxlayers::Int | "-"
    n::Int | "-"
    nlayers::Vector{Int} | "-"
    n_unsatlayers::Vector{Int} | "-"
    riverfrac::Vector{T} | "-"
    θₛ::Vector{T} | "-"
    θᵣ::Vector{T} | "-"
...

```

An instance of this struct is updated each time step with:

```julia
function update(sbm::SBM)
     for i = 1:sbm.n
...

```

I understand that with `MPI.Send` and `MPI.Recv` arrays can be distributed, and this is faster than passing a struct (requires serialization).

What would be a good approach here, to distribute arrays that are part of a struct, without the use of serialization?

Do I need to initialize the struct on all ranks then? I guess normally you would initialize (and for example read parameter values from files) on the root rank and then distribute.

Or would it better to use Distributed.jl in this case?
