MATLAB PARALLEL COMPUTING TOOLBOX - S User's Guide Page 27

  • Download
  • Add to my manuals
  • Print
  • Page
    / 656
  • Table of contents
  • TROUBLESHOOTING
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 26
Introduction to Parallel Solutions
1-13
The line above retrieves the data from worker 3 to assign the value of X. The following
code sends data to worker 3:
X = X + 2;
R{3} = X; % Send the value of X from the client to worker 3.
If the parallel pool remains open between spmd statements and the same workers are
used, the data on each worker persists from one spmd statement to another.
spmd
R = R + labindex % Use values of R from previous spmd.
end
A typical use for spmd is to run the same code on a number of workers, each of which
accesses a different set of data. For example:
spmd
INP = load(['somedatafile' num2str(labindex) '.mat']);
RES = somefun(INP)
end
Then the values of RES on the workers are accessible from the client as RES{1} from
worker 1, RES{2} from worker 2, etc.
There are two forms of indexing a Composite, comparable to indexing a cell array:
AA{n} returns the values of AA from worker n.
AA(n) returns a cell array of the content of AA from worker n.
Although data persists on the workers from one spmd block to another as long as the
parallel pool remains open, data does not persist from one instance of a parallel pool to
another. That is, if the pool is deleted and a new one created, all data from the first pool
is lost.
For more information about using distributed arrays, spmd, and Composites, see
“Distributed Arrays and SPMD”.
Page view 26
1 ... 26 27 28 ... 656

Comments to this Manuals

No comments