且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 ClusterEvalQ 编译 Rcpp 函数

更新时间:2023-11-24 11:33:28

是的,有一种方法可以加快编译速度,只需一次.

Yes, there is a way to speed it up by taking the compilation hit only once.

特别是,将所有已编译的代码移动到R包中.从那里,将 R 包安装到集群上,然后加载该包.在并行代码中,调用包中的函数.

In particular, move all the compiled code into an R package. From there, install the R package onto the cluster and, then, load the package. Inside the parallel code, call the function in the package.

这是必需的,因为导入到 R 中的 C++ 函数是特定于会话的.因此,每个会话都需要自己的编译.编译是昂贵"的部分.

This is required because C++ functions imported into R are session-specific. As a result, each session requires its own compilation. The compilation is the "expensive" part.

另外,不要 使用 inline.相反,您应该使用 Rcpp 属性.