我的工作主要是高性能的"科学"计算.我已经做了大约15年了,但直到最近才意识到我的软件浪费了计算时间.简而言之:我编写高效C++代码的方式不再适用.
我不时会看到一段由一些孩子编写的代码,它与我的计算基本相同(相同的算法,类似的方法),但是 - 神奇地! - 表现得更快.在大多数情况下,我甚至无法追踪差异的起源!
我的问题是:我如何学习现代C++代码优化的艺术?也许在SSE,缓存/内存对齐问题上有什么问题?欢迎任何书籍,PDF,文章,练习或网站的建议!
PS.我很清楚这些技巧:
这些不是我要问的.
我希望以下片段解释一切:
struct TBase {
virtual void f() {}
};
struct TDerived : public TBase {
TDerived() {
/* These are all fine either under GCC 4.4.3, ICC 12 and Comeau online: */
f();
this->f();
TBase::f();
this->TBase::f();
/* This one fails under Comeau: */
TBase::TBase();
/* While this one fails in every case: */
//this->TBase::TBase();
/* e.g. GCC says:
test.cpp: In constructor ‘TDerived::TDerived()’:
test.cpp:17: error: invalid use of ‘struct TBase’ */
}
void f() {}
};
Run Code Online (Sandbox Code Playgroud)
问题是:为什么?(即为什么是TBase::TBase()错的,根据Comeau C++?为什么this->TBase::TBase() …