Is there an example on how to use parallel programming with Parallel Computing Toolbox to do a simple matrix computation?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would like to know how to compute A*B using the Parallel Computing Toolbox 4.0 (R2008b).
Réponse acceptée
MathWorks Support Team
le 27 Juin 2009
This example computes A*B over four workers using the local scheduler. Note that in this simple example the communication outweighs the actual computation, so it is not a useful speed benchmark.
The code for the task is as follows
function out = multtrans(x,y)
% Codistribute the input matrices
A = codistributed(x,'convert');
B = codistributed(y,'convert');
% Multiply local parts
C = A * B;
% Gather the result on lab 1
out = gather(C,1);
end
The code that is run on the client is
% Declare the two matrices on the client. The matrix must preserve innner product convention: 'm x n' matrix can multiply only with 'n x p'
X = [1 2;3 4;5 6];
Y = [7 8 9;10 11 12];
% Pass sections to workers
jm = findresource('scheduler', 'type', 'local');
pjob = createParallelJob(jm);
tsk = createTask(pjob, @multtrans, 1, {X,Y});
pjob.MaximumNumberOfWorkers=4;
pjob.MinimumNumberOfWorkers=4;
set(pjob, 'FileDependencies', {'multtrans.m'});
submit(pjob);
waitForState(pjob);
result = getAllOutputArguments(pjob);
destroy(pjob);
To access the result, execute the following on the client
result{1}
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Server Management dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!