Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
原始版本
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
1.f / RAND_MAX * 2
编译期求值,这样使得frand()
内部的1次除法和1次乘法变成1次乘法G * dt
、eps * eps
、G / 2
在编译期求值,减少乘法次数step()
和calc()
的内部循环要使用外部循环中的值,在外部循环设置变量保存需要用的值,减少访存step()
函数中stars.vx[i],stars.vy[i],stars.vz[i]
的累加都使用局部变量替代,内部循环结束后再乘以公共乘数再累加,减少内部循环的乘法次数calc()
函数中内部循环也是先用局部变量累加,结束后再乘以公共乘数,随后累加到energy
中