Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish hw4 #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

finish hw4 #44

wants to merge 1 commit into from

Conversation

gamdwk
Copy link

@gamdwk gamdwk commented Aug 21, 2024

初始数据
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 1758 ms

(other.mass * G * dt / d2) 把重复计算的部分括号起来,编译器会将其移动到循环外。这步减少了大量计算。也帮助矢量化
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 1273 ms

sqrt使用std,std里的函数优化更好
Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 1131 ms

添加优化指令-O3 -ffast-math -march=native,-ffast-math 选项让 GCC 更大胆地尝试浮点运算的优化,-O3提升优化等级。
-march=native指示编译器生成针对当前编译代码的机器上运行的CPU架构进行优化的代码
Initial energy: -13.413999
Final energy: -13.380254
Time elapsed: 359 ms
但是优化后精度出现了问题

修改成SOA。把所有的变量都变成数组的形式,当计算的时候就可以实现simd
Initial energy: -13.413999
Final energy: -13.356841
Time elapsed: 123 ms

其他的优化比如AOSOA,循环展开,除法变乘法, constexpr等等基本上都没什么提升。估计编译器本身就已经有优化了吧。
总共只提升了10倍左右。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant