I'm going to buy a dual CPU workstation and would like to know if a vectorized MATLAB code uses
all the cores of both CPUs without the need to
use the Parallel Computing Toolbox.
Thanks!
Best Answer
Yes. Matlab will use the available cores. At least most likely. Matlab might split the array columnwise and if the input has 5 columns, there is a chance that only 5 cores are used. Many functions are multi-threaded, but this is applied for "large" arrays only.
I'm not sure, if hyper-threading is used in Matlab. Maybe only the physical cores are used for the reason of efficiency.
Note that:
[m,n]=size(matrix);
for i=1:m
for l=1:n
matrix(i,l) = matrix(i,l)^2;
end
end
and
[m,n]=size(matrix)
matrix(:,:)=matrix(:,:)^2;
do not compute the same result. The 2nd code works for square matrices only and is a matrix multiplication. Equivalent to the first code would be:
% No need to determine the size...
matrix(:,:) = matrix(:,:) .^ 2;
% ^ elementwise squaring
It would be even more efficient, to omit the (:,:):
The amount of memory available in your GPU should not affect how quickly it performs calculations (all other things being equal), but it will affect the size of problem you can solve. When you convert MATLAB data to be agpuArray, it must be able to fit in the memory of your GPU - in other words,gpuArray can only access the memory of the GPU device.
Best Answer