Reduce number of allocations in matrix multiplication in Julia?

368 Views Asked by At

Is there any way to reduce the number of allocations when multiplying matrices in Julia? I would like to reduce this number if possible. I have attached a screenshot that displays this.

enter image description here

1

There are 1 best solutions below

3
Bogumił Kamiński On

You can go down to no allocations if you pre-allocate the output matrix:

julia> x = rand(600, 600);

julia> y = rand(600, 600);

julia> z = zeros(600, 600);

julia> @allocated mul!(z, x, y)
0