Created
March 18, 2015 17:47
-
-
Save kelindar/dbfbabb4b9069b5e6f74 to your computer and use it in GitHub Desktop.
Data Locality: Particle System
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Particle { | |
| float x; | |
| float y; | |
| float z; | |
| float w; | |
| float vx; | |
| float vy; | |
| float vz; | |
| float vw; | |
| } | |
| struct A | |
| { | |
| Particle *particles; | |
| int count; | |
| void update(float dt) | |
| { | |
| for (int i = 0; i<count; i++) | |
| { | |
| auto p = particles[i]; | |
| p.x += p.vx * dt; | |
| p.y += p.vy * dt; | |
| p.z += p.vz * dt; | |
| p.w += p.vw * dt; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Particle { | |
| float x; | |
| float y; | |
| float z; | |
| float w; | |
| float vx; | |
| float vy; | |
| float vz; | |
| float vw; | |
| } | |
| struct B | |
| { | |
| Particle *particles; | |
| int count; | |
| void update(float dt) | |
| { | |
| parallel_for(0, count, [&](int i) | |
| { | |
| auto p = particles[i]; | |
| p.x += p.vx * dt; | |
| p.y += p.vy * dt; | |
| p.z += p.vz * dt; | |
| p.w += p.vw * dt; | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment