[R] Assigning cores

Rasmus Liland jr@| @end|ng |rom po@teo@no
Thu Sep 3 22:32:39 CEST 2020


On 2020-09-03 13:44 -0400, Leslie Rutkowski wrote:
> Hi all,
> 
> I'm working on a large simulation and 
> I'm using the doParallel package to 
> parallelize my work. I have 20 cores 
> on my machine and would like to 
> preserve some for day-to-day 
> activities - word processing, sending 
> emails, etc.
> 
> I started by saving 1 core and it was 
> clear that *everything* was so slow as 
> to be nearly unusable.
> 
> Any suggestions on how many cores to 
> hold back (e.g., not to put to work on 
> the parallel process)?

Dear Leslie,

you can also use the core parallel 
package.  See ?parallel::makeCluster and 
?parallel::parSapply.

Here I run the function FUN on the 
vector 1:3 over three threads.  FUN 
needs otherFun, so you can export it to 
the cluster.  Remember to stop the 
cluster in the end.

	cl <- parallel::makeCluster(3)
	FUN <- function(x) {
	  return(otherFun(x^2))
	}
	otherFun <- function(x) {
	  return(x+1)
	}
	parallel::clusterExport(cl, "otherFun")
	parallel::parSapply(
	  cl=cl,
	  X=1:3,
	  FUN=FUN)
	parallel::stopCluster(cl)

You could run e.g. 15 cores or 
something?  parallel::makeCluster(15) 
...

Best,
Rasmus

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200903/30aa348d/attachment.sig>


More information about the R-help mailing list