Rcpp::List 线程中的 accessing/setting 个元素是否安全?
Is accessing/setting elements in a Rcpp::List thread safe?
我想在列表的列表上执行 Rcpp 内部的有效并行 lapply,有效地执行列表中的 taking/removing 元素并使用它们进行计算。
基本上做 Rcpp parallel 做的事情,但使用列表而不是数字向量。在 Rcpp 中 getting/setting 如果由数字索引完成,列表元素线程安全吗?
下面我想做的事情的伪代码:
List original = // created somewhere else,
List results = List(original.size());
// Is this function thread safe?
auto func = [original&, results&](int i) {
List data = original[i];
// Calculate a new List, stuff
results[i] = stuff;
};
```
你问
In Rcpp is getting/setting a list element thread safe if done by numeric index?
答案(通常)是公司 "No" 因为(给予或接受)没有 关于 R 和 R 数据结构是。
查看现有的关于将 OpenMP 与 R 一起使用的文章,包括 Writing R Extensions —— 在第 1.2.1.1 节中明确指出
Calling any of the R API from threaded code is ‘for experts only’: they will need to read the source code to determine if it is thread-safe. In particular, code which makes use of the stack-checking mechanism must not be called from threaded code.
另请参阅我们的 Rcpp Gallery on OpenMP as well and the fine documentation for RcppParallel 及其示例了解更多信息。
我想在列表的列表上执行 Rcpp 内部的有效并行 lapply,有效地执行列表中的 taking/removing 元素并使用它们进行计算。 基本上做 Rcpp parallel 做的事情,但使用列表而不是数字向量。在 Rcpp 中 getting/setting 如果由数字索引完成,列表元素线程安全吗?
下面我想做的事情的伪代码:
List original = // created somewhere else,
List results = List(original.size());
// Is this function thread safe?
auto func = [original&, results&](int i) {
List data = original[i];
// Calculate a new List, stuff
results[i] = stuff;
};
```
你问
In Rcpp is getting/setting a list element thread safe if done by numeric index?
答案(通常)是公司 "No" 因为(给予或接受)没有 关于 R 和 R 数据结构是。
查看现有的关于将 OpenMP 与 R 一起使用的文章,包括 Writing R Extensions —— 在第 1.2.1.1 节中明确指出
Calling any of the R API from threaded code is ‘for experts only’: they will need to read the source code to determine if it is thread-safe. In particular, code which makes use of the stack-checking mechanism must not be called from threaded code.
另请参阅我们的 Rcpp Gallery on OpenMP as well and the fine documentation for RcppParallel 及其示例了解更多信息。