向量化 C++提高STL性能的代码
我正在使用 C++/Linux/GCC/Windows XP/Intel 编译器构建的应用程序中对几个大型 STL 向量容器中包含的值进行计算
是否值得通过更改对齐属性或使用 Intel 库函数等来研究向量化的优化机会 -或者编译器会自动处理?
I am doing calculations on values contained in several large STL vector containers in an application built using C++/ Linux/ GCC / Windows XP/ Intel compiler
Is it worthwile investigating optimization opprtunity with vectorization by changing aligment attributes or using intel library functions, etc. - or the comipler automatically takes care?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,编译器会使用适当的设置来处理它,因此您必须进行一些调整。
也就是说,如果您针对特定硬件,最好确保编译器确实利用了此类系统。例如,众所周知,英特尔编译器是其处理器的出色优化器。
现在,有时手动矢量化也很好。事实上,它就像任何优化一样:首先使用有效的算法实现一个简单的可读版本。然后使用分析器优化代码。分析器会让您知道应该在哪里集中精力。
如果您知道您将拥有一个特定的函数处理成员,并且具有为此类函数生成的代码(来自编译器)的经验,您可能会从一开始就开始应用一些优化,但请确保您已经知道会发生什么被生成。
Normally, the compiler will take care of it with the appropriate settings, so you'll have to tweak a bit.
That said, if you target a specific hardware, you'd better make sure the compiler does take advantage of such system. For example Intel compiler is known to be an excellent optimizer for their processors.
Now, sometimes it's also good to manually vectorize. In fact it's like any optimization : first implement a simple readable version with an efficient algorithm. Then optimize the code using a profiler. The profiler will let you know where to concentrate your efforts.
If you know you'll have one particular function crunching members, and have experience with the generated code (from the compiler) for this kind of function, you might start to apply some optimization from the very start but make sure you already know what will be generated.