[R] Using multicores in R

Spencer Graves spencer.graves at structuremonitoring.com
Mon Dec 3 20:02:56 CET 2012


       1.  Have you looked at CRAN Task View: High-Performance and 
Parallel Computing with R 
(http://cran.r-project.org/web/views/HighPerformanceComputing.html)?


       2.  Have you tried the "compiler" package?  If I understand 
correctly, R is a two-stage interpreter, first translating what we know 
as R into byte code, which is then interpreted by a byte code 
interpreter.  If my memory is correct, this approach can cut the compute 
time by a factor of 100.


       3.  Have you reviewed the section on "Profiling R code for speed" 
in the "Writing R Extensions" manual that becomes available after 
help.start()?  The profiling tools discussed there help identify the 
portion of more complex code that takes the most time.  The standard 
advice then is to experiment with writing the most time consuming 
portion several different ways.  I've seen many examples where writing 
what appears to be the same thing in R several different ways identifies 
one that is easily 10 and maybe 100 or 1000 times faster than the 
slowest alternative tried.


       4.  Have you tried using the "sos" package to search for other 
functions and packages in R that may already have good code doing some 
of the things you want to do?  The "findFn" function in "sos" searches 
the "functions" subset of the "RSiteSearch" database and returns the 
result sorted by package.  There are also a "union" and 
"writeFindFn2xls" functions to make it easy to manipulate and evaluate 
the results, described in a vignette. It's the best literature search I 
know for anything statistical: If I don't find it there, it's OK to look 
someplace else. [Caveat:  I'm the lead author of "sos", so I'm biased.]


       Best Wishes,
       Spencer


On 12/3/2012 6:24 AM, Steve Lianoglou wrote:
> And also:
>
> On Monday, December 3, 2012, Uwe Ligges wrote:
>
>>
>> On 03.12.2012 11:14, moriah wrote:
>>
>>> Hi,
>>>
>>> I have an R script which is time consuming because it has two nested loops
>>> in it of at least 5000 iterations each, I have tried to use the multicore
>>> package but id doesn't seem to improve the elapsed time of the script(a
>>> shorter script for example) and I can't use the mcapply because of
>>> technical
>>> reasons.
>>>
>> Errr, but otherwise multicore does not have an effect ...
>>
>> See package "parallel" that offers various functions for parallel
>> computations. We cannot help much more if you do not tell us what the
>> technical reasons are why mcapply() does not work.
>
> If the work you are doing within each iteration of the loop is trivial, you
> will likely even see a decrease in performance if you try to parallelize it.
>
> Without more info from you regarding your problem, there's little we can do
> to help, tho.
>
>   -Steve
>
>
>


-- 
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.com


-- 
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.com




More information about the R-help mailing list