using openmp in windows R, does rtools support openmp?

非 Y 不嫁゛ 提交于 2019-12-04 10:03:52

No, per discussions on the R-devel mailing list. It also came up on the Rcpp-devel list.

R itself does not use OpenMP on Windows, so there is not support in Rtools. On other OSs R does of course have OpenMP support.

In 2015, Rtools has openmp support under Windows, which plays nicely with Rcppp. Here is a simple example creating a squares function for numeric vectors:

// src/example.cpp

#include <Rcpp.h>
#include <omp.h>
// [[Rcpp::plugins(openmp)]]]

// [[Rcpp::export]]
Rcpp::NumericVector squares (Rcpp::NumericVector data)
{
  Rcpp::NumericVector result(data.size());
  #pragma omp parallel
  {
    Rcpp::Rcout << omp_get_num_threads() << std::endl;
    for (int i = 0; i < data.size(); i++) {
      result[i] = data[i] * data[i];
    }

  }
  return result;
}

We also need to create src/Makevars.win with the openmp compilation flags. In this example, the sample src/Makevars will work on linux:

# src/Makevars.win

PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)

By reference to these posts (R-devel mailing list), I tried to use OpenMP in windows R packages by using TDM-GCC. It seems to run right.

But I recommend to use officially supported OSs. I don't know what problems will happen.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!