NbodyGradient.jl icon indicating copy to clipboard operation
NbodyGradient.jl copied to clipboard

Efficient use of arrays

Open ericagol opened this issue 5 years ago • 7 comments

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

ericagol avatar Feb 05 '20 03:02 ericagol

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.

giordano avatar Feb 05 '20 09:02 giordano

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

ericagol avatar Feb 25 '21 00:02 ericagol

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 avatar Feb 25 '21 00:02 giordano

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

giordano avatar Feb 28 '21 16:02 giordano

Is MKL faster thanks to multi-threading?

ericagol avatar Mar 01 '21 06:03 ericagol

We may want to try Octavian.jl

ericagol avatar Mar 06 '21 22:03 ericagol

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.

langfzac avatar Jul 07 '21 23:07 langfzac