简体   繁体   English

在 windows R 中使用 openmp,rtools 是否支持 openmp?

[英]using openmp in windows R, does rtools support openmp?

I got lots of error messages when trying to use openmp in a c++ code for building my R package on windows 7:当我尝试在 c++ 代码中使用 openmp 来构建我的 R package 时收到很多错误消息:C

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? Rtools 不支持 openmp 吗? Does anyone know how to use openmp in windows R packages please?有谁知道如何在 windows R 包中使用 openmp 吗?

In 2015, Rtools has openmp support under Windows, which plays nicely with Rcppp . 2015 年, Rtoolsopenmp下支持 openmp,与Rcppp配合得很好。 Here is a simple example creating a squares function for numeric vectors:这是一个为数字向量创建squares function 的简单示例:

// 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.我们还需要使用openmp编译标志创建src/Makevars.win In this example, the sample src/Makevars will work on linux:在此示例中,示例src/Makevars将适用于 linux:

# src/Makevars.win

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

No, per discussions on the R-devel mailing list .不,根据R-devel 邮件列表上的讨论。 It also came up on the Rcpp-devel list .它也出现在Rcpp-devel 列表中

R itself does not use OpenMP on Windows, so there is not support in Rtools. R 本身并没有在 Windows 上使用 OpenMP,因此 Rtools 中不支持。 On other OSs R does of course have OpenMP support.在其他操作系统上,R 当然支持 OpenMP。

By reference to these posts (R-devel mailing list), I tried to use OpenMP in windows R packages by using TDM-GCC .通过参考 这些帖子(R-devel 邮件列表),我尝试通过使用TDM-GCC在 windows R 包中使用 OpenMP。 It seems to run right.它似乎运行正确。

But I recommend to use officially supported OSs.但我建议使用官方支持的操作系统。 I don't know what problems will happen.我不知道会出现什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM