Live data from Hacker News

Outperforming LAPACK with C++ metaprogramming

wordsandbuttons.online

21–30 of 82 posts

Re: Outperforming LAPACK with C++ metaprogramming

#21
post #19
post #16

D's Mir does the same sort of thing, and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++. http://docs.mir.dlang.io/latest/index.html http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/...

> instead of the bug elevated to feature that metaprogramming is in C++. That inflammatory wording doesn’t add anything to your comment. If you wanted to compare D with C++ it’d be a lot more useful to link to something which does that rather than just the documentation index.

C++ metaprogramming was an accident. Expression templates are a huge, obscure, and very surprising hack. I don't know about you, but I find them really hard to understand. SFINAE wasn't meant to be used for compile-time branching, but when people realised that it could be used that way, it was just about the only tool for metaprogramming in C++. It certainly wasn't designed for that purpose, though.

C++ has for a long time embraced metaprogramming and given new tools for it (I think there's `static if` now? Or will be soon?), but it really all started out as an accident:

https://softwareengineering.stackexchange.com/questions/1253...

> If you wanted to compare D with C++

My second link does that, compares Mir to a bunch of other numeric libraries, most in C++.

Edit: (Replying to comment below by acdha because HN does not allow me to post new comments right now.)

I don't have that kind of example handy. I can point you to the D Gems section of the D tour to give you a taste of what is possible in D. Click on "Gems" in the navigation menu above to see them.

https://tour.dlang.org/tour/en/gems/uniform-function-call-sy...

If you want a detailed blog post comparing D and C++ metaprogramming, I don't have it ready yet. If you're curious to learn about it, look in more depth at the links I've provided. I'm sorry I don't have the resources to give you the detailed answer you require.

Re: Outperforming LAPACK with C++ metaprogramming

#23
post #19
post #16

D's Mir does the same sort of thing, and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++. http://docs.mir.dlang.io/latest/index.html http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/...

> instead of the bug elevated to feature that metaprogramming is in C++. That inflammatory wording doesn’t add anything to your comment. If you wanted to compare D with C++ it’d be a lot more useful to link to something which does that rather than just the documentation index.

c++ is a hack

Re: Outperforming LAPACK with C++ metaprogramming

#24
post #7

Earlier quoted context omitted.

As an anecdote of just how powerful this can be, I once wrote a prototype of a simulation (written in C) that used a lot of integer divisions and needed to be run many times with different parameters. As a quick and dirty hack that took about half hour to implement, I decided to just have the program as a template string and the parameters be substituted in by a python script that called GCC. To the amazement of a ve…

What made you choose a python script rather than C++ templates or the C preprocessor?

It was a hack. I knew the C compiler could do these optimizations at compile-time that would take me longer to implement at run-time and would probably introduce mistakes. I could well have used the C-processor, but the parameters needed to be taken from a file for each program.

The simulation was run about 100 times with different parameters. Instead of taking about an hour each they instead took about 12 minutes each, with the only difference being baking in all the parameters as constants and letting GCC do the rest.

Re: Outperforming LAPACK with C++ metaprogramming

#25
post #19
post #16

D's Mir does the same sort of thing, and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++. http://docs.mir.dlang.io/latest/index.html http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/...

> instead of the bug elevated to feature that metaprogramming is in C++. That inflammatory wording doesn’t add anything to your comment. If you wanted to compare D with C++ it’d be a lot more useful to link to something which does that rather than just the documentation index.

I know that SFINAE exploited the preprocessor's template overload resolution rules. It was later standardized and expanded on.

https://books.google.com/books?id=i7M1DwAAQBAJ&pg=PT564

Re: Outperforming LAPACK with C++ metaprogramming

#26
post #16

D's Mir does the same sort of thing, and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++. http://docs.mir.dlang.io/latest/index.html http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/...

>and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++

Yet neither of them are as elegant as LISP macros.

Re: Outperforming LAPACK with C++ metaprogramming

#27
post #19

Earlier quoted context omitted.

> instead of the bug elevated to feature that metaprogramming is in C++. That inflammatory wording doesn’t add anything to your comment. If you wanted to compare D with C++ it’d be a lot more useful to link to something which does that rather than just the documentation index.

I know that SFINAE exploited the preprocessor's template overload resolution rules. It was later standardized and expanded on. https://books.google.com/books?id=i7M1DwAAQBAJ&pg=PT564

there is no preprocessor template overloading, or overloading at all really. The preprocessor has nothing to do with templates.

Re: Outperforming LAPACK with C++ metaprogramming

#28
post #18

Earlier quoted context omitted.

What made you choose a python script rather than C++ templates or the C preprocessor?

The way I read GP, the python script can very well do the equivalent of gcc -DPARAM=42 -o binary-param=42 && ./binary-param-42. edit: oh nm, reread GP...

Pretty much, except with more parameters taken from a file. The substituting in of parameters was done in Python just so that I could manually check the output for a few cases.

I think if I had to do something similar again today, any script would output a shell script that used command line macro definitions. That didn't really occur to me at the time.

Re: Outperforming LAPACK with C++ metaprogramming

#29

In his first factorial example, he could've avoided templates altogether with constexpr: https://godbolt.org/g/ZaoMNa Or just use a template specialisation: https://godbolt.org/g/TVkHMd

Thanks for sharing the godbolt site, can see myself using it for debugging.

Re: Outperforming LAPACK with C++ metaprogramming

#30
post #26
post #16

D's Mir does the same sort of thing, and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++. http://docs.mir.dlang.io/latest/index.html http://blog.mir.dlang.io/glas/benchmark/openblas/2016/09/23/...

>and metaprogramming in D is much nicer, because it was designed from the ground up instead of the bug elevated to feature that metaprogramming is in C++ Yet neither of them are as elegant as LISP macros.

[deleted]
Post reply on HN