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

Hw04/simd #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Hw04/simd #22

wants to merge 2 commits into from

Conversation

Tigerrr07
Copy link

原始版本
Initial energy: -13.41400
Final energy: -13.356842
Time eplased: 1812 ms

SIMD加速版本
Initial energy: -13.414012
Final energy: -13.403986
Time elapsed: 195 ms

  • AOS 转换为 SOA 分离存储多个属性便于SIMD优化
  • 数学优化
    • 除法变乘法:让1.f / RAND_MAX * 2编译期求值,这样使得frand()内部的1次除法和1次乘法变成1次乘法
    • 提前计算公共乘法:让G * dteps * epsG / 2在编译期求值,减少乘法次数
  • 设置局部变量减少不必要的内存访问:step()calc()的内部循环要使用外部循环中的值,在外部循环设置变量保存需要用的值,减少访存
  • 使用局部变量便于SIMD优化,且让结果更加精确以及能让公共乘数放到外部循环
    • step()函数中stars.vx[i],stars.vy[i],stars.vz[i]的累加都使用局部变量替代,内部循环结束后再乘以公共乘数再累加,减少内部循环的乘法次数
    • calc()函数中内部循环也是先用局部变量累加,结束后再乘以公共乘数,随后累加到energy

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