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);ticfor jj = 1:4diag(t1.'*(t2\(t2.'\t1)));endtoct1 = repmat(t1,1,1,4);t2 = repmat(t2,1,1,4);ticfor jj = 1:4diag(t1(:,:,jj).'*(t2(:,:,jj)\(t2(:,:,jj).'\t1(:,:,jj))));endtocend
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.
Best Answer