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...?