Description Usage Arguments Details Value Functions Examples
Control parallel process for parallel computation.
1 2 3 4 5 6 7 8 9 10 11 12 13 | enable_parallel(
env_globals = .pkg_globals,
parallel_switch_option = "zstmodelr.common.parallel"
)
disable_parallel(
env_globals = .pkg_globals,
parallel_switch_option = "zstmodelr.common.parallel"
)
parallel_status(env_globals = .pkg_globals)
parallel_is_on()
|
env_globals |
a environment with parallel process information. Default .pkg_globals means to use global vars of the package. NULL means to use environment of caller. |
parallel_switch_option |
a string name of option to turn on/off parallel computation in functions with parallel feature. Default is "zstmodelr.common.parallel". |
There are two levels of controlling parallel process for computation:
Global level: enable/disable parallel process for R session.
Through enable_parallel
, we could set parallel process ready for current R
session by initiating back-end clusters which normally are processes running
on multiple cores in a computer, and setting zstmodelr.common.parallel
option to TRUE.
we could use disable_parallel
to shut parallel process by closing
back-end clusters and setting zstmodelr.common.parallel
option to FALSE
Function level: enable/disable parallel process for running functions.
In a R session enabling parallel process, we could control a function being able to running parallel process, for example:
1 2 3 4 |
Its argument parallel
controls whether the function run in parallel process
or sequential process, whose default value is from options of
zstmodelr.common.parallel
or TRUE. By default, zstmodelr.common.parallel
is controlled by enable_parallel
and disable_parallel
as well.
In addition, parallel_status
could provide current status of parallel
process and configuration options, which return a list including following
fields:
cluster: a object with class of c("SOCKcluster", "cluster") containing information about back-end clusters for parallel process.
parallel_log: a path of parallel log file containing log info from parallel process.
foreach_workers: a number of current process workers ready for foreach computation.
zstmodelr.common.clusters: a number of clusters to be used for parallel process.
zstmodelr.common.parallel: a logical as default value for parallel argument of function with ability of parallel computation.
parallel_status
return a list containing parallel status, see details.
return a logic, TRUE mean parallel process is on.
enable_parallel
: enable parallel process by initiating back-end
clusters.
disable_parallel
: disable parallel process by stopping back-end
clusters.
parallel_status
: get current status of parallel process.
parallel_is_on
: Judge whether parallel process is on or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ## Not run:
# Set clusters number of parallel process
options(zstmodelr.common.clusters = 4)
# Enable parallel process for the R session
enable_parallel()
# Inspect status of parallel process
parallel_status()
# Conduct parallel computation ...
# compute indicators by parallel process
ds_indicator <- compute_indicator(ds_vars,
compute_fun = ind_def_fun,
date_index_field = "date",
key_fields = "stkcd"
)
# compute indicators by sequential process
ds_indicator <- compute_indicator(ds_vars,
compute_fun = ind_def_fun,
date_index_field = "date",
key_fields = "stkcd",
parallel = FALSE
)
# Disable parallel process for the R session
disable_parallel()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.