在OSX Yosemite上使用intel composer编译的R上安装Rcpp

时间:2015-02-20 16:44:07

标签: r clang openmp rcpp intel-composer

尽管使用英特尔编译器ver.2015.0.077汇编了R-3.1.2,包括MKL在2014年末运行Yosemite的MacBook Pro(概述here),我无法通过预先打包的二进制Rcpp为小牛安装我一直非常享受的优秀R包。现在,我想加快速度,特别是使用看似与默认OpenMP不兼容的clang。我知道OpenMP/clang项目,但似乎Yosemite上的安装仍然很狡猾。

除了在Warning in strptime期间提到make -j8时,make install成功完成,我能够在新编译的R上安装大多数软件包。但Rcpp包失败了:

> install.packages("Rcpp")

Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'Asia/Kolkata'
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'GMT'
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
  unknown timezone 'America/New_York'
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
Warning in as.POSIXlt.POSIXct(x, tz) : unknown timezone 'GMT'
Warning in as.POSIXlt.POSIXct(x, tz) :
  unknown timezone 'America/New_York'
** libs
icpc -I/Users/username/R-3.1.2/include -DNDEBUG -I../inst/include/ -I/sw/include -I/usr/local/include    -fPIC  -g -O3   -c Date.cpp -o Date.o
In file included from ../inst/include/Rcpp/Vector.h(69),
                 from ../inst/include/Rcpp.h(38),
                 from Date.cpp(31):
../inst/include/Rcpp/vector/swap.h(35): error: "swap" is not a class or function template name in the current scope
  RCPP_GENERATE_SWAP(generic_proxy,VECSXP)
  ^

In file included from ../inst/include/Rcpp/Vector.h(69),
                 from ../inst/include/Rcpp.h(38),
                 from Date.cpp(31):
../inst/include/Rcpp/vector/swap.h(36): error: "swap" is not a class or function template name in the current scope
  RCPP_GENERATE_SWAP(generic_proxy,EXPRSXP)
  ^

In file included from ../inst/include/Rcpp/Vector.h(69),
                 from ../inst/include/Rcpp.h(38),
                 from Date.cpp(31):
../inst/include/Rcpp/vector/swap.h(37): error: "swap" is not a class or function template name in the current scope
  RCPP_GENERATE_SWAP(string_proxy,STRSXP)
  ^

Date.cpp(562): warning #437: reference to local variable of enclosing function is not allowed
              2 * sizeof *sp + 4 * TZ_MAX_TIMES];
                          ^

compilation aborted for Date.cpp (code 2)
make: *** [Date.o] Error 2
ERROR: compilation failed for package ‘Rcpp’

有没有办法解决这个问题?或者,我如何切换编译器以便能够调用“OpenMP&#39;通过我的MacBook上的Rcpp

1 个答案:

答案 0 :(得分:2)

这是我对正在发生的事情的最好猜测。在Rcpp中,我们为std::swap() here提供了专业化,为简洁起见复制了相关位:

namespace std {

#undef RCPP_GENERATE_SWAP
#define RCPP_GENERATE_SWAP(TYPE,RTYPE)                          \
    template<> inline void swap< Rcpp::internal::TYPE<RTYPE> >( \
        Rcpp::internal::TYPE<RTYPE>& a ,                            \
        Rcpp::internal::TYPE<RTYPE>& b) {                           \
            a.swap(b) ;                                             \
        }

RCPP_GENERATE_SWAP(generic_proxy,VECSXP)
RCPP_GENERATE_SWAP(generic_proxy,EXPRSXP)
RCPP_GENERATE_SWAP(string_proxy,STRSXP)
#undef RCPP_GENERATE_SWAP

}

看起来您的编译器遇到此标头的时刻,尚未看到std::swap()的相应模板定义,因此barfs。这似乎让我感到惊讶,因为我们在#include <algorithm>中明确提供了RcppCommon.h,默认情况下包括在内。或者,也许您的编译器使用的标题定义std::swap(),这种形式的专业化不起作用 - 我不确定。

FWIW,cppreference提倡在命名空间内提供这些特化,其中定义类型而不是std,以允许ADL。

您可以尝试在本地修改Rcpp源,看看您是否可以提供支持std::swap()的替代方法(如cppreference所示),然后建议对Rcpp进行上游修改如果一切似乎都很好。