ericagol / NbodyGradient.jl

N-body integrator computes derivatives with respect to initial conditions for TTVs, RV, Photodynamics & more
MIT License
20 stars 9 forks source link

Efficient use of arrays #30

Open ericagol opened 4 years ago

ericagol commented 4 years ago

Could it help to use StaticArrays?

Might it help to use a more specific type than Real?

For the Jacobian propagation, should we use views?

https://stackoverflow.com/questions/38777469/function-for-reshape-view/38778099

giordano commented 4 years ago

Could it help to use StaticArrays?

StaticArrays are very efficient for small sizes, around 16 (so square matrices 4x4 for example). I think they incur in larger compilation latency, if that matters. One useful thing, however, is to have function methods with arguments AbstractArray, rather than Array, so that switching from one type to of array to another one is easy, if necessary.

For the Jacobian propagation, should we use views?

This can give a good performance boost: slicing allocates memory because it copies the content of the slice to another part of the memory, while views just access that part of the memory, with no extra allocations.

ericagol commented 3 years ago

I've seen some mentions of the MKL linear algebra library being fast. I'm wondering if we should try this out: https://github.com/JuliaLinearAlgebra/MKL.jl

giordano commented 3 years ago

As far as I know, using that package is a bit painful, especially on Windows (never tried myself though).

I'd mention that in Julia v1.7 there will be a much easier mechanism to choose the BLAS library to call (OpenBLAS, MKL, etc), but that's a few months away at the moment.

giordano commented 3 years ago

For the record, here is some preliminary work to make switching to MKL much more seamless: https://github.com/JuliaLinearAlgebra/MKL.jl/pull/63. But as I mentioned above, this will happen with Julia v1.7

ericagol commented 3 years ago

Is MKL faster thanks to multi-threading?

ericagol commented 3 years ago

We may want to try Octavian.jl

langfzac commented 3 years ago

I tried using StaticArrays for the non-gradient code. Little difference in computation time. However, in the future it might be better than using structures to hold pre-allocated arrays that the user doesn't need to access.