9
$\begingroup$

As exemplified by Jed Brown's answer to Costs of lookups versus calculations, using vectorized vs non-vectorized floating point operations results in much faster code. Many modern compilers claim that they can perform automatic vectorization. How do I which parts of my code are being successfully vectorized?

$\endgroup$
10
$\begingroup$

With the Intel compiler of any modern vintage, -O3 -vec-report3. Optimization level three guarantees that it's trying to vectorize, and the vector report will tell you what it's doing.

The GNU page on vectorization says that it's on by default at optimization level 3, but I can't find the equivalent of vec-report.

$\endgroup$
  • $\begingroup$ Thanks for the quick response. I didn't know about -vec-report3. Do you have a compiler preference when it comes to this type of thing (automatic vectorization)? $\endgroup$ – Matthew Emmett Jun 13 '12 at 19:54
  • $\begingroup$ Intel compilers are really good, but only for intel chips. You just have to add all the right pragmas (#pragma ivdep is easiest) GCC 4.7 has gotten a lot better but looking over some code with a colleague it still has bugs (like no vectorization inside openmp pragmas). $\endgroup$ – aterrel Jun 13 '12 at 20:44
  • 1
    $\begingroup$ I would advise double checking how the Intel compiler does with vectorization on AMD chips. I'm not 100% sure that the problems of old still exist. $\endgroup$ – Bill Barth Jun 13 '12 at 22:18
  • 2
    $\begingroup$ @BillBarth Yes, still an issue. See the Optimization Notice (in many place, e.g. software.intel.com/sites/products/collateral/hpc/compilers/…). AMD won the court battle requiring Intel to disclose that they are anti-competitive, not to make them stop being. en.wikipedia.org/wiki/Intel_C%2B%2B_Compiler#Criticism Agner Fog on workarounds: agner.org/optimize/blog/read.php?i=49 $\endgroup$ – Jed Brown Jun 14 '12 at 13:28
  • $\begingroup$ @JedBrown, sure SSE is still weird, but what's the story with AVX? Those links indicate that things should be fine (since both companies implement AVX), but I haven't tested it on a Bulldozer machine. $\endgroup$ – Bill Barth Jun 14 '12 at 18:07
8
$\begingroup$

Within the GNU compiler collection, you have the option -ftree-vectorizer-verbose=n where n is a number between 0 and 6 which will print information similar to icc/ifort.

$\endgroup$
5
$\begingroup$

With GNU compilers, adding -Wa,-ahl=asm.s will dump the generated assembly code to asm.s.

With Intel compilers, adding -fcode-asm -Faasm.s will dump the generated code to asm.s.

You can then inspect the assembly code and look for vector float point operations.

$\endgroup$
  • $\begingroup$ I completely agree that inspecting assembly output is the only reliable way to determine if code is actually vectorized. There is nothing that requires compilers to be honest about their claims to vectorize code. $\endgroup$ – Jeff Apr 13 '13 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.