I compared the following codes. Serial:
N = 500;
M = rand(500,500,N);
R = zeros(500,500,N);
tic
for k = 1:N
R(:,:,k) = inv(M(:,:,k));
end
toc
Parallel:
N = 500;
M = rand(500,500,N);
R = zeros(500,500,N);
tic
parfor k = 1:N
R(:,:,k) = inv(M(:,:,k));
end
toc
I get that the serial time is 3 times shorter than parallel time - though I have 4 available local cores that seem to be in use. Any thoughts on why is it happening?