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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!