I am wondering how one should compare a vectorized code to its non-vectorized version? For example, I have a simple fortran code and I compile it with -O2
to enable auto vectorization. Afterwards, I can see from the optimization report, that the loop was vectorized. Now, if I want to compare this vectorized code with its non-vectorized version, should I compile the same code with -O2 -no-vec
or -O1
or even -O0
? Well, based on my experience, both -O2 -no-vec
and -O1
give no significant differences, although the former is always slightly better. However, if I compare -O2
and -O0
, the results differ significantly which are more than the number of vector widths; therefore, I am sure one should not compare these for emphasizing the benefits of vectorization. So, I would like only to know should I compare -O2
with -O2 -no-vec
or -O1
since I read many journals which never explained this matter in detail but only stated for example "... compared to its non-vectorized version, the vectorized code achieves ..."
Asked
Active
Viewed 168 times
1

bestrong
- 151
- 10
-
1It rather depends on why you want to compare it. For the case of "... compared to its non-vectorized version, the vectorized code achieves ...", you probably want as little difference outside vectorization – Caleth Dec 05 '18 at 11:32
-
@HighPerformanceMark: Thanks anyway :) – bestrong Dec 05 '18 at 11:46
-
@Caleth: I just want to emphasize the benefit of vectorization. For example, if I'm using single-precision arithmetic and run my code on an AVX machine (with a vector length of 8 for single-precision) so that max. theoretical speedup is 8x. For this reason, can I compare '-O2' with '-O2 -no-vec'? Thanks. – bestrong Dec 05 '18 at 11:46
-
@MatthieuBrucher: I see. So, the answer is: I shouldn't go for lower optimization and I should only set '-no-vec' for emphasizing the effect of vectorization for each optimization flag, right? – bestrong Dec 05 '18 at 11:49
-
@MatthieuBrucher: Yes, please do it. I will vote it :) – bestrong Dec 05 '18 at 11:52
1 Answers
2
Compiler optimization level encompass lots of individual optimizations, not just vectorization. It can be the math model, loop unrolling...
The results will be different for all of these, so yes deactivate your compiler (unspecified...) vectorization routines to see the differences made by just the vectorization.
You shouldn't go for lower optimization because of these other optimizations that are done that could add numerical differences on their own.

Matthieu Brucher
- 21,634
- 7
- 38
- 62