User`s guide
3 Single Program Multiple Data (spmd)
3-2
Execute Simultaneously on Multiple Data Sets
In this section...
“Introduction” on page 3-2
“When to Use spmd” on page 3-2
“Define an spmd Statement” on page 3-3
“Display Output” on page 3-5
Introduction
The single program multiple data (spmd) language construct allows seamless
interleaving of serial and parallel programming. The spmd statement lets you define a
block of code to run simultaneously on multiple workers. Variables assigned inside the
spmd statement on the workers allow direct access to their values from the client by
reference via Composite objects.
This chapter explains some of the characteristics of spmd statements and Composite
objects.
When to Use spmd
The “single program” aspect of spmd means that the identical code runs on multiple
workers. You run one program in the MATLAB client, and those parts of it labeled
as spmd blocks run on the workers. When the spmd block is complete, your program
continues running in the client.
The “multiple data” aspect means that even though the spmd statement runs identical
code on all workers, each worker can have different, unique data for that code. So
multiple data sets can be accommodated by multiple workers.
Typical applications appropriate for spmd are those that require running simultaneous
execution of a program on multiple data sets, when communication or synchronization is
required between the workers. Some common cases are:
• Programs that take a long time to execute — spmd lets several workers compute
solutions simultaneously.
• Programs operating on large data sets — spmd lets the data be distributed to multiple
workers.