views:

725

answers:

5

I have a quad-core laptop running Windows XP, but looking at Task Manager R only ever seems to use one processor at a time. How can I make R use all four processors and speed up my R programs?

+3  A: 

I hear tell that REvolution R supports better multi-threading then the typical CRAN version of R and REvolution also supports 64 bit R in windows. I have been considering buying a copy but I found their pricing opaque. There's no price list on their web site. Very odd.

JD Long
If you have to ask the price, you can't afford it.
Buhb
Academic pricing is listed here: http://www.revolution-computing.com/industry/academic.php .
David Smith
+8  A: 

The CRAN Task View on High-Performance Compting with R lists several options. XP is a restriction, but you still get something like snow to work using sockets within minutes.

Dirk Eddelbuettel
+4  A: 

R is not inherently a multi-threaded application, so in normal circumstances it only uses one processor at a time.

If you use the REvolution R distribution (free download here), it will use all available processors for some common math operations, like matrix multiplication. (It is linked with multi-threaded math libraries which improve performance on multi-core Intel processors.)

You can also write explicit parallel code with the foreach function from the "foreach" package, with parallelism from doSnow. More details in this post at the Revolutions blog: Parallel programming with foreach and snow.

David Smith
+2  A: 

On Windows I believe the best way to do this would probably be with foreach and snow as David Smith said.

However, Unix/Linux based systems can compute using multiple processes with the 'multicore' package. It provides a high-level function, 'mclapply', that performs a list comprehension across multiple cores. An advantage of the 'multicore' package is that each processor gets a private copy of the Global Environment that it may modify. Initially, this copy is just a pointer to the Global Environment, making the sharing of variable extremely quick if the Global Environment is treated as read-only.

Rmpi requires that the data be explicitly transferred between R processes instead of working with the 'multicore' closure approach.

-- Dan

ephpostfacto
+2  A: 

I believe the multicore package works on XP. It gives some basic multi-process capability, especially through offering a drop-in replacement for lapply() and a simple way to evaluate an expression in a new thread (mcparallel()).

Peter McMahan
the drop in replacement for `lapply()` is called `mclapply()`. It's really that simple: N processors are N times faster (so long as all the heavy lifting is inside the function that's being applied)
Michael Dunn
the multicore package requires a POSIX compliant OS so it does not work in Win. You can read the requirements here: http://cran.r-project.org/web/packages/multicore/index.html
JD Long

related questions