Is there a way to run several RLink computations via REvaluate[] in parallel, e.g. with ParallelTable[]?
Answer
It is actually possible, if you run several copies of RLink in parallel. This would mean several parallel kernels, R and JVM processes. Here is an example (I have 6 cores):
ParallelEvaluate[Needs["RLink`"]; RLink`InstallR[]]
ParallelEvaluate[RLink`REvaluate["fn <- function(max){sum(sin(1:max))}"]]
and then,
ParallelTable[RLink`RFunction["fn"][i],{i,500000,501000}]//Short//AbsoluteTiming
(* {13.027344,{{1.90482},<<999>>,{1.19949}}} *)
while for a single core, we get:
Needs["RLink`"]
InstallR[]
REvaluate["fn <- function(max){sum(sin(1:max))}"]
and then
Table[RLink`RFunction["fn"][i],{i,500000,501000}]//Short//AbsoluteTiming
(* {57.647461,{{1.90482},<<999>>,{1.19949}}} *)
The more computationally intensive is a single call to R functions, the more you will see the speed benefit of parallelization. Since R is vectorized and also based on immutable expressions, it should be relatively easy to write R functions is a way which would be easy to parallelize and use with parallel Mathematica functionality.
Comments
Post a Comment