Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:/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?

like image 425
user741819 Avatar asked Jun 03 '11 15:06

user741819


People also ask

Does OpenMP work in Windows?

Compile with -fopenmp to enable OpenMP. GCC binary builds are provided by Linux distributions, often with offloading support provided by additional packages, and by multiple entities for other platforms – and you can build it from source. Windows, Linux, and MacOSX.

How do I enable OpenMP?

Enable OpenMP Right-click on your project in Solution Explorer, and select properties. Select C/C++ -> Language, and change OpenMP Support to Yes.

What is OpenMP support?

OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared-memory multiprocessing programming in C, C++, and Fortran, on many platforms, instruction-set architectures and operating systems, including Solaris, AIX, FreeBSD, HP-UX, Linux, macOS, and Windows.


3 Answers

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)
like image 125
ivan-k Avatar answered Nov 14 '22 21:11

ivan-k


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.

like image 31
Dirk Eddelbuettel Avatar answered Nov 14 '22 21:11

Dirk Eddelbuettel


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.

like image 28
Triad sou. Avatar answered Nov 14 '22 21:11

Triad sou.