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?
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.
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.
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.
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
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()
).