Also, your pre-allocation of matr_C
isn’t effective or needed, since that allocation is not used. Unlike in Fortran or Matlab, when you write matr_C = ...
, this does not copy the right-hand side into matr_C
. Instead, the label matr_C
in effect is “re-pointed” to whatever is on the right-hand side, in this case a KroneckerProduct
type as defined in the Kronecker
package. So the memory you allocated for matr_C
is discarded and eventually cleaned up by Julia’s garbage collector.
This is an important point to understand about Julia, and it is often discussed in this forum, e.g. here.