# Preallocating large matrices in all cores is slower than allocating every time

**URL:** <https://discourse.julialang.org/t/preallocating-large-matrices-in-all-cores-is-slower-than-allocating-every-time/59261>\
**Category:** Performance\
**Tags:** distributed\
**Created:** [April 14, 2021, 9:51am UTC](https://discourse.julialang.org/t/preallocating-large-matrices-in-all-cores-is-slower-than-allocating-every-time/59261 "2021-04-14T09:51:10Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [April 20, 2021, 5:24pm UTC](https://discourse.julialang.org/t/preallocating-large-matrices-in-all-cores-is-slower-than-allocating-every-time/59261/5 "2021-04-20T17:24:44Z")

</div>

> [@kaslusimoes](#):
>
> I was already accounting for the effect of “re-sending matrices”

As I demonstrated in my first comment, it wasn’t working the way you expected. Distributed.jl tries to send the globals like `matrices` to remote workers, if the globals are mentioned in `@distributed` body. The function `getmatrices` is a way to workaround this problem; i.e., it let us not mention the globals in `@distributed`.

> [@kaslusimoes](#):
>
> LoadError: syntax: invalid syntax in “local” declaration

It’s hard to tell what went wrong without an MWE.

See also: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

_[View the full topic](https://discourse.julialang.org/t/preallocating-large-matrices-in-all-cores-is-slower-than-allocating-every-time/59261)._
