parfor inefficiency for large matrix operations

Good day all
I have two large matrices which I need to compute in a for loop. I know the index of the for loop is small, but the computations take long due to the size of the matrices. Could anyone tell me why there is no speed boost using parfor? I also tried different matrix sizes and parfor never works. I have a quad core PC that makes 4 parallel workers. Here is the code:
if true
parpool(4)
N = 5000;P=2000;
mean = zeros(N,10);var = zeros(N,10);
t1 = ones(P,N);t2 = eye(P);
tic
for jj = 1:4
diag(t1.'*(t2\(t2.'\t1)));
end
toc
t1 = repmat(t1,1,1,4);t2 = repmat(t2,1,1,4);
tic
for jj = 1:4
diag(t1(:,:,jj).'*(t2(:,:,jj)\(t2(:,:,jj).'\t1(:,:,jj))));
end
toc
end
I duplicate the code and add par in front of the for to get the parfor result.
The result I got with for was:
Elapsed time is 6.292219 seconds.
Elapsed time is 6.280422 seconds.
And with parfor:
Elapsed time is 7.617721 seconds.
Elapsed time is 6.583254 seconds.
I have also tried using this code:
to first send the data to each worker. There was no improvement.
Many thanks in advance for any insights.

 채택된 답변

Edric Ellis
Edric Ellis 2016년 9월 29일
편집: Edric Ellis 2016년 9월 29일

0 개 추천

This appears to be because MATLAB's intrinsic multi-threading is already doing a decent job of running your code in parallel. When this is the case, parfor using local workers tends to be no faster - because you have no additional hardware to apply to the problem. ( parfor is often slower in these sort of cases because of the overhead of transferring the data to the workers).
If you have MDCS workers available, then it's possible you might see speedup - because that way you're using more hardware than just your local machine.

댓글 수: 1

Allan
Allan 2016년 9월 29일
Thanks Edric, I wasnt aware of MATLAB's intrinsic multi-threading. I will look into it and also look into MDCS.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

태그

질문:

2016년 9월 28일

댓글:

2016년 9월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by