::setUseOpenMP(TRUE) SLmetrics
#> OpenMP usage set to: enabled
{SLmetrics} supports parallelization through OpenMP. In this section this functionality is introduced.
OpenMP is disabled by default
, but can be enabled as follows:
::setUseOpenMP(TRUE) SLmetrics
#> OpenMP usage set to: enabled
And disabled as follows:
::setUseOpenMP(FALSE) SLmetrics
#> OpenMP usage set to: disabled
By default
all cores are used. To control the amount of cores, see the following code:
::setNumberThreads(3) SLmetrics
#> Number of threads set to: 3
To use all cores:
::setNumberThreads(-1) SLmetrics
#> Number of threads set to: All (4 threads)
# 1) set seed for reproducibility
set.seed(1903)
# 2) create classification
# problem
<- create_factor()
fct_actual <- create_factor() fct_predicted
::setUseOpenMP(TRUE) SLmetrics
#> OpenMP usage set to: enabled
benchmark(
`With OpenMP` = SLmetrics::cmatrix(fct_actual, fct_predicted)
)
#> # A tibble: 1 × 4
#> expression execution_time memory_usage gc_calls
#> <fct> <bch:tm> <bch:byt> <dbl>
#> 1 With OpenMP 3.85ms 0B 0
::setUseOpenMP(FALSE) SLmetrics
#> OpenMP usage set to: disabled
benchmark(
`Wihtout OpenMP` = SLmetrics::cmatrix(fct_actual, fct_predicted)
)
#> # A tibble: 1 × 4
#> expression execution_time memory_usage gc_calls
#> <fct> <bch:tm> <bch:byt> <dbl>
#> 1 Wihtout OpenMP 8.6ms 0B 0