parfor.Rd
Sequential or parallel for loop.
parfor(
what,
args,
cl = NULL,
combine = c,
errorhandling = c("stop", "remove", "pass"),
verbose = FALSE,
show_progress = TRUE,
export = NULL,
...
)
A function.
A list of arguments.
Number of cores to use. If NULL
, the loop will be sequential. It -1, the number of cores will be detected automatically.
A function to combine the results.
A character string specifying how to handle errors. Possible values are "stop"
, "remove"
, and "pass"
.
A logical indicating whether to print progress.
A logical indicating whether to show a progress bar.
A list of objects to export to the workers.
Additional arguments to pass to what
for foreach::foreach
(excludind .combine
, .errorhandling
, .options.snow
, .verbose
, and .export
).
A list of results.
# Sequential
print(misc::parfor(function(x) x^2, 1:10))
#>
|
| | 0%
|
|======= | 10%
|
|============== | 20%
|
|===================== | 30%
|
|============================ | 40%
|
|=================================== | 50%
|
|========================================== | 60%
|
|================================================= | 70%
|
|======================================================== | 80%
|
|=============================================================== | 90%
|
|======================================================================| 100%
#> [1] 1 4 9 16 25 36 49 64 81 100
# Parallel
print(misc::parfor(function(x) x^2, 1:10, cl = 2))
#>
|
| | 0%
|
|======= | 10%
|
|============== | 20%
|
|===================== | 30%
|
|============================ | 40%
|
|=================================== | 50%
|
|========================================== | 60%
|
|================================================= | 70%
|
|======================================================== | 80%
|
|=============================================================== | 90%
|
|======================================================================| 100%
#> [1] 1 4 9 16 25 36 49 64 81 100