Can anybody replicate the curious way I found to speed up my matlab code?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have found that sometimes my matlab code runs faster when the machine I am running on is NOT idle. I suspect that this has something to do with the intel turbo boost feature. Below is some simplified code I wrote in hopes that someone can confirm this (I have duplicated this on multiple machines already, so I don't think I am crazy, but don't hesitate to prove otherwise!). Basically, the code runs a bunch of pointless computations, and measures how long it takes to run. It then spawns a process called stress (available in RHEL 6) that keeps two of the cores very busy (one doing sqrt calls, the other doing malloc/free calls). It waits a little while for the CPU to adjust to the added load (enable turbo boost), and then repeats the experiment. I find that the code runs faster when the cpu is burdened in this way.
t=[];
for i=1:3
tic
data = randn(45,95,81,2);
for j=1:2800
data1_plus5 = data(:,:,:,1)+5;
end
t(i) = toc
end
time1 = sum(t);
system('stress -m 1 -c 1 &')
pause(15)
t=[];
for i=1:3
tic
data = randn(45,95,81,2);
for j=1:2800
data1_plus5 = data(:,:,:,1)+5;
end
t(i) = toc
end
time2 = sum(t);
result = sprintf('Stressing two cores gave a code speedup factor of %f.\n',time1/time2)
cmd = '/sbin/pidof stress'
[err,res] = system(cmd);
system(sprintf('kill %s',res));
Obviously, the code is not portable because it makes some system calls. You will need linux (mine is RHEL 6).
The results are probably also dependent on the system (e.g., cache sizes, etc), and I find the speedup factor varies quite a bit from run to run and with different parameters (probably based on the temperature of the CPU when I run it). Still, I have seen speedups of up to 43% in some cases by stressing two of my 16 cores.
The nodes I have tested on are dual-octocore Intel® Xeon® CPU E5-2670 0 @ 2.60GHz.
I imagine that a better way is to put the machine into a performance mode for the cpu governor (see, e.g., this article), but I don't have root on these machines, so this is my odd workaround. The above code is just for testing, my real code uses many threads much of the time to make use of the many cores, and even does something somewhat useful ;-)
0 commentaires
Réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!