简体   繁体   English

使用O3优化级别编译GSL

[英]Compile GSL with O3 optimization level

My program heavily depends on the special functions from GSL and thus I would like to make it run faster, so I wish to compile GSL with higher optimization levels. 我的程序在很大程度上取决于GSL的特殊功能,因此我想使其运行更快,因此我希望以更高的优化级别来编译GSL。

When I compile gsl, the default CFLAGS is "-g -O2" if I do nothing when I configure with "./configure". 编译gsl时,如果在使用“ ./configure”配置时不执行任何操作,则默认CFLAGS为“ -g -O2”。 I am wondering why gsl is defaulting to an optimization level of O2 only since O3 is compliant to standards. 我想知道为什么仅因为O3符合标准,gsl才默认设置为O2的优化级别。 I tried to compile and test with "./configure CFLAGS='-g -O3'", things worked. 我尝试使用“ ./configure CFLAGS ='-g -O3'”进行编译和测试,结果正常。 But I'm still not sure if everything would work. 但是我仍然不确定一切是否正常。

Can anyone tell me why GSL is defaulting to O2 instead of O3? 谁能告诉我为什么GSL默认使用O2而不是O3? Would it be dangerous if I default to O3? 如果我默认使用O3会很危险吗? Thanks! 谢谢!

The optimization level 3 is something that should only be used in case it is absolutely sure that it helps the library. 优化级别3是仅在绝对确定对库有帮助的情况下才应使用。

Since that level activates optimizations that may increase the size of the code a lot. 由于该级别激活了优化,可能会大大增加代码的大小。 This means in some cases it creates binaries that are even slower compared to a binary optimized with -O2 . 这意味着在某些情况下,它创建的二进制文件比用-O2优化的二进制文件还要慢。 How ever that happens rarely. 这种情况很少发生。 More likely are effects like a massively increased time to compile it, along with a increased binary size and a barely measurable performance change. 更有可能出现这样的影响,例如编译时间大大增加,二进制文件大小增加并且性能变化几乎无法测量。

That -O3 actually breaks something was pretty common some time back, but in the last couple of years I did not have a single case where -O3 actually optimized something that caused the binary to break. -O3实际上破坏了某些东西在-O3是很普遍的,但是在过去的几年中,我没有遇到过-O3实际上优化了导致二进制破坏的东西的情况。

In the end the optimization level is something you can just test. 最后,您可以测试优化级别。 Since -O2 is the default, it is a pretty safe bet that this is the best settings for the compile operation in this case. 由于-O2是默认设置,因此可以肯定地说,在这种情况下,这是编译操作的最佳设置。 If you feel like it you could try to compile it with a different setting to see if it makes any performance difference. 如果您愿意,可以尝试使用其他设置进行编译,以查看其性能是否有所不同。

Interesting options are -O3 and even -Os . 有趣的选项是-O3甚至-Os I had cases in the past were both options gave improved performance over -O2 . 过去我曾遇到过两种选择都比-O2改善了性能的情况。

So the real answer is: Try it and see what happens. 因此,真正的答案是: 试试看,看看会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM