if I type lscpu in the command-line:
CPU(s): 4
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
so I have 2 physical cores.
I have no background on parallel computing, but I need it for my purposes. So, since I am a MatLab user, I'm interested in parfor loops, but I need to understand what is really going on.
I've red from MatLab documentation, that default number of workers is one per physical CPU core using a single computational thread, and also that this choice optimize performance. What I want to understand is how the number of workers affects the performance:
To see this, I tried to run (inspired by this) the following standard piece of code, changing the number of workers in the parpool line.
m = 500;
A = randn(m);
N = 200;
parpool(1);
tic
x = zeros(1,N);
parfor i=1:N
x(i) = max(abs(eig(A)));
end
toc
and I measure with tic-toc the time taken.
With 1 worker: % Elapsed time is 26.534430 seconds.
With 2 workers: % Elapsed time is 14.528462 seconds.
With 3 workers: % Elapsed time is 14.403359 seconds.
With 4 workers: % Elapsed time is 17.946775 seconds.
If I go on with the workers, it takes more time.
I have two questions:
I would expect to have the best performance with 2 workers: why with 3 workers I have still good results?
Why more workers implies more time?