When matlab R2011b is running a program, it only use about 20% CPU. So I'm wondering how could I make it fully use the CPU and thus takes less time to finish the program. Is there an easy way to make this?
MATLAB: How to fully use the CPU of the PC
parallel computing
Related Solutions
I ran this on my 8-core machine using R2009a:
function myFilterTestx = rand(1e6, 8);x1 = x(:,1);x2 = x(:,2); x3 = x(:,3);x4 = x(:,4); x5 = x(:,5);x6 = x(:,6); x7 = x(:,7);x8 = x(:,8); [B, A] = butter(3, 0.2, 'low');tic;for i=1:100 y = filter(B, A, x); % Matrix
% clear('y'); % Avoid smart JIT interferences => same effects!
endtoctic;for i=1:100 y1 = filter(B, A, x1); % Eight vectors
y2 = filter(B, A, x2); y3 = filter(B, A, x3); y4 = filter(B, A, x4); y5 = filter(B, A, x5); y6 = filter(B, A, x6); y7 = filter(B, A, x7); y8 = filter(B, A, x8); % clear('y1', 'y2'); % No qualitative changes
endtoc
clear all;
And got this:
Elapsed time is 16.865596 seconds. Elapsed time is 16.117599 seconds.
Only one core was active during each test.
I ran this on my 8-core machine using R2011a and got:
Elapsed time is 12.542615 seconds.Elapsed time is 16.268821 seconds.
All eight cores were active for the first test (on the matrix) and only a single core for the seconds test (on individual vectors).
I added this to the bottom of the test:
y_par = zeros(size(x));matlabpool(8);tic; parfor j = 1:8 for i=1:100 y_par(:,j) = filter(B, A, x(:,j)); end % clear('y_par'); % No qualitative changes
endtoc; matlabpool close;
And got this when using R2011a:
Elapsed time is 13.305009 seconds.Elapsed time is 16.398203 seconds.Starting matlabpool using the 'local' configuration ... connected to 8 labs.Elapsed time is 3.542021 seconds.Sending a stop signal to all the labs ... stopped.
If e.g. the memory is exhausted and the laptop uses a slow harddisk or cheap eMMC drive as virtual memory instead of a modern SSD, the speed on a dektop with enough RAM can be 100 times faster.
How many cores does Simulink use? With sufficient RAM you can start to Matlab sessions and run two simulations in parallel. This can increase the speed by a factor 2 by no extra costs.
Of course the fastest CPU would be the best for accelerating. But "fast" is not uniquely defined anymore in the times of turbo-boosts to increase the CPU frequency as long as the temperature is under a certain limit. The same laptop can be twice as fast, if it is cooled down sufficiently.
There I suggest to try it. Ask a friend or colleague for a modern desktop and MathWorks for a trial version. Then run your code to see, if it works fast enough for your needs.
As said in the comments already: Usually a faster CPU can run the (single-threaded) code in 90% or 50% of the time. But with improving the code we had some examples in this forum, which had a speedup of the factor 100.
Best Answer