News for hackers. Stuff that matters.
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by snicker7 on Monday June 15, 2020 @01:23PM (#23530076)
The real performance win seems to be reducing the number of allocations (2 vs. 30 thousand).
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by spacedome on Monday June 15, 2020 @02:33PM (#23531158)
This has been my general experience writing numerical linear algebra methods in Julia. Optimizing a specific algorithm, eliminating unnecessary allocations is the first thing I do, and can give large performance gains, especially for iterative methods.

It can be a bit annoying, and can result in much less readable code (eg having to explicitly write things like mul!(C, A, B)). It ends up looking a lot more like the FORTRAN it is meant to replace, and if you aren't careful you lose the ability to use generic types, though multiple dispatch is a great solution. The worst case I have found is iteratively calling linear algebra solvers (Eig, SVD, LU) which do not have any option for preallocating and reusing work arrays. The only way to do this now is to call the BLAS/LAPACK routines directly with ccall, which is a huge pain. There was an attempt to fix this with PowerLAPACK.jl, but it seems abandoned, so for the moment writing optimized methods in FORTRAN/C and calling from Julia is sometimes still preferable.

Julia does quite well though, so this only seems necessary for things like core NLA libraries, for example I would not try rewriting ARPACK in Julia for a performance gain. The gain in flexibility for writing these in Julia is absolutely huge though, and I definitely recommend it. The Grassmann.jl library has many examples of what a language like Julia makes possible, or DifferentialEquations.jl.

Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by etik on Monday June 15, 2020 @03:56PM (#23532210)
There is a recent effort [1] to provide low-level support for faster operations by transforming user code to take advantage of a compiler's instruction set, memory packing, etc. This is being expanded upon to essentially provide a Julia-native BLAS. Some of the benchmarks are even competitive with or beat Intel MKL (calibrate that statement appropriately to your level of trust in benchmarks). I wouldn't count out a Julia ARPACK implementation just yet.

[1] LoopVectorization: https://github.com/chriselrod/LoopVectorization.jl Announcement post and discussion: https://discourse.julialang.org/t/ann-loopvectorization/3284...

Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by stabbles on Monday June 15, 2020 @04:59PM (#23532904)
You're probably confusing ARPACK with BLAS / LAPACK.

Pure julia ARPACK already exists, e.g. https://github.com/haampie/ArnoldiMethod.jl/.

A competive BLAS-gemm is implemented here https://github.com/YingboMa/MaBLAS.jl/blob/master/src/gemm.j... (single-threaded).

A LAPACK-like library could be https://github.com/JuliaLinearAlgebra/GenericLinearAlgebra.j...

Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by etik on Monday June 15, 2020 @05:12PM (#23533034)
I was mostly referring to the parent comment's suggestion that low level numerical libraries wouldn't benefit from a pure Julia implementation, specifically to the statement that it was still better to write optimized C/FORTRAN and call from Julia. Indeed, MaBLAS, which you linked, is built on top of LoopVectorization.jl.

I don't know how well ArnoldiMethod.jl compares with ARPACK, but if there is a gap my suggestion is simply that these recent developments might help bridge it :)

Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by stabbles on Monday June 15, 2020 @05:37PM (#23533289)
FWIW, MaBLAS currently does not depend on LoopVectorization.jl, the code to generate kernels is all handwritten.
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by spacedome on Monday June 15, 2020 @05:25PM (#23533148)
This is great, a lot of the performance in BLAS comes from memory management. This does not solve my problem though. Sometimes you want to manually control memory, and Julia does not make it easy to do so. In particular when interfacing with BLAS/LAPACK though Julia, memory management is quite ugly, mainly due to the need for allocating work arrays, and a pure Julia implementation of BLAS is unlikely to fix this. I don't think writing eg ARPACK performantly in Julia is imposible, just painful to the point that writing it in FORTRAN starts to make sense (to me).
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by stabbles on Monday June 15, 2020 @05:35PM (#23533252)
> I don't think writing eg ARPACK performantly in Julia is impossible

Not sure what you mean, ARPACK just wraps a bunch of calls to LAPACK and BLAS, that's all. It does not have any low-level linalg kernels of its own. Also, its main bottleneck is typically outside of the algorithm, namely matrix-vector products. ArnoldiMethod.jl is pretty much a pure Julia implementation of ARPACK without any dependency on LAPACK (only BLAS when used with Float32/Float64/ComplexF32/ComplexF64). Finally note that you can easily beat ARPACK by adding GPU support, since they don't provide it.

Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by spacedome on Monday June 15, 2020 @06:52PM (#23533998)
The person I was responding to seemed to have read my comment and thought I had an issue with raw performance. My point above is that writing iterative code that makes many LAPACK calls becomes difficult to write in Julia because there is no way to manage the memory in this situation other than ccall-ing everything yourself, at which point I would rather write FORTRAN. I work on eigenvalue solvers, so it is all more or less just wrapping a bunch of calls to BLAS/LAPACK. As you say, the main bottleneck is in the BLAS calls anyways, but the excess allocation in Julia can really slow you down. ARPACK is maybe a bad example because its all just mat-vec, when you need to do something like compute an SVD every iteration, thats where you run into issues.
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by Xcelerate on Monday June 15, 2020 @03:32PM (#23531937)
I love Julia and have used it for years, but this is really my only complaint with my language. I used to do HPC work and ended up spending a lot of time tracking down where tiny bits of memory were being allocated in for loops. A lot of my routines ended up having “blocks” of memory to pass in as arguments, which as you mention, moves the language a bit closer to C or Fortran IMO.
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by snicker7 on Tuesday June 16, 2020 @11:59AM (#23540700)
Minimizing allocations (and deallocations) and optimizing memory layout are just things you have to do for HPC in any language. Though I think that it is easier in Julia than in C/Fortran.
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by doublesCs on Monday June 15, 2020 @02:24PM (#23531056)
That's not uncommon in HPC.

I'm surprised if this was inherent to StaticArrays.jl though. Probably some interop edge case, I'm imagining.

Shall we summon Chris Rackauckas?

Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by ChrisRackauckas on Tuesday June 16, 2020 @01:18PM (#23541588)
It worked, I answered on Discourse because someone pinged me for an answer, saying "you've been summoned" haha.
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by marmaduke on Monday June 15, 2020 @02:28PM (#23531105)
So the real question is why a library with the word "static" in its title does 30 thousand allocations..
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by dnautics on Monday June 15, 2020 @03:06PM (#23531599)
I believe the "static" refers to static, aka, compile-time dimension of the array (yes, julia is a compiling language), versus an array that has a run-time, mutable array dimensionality.
Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by ChrisFoster on Monday June 15, 2020 @07:13PM (#23534180)
"Static" is a reference to the size of the arrays being fixed and encoded in the type. There's various allocation strategies, for instance StaticArrays.SizedArray uses a normal heap-allocated Array as the storage.

That said, the backing storage for the particular static array types used in this example (SMatrix,SVector) is an immutable Tuple which should generally be stack allocated if the library and optimizer are working together as intended. So the allocations here are a bit of a surprise; they may indicate a lack of inlining in something we expected to be inlined.

Re:Grassmann.jl A\b 3x faster than Julia's StaticArrays.jl by tkoolen on Monday June 15, 2020 @09:15PM (#23534955)
1) a mistake in the benchmark procedure explained in https://discourse.julialang.org/t/grassmann-jl-a-b-3x-faster..., and 2) the dynamically-sized result vector containing 10000 statically-sized 5-vectors still needs to be allocated.