Previous | Next --- Slide 15 of 20
Back to Lecture Thumbnails

The meaning ("semantics") of foreach are a little tricky. A foreach loop means the following:

  • Each iteration of the loop is executed exactly once for the entire gang of ISPC program instances.
  • Each iteration is performed by one program instance.

ISPC determines which program instance executes which loop iteration. This assignment is not defined in the semantics of the language and is an implementation detail. In practice, the implementation of the foreach construct by the current ISPC compiler will be very similar to the interleaved assignment shown on slide 8. You can think of 'foreach' as convenient syntax for having to write the explicitly interleaved assignment yourself.