[Rcpp-devel] Fwd: fatal error: 'omp.h' file not found

aakremena at aol.com aakremena at aol.com
Mon Mar 14 22:42:27 CET 2016


 Hi everyone and thank you for your advice.

Seems like a possible solution for the problem on OS X Mavericks is as follows:
    1. Install clang-omp,
          If you use homebrew as a package management system, insert in terminal
                brew install clang-omp
    2. Change the content of the your_home_directory/.R/Makevar file (say, using OS X built-in nano editor) from the default content
            CC=clang
            CXX=clang++

to

        CC=clang-omp
        CXX=clang-omp++
        CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
        CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
        FLIBS=lgfortran

Once this is done, the OpenMP works on OS X Mavericks.

Say, on my MacBook Pro 8,3 ( with 4 physical cores and 8 logical ones), Intel Core i7, 2.3 Ghz, L2 Cache (per core) 256 kB, L3 Cache 8 MB,
        the simple test function function omp_test

#include <RcppArmadillo.h>
#include <math.h>
#include <omp.h>
#include<map>
#include<vector>
#include<random>

//[[Rcpp::plugins(openmp)]]
//[[Rcpp::depends(RcppArmadillo)]]

// [[Rcpp::export]]
long omp_test(int nn) {
  long m = 0;
  omp_set_num_threads(8);
  #pragma omp parallel for schedule(auto)
  for(int i = 1; i < nn; ++i) {
    m = m + log(i);
  }

  Rcpp::Rcout << "m is: " << m << std::endl;
  return(m);
}

     with nn = 1,000,000,000 run from R with
R> ptc <- Sys.time()
R> b <- ala(1000000000)
R> print(Sys.time() - ptc)


runs for 10.75 sec with 1 thread 
              3.6 sec with 4 threads (speadup = 3)              
              2.5 sec with 8 threads (speedup = 4.3)

Again, thank you all for your prompt and competent advice.

Anguel


 

 

-----Original Message-----
From: aakremena <aakremena at aol.com>
To: krthornt <krthornt at uci.edu>; rcpp-devel <rcpp-devel at r-forge.wu-wien.ac.at>
Sent: Mon, Mar 14, 2016 11:55 am
Subject: Fwd: [Rcpp-devel] fatal error: 'omp.h' file not found



 Sorry,

I guess James' e-mail contains some directions, albeit not for RStudio specifically.  I'll try them.

Thanks.

Anguel

 

 

-----Original Message-----
From: aakremena <aakremena at aol.com>
To: krthornt <krthornt at uci.edu>; rcpp-devel <rcpp-devel at r-forge.wu-wien.ac.at>
Sent: Mon, Mar 14, 2016 11:45 am
Subject: Re: [Rcpp-devel] fatal error: 'omp.h' file not found


Hi James and Kevin,

Thank you very much for the advices (I'll try James' directions shortly).

But I have already installed clang-omp via

                    $ brew install clang-omp

The compiler is available at /usr/local/Library/Formula/clang-omp.rb


Can I ask you for some directions as to how to configure clang-omp with RStudio (if possible), i.e. how to make R recognize clang-omp?

Thank you in advance.

Anguel

 

 

 

-----Original Message-----
From: Kevin Thornton <krthornt at uci.edu>
To: rcpp-devel at lists.r-forge.r-project.org <rcpp-devel at r-forge.wu-wien.ac.at>
Sent: Mon, Mar 14, 2016 11:33 am
Subject: Re: [Rcpp-devel] fatal error: 'omp.h' file not found



One may also use clang-omp from Homebrew if you wish to still use clang on OS X, but have OpenMP.


--Kevin


On Mon, Mar 14, 2016 at 9:31 AM Balamuta, James Joseph <balamut2 at illinois.edu> wrote:



Greetings and Salutations,
 
OS X does not currently support OpenMP under the default compiler (clang). Hence, you are receiving an error as it relates to the header file not being found. For more details, see:
 
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#OpenMP-support
 
Support for OpenMP with clang should be arriving sometime in June after WWDC as the intel funded clang-OpenMP feature has been merged into the main clang branch. (http://openmp.llvm.org/ , https://clang-omp.github.io/ )

If this is just for personal use, you may wish to set the ~/.R/Makevar information for R via:

https://cran.r-project.org/doc/manuals/r-release/R-admin.html#OS-X-packages

VER=-4.8 
CC=gcc$(VER)
CXX=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-lgfortran
 
Sincerely,
 
JJB
 
From: rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:rcpp-devel-bounces at lists.r-forge.r-project.org]On Behalf Of aakremena at aol.com
Sent: Monday, March 14, 2016 10:01 AM
To: rcpp-devel at lists.r-forge.r-project.org
Subject: [Rcpp-devel] fatal error: 'omp.h' file not found


 
Dear Rcpp development list members,

I am trying to use OpenMP with Rcpp.  The code (placed in omp_experiment.cpp file) is pretty basic:

#include <RcppArmadillo.h>
#include <omp.h>

//[[Rcpp::plugins(openmp)]]
//[[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;

// [[Rcpp::export]]
int timesTwo(int x) {
   return x * 2;
}



Once I try to compile the file I get the error output

clang: warning: argument unused during compilation: '-fopenmp'
omp_experiment.cpp:2:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^
1 error generated.
make: *** [omp_experiment.o] Error 1
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include  -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.2/Resources/library/RcppArmadillo/include" -I"/Users/anguelgrigorov/Documents/Business/MISO/R/Functions/Trading/Experiments"   -fopenmp  -fPIC  -Wall -mtune=core2 -g -O2  -c omp_experiment.cpp -o omp_experiment.o
Error in Rcpp::sourceCpp("Documents/Business/MISO/R/Functions/Trading/Experiments/omp_experiment.cpp") :
  Error 1 occurred building shared library.

My QUESTION: How to configure OpenMP to work with Rcpp on my system?

I am working with RStudio, version 0.98.945 on Mac OS X Mavericks.

Every insight into this will be highly appreciated.

Thank you very much in advance.

Anguel


P.S. I've done some reading on the Internet that advised me to check whether omp.h is even available on my laptop (MacBook Pro).  I have used OS X
        locate "omp.h" command that proved that omp.h is indeed available in 4 locations:

/usr/local/Cellar/gcc/5.3.0/lib/gcc/5/gcc/x86_64-apple-darwin13.2.0/5.3.0/include/omp.h
/usr/local/Cellar/gcc6/6-20160124/lib/gcc/6/gcc/x86_64-apple-darwin13.2.0/6.0.0/include/omp.h
/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2/include/omp.h
/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0/include/omp.h

_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel


_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160314/835f7f36/attachment-0001.html>


More information about the Rcpp-devel mailing list