problème0123
problème0123

Reputation: 871

Set the number of CPU cores

I am testing keras tensorflow under R, i would like to know how to specify the number of CPU cores. I only find tensorflow solutions under python without keras.


> library(keras)
> library(doParallel)
> cl <- makeCluster(2)
> registerDoParallel(cl)
> is_keras_available()
[1]TRUE
> foreach(i=1:3) %dopar% { is_keras_available()}
Error in { : 
  task 1 failed - "impossible to find the function "is_keras_available""
> parallel::stopCluster(cl)

Upvotes: 2

Views: 3481

Answers (1)

R18
R18

Reputation: 1560

Using doParallel library, you can detect the number of cores using detectCores() function, and specify the number of cores to use with registerDoParallel() function.

Take a look to https://cran.r-project.org/web/packages/doParallel/vignettes/gettingstartedParallel.pdf

Remember to include your libraries in the parallelization of your code through the .export parameter

foreach(i=1:3, .packages = c("keras")) %dopar% { is_keras_available()}

Upvotes: 2

Related Questions