Reputation: 871
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
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