Comparing G++ and Intel Compilers and Vectorized Code 225
Nerval's Lobster writes "A compiler can take your C++ loops and create vectorized assembly code for you. It's obviously important that you RTFM and fully understand compiler options (especially since the defaults may not be what you want or think you're getting), but even then, do you trust that the compiler is generating the best code for you? Developer and editor Jeff Cogswell compares the g++ and Intel compilers when it comes to generating vectorized code, building off a previous test that examined the g++ compiler's vectorization abilities, and comes to some definite conclusions. 'The g++ compiler did well up against the Intel compiler,' he wrote. 'I was troubled by how different the generated assembly code was between the 4.7 and 4.8.1 compilers—not just with the vectorization but throughout the code.' Do you agree?"
Documentation is King (Score:3, Interesting)
For better or worse, I've always given the intel compiler the benefit of the doubt. They have access to documents that the GCC folks don't.
Very different code (Score:4, Interesting)
I have worked on a couple of projects that compiled and ran perfectly with GCC 4.6 and 4.7. They no longer run when compiled with the latest versions of GCC. No warnings, no errors during compilation, they simply crash when run. It's the same source code, so something has changed. The same code, when compiled with multiple versions of Clang, runs perfectly. The GCC developers are doing something different and it is causing problems. Now it may be that a very well hidden bug is lurking in the code and the latest GCC is exposing that in some way, but this code worked perfectly for years under older versions of the compiler so it's been a nasty surprise.
Vectorized factorials! (Score:4, Interesting)
One amusing thing I discovered is that GCC 4.8.0 will actually unroll and vectorize this simple factorial function: [spatula-city.org] Just look at that output! [spatula-city.org]
Why is this still a topic? (Score:4, Interesting)
This is 2013 (almost 2014!) why are we talking about vectorization? Why don't people write code in vector notation in the first place anyway? If Matlab and Fortran could implement this 25 years ago, I am sure we are ready to move on now...
Re:Documentation is King (Score:5, Interesting)
Yep, they have access to some cool documents. It took a lot of work to document the fact that the intel compiler was actually crippling code if it was run on AMD processors. I mean, some suspicious, somewhat paranoid people suspected that intel was crippling code on AMD processors, but it took a good deal of work to actually demonstrate it.
That is just one of the many reasons I don't use Intel.
Re:Not sure why it's troubling. (Score:4, Interesting)
Explicit vectorization is indeed much more reliable than automatic vectorization, and it will always deliver better performance.
Interestingly, there seems to be quite a few abstraction layer libraries for SIMD. There are also at least Boost.SIMD (part of NT2 [1]) and Vc [2].
Several array-handling libraries (NT2 [1], Eigen [3]) also a leverage SIMD explicitly.
Alternatively there are plenty of languages based on C with explicit SIMD programming, like the Intel SPMD Compiler [4].
If you're interested in SIMD, there is also apparently a workshop being held soon on this subject in Orlando [5].
[1] https://github.com/MetaScale/nt2 [github.com]
[2] http://code.compeng.uni-frankfurt.de/projects/vc/ [uni-frankfurt.de]
[3] http://eigen.tuxfamily.org/index.php?title=Main_Page [tuxfamily.org]
[4] http://ispc.github.io/ [github.io]
[5] https://sites.google.com/site/wpmvp2014/ [google.com]