Parallelizing
                           a Real-Time
                       Steering Simulation
                      for ...
Dienstag, 11. September 2007   2
Steering a flock of birds



Dienstag, 11. September 2007                2
Dienstag, 11. September 2007   3
Dienstag, 11. September 2007   3
Dienstag, 11. September 2007   3
Bird




Dienstag, 11. September 2007          3
Bird
                               Boid




Dienstag, 11. September 2007          3
Bird
                                Boid
                               Agent



Dienstag, 11. September 2007           3
Dienstag, 11. September 2007   4
CPU
                               core




Dienstag, 11. September 2007          4
Dienstag, 11. September 2007   4
CPU    CPU    CPU    CPU
                               core   core   core   core

                               CPU    C...
Dienstag, 11. September 2007   4
Outline




Dienstag, 11. September 2007             5
Outline
                    1. Steering behaviors




Dienstag, 11. September 2007                5
Outline
                    1. Steering behaviors
                    2. OpenSteerDemo




Dienstag, 11. September 2007   ...
Outline
                    1. Steering behaviors
                    2. OpenSteerDemo
                    3. Bad parallel...
Outline
                    1. Steering behaviors
                    2. OpenSteerDemo
                    3. Bad parallel...
Outline
                    1. Steering behaviors
                    2. OpenSteerDemo
                    3. Bad parallel...
Outline
                    1. Steering behaviors
                    2. OpenSteerDemo
                    3. Bad parallel...
Steering behaviors



Dienstag, 11. September 2007                        6
Dienstag, 11. September 2007   7
Dienstag, 11. September 2007   7
Dienstag, 11. September 2007   7
Dienstag, 11. September 2007   7
Alignment
Dienstag, 11. September 2007               8
OpenSteerDemo




Dienstag, 11. September 2007                   9
OpenSteerDemo
                               Testbed for the open source library
                               OpenSteer ...
OpenSteerDemo
                               Testbed for the open source library
                               OpenSteer ...
OpenSteerDemo
                               Testbed for the open source library
                               OpenSteer ...
OpenSteerDemo
                               Testbed for the open source library
                               OpenSteer ...
OpenSteerDemo
                               Testbed for the open source library
                               OpenSteer ...
Main loop




Dienstag, 11. September 2007               10
Main loop


                               Input   Update   Output




Dienstag, 11. September 2007                       ...
Main loop


                                                Graph-
                               Input   Update
         ...
Input stage


                                                     Graph-
                               Input     Update
...
Update stage


                                                     Graph-
                               Input     Update...
Graphics stage


                                                     Graph-
                               Input     Upda...
Next main loop cycle


                                                       Graph-
                               Input ...
Update stage


                                                Graph-
                               Input   Update
      ...
Agent update
                                        Update
                                         agent

              ...
Time step t
                In state t-1

                    Update     Update   Update         Update
                  ...
Time step t
                In state t-1

                    Update     Update   Update           Update
                ...
Time step t
                               In state t-1

                   Update       Update        Update         Upda...
Time step t
                    In state t            In state t-1

                    Update       Update    Update     ...
Time step t
                               In state t              In state t-1

                    Update     Update    ...
Time step t
                               In state t              In state t-1

                    Update     Update    ...
Bad parallelization



Dienstag, 11. September 2007                         22
Dienstag, 11. September 2007   23
Questionable reliability
                     and correctness


Dienstag, 11. September 2007                  23
No speedup




Dienstag, 11. September 2007                24
No speedup




Dienstag, 11. September 2007                24
Main
                 parallelization problems


Dienstag, 11. September 2007                25
Dienstag, 11. September 2007   26
Race conditions




Dienstag, 11. September 2007                     26
Race conditions

                                Global variables, deep inheritance
                                hierar...
Race conditions

                                Global variables, deep inheritance
                                hierar...
Race conditions

                                Global variables, deep inheritance
                                hierar...
Race conditions

                                Global variables, deep inheritance
                                hierar...
Parallelization
                                that works


Dienstag, 11. September 2007                     27
Guiding ideas




Dienstag, 11. September 2007                   28
Guiding ideas
                               Update order independent simulation




Dienstag, 11. September 2007         ...
Guiding ideas
                               Update order independent simulation
                               Agent modi...
Guiding ideas
                               Update order independent simulation
                               Agent modi...
Guiding ideas
                               Update order independent simulation
                               Agent modi...
Guiding ideas
                               Update order independent simulation
                               Agent modi...
Refactorization



Dienstag, 11. September 2007                     29
Split agent update
                                     Agent update


                                   Sim.      Modify...
Simulate agent stage
                               read + write    Sim.
                                               ag...
Simulate agent stage
                               read + write    Sim.
                                               ag...
Modify agent stage
                               read   Modify
                                      agent
              ...
Modify neighbor data
                             structure
                                                     Modify
  ...
Refactor update stage


                               Input   Update   Output




Dienstag, 11. September 2007           ...
Split update stage

                                           Update stage



                                         Si...
Old update stage

               Update agent              Update agent           Update agent

            Sim.          ...
Time step t

                                         Agents in state t-1

           Sim.                Modify      Sim....
Time step t

                    Agent in state t                        Agents in state t-1

            Sim.            ...
New update stage

                   Simulation sub-stage                  Modification sub-stage

        Sim.           ...
Time step t

               Agents in public state t-1

        Sim.                   Sim.          Sim.    Modify   Modi...
Time step t

                Agents in public state t-1

         Sim.                  Sim.          Sim.    Modify   Mod...
Time step t

                Agents in public state t-1

         Sim.                  Sim.          Sim.    Modify   Mod...
Time step t

                Agents in public state t-1

         Sim.                  Sim.          Sim.    Modify   Mod...
Parallelization



Dienstag, 11. September 2007                     43
Parallel update stage
                               Simulation                                  Modification
            ...
Parallel simulation
                                       sub-stage
                               Simulation            ...
Parallel modification
                                 sub-stage
                               Simulation           Modifi...
Parallel modification
                                 sub-stage
                               Simulation       Modificati...
Performance




Dienstag, 11. September 2007                 48
Test-computer
                           Dual-processor dual-
                           core 2 GHz AMD
                  ...
Max speedups




Dienstag, 11. September 2007                  50
Max speedups
                               Comparison of OpenSteerDemo flock of
                               birds simul...
Max speedups
                               Comparison of OpenSteerDemo flock of
                               birds simul...
Max speedups
                               Comparison of OpenSteerDemo flock of
                               birds simul...
Summary



Dienstag, 11. September 2007             51
Dienstag, 11. September 2007   52
Refactored first




Dienstag, 11. September 2007                     52
Refactored first

                               Simplicity!




Dienstag, 11. September 2007                     52
Refactored first

                               Simplicity!

                               High-level design to min. sync...
Refactored first

                               Simplicity!

                               High-level design to min. sync...
Refactored first

                               Simplicity!

                               High-level design to min. sync...
Refactored first

                               Simplicity!

                               High-level design to min. sync...
Thank you!



Dienstag, 11. September 2007                53
Upcoming SlideShare
Loading in …5
×

Parallelizing a Real-Time Steering Simulation for Computer Games with OpenMP by Bjoern Knafla and Claudia Leopold (now Fohry)

1,384 views

Published on

Slides from my presentation of a paper with the same title at ParCo 2007 - http://www.fz-juelich.de/nic-series/volume38/knafla.pdf .

Future computer games need parallel programming to meet their ever growing hunger for per- formance. We report on our experiences in parallelizing the game-like C++ application Open- SteerDemo with OpenMP. To enable deterministic data-parallel processing of real-time agent steering behaviour, we had to change the high-level design, and refactor interfaces for explicit shared resource access. Our experience is summarized in a set of guidelines to help parallelizing legacy game code.

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,384
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
14
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Parallelizing a Real-Time Steering Simulation for Computer Games with OpenMP by Bjoern Knafla and Claudia Leopold (now Fohry)

  1. 1. Parallelizing a Real-Time Steering Simulation for Computer Games with OpenMP Bjoern Knafla and Claudia Leopold University of Kassel (Germany) Dienstag, 11. September 2007 1
  2. 2. Dienstag, 11. September 2007 2
  3. 3. Steering a flock of birds Dienstag, 11. September 2007 2
  4. 4. Dienstag, 11. September 2007 3
  5. 5. Dienstag, 11. September 2007 3
  6. 6. Dienstag, 11. September 2007 3
  7. 7. Bird Dienstag, 11. September 2007 3
  8. 8. Bird Boid Dienstag, 11. September 2007 3
  9. 9. Bird Boid Agent Dienstag, 11. September 2007 3
  10. 10. Dienstag, 11. September 2007 4
  11. 11. CPU core Dienstag, 11. September 2007 4
  12. 12. Dienstag, 11. September 2007 4
  13. 13. CPU CPU CPU CPU core core core core CPU CPU CPU CPU core core core core CPU CPU CPU CPU core core core core CPU CPU CPU CPU core core core core Dienstag, 11. September 2007 4
  14. 14. Dienstag, 11. September 2007 4
  15. 15. Outline Dienstag, 11. September 2007 5
  16. 16. Outline 1. Steering behaviors Dienstag, 11. September 2007 5
  17. 17. Outline 1. Steering behaviors 2. OpenSteerDemo Dienstag, 11. September 2007 5
  18. 18. Outline 1. Steering behaviors 2. OpenSteerDemo 3. Bad parallelization Dienstag, 11. September 2007 5
  19. 19. Outline 1. Steering behaviors 2. OpenSteerDemo 3. Bad parallelization 4. Parallelization that works Dienstag, 11. September 2007 5
  20. 20. Outline 1. Steering behaviors 2. OpenSteerDemo 3. Bad parallelization 4. Parallelization that works 5. Performance Dienstag, 11. September 2007 5
  21. 21. Outline 1. Steering behaviors 2. OpenSteerDemo 3. Bad parallelization 4. Parallelization that works 5. Performance 6. Summary Dienstag, 11. September 2007 5
  22. 22. Steering behaviors Dienstag, 11. September 2007 6
  23. 23. Dienstag, 11. September 2007 7
  24. 24. Dienstag, 11. September 2007 7
  25. 25. Dienstag, 11. September 2007 7
  26. 26. Dienstag, 11. September 2007 7
  27. 27. Alignment Dienstag, 11. September 2007 8
  28. 28. OpenSteerDemo Dienstag, 11. September 2007 9
  29. 29. OpenSteerDemo Testbed for the open source library OpenSteer from Craig W. Reynods Dienstag, 11. September 2007 9
  30. 30. OpenSteerDemo Testbed for the open source library OpenSteer from Craig W. Reynods Simulates steering behavior of agents Dienstag, 11. September 2007 9
  31. 31. OpenSteerDemo Testbed for the open source library OpenSteer from Craig W. Reynods Simulates steering behavior of agents Game-like C++ real-time application Dienstag, 11. September 2007 9
  32. 32. OpenSteerDemo Testbed for the open source library OpenSteer from Craig W. Reynods Simulates steering behavior of agents Game-like C++ real-time application OpenGL Dienstag, 11. September 2007 9
  33. 33. OpenSteerDemo Testbed for the open source library OpenSteer from Craig W. Reynods Simulates steering behavior of agents Game-like C++ real-time application OpenGL http://opensteer.sourceforge.net Dienstag, 11. September 2007 9
  34. 34. Main loop Dienstag, 11. September 2007 10
  35. 35. Main loop Input Update Output Dienstag, 11. September 2007 10
  36. 36. Main loop Graph- Input Update ics Dienstag, 11. September 2007 11
  37. 37. Input stage Graph- Input Update ics Time step t Dienstag, 11. September 2007 12
  38. 38. Update stage Graph- Input Update ics Time step t Dienstag, 11. September 2007 13
  39. 39. Graphics stage Graph- Input Update ics Time step t Dienstag, 11. September 2007 14
  40. 40. Next main loop cycle Graph- Input Update ics Time step t+1 Dienstag, 11. September 2007 15
  41. 41. Update stage Graph- Input Update ics Dienstag, 11. September 2007 16
  42. 42. Agent update Update agent read + write read + write read + write write Agent Neighbors Random. Graphics state references Dienstag, 11. September 2007 17
  43. 43. Time step t In state t-1 Update Update Update Update agent agent agent ... agent 0 1 2 n Sequential agent update order Dienstag, 11. September 2007 18
  44. 44. Time step t In state t-1 Update Update Update Update agent agent agent ... agent 0 1 2 n Sequential Neighbors agent update order In state t-1 Dienstag, 11. September 2007 18
  45. 45. Time step t In state t-1 Update Update Update Update agent agent agent ... agent 0 1 2 n Sequential agent update order Dienstag, 11. September 2007 19
  46. 46. Time step t In state t In state t-1 Update Update Update Update agent agent agent ... agent 0 1 2 n Sequential agent update order Dienstag, 11. September 2007 20
  47. 47. Time step t In state t In state t-1 Update Update Update Update agent agent agent ... agent 0 1 2 n Sequential agent update order Dienstag, 11. September 2007 21
  48. 48. Time step t In state t In state t-1 Update Update Update Update agent agent agent ... agent 0 1 2 n Sequential Neighbors agent update order In state ? Dienstag, 11. September 2007 21
  49. 49. Bad parallelization Dienstag, 11. September 2007 22
  50. 50. Dienstag, 11. September 2007 23
  51. 51. Questionable reliability and correctness Dienstag, 11. September 2007 23
  52. 52. No speedup Dienstag, 11. September 2007 24
  53. 53. No speedup Dienstag, 11. September 2007 24
  54. 54. Main parallelization problems Dienstag, 11. September 2007 25
  55. 55. Dienstag, 11. September 2007 26
  56. 56. Race conditions Dienstag, 11. September 2007 26
  57. 57. Race conditions Global variables, deep inheritance hierarchies, strongly interdependent classes Dienstag, 11. September 2007 26
  58. 58. Race conditions Global variables, deep inheritance hierarchies, strongly interdependent classes Non-determinism Dienstag, 11. September 2007 26
  59. 59. Race conditions Global variables, deep inheritance hierarchies, strongly interdependent classes Non-determinism Order of agent updates and random numbers Dienstag, 11. September 2007 26
  60. 60. Race conditions Global variables, deep inheritance hierarchies, strongly interdependent classes Non-determinism Order of agent updates and random numbers Non-thread-safe functions Dienstag, 11. September 2007 26
  61. 61. Parallelization that works Dienstag, 11. September 2007 27
  62. 62. Guiding ideas Dienstag, 11. September 2007 28
  63. 63. Guiding ideas Update order independent simulation Dienstag, 11. September 2007 28
  64. 64. Guiding ideas Update order independent simulation Agent modification only dependent on its steering vector Dienstag, 11. September 2007 28
  65. 65. Guiding ideas Update order independent simulation Agent modification only dependent on its steering vector Minimize synchronization Dienstag, 11. September 2007 28
  66. 66. Guiding ideas Update order independent simulation Agent modification only dependent on its steering vector Minimize synchronization Finish parallel processing before graphics stage Dienstag, 11. September 2007 28
  67. 67. Guiding ideas Update order independent simulation Agent modification only dependent on its steering vector Minimize synchronization Finish parallel processing before graphics stage Interfaces for explicit context Dienstag, 11. September 2007 28
  68. 68. Refactorization Dienstag, 11. September 2007 29
  69. 69. Split agent update Agent update Sim. Modify agent agent Agent update order Dienstag, 11. September 2007 30
  70. 70. Simulate agent stage read + write Sim. agent Steering Vector read read write Agent Render- Random. Neighbors state Feeder Agent Agent public state references Agent private Dienstag, 11. September 2007 31
  71. 71. Simulate agent stage read + write Sim. agent Steering Vector read on st read on st write c c Agent Render- Random. Neighbors state Feeder Agent Agent public state references Agent private Dienstag, 11. September 2007 31
  72. 72. Modify agent stage read Modify agent Steering Vector read + write Agent Render- Random. Neighbors state Feeder Agent Agent public state references Agent private Dienstag, 11. September 2007 32
  73. 73. Modify neighbor data structure Modify neigh- bors Steering Vector read write Agent Render- Random. Neighbors state Feeder Agent Agent public state references Agent private Dienstag, 11. September 2007 33
  74. 74. Refactor update stage Input Update Output Dienstag, 11. September 2007 34
  75. 75. Split update stage Update stage Sim. Modify Sub-stages: simulation and modification Dienstag, 11. September 2007 35
  76. 76. Old update stage Update agent Update agent Update agent Sim. Modify Sim. Modify Sim. Modify agent agent agent agent ... agent agent 0 0 1 1 n n Sequential processing order Dienstag, 11. September 2007 36
  77. 77. Time step t Agents in state t-1 Sim. Modify Sim. Modify Sim. Modify agent agent agent agent ... agent agent 0 0 1 1 n n Sequential processing order Dienstag, 11. September 2007 37
  78. 78. Time step t Agent in state t Agents in state t-1 Sim. Modify Sim. Modify Sim. Modify agent agent agent agent ... agent agent 0 0 1 1 n n Sequential processing order Dienstag, 11. September 2007 38
  79. 79. New update stage Simulation sub-stage Modification sub-stage Sim. Sim. Sim. Modify Modify Modify agent agent ... agent agent agent ... agent 0 1 n 0 1 n Sequential processing order Dienstag, 11. September 2007 39
  80. 80. Time step t Agents in public state t-1 Sim. Sim. Sim. Modify Modify Modify agent agent ... agent agent agent ... agent 0 1 n 0 1 n Sequential processing order Dienstag, 11. September 2007 40
  81. 81. Time step t Agents in public state t-1 Sim. Sim. Sim. Modify Modify Modify agent agent ... agent agent agent ... agent 0 1 n 0 1 n Sequential processing order Dienstag, 11. September 2007 41
  82. 82. Time step t Agents in public state t-1 Sim. Sim. Sim. Modify Modify Modify agent agent ... agent agent agent ... agent 0 1 n 0 1 n Sequential processing order Dienstag, 11. September 2007 42
  83. 83. Time step t Agents in public state t-1 Sim. Sim. Sim. Modify Modify Modify agent agent ... agent agent agent ... agent 0 1 n 0 1 n Sequential Each agent is modified processing based solely on its own order state Dienstag, 11. September 2007 42
  84. 84. Parallelization Dienstag, 11. September 2007 43
  85. 85. Parallel update stage Simulation Modification S S M M M P P B B a S S a M M M a a r r r r Update a S S S a M M M r r neigh- l l i i bors l S S l M M M e e e e Possibly r r l S S S l M M M parallel Dienstag, 11. September 2007 44
  86. 86. Parallel simulation sub-stage Simulation Modification S S P P B B a S S a a a r r r r Update a S S S a r r neigh- l l i i bors l S S l e e e e Possibly r r l S S S l parallel Dienstag, 11. September 2007 45
  87. 87. Parallel modification sub-stage Simulation Modification M M M P P B B a a M M M a a r r r r Update a a M M M r r neigh- l l i i bors l l M M M e e e e Possibly r r l l M M M parallel Dienstag, 11. September 2007 46
  88. 88. Parallel modification sub-stage Simulation Modification P P B B a a a a r r r r Update a a r r neigh- l l i i bors l l e e e e Possibly r r l l parallel Dienstag, 11. September 2007 47
  89. 89. Performance Dienstag, 11. September 2007 48
  90. 90. Test-computer Dual-processor dual- core 2 GHz AMD Opteron with 2 GB Ram 2x Nvidia 7800 GTX graphics cards in SLI mode Linux OS Dienstag, 11. September 2007 49
  91. 91. Max speedups Dienstag, 11. September 2007 50
  92. 92. Max speedups Comparison of OpenSteerDemo flock of birds simulation with 4 threads with OpenMP-disabled version Dienstag, 11. September 2007 50
  93. 93. Max speedups Comparison of OpenSteerDemo flock of birds simulation with 4 threads with OpenMP-disabled version Whole application: ! 2.84 Dienstag, 11. September 2007 50
  94. 94. Max speedups Comparison of OpenSteerDemo flock of birds simulation with 4 threads with OpenMP-disabled version Whole application: ! 2.84 Update stage: !! ! 3.54 Dienstag, 11. September 2007 50
  95. 95. Summary Dienstag, 11. September 2007 51
  96. 96. Dienstag, 11. September 2007 52
  97. 97. Refactored first Dienstag, 11. September 2007 52
  98. 98. Refactored first Simplicity! Dienstag, 11. September 2007 52
  99. 99. Refactored first Simplicity! High-level design to min. synchronization Dienstag, 11. September 2007 52
  100. 100. Refactored first Simplicity! High-level design to min. synchronization Explicit context Dienstag, 11. September 2007 52
  101. 101. Refactored first Simplicity! High-level design to min. synchronization Explicit context Deferred computation Dienstag, 11. September 2007 52
  102. 102. Refactored first Simplicity! High-level design to min. synchronization Explicit context Deferred computation Identified slices for data-parallel computation Dienstag, 11. September 2007 52
  103. 103. Thank you! Dienstag, 11. September 2007 53

×