root/OptimizingMATLABCode/SPMD/advanced.m @ 11
10 | anderm8 | spmd
|
|
if( labindex == 1 )
|
|||
% Wait to receive data from any worker
|
|||
[data,workerID] = labReceive;
|
|||
% Display received data
|
|||
fprintf('Received data from Worker %1.0f:\n',workerID);
|
|||
disp(data);
|
|||
% Modify data to send back
|
|||
newData = data*2;
|
|||
% Send data back to the worker that messaged you
|
|||
labSend(newData,workerID);
|
|||
elseif( labindex == 2 )
|
|||
% Create original data to send to Worker 1
|
|||
originalData = magic(3);
|
|||
% Send data to Worker 1
|
|||
labSend(originalData,1);
|
|||
% Wait to receive response data for any worker
|
|||
[data,workerID] = labReceive;
|
|||
% Display received data
|
|||
fprintf('Received data from Worker %1.0f:\n',workerID);
|
|||
disp(data);
|
|||
end
|
|||
end
|