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.
Parallelizing a Real-Time Steering Simulation for Computer Games with OpenMP by Bjoern Knafla and Claudia Leopold (now Fohry)
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
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
29. OpenSteerDemo
Testbed for the open source library
OpenSteer from Craig W. Reynods
Dienstag, 11. September 2007 9
30. OpenSteerDemo
Testbed for the open source library
OpenSteer from Craig W. Reynods
Simulates steering behavior of agents
Dienstag, 11. September 2007 9
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. 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. 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
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. 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. 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. 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. 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. 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
57. Race conditions
Global variables, deep inheritance
hierarchies, strongly interdependent
classes
Dienstag, 11. September 2007 26
58. Race conditions
Global variables, deep inheritance
hierarchies, strongly interdependent
classes
Non-determinism
Dienstag, 11. September 2007 26
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. 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
63. Guiding ideas
Update order independent simulation
Dienstag, 11. September 2007 28
64. Guiding ideas
Update order independent simulation
Agent modification only dependent on its
steering vector
Dienstag, 11. September 2007 28
65. Guiding ideas
Update order independent simulation
Agent modification only dependent on its
steering vector
Minimize synchronization
Dienstag, 11. September 2007 28
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. 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
69. Split agent update
Agent update
Sim. Modify
agent agent
Agent
update
order
Dienstag, 11. September 2007 30
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. 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. 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. 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
75. Split update stage
Update stage
Sim. Modify
Sub-stages: simulation and modification
Dienstag, 11. September 2007 35
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. 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. 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. 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. 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. 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. 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. 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
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. 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. 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. 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
92. Max speedups
Comparison of OpenSteerDemo flock of
birds simulation with 4 threads with
OpenMP-disabled version
Dienstag, 11. September 2007 50
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. 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