thread-control | R Documentation |
Use get_SparseArray_nthread
or set_SparseArray_nthread
to get or set the number of threads to use by the multithreaded
operations implemented in the SparseArray package.
get_SparseArray_nthread()
set_SparseArray_nthread(nthread=NULL)
nthread |
The number of threads to use by multithreaded operations implemented in the SparseArray package. On systems where OpenMP is available, this must be On systems where OpenMP is not available, the supplied |
Multithreaded operations in the SparseArray package are implemented in C with OpenMP (https://www.openmp.org/).
Note that OpenMP is not available on all systems. On systems where it's
available, get_SparseArray_nthread()
is guaranteed to return a
value >= 1. On systems where it's not available (e.g. macOS),
get_SparseArray_nthread()
returns 0 and
set_SparseArray_nthread()
is a no-op.
IMPORTANT: The portable way to disable multithreading is by calling
set_SparseArray_nthread(1)
, NOT set_SparseArray_nthread(0)
(the latter returns an error on systems where OpenMP is available).
get_SparseArray_nthread()
returns an integer value >= 1 on systems
where OpenMP is available, and 0 on systems where it's not.
set_SparseArray_nthread()
returns the previous nthread
value, that is, the value returned by get_SparseArray_nthread()
before the call to set_SparseArray_nthread()
. Note that the value
is returned invisibly.
SparseArray_matrixStats for SparseArray col/row summarization methods.
SparseMatrix_mult for SparseMatrix multiplication and cross-product.
SparseArray objects.
get_SparseArray_nthread()
if (get_SparseArray_nthread() != 0) { # multithreading is available
svt1 <- poissonSparseMatrix(77000L, 15000L, density=0.01)
## 'user' time is typically N x 'elapsed' time where N is roughly the
## number of threads that was effectively used:
system.time(cv1 <- colVars(svt1))
svt2 <- poissonSparseMatrix(77000L, 300L, density=0.3) * 0.77
system.time(cp12 <- crossprod(svt1, svt2))
prev_nthread <- set_SparseArray_nthread(1) # disable multithreading
system.time(cv1 <- colVars(svt1))
system.time(cp12 <- crossprod(svt1, svt2))
## Restore previous 'nthread' value:
set_SparseArray_nthread(prev_nthread)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.