blog.awill.me

blog.awill.me

04 Dec 2007

Windows vs Linux Benchmarks with Matlab

I finally got around to getting Matlab 2007b (7.5) to work in Linux.

It’s not overly difficult, but it certainly isn’t the double-click the .exe we’re all used to πŸ˜‰

For it to work in Ubuntu 7.10 (Gutsy), I had to do the following

sudo mkdir /usr/local/matlab75
  
sudo cp license.dat /usr/local/matlab75/license.dat
  
sudo sh /media/cdrom/install

tell it the location of your matlab dir

/usr/local/matlab75

select arch and options

sudo sh /usr/local/matlab75/bin/scripts/matlab

It will now work if you’re using the metacity windows manager, but if you’re running compiz

gksudo gedit /usr/local/matlab75/bin/matlab

add the following line directly after the ‘#!/bin/sh’

export MATLAB\_JAVA=/usr/lib/jvm/java-6-sun/jre/

note, java-6-sun is a symbolic link for java 1.6.0.03

add a shortcut that loads the following

/usr/local/matlab75/bin/matlab -desktop

I tested this by installing it on both my desktop (64bit) and laptop (32bit) and it worked perfectly.

Since previously I’d only been running matlab in Windows, I thought it would be a good oportunity to compare some benchmarks.

The built in matlab bench is a terrible benchmark, and gets faster the more times you run it, so i decided to run a benchmark written by Jan Mandel, which tests matlab’s speed at LLU (local loop unbundling).

I decided to be fair, to compare my laptop running matlab natively in both Windows and Linux.

I also added my desktops scores for comparison, but it’s running different hardware, and the 64bit version of matlab, so we can’t compare with windows.

Specs are as follows for my laptop

Thinkpad T61 T7500 C2D 2.2Ghz

3GB 667 RAM

Santa Rosa chipset

Hitachi 5K160 HD

nVidia Quadro NVS 140M 128MB

(the rest of the specs don’t matter as they wouldn’t affect benchmark scores)

The results are measured in the amount of seconds it takes to complete the operation, so obviously the lower the better

Matlab benchmark

Jan Mandel, December 2000

Last updated August 2004

Matlab version 7.5.0.338 (R2007b)

Linux x86 (32bit) Thinkpad T61

  1. large LU: 0.205

  2. small LU: 0.506

  3. sparse : 0.133

Windows Vista x86 Thinkpad T61

  1. large LU: 0.261

  2. small LU: 0.664

  3. sparse : 0.172


Here’s my desktop scores

Linux x64

  1. large LU: 0.186

  2. small LU: 0.507

  3. sparse : 0.133

large LLU was 27% faster in linux

small LLU was 31% faster in linux

Sparse was 29% faster in linux

Considering the hardware is identical, that difference is HUGE. And all because of all the screwups Microsoft have made, Vista might well be the biggest! (I should really test Windows XP. I would guess it’s about 10-15% faster than Vista, but still 15% or more slower than Linux)

64bit saw marginal improvements of about 10%. Obviously Matlab isn’t optimized for 64bit πŸ™

One thing of note is that recently, Mathworks added multi-threading optimisations to Matlab.

They give a hefty improvement on a dual/quad core machine. The improvement is fairly linear, ranging from 50-70% improvement when you double the cores, with my quad core being over 200% faster with multi-threading enabled. Multi-threading is, however, disabled by default because crash recovery is not yet possible, as information would be split across 4 cores and separate L2 caches.

In the screenshot the first benchmark was single, 2nd with quad, and 3rd in dual mode.

The benchmark named AntonyJMbench.m was a modification I made of the above benchmark. The JMbench was written years ago when computers were much slower. A benchmark can’t be accurate when it takes a few hundred miliseconds to run, so I modified it so that the first test take 40 seconds on a decent single core machine.

note, the 3rd test works in an way that cannot be optimized for multiple cores.

below is the code for the benchmark should you want to compare your scores with mine.

% function jmbench

disp('Matlab benchmark')
  
disp('Jan Mandel, December 2000')
  
disp('Last updated August 2004')
  
disp('updated by Antony Williams - December 2007')

disp(['Matlab version ',version])

for iii=1:1
  
disp(' ')

f='%7.3f\n';
  
fprintf('1. large LU: ')
  
n=5000;m=3;
  
A=ones(n)+eye(n);
  
tic
  
for i=1:m,R=chol(A); end
  
t=toc; fprintf(f,t)

fprintf('2. small LU: ')
  
n=500;m=3000;
  
A=ones(n)+eye(n);
  
tic
  
for i=1:m,R=chol(A);end
  
t=toc; fprintf(f,t)

fprintf('3. sparse : ')
  
n=100000;m=50;k=10;
  
B=ones(n,2\*m+1);
  
B(:,m+1)=m+1;
  
d=[-m:m];
  
tic
  
A=spdiags(B,d,n,n);
  
R=chol(A);
  
R=A-R'\*R;
  
t=toc; fprintf(f,t)

pause(1)

end
  
disp(' ')
  
disp('end of jmbench')

Categories