Learn R Programming

mirai (version 2.6.0)

with_daemons: With Daemons

Description

Evaluate an expression using a specific compute profile.

Usage

with_daemons(.compute, expr)

local_daemons(.compute, frame = parent.frame())

Value

For with_daemons: the return value of expr.

For local_daemons: invisible NULL.

Arguments

.compute

(character) name of the compute profile. Each profile has its own independent set of daemons. NULL (default) uses the 'default' profile.

expr

(expression) to evaluate using the compute profile.

frame

(environment) scope for the compute profile setting.

Details

Will error if the specified compute profile is not yet set up.

Examples

Run this code
if (FALSE) { # interactive()
daemons(1, dispatcher = FALSE, .compute = "cpu")
daemons(1, dispatcher = FALSE, .compute = "gpu")

with_daemons("cpu", {
  m1 <- mirai(Sys.getpid())
})

with_daemons("gpu", {
  m2 <- mirai(Sys.getpid())
  m3 <- mirai(Sys.getpid(), .compute = "cpu")
  local_daemons("cpu")
  m4 <- mirai(Sys.getpid())
})

m1[]

m2[] # different to m1

m3[] # same as m1
m4[] # same as m1

with_daemons("cpu", daemons(0))
with_daemons("gpu", daemons(0))
}

Run the code above in your browser using DataLab