Filter löschen
Filter löschen

Three tasks in parallel

2 Ansichten (letzte 30 Tage)
John
John am 10 Mär. 2015
Bearbeitet: Christiaan am 11 Mär. 2015
If I have a 10x10x10 matrix A, and want to do some operations on three different dimensions separately, then how to do that in parallel? For example, I have to compute inverse of all 2D matrices in it, like:
for k=1:10
B(k,:,:)=inv(squeeze(A(k,:,:);
end
for k=1:10
B(:,k,:)=inv(squeeze(A(:,k,:);
end
for k=1:10
B(:,:,k)=inv(squeeze(A(:,:,k);
end
Now,I want to do the same thing, but three for-loops in parallel. Is there any way to do it in matlab? A help is greatly appreciated. Thanks.

Antworten (1)

Christiaan
Christiaan am 11 Mär. 2015
Bearbeitet: Christiaan am 11 Mär. 2015
Dear John,
Parallel computation can be performed with the Parallel Computing Toolbox from Mathworks. To obtain the list of all the toolboxes on your license, can be done by typing 'ver' in your MATLAB prompt.
Here is an example how a code could look like:
tic
A = round(rand(3, 3, 3)*10);
parfor k = 1:3
B(k,:,:)=inv(squeeze(A(1,:,:)));
end
toc
If you have any problems with the toolbox, you may want to look at a previous answer first.
Note: for small computations the for command is faster then the parfor command. However if large calculations are performed, parfor will be faster .
Kind regards, Christiaan

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by