I have a PDE model in which I am trying to reduce allocations. Currently the following line is the biggest source of allocations:
part2 .= r.*u .+ deriv .+ q .+ u.^3
part2, deriv, and u are preallocated Float64 matrices. r and q are Float64 numbers.
My understanding was that the use of preallocated left hand side and . notation throughout should avoid allocation of intermediate temporary arrays, so why is this line still my biggest source of allocations?
If I replace this line with the following and add another preallocated matrix part1, I get zero allocations, but much less readable code.
broadcast!(*,part2,u,u,u)
broadcast!(*,part1,r,u)
broadcast!(+,part2,part2,part1,deriv,q)