Why is parfor so slow?

11 views (last 30 days)
Anders G
Anders G on 4 Oct 2013
Commented: Edric Ellis on 7 Oct 2013
Hi,
I want to run Matlab on a cluster node with 4 processors and 48 cores (128GB ram). Typically what I do is 3D ffts. Toy example: -----------------------------------
function test(a)
N = 100;
FT = @(x)(fftshift(fftn(ifftshift(x))));
iFT = @(x)(fftshift(ifftn(ifftshift(x))));
X = randn(64,64,64);
for ii = 1:N
X = iFT(FT(X));
end
toc(a)
end
-----------------------------------
when calling this function from a parfor loop:
-----------------------------------
N = 8
poolSize = 11;
matlabpool(poolSize)
disp(['Pool created at ',num2str(toc(a))])
for ii = 1:N
test(a);
end
disp('Done processing')
toc(a)
matlabpool close
disp('Pool closed')
toc(a)
disp('DONE!!');
toc(a)
-----------------------------------
I almost not getting any speedup compared to running it serially on a single core. WHY? Is it reading and writing from RAM that takes all time?
Thankful for all answers, Anders
  2 Comments
cr
cr on 7 Oct 2013
Just a comment to make sure that not so obvious things aren't taken for granted. Is the PCT installed?
Edric Ellis
Edric Ellis on 7 Oct 2013
We can assume PCT is installed otherwise the calls to matlabpool could not succeed.

Sign in to comment.

Answers (1)

Edric Ellis
Edric Ellis on 7 Oct 2013
Firstly, I assume you meant to put a PARFOR loop in your example code for the 1:N loop. The reason you are not seeing any speedup is that the FFT operation is itself intrinsically multi-threaded by MATLAB. Intrinsic multi-threading is always more efficient than sending the data to the workers and executing (in a single-threaded manner) there.

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!