# Should I use mutable or immutable types for parameters when writing parallel code?

**URL:** <https://discourse.julialang.org/t/should-i-use-mutable-or-immutable-types-for-parameters-when-writing-parallel-code/4792>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 11, 2017, 3:05pm UTC](https://discourse.julialang.org/t/should-i-use-mutable-or-immutable-types-for-parameters-when-writing-parallel-code/4792 "2017-07-11T15:05:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thudso](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@thudso](https://discourse.julialang.org/u/thudso)\
**Post date:** [July 11, 2017, 3:05pm UTC](https://discourse.julialang.org/t/should-i-use-mutable-or-immutable-types-for-parameters-when-writing-parallel-code/4792/1 "2017-07-11T15:05:53Z")

</div>

Hi there,

I’m a newbie to both Julia and parallel computing, trying to parallelise some code which runs a sampling algorithm. I have a master and multiple workers, all of which need access to some global parameters. I have defined a type which contains all of these parameters (not too many, ~20 variables).

It would seem good practice to make this type immutable since it effectively contains global variables, but the docs mention that immutable types are copied each time they are passed. Is it therefore better from the point of view of efficiency to make the type containing the global parameters mutable, or is there a totally different solution that I’m not seeing?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 11, 2017, 3:35pm UTC](https://discourse.julialang.org/t/should-i-use-mutable-or-immutable-types-for-parameters-when-writing-parallel-code/4792/2 "2017-07-11T15:35:10Z")

</div>

AFAIK immutable are passed by reference if they are large enough for it to be worthwhile.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 11, 2017, 3:35pm UTC](https://discourse.julialang.org/t/should-i-use-mutable-or-immutable-types-for-parameters-when-writing-parallel-code/4792/3 "2017-07-11T15:35:22Z")

</div>

Be very careful with any kind of mutation or globals with parallel computing. In general, anything which will be changed should be local to specific processes.
