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 hw04 #19

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

finish hw04 #19

wants to merge 1 commit into from

Conversation

chaixuqing
Copy link

加速之前

Initial energy: -13.414000
Final energy: -13.356842
Time elapsed: 1373 ms

加速之后

Initial energy: -13.413999
Final energy: -13.403915
Time elapsed: 100 ms

  1. 将frand()函数声明为 static,有几毫秒的提升。
  2. 将Star结构体的内存布局改为SOA,同时设置内存对齐(基本没有提升)
  3. 将计算eps的平方放在循环外面,同时打上括号(G * dt)帮助编译器识别
  4. 将px, py, pz的值在循环之外赋值给局部变量,减少读取次数。将内部循环中关于vx, vy, vz的累加,先读到局部变量,累加完毕后再写入
  5. 给sqrt加 std:: 前缀,矢量化成功
  6. 对小循环体用 #pragma unroll
  7. 编译选项中加入-ffast-math -march=native

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