This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Help: enabling of eigen multithreading doesn't work

Tags: None
(comma "," separated)
maxleocorreacordova
Registered Member
Posts
3
Karma
0
Hi, I am using Eigen for my project. I want to exploit my hardware (8 cores) so I have enabled multithreading as explained in the reference link http://eigen.tuxfamily.org/dox/TopicMultiThreading.html. So I compile with:
g++ -fopenmp -o example example.cpp
and run with
OMP_NUM_THREADS=8 ./example.cpp
but the performance is still the same. When checking the system monitor, in run time it is only used one core as in the normal case. What is the correct form of using multithreading in Eigen??
Thanks in advance
Max
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
As explained in the doc:

Currently, the following algorithms can make use of multi-threading:

general dense matrix - matrix products
PartialPivLU
row-major-sparse * dense vector/matrix products
ConjugateGradient with Lower|Upper as the UpLo template parameter.
BiCGSTAB with a row-major sparse matrix format.
LeastSquaresConjugateGradient
maxleocorreacordova
Registered Member
Posts
3
Karma
0
Thanks for the reply. But I have some doubts. When running eigen, it seems to use only one core, even when compiling with -fopenmp and running with OMP_NUM_THREADS ./example. Is it possible to make Eigen use all my cores for the computation (matrix-matrix and matrix-product multiplications). If so, could you please give me an example how to compile?
thanks in advance
User avatar
nate-y
Registered Member
Posts
5
Karma
0
What is the code for your example.cpp? Not all operations are supported with OpenMP. Also, if your calculations are too small they might not show up on your resource manager.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Try the following:
Code: Select all
#include <Eigen/Core>
#include <iostream>
using namespace Eigen;
int main() {
 int n = 4000;
 MatrixXd A = MatrixXd::Ones(n,n);
 MatrixXd B = MatrixXd::Ones(n,n);
 MatrixXd C = MatrixXd::Ones(n,n);
 C.noalias() += A*B;
 std::cout << C.sum() << "\n";
}

This should really use all your cores!
maxleocorreacordova
Registered Member
Posts
3
Karma
0
:o Hey! it really worked. Thanks so much. I have a question. When using MPI for Eigen, should i compile with any options in order to have any different core as a process when running "mpirun -np "??? Please I would be grateful any advice using Eigen with mpi.
User avatar
nate-y
Registered Member
Posts
5
Karma
0
I can start you off with the basics of Open MPI, but I am not familiar with Eigen's specific interface.
To begin, search Google on "how to compile an MPI program" - it's well documented.
Here is a trivial way to use MPI for adding vectors, just to get you started.

Code: Select all

#include <mpi.h>
main( int argc, char** argv ){
int size, rank; // each process will be given a unique number
MPI_Init(&argc, &argv)
MPI_Comm_size(MPI_COMM_WORLD, &size); // np total
MPI_Comm_rank(MPI_COMM_WORLD, &rank); // unique rank
int n = 4000;
MatrixXd myMatrix = MatrixXd::Ones(n,n);
MatrixXd receiveMat = MatrixXd::Ones(n,n);
if( rank == 0 ){ // only process 0
  while( --size ) { // loop for each process except 0
    MPI_Recv( &(receiveMat.data), ... """args""" ... ); // receive data in buffer, Google will help you here
    myMatrix += receiveMat; // add the new data
  }
}
else{ // processors rank = [1..size] do this
  MPI_Send( &(myMatrix.data), ..."""to rank 0"""... """args""" ... ); // send my matrix data to rank 0, Google will help you here
}
 // only processor 0 has changed its values and it contains the solution
// every other process has the original matrices of ones
MPI_FINALIZE();
}
engr.mechie
Registered Member
Posts
2
Karma
0
I am using Eigen for CFD coding. I am utilizing Eigen's BiCGSTAB solver to solve the pressure Poisson equation, during the solution of Navier-Stokes equations.

I noticed that while BiCGSTAB solver alone (without preconditioner) utilizes multithreading effectively, when I use a preconditioner such as IncompleteLUT, multithreading no longer works! I understand that it may not work for the step:
solver.compute(A);

But it does not even work for this step:
x = solver.solve(b);

This is a problem because while I need only have to execute solver.compute(A) one time initially, solver.solve(b) has to be executed for every timestep. Due to this limitation, I have tested and found that the multithreaded BiCGSTAB without preconditioner is almost twice as fast as the sequential BiCGSTAB with IncompleteLUT preconditioner.

Am I missing something or is it a limitation of Eigen's BiCGSTAB solver?


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]