This programming example illustrates many of the concepts discussed
earlier in this chapter.
It can be found in the SDK under:
/opt/cell/sdk/src/tutorial/euler
This example — a simple Euler-based particle-system simulation — illustrates
the following steps involved in coding for the
Cell Broadband Engine:
- Transform scaler code to vector code (SIMDize) for execution
on the PPE's VXU.
- Port the code for execution on the SPE's SPU unit.
- Parallelize the code for execution across multiple SPEs.
A subsequent step — tuning the code for performance on the SPE — is covered
in Performance analysis. The above steps are
only one example of coding for the Cell Broadband Engine.
The steps can be reordered or combined, depending upon the skill and comfort
level of the programmer.
This example shows a particle-system simulation using numerical integration
techniques to animate a large set of particles. Numerical integration is implemented
using Euler's method of integration. It computes the next value of a function
of time,
F(t), by incrementing the current value of the function
by the product of the time step and the derivative of the function:
F(t + dt) = F(t) + dt*F'(t);
Our simple particle system consists of:
- An array of 3-D positions for each particle (pos[])
- An array of 3-D velocities for each particle (vel[])
- An array of masses for each particle (mass[])
- A force vector that varies over time (force)
This programming example is intended to illustrate programming concepts
for the
Cell Broadband Engine, and is not meant
to be a physically realistic simulation. For example, it does not consider:
- how the time-variant force function and the time step, dt,
is computed (instead, the example treats them as constants).
- particle collisions.
In addition, we assume that all 3-D vectors (
x,y,z)
are expressed as 4-D homogeneous coordinates (
x,y,z,1).