News for hackers. Stuff that matters.
Re:Outperforming LAPACK with C++ metaprogramming by vog on Monday January 29, 2018 @08:35AM (#16257373)
I wonder if the similar tricks work in other languages with similarily optimizing compilers, but "nicer" metaprogramming, such as Common LISP, Rust and perhaps OCaml? (with camlp4)

Even more interesting would be whether this leads to the same huge performance gains in those languages as well.

Re:Outperforming LAPACK with C++ metaprogramming by ChrisRackauckas on Monday January 29, 2018 @11:12AM (#16258285)
It does lead to performance gains. This kind of stuff is done all the time in Julia's numerical codes. Flexible macros definitely make this easier, and multiple dispatch + automatic function specialization on types + inlining + interprocedural optimizations makes a lot of what's discussed here automatic. If it's not automatic, then libraries like StaticArrays.jl make functions that use small arrays do these kinds of tricks automatically (it overloads and unrolls operations specifically to match the size of the array which is compile time information). I am sure other languages can do this too, but having it semi-automatic is pretty cool if what you do all day is write numerical codes.
Re:Outperforming LAPACK with C++ metaprogramming by uadjet on Monday January 29, 2018 @10:31PM (#16262710)
Julia's flexibility in the numerical space is why it's my daily driver language for prototyping and implementation nowadays. Truly a fantastic language.
Re:Outperforming LAPACK with C++ metaprogramming by ufo on Monday January 29, 2018 @09:31AM (#16257673)
These kinds of tricks certainly are more pleasant to do in languages with real metaprogramming support.

For numerical applications, one interesting project that comes to mind is the Terra programming language. It uses a flexible high level language (Lua) to metaprogram a fast and predictable C-like language (Terra). The advantage compared to the examples you mentioned is that each language can focus on its strength: the low level language being similar to C allows the programmer to better reason about performance and having a high level language for metaprogramming keep things simple.

https://terralang.org

There are also systems out there specifically designed for numeric applications that let you specify an algorithm in a high level DSL and generate highly performing C code, some of which might even tesr various versions of the code to find one that runs better on your machine (for example, the best way to iterate the data might be affected by cache sizes). I don't remember the names of these off the top of my head but the Terra PhD thesis has lots of references to them.

Re:Outperforming LAPACK with C++ metaprogramming by ska on Monday January 29, 2018 @09:50AM (#16257776)
It was playing around with exactly these sorts of tricks in c++ (with late 90's compilers) that drove me to learn common lisp. It's a much nicer environment to do this sort of thing in, but difficult to compete head to head with a good optimizing c++ compiler on code generation in general. Fwiw, in common lisp particularly having access to to compiler macros allows for interesting approaches.

I was doing primarily research code at the time though, and the overall improvement in productivity more than made up for the fractional difference in run times for me. Of course, ymmv.

Re:Outperforming LAPACK with C++ metaprogramming by sidlls on Monday January 29, 2018 @11:37AM (#16258478)
Just be wary of performance gains claims. Per other comments this implementation is highly optimized for a specific use and uses a numerically unstable algorithm.
Re:Outperforming LAPACK with C++ metaprogramming by fithisux on Monday January 29, 2018 @08:40AM (#16257398)
Or even Dlang .