Mac vs. PC in scientific computing

richarddmorey

Junior Member
Aug 31, 2004
5
0
0
My adviser has a Mac notebook that he bought 6 months ago, and I have a PC notebook I bought a month ago. Here are the respective specs, as far as I know them:

His:
Mac OSX
1 GB DDR2 RAM
Intel Core Duo, 2 GHz (2MB cache per core)
Unknown HD

Mine
Windows Vista Home Premium 32bit
2 GB DDR2 RAM
Intel Core 2 Duo, 2 GHz (4MB cache)
5400 RPM Hard Drive


We are both running R (available here) that we use in our work. As a test to see whose laptop was faster, we decided to invert large random matrices. In R language, it looks like this:

N=2000
A=rnorm(N^2)
A=matrix(A,ncol=N)
solve(A)

This creates a matrix of 4,000,000 random normal deviates and inverts it. His computer takes about 7 seconds, while mine takes about 14. Why the difference? I have several working hypotheses, and it would be interesting to see what you guys think.

1. R on Mac was compiled with optimizations for the CPU, with R for Windows was not. I could test this by compiling R with the Intel compiler, or GCC with optimizations, and seeing if I get a significant speed boost.

2. His R is 64 bit, while mine is for 32 bit windows. (I'm not sure how much of a diference that makes, or whether OSX is 64 bit.)

3. Data is getting swapped to the hard drive, and my hard drive is slower than his. I chose a slower hard drive to get bigger capacity for the price.

This is not intended to be an OMG MACOS = TEH R0X0R thread. I'm just trying to explain the discrepency.

Thanks!
 

f95toli

Golden Member
Nov 21, 2002
1,547
0
0
My guess is that alternative 3 might be importantt.
Having to swap against the HD in these types of applications can slow things down A LOT. If the HD is slow (access time) it obviously gets even worse. Also, perhaps the mac is simply handling the virtual memory in a more effiecent manner?

It would be interesting to repeat this experiment with a smaller matrix to avoid swapping.
Also, if the win version isn't optimized it will obviously slow things down. Is there any way to check the number of floating point operations used for an operation in R?
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
What compiler did you use? In general, don't use GCC if performance matters, use Visual Studio or Intel's compiler.
 

richarddmorey

Junior Member
Aug 31, 2004
5
0
0
I didn't compile it, both were downloaded as binaries form the site. I'm not sure what compiler they used. I think what I may do is install linux on a partition and compile it there with the intel compiler (I think we have a copy of it for linux that we use in the lab). That may improve performance.

But what I'm really interested is not improving performance in R, but rather figuring out why the Mac is faster.
 

pcy

Senior member
Nov 20, 2005
260
0
0
Hi,


4 million numbers only requires a fairly small amount of RAM in comparison with 1GB.


So the process shuold be entirely CPU bound.


It's just possible that a well complied version would run twice the speed of a less well optimized version, but it seems extreme.


I'd suggest looking at task manager to see if the WINdows version is usig both cores. Igf it isn't and the OSX version is multi threaded, that would explain it.


14 secs vs 7 secs is awefully suggestive...



Peter
 

f95toli

Golden Member
Nov 21, 2002
1,547
0
0
I don't think the 4 million numbers is the problem, but remember that we are presumably talking about double arrays here, in e.g. Matlab a 4000x4000 matrix is
128 megabytes in size (4000^2*8 bytes).
Also, inverting a matrix of that size does take a lot of time and depending on the algorithm used it might use up quite a lot of memory (it takes about 15s on my computer using Matlab).

 

richarddmorey

Junior Member
Aug 31, 2004
5
0
0
Originally posted by: pcy

I'd suggest looking at task manager to see if the WINdows version is usig both cores. Igf it isn't and the OSX version is multi threaded, that would explain it.


14 secs vs 7 secs is awefully suggestive...



Peter

You win the prize! I asked on the R help forum as well, and it turns out that the Windows Linear Algebra routines DLL does not use both cores. The MacOS one, however, does. I got a version of the DLL built for it, and it works like a charm :)

Thanks!
 

natto fire

Diamond Member
Jan 4, 2000
7,117
10
76
Originally posted by: richarddmorey
Originally posted by: pcy

I'd suggest looking at task manager to see if the WINdows version is usig both cores. Igf it isn't and the OSX version is multi threaded, that would explain it.


14 secs vs 7 secs is awefully suggestive...



Peter

You win the prize! I asked on the R help forum as well, and it turns out that the Windows Linear Algebra routines DLL does not use both cores. The MacOS one, however, does. I got a version of the DLL built for it, and it works like a charm :)

Thanks!

Heh, that was going to be my guess as well. So convenient that it was half the time.
 

jagec

Lifer
Apr 30, 2004
24,442
6
81
Originally posted by: Captain Howdy
You win the prize! I asked on the R help forum as well, and it turns out that the Windows Linear Algebra routines DLL does not use both cores. The MacOS one, however, does. I got a version of the DLL built for it, and it works like a charm :)

Thanks!

Heh, that was going to be my guess as well. So convenient that it was half the time.[/quote]

Yup. First rule of problem solving: Things are NEVER convenient.:)