Search code examples
c++multithreadingparallel-processingopenmpeigen

Make Eigen run in a Multi-Thread


I have some questions regarding Eigen parallelization.

To my understanding, Eigen handles its internal parallelization but I want to activate multi threading. I just started compiling with G++ using the flag "-fopenmp" and running my executable with OMP_NUM_THREADS=4 ./exec.

Some parts of the code that run only using C++ code I used:

#pragma omp parallel
{
}

Looking at my system monitor I can see that sometimes I used more than one thread, but most of the time it isn't. I don't know if I have to use additional OpenMp code.

In the following link:

https://eigen.tuxfamily.org/dox/TopicMultiThreading.html

They mention that "in the case your application is parallelized with OpenMP, you might want to disable Eigen's own parallization as detailed in the previous section", but I don't really understand if I have to or how to do it.

I hope I am not mixing concepts here.

My thanks in advance.


Solution

  • Quoting from the link you posted:

    Currently, the following algorithms can make use of multi-threading: general matrix - matrix products PartialPivLU

    Thus, without knowing exactly what your program is doing, I'd hazard a guess that it's not mostly large matrix-matrix multiplications and/or PartialPivLU. This only regards Eigen's internal parallelization. What you do within the omp parallel blocks will probably run as expected (multiple threads).