rclangopenmprcppintel-composer

installing Rcpp on R compiled with intel composer on OSX Yosemite


Inspite of succeeding with the compilation of R-3.1.2 using the intel suite of compilers ver.2015.0.077 including MKL on my late 2014 MacBook Pro running Yosemite (outlined here), I am unable to install the excellent Rcpp package that I have been thoroughly enjoying thus far via the prepackaged binary R for Mavericks. Now, I would like to speed things up a bit, in particular use OpenMP that is seemingly incompatible with the default clang. I am aware of the OpenMP/clang project but it seems that installation on Yosemite is still dodgy.

Apart from several mentions of Warning in strptime during make -j8, make install completes successfully and I am able to install most packages on the freshly compiled R. The Rcpp package nevertheless fails with:

> 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’

Is there a way to fix this? Alternatively, how can I switch compilers to be able to invoke 'OpenMP' via Rcpp on my MacBook?


Solution

  • Here's my best guess at what's going on. In Rcpp, we provide specializations for std::swap() here, with relevant bits copied for brevity:

    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
    
    }
    

    It looks like the moment at which your compiler is encountering this header, the appropriate template definition for std::swap() has not yet been seen, and so it barfs. This seems surprising to me since we do explicitly provide an #include <algorithm> in RcppCommon.h, which is included by default. Alternatively, maybe the headers used by your compiler define std::swap() in such a way that this form of specialization just doesn't work -- I am not sure.

    FWIW, cppreference advocates providing these specializations within the namespace wherein the types are defined, rather than std, to allow for ADL.

    You might try modifying the Rcpp sources locally to see if you can provide an alternate way of supporting std::swap() (as suggested by cppreference), and then proposing an upstream modification to Rcpp as well if all seems well.