For high number of randomization and number of weights, the multiprocessing strategy is faster.
But for low randomization numbers and number of weights, prefer sequential processing for better performances.
## increase the randomization_number to at least 1000 to have
## better results
## our analysis parameters:
list(
tad_analysis_parameter <-weights = TAD::AB[, c(5:102)],
weights_factor = TAD::AB[, c("Year", "Plot", "Treatment", "Bloc")],
trait_data = log(TAD::trait[["SLA"]]),
aggregation_factor_name = c("Year", "Bloc"),
statistics_factor_name = c("Treatment"),
regenerate_abundance_df = TRUE,
regenerate_weighted_moments_df = TRUE,
regenerate_stat_per_obs_df = TRUE,
regenerate_stat_per_rand_df = TRUE,
seed = 1312,
significativity_threshold = c(0.05, 0.95)
)
## We will try different strategies, with different number of randomisations
## with a fixed number of weights (98)
list(
strategies <-sequencial = future::sequential,
multisession = future::multisession
) list()
results_string <-
## We run the TAD with 10 and then with 1000 randomisations, with
## multiprocessing and without multiprocessing to see the difference
for (randomization_number in c(10, 1000)) {
$randomization_number <- randomization_number
tad_analysis_parameter
for (strat in names(strategies)) {
## We set the strategy
::plan(strategies[[strat]])
future
proc.time()[[1]]
time_before <-do.call(TAD::launch_analysis_tad, tad_analysis_parameter)
proc.time()[[1]] - time_before
ellapsed_time <-
length(results_string) + 1]] <- sprintf(
results_string[["[%s rand - %12s] The TAD Analysis took %s seconds.",
as.character(randomization_number),
as.character(strat),
as.character(ellapsed_time)
)
}## Always reset the strategy to sequential after your processing
::plan(future::sequential)
future
}#> Loading required package: foreach
#> Loading required package: future
cat(paste(results_string, collapse = "\n"), "\n")
#> [10 rand - sequencial] The TAD Analysis took 4.574 seconds.
#> [10 rand - multisession] The TAD Analysis took 6.907 seconds.
#> [1000 rand - sequencial] The TAD Analysis took 333.664 seconds.
#> [1000 rand - multisession] The TAD Analysis took 60.419 seconds.