Deep Multithreading {base} | R Documentation |
Tools for working with multithreading and concurrency.
thread.time() import(...) cache(value) nocache(...) cacheenv(env) thread.attach(what, pos = 2L, name = deparse(substitute(what)), warn.conflicts = TRUE) thread.detach(pos = 2L) thread.search() sync.inspect(thread = NULL) sync.cleanup() sync.remove(obj.addr) define(...) show.code()
env |
an environment. |
value |
a 'logical' object of length one. |
obj.addr |
a character representing an object memory address in hexadecimal format. |
thread |
a character. |
'thread.time' returns a numeric vector of two zero elements, when called the first time by the calling thread. In subsequent calls, it returns the total time elapsed from the first call and the time increment elapsed from the last call.
import
finds and puts objects into the environment where
the call is made.
cache
enables cache, with value=TRUE, and disable cache, with value = FALSE, for the environment where such calls are made.
Objects in cache tables are bindings from where they were found.
nocache
prevents named values from being cached locally.
cacheenv
finds the cache hashtable of its argument 'env'
and returns an environment object enclosing the hashtable or
NULL if 'env' doesn't have a cache hashtable.
'sync.inspect' reports the objects used for synchronization, by
sync.eval
, wait
, and wait
functions.
sysn.cleanup
removes the objects that were used for synchronization
but no longer used by the alive threads for synchronization.
Such objects are removed automatically for normal evaluations, but
can continue to exist due to thread cancellations.
sysn.remove
removes the objects specified by its arguments.
These arguments must be character representing memory addresses
of objects. When called with no argument, it returns
the addresses of all the objects that can be removed.
thread.attach
,
thread.detach
, and
thread.search
are similar to
attach
,
detach
, and
search
, but from the .ThreadEnv
instead of .GlobalEnv
.
define
and show.code
are two primitive function.
They are an part of a new experiment for developing
simple but efficient runtime code for large number of iterations.
These functions are experimental tools.
Chuanhai Liu, ...
http://www.stat.purdue.edu/~chuanhai/SupR/
'start.master', 'start.worker', 'start.driver',
and thread
.
new.thread({ print(thread.time()) thread.sleep(10) print(thread.time()) thread.sleep(30) thread.time() }, join = TRUE) # Display bindings cached in the global cache: e <- cacheenv(globalenv()) ls(e) # Display bindings cached in the .ThreadEnv ls(new.thread({cacheenv(environment())}, join=T)) # Import objects with the import function: new.thread({import(var, "print"); ls()}, join = TRUE) new.thread({ cache(TRUE); nocache(var); var <- 2}, join=T) new.thread({ cache(TRUE); nocache(var); var}, join=T) new.thread({ cache(TRUE); nocache(var); ls()}, join=T) new.thread({ cache(TRUE); sin(1); cache(FALSE); cos(1); cache(TRUE); log(1); ls(cacheenv(environment()))}, join=T) ## ## The experimental version of the define() and show.code() functions ## ## An artificial example: ## new.thread({ thread.time() define(Y = numeric(1000000), i=0L, X = as.numeric(1:1000000), j=0L) # show.code(Y, i, X, j) for(i in 1:10) { define(Y = numeric(1000000), X = numeric(1000000), j=0L) # show.code(Y, X, j) print(i) for(j in 1:10000) { Y[j+i] <- i + j X <- Y } } list(Y) thread.time() }, join=T) ## ## Run it in R ? ## system.time({ Y = numeric(1000000) X = numeric(1000000) for(i in 1:10) { print(i) for(j in 1:10000) { Y[j+i] <- i + j X <- Y } } list(Y) })