Generate a cluster and optimizes the affinity of the provided cluster to perform NUMA-like optimization and avoid as much as possible inter-core communication. Basically, makes core selection sequential in the order of provided clusters. Currently works only on Windows!!!
parallel.threading(cl = parallel::detectCores(), max_threads = parallel::detectCores(), first_thread = 1)
cl | Type: cluster or integer. A parallel cluster. When it is a number, creates a cluster with the specified number of parallel clusters. Defaults to |
---|---|
max_threads | Type: numeric. The maximum number of threads allowed (for all clusters together, not for each cluster). Make sure the result of |
first_thread | Type: numeric. The first core to use as the first thread to setup affinity. Useless for NUMA environments when using multiple R scripts. Defaults to |
The cluster itself.
# NOT RUN { # Cannot pass CRAN checks. Disabled. library(parallel) # Core 1-2, Core 3-4, Core 5-6, Core 7-8 cl <- parallel.threading(cl = 4, max_threads = 8) stopCluster(cl) # Core 5-6, Core 7-8 cl <- parallel.threading(cl = 2, max_threads = 4, first_thread = 4) stopCluster(cl) # }