ExponentialUtilities.jl expv!() allocations

Hi everyone,

I’m trying to use Julia’s ExponentialUtilities.jl package to perform matrix-exponential-matrix multiplication. I have a sparse NxN Hamiltonian H, a small time step dt, and an NxN matrix A. The goal is to compute exp(-idt*H)A. In order to do this using the ExponentialUtilities.jl package, I first pre-allocate a Krylov subspace Ks. Then, I loop over the columns aj of A. At each iteration, I use the arnoldi!() function, H, and aj to fill the pre-allocated Krylov subspace. Then, I call expv!() to write the output into a temporary workspace vector, and copy this workspace vector into the jth column of the output NxN matrix.

My issue is that the expv!() function seems to be allocating a lot of memory, about 100 KiB to perform each matrix-exponential-vector multiplication for a 997x997 matrix and a vector of length 997. Is this something that I should expect? I was under the impression that if I preallocated the Krylov subspace, I wouldn’t have to allocate a lot of extra memory. Thank you in advance for any guidance on this matter.

@ChrisRackauckas

Where does the allocation profiler point to?

Hi Chris, thank you for your response. I ran the allocation profiler and it’s indicating that the allocations are due to expv!(). Each time it’s called, it allocates 3 arrays. Moreover, there are internal calls to exponential!() that also allocate memory as well. As far as I can tell, all of the memory allocation is due to something that’s going on with expv!().

I noticed in the ExponentialUtilities.jl documentation that there’s an expv!() function that takes a cache as an argument as well:

Could this be used to reduce the number of allocations? I would like to try it out, but I cannot find instructions in the documentation on how to use the cache. Thanks again!