utils_parallel: Utils functions to control parallel process

Description Usage Arguments Details Value Functions Examples

Description

Control parallel process for parallel computation.

Usage

 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()

Arguments

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".

Details

There are two levels of controlling parallel process for computation:

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

In a R session enabling parallel process, we could control a function being able to running parallel process, for example:

1
2
3
4
        compute_indicator(ts_compute_vars, compute_fun, ...,
                  date_index_field = "stkcd"
                  c("date"), key_fields = NULL,
                  parallel = getOption("zstmodelr.common.parallel", TRUE))

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:

Value

parallel_status return a list containing parallel status, see details.

return a logic, TRUE mean parallel process is on.

Functions

Examples

 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)

chriszheng2016/zstmodelr documentation built on June 13, 2021, 8:59 p.m.