0

Since my research involves doing large matrix products I am trying to enable OpenMP multi-threading capabilities for Eigen. Unfortunately I haven't had any luck so far.

I use Xcode 7 with the following compiler: gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix

After that I have configured the number of OpenMP threads I want to use, by setting export OMP_NUM_THREADS=4. Then I compile my program using the following flags: -O3 -fopenmp=libomp -DNDEBUG. However trying to set or print the number of threads used by Eigen always returns 1. So it looks like only one thread is used:

#include <Eigen/Dense>
...
Eigen::initParallel();
Eigen::setNbThreads(4);
int nthreads = Eigen::nbThreads( );
std::cout << "THREADS = " << nthreads <<std::ends; // returns '1'

Anyone has any idea why Eigen is only using one thread? According to the steps on the Eigen website (http://eigen.tuxfamily.org/dox/TopicMultiThreading.html) this should work...?

maxshuty
  • 9,708
  • 13
  • 64
  • 77
verified.human
  • 1,287
  • 3
  • 17
  • 26
  • Are you sure that your OMP_NUM_THREADS environment variable is actually being passed as a preprocessor definition? I'm not sure if all environment variables are treated as such when using gcc. – Jack O'Reilly Jan 06 '16 at 18:10
  • Never mind -- just saw that the env variable in question is checked at runtime, as specified in the Eigen multithreading docs. – Jack O'Reilly Jan 06 '16 at 18:12
  • Your compiler does not implement OpenMP. – ggael Jan 06 '16 at 20:55
  • Are you sure my compiler does not support OpenMP? Since I am using all the latest OSX software (El Capitan, Xcode 7), I would think OpenMP is supported since it is listed here as supported compiler on the [official website](http://openmp.org/wp/openmp-compilers/). If you are right and OpenMP is not supported by my compiler. What would your advise be? – verified.human Jan 06 '16 at 21:51
  • @verified.human Try it. Add a parallel section with that prints the thread number: `#pragma omp parallel { printf("Hello World from thread = %d\n", omp_get_thread_num()); }` Just make sure that you add a line break after the `pragma` line (I can't do that in comments). – Avi Ginsburg Jan 07 '16 at 09:13
  • 1
    See http://stackoverflow.com/questions/33668323/clang-omp-in-xcode-under-el-capitan/33687414 – High Performance Mark Jan 07 '16 at 13:33
  • @verified.human This website is listing clang 3.7, but not Apple's clang 7.0.x – ggael Jan 08 '16 at 21:00
  • @verified.human, Did you solve ti? Thank You. – Royi Feb 06 '17 at 15:50

0 Answers0