[R-sig-hpc] multicore package and C/C++ code: any special care?

Brian G. Peterson brian at braverock.com
Thu Mar 18 12:36:02 CET 2010


Renaud Gaujoux wrote:
> Hi,
>
> my package aims to be used in a multicore and/or computer-cluster 
> environment.
> I'm re-implementing part of the code in C++. Apparently it's running 
> ok in multicore mode, but I want to be sure there is no potential 
> problem with this, on any platform.
> Is there any special things to worry about (thread-safe, memory, etc, 
> ...)?
> Thanks.
>
> Bests,
> Renaud
>
> PS: even if there is nothing to worry about, I'd be happy to get some 
> insights on the reason behind it.
'multicore' spawns separate R processes to run for each core.  Your 
custom C/C++ code should not make use of shared memory blocks that could 
be overwritten by one of the other R processes, or expect interprocess 
communication to work between the processes without explicit handling.  
If all your memory is explicitly allocated, used, and cleaned up, you 
should have no problems.  Loop dependence, or dependence on some shared 
global in the calling R environment, should be avoided.  Be explicit 
about both inputs and outputs to your code.

Others are definitely more qualified to get at the nuances, but this 
should cover the broad strokes.

Regards,

    - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-sig-hpc mailing list