Commit b2231316 authored by Romulo Pereira Goncalves's avatar Romulo Pereira Goncalves
Browse files

The user can now specify the max number of cores. This helps us to control the...

The user can now specify the max number of cores. This helps us to control the ratio of available cores and main memory.
parent 2546336b
......@@ -15,7 +15,8 @@
#' @param last only true for one class classifier c("FALSE", TRUE")
#' @param seed set seed for reproducable results
#' @param init.seed "sample" for new or use run1@seeds to reproduce previous steps
#' @param parallel_mode run loops using all available cores
#' @param parallel_mode run loops in parallel
#' @param max_num_cores maximum number of cores for parallelism
#'
#' @return a list with 3 elements:
#' 1) An index
......@@ -46,7 +47,8 @@ sample_nb <- function(raster,
last,
seed,
init.seed,
parallel_mode) {
parallel_mode,
max_num_cores) {
###
n_channel <- length(names(raster))
###velox
......@@ -85,6 +87,12 @@ sample_nb <- function(raster,
if (parallel_mode == TRUE) {
cores = parallel::detectCores( logical = TRUE)
if (cores > max_num_cores) {
cores <- max_num_cores
} else {
cores <- cores - 1
}
res <- parallel::mclapply(
1:nb_mean,
model_opt_r,
......
......@@ -23,6 +23,7 @@
#' @param overwrite overwrite the results file
#' @param save_runs if it saves the Habitat object or not (default TRUE)
#' @param parallel_mode run loops using all available cores
#' @param max_num_cores maximum number of cores for parallelism
#' @param plot_on_browser plot on the browser or inline in a notebook (default TRUE)
#'
......@@ -87,6 +88,7 @@ multi_Class_Sampling <- function(in.raster,
overwrite = TRUE,
save_runs = TRUE,
parallel_mode = FALSE,
max_num_cores = 5,
plot_on_browser = TRUE) {
###first steps: data preparation
if (class(reference) == "SpatialPointsDataFrame") {
......@@ -156,7 +158,8 @@ multi_Class_Sampling <- function(in.raster,
last = last,
seed = seed,
init.seed = init.seed,
parallel_mode = parallel_mode
parallel_mode = parallel_mode,
max_num_cores = max_num_cores
)
index <- maFo_rf$index
......@@ -207,7 +210,8 @@ multi_Class_Sampling <- function(in.raster,
last = last,
seed = seed,
init.seed = init.seed,
parallel_mode = parallel_mode
parallel_mode = parallel_mode,
max_num_cores = max_num_cores
)
index <- maFo_rf$index
......@@ -263,7 +267,8 @@ multi_Class_Sampling <- function(in.raster,
last = last,
seed = seed,
init.seed = init.seed,
parallel_mode = parallel_mode
parallel_mode = parallel_mode,
max_num_cores = max_num_cores
)
index <- maFo_rf$index
......
......@@ -26,6 +26,7 @@ multi_Class_Sampling(
overwrite = TRUE,
save_runs = TRUE,
parallel_mode = FALSE,
max_num_cores = 5,
plot_on_browser = TRUE
)
}
......@@ -72,6 +73,8 @@ multi_Class_Sampling(
\item{parallel_mode}{run loops using all available cores}
\item{max_num_cores}{maximum number of cores for parallelism}
\item{plot_on_browser}{plot on the browser or inline in a notebook (default TRUE)}
}
\value{
......
......@@ -18,7 +18,8 @@ sample_nb(
last,
seed,
init.seed,
parallel_mode
parallel_mode,
max_num_cores
)
}
\arguments{
......@@ -46,7 +47,9 @@ sample_nb(
\item{init.seed}{"sample" for new or use run1@seeds to reproduce previous steps}
\item{parallel_mode}{run loops using all available cores}
\item{parallel_mode}{run loops in parallel}
\item{max_num_cores}{maximum number of cores for parallelism}
\item{nb_models}{number of models (independent classifiers) to collect}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment