using openmp in windows R, does rtools support openmp?

半城伤御伤魂 提交于 2019-12-06 07:03:09

问题


I got lots of error messages when trying to use openmp in a c++ code for building my R package on windows 7:

c:/rtools/mingw/bin/../lib/gcc/mingw32/4.5.0/libgomp.a(parallel.o):(.text+0x19): undefined      reference to `_imp__pthread_getspecific'
c:/rtools/mingw/bin/../lib/gcc/mingw32/4.5.0/libgomp.a(parallel.o):(.text+0x7a): undefined reference to `_imp__pthread_mutex_lock'
c:/rtools/mingw/bin/../lib/gcc/mingw32/4.5.0/libgomp.a(env.o):(.text+0x510): undefined reference to `_imp__pthread_mutex_init'

...

Is Rtools not supporting openmp? Does anyone know how to use openmp in windows R packages please?


回答1:


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.




回答2:


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)



回答3:


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.



来源:https://stackoverflow.com/questions/6228924/using-openmp-in-windows-r-does-rtools-support-openmp

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