2

I am trying to solve a linear system of equations of the form Ax=b with the LeastSquaresConjugateGradient of the Eigen library and A is a sparse matrix.

LeastSquaresConjugateGradient < SparseMatrix < double > > solver;

solver.compute( A );

x = solver.solve( b );

In principle it works perfectly. But I want to use this for quite huge matrices and hence it would be nice to run this in parallel. The Eigen documentation only mentions to put the following lines on top.

omp_set_num_threads( 2 );

setNbThreads( 2 );

Moreover the documentation states that the LeastSquaresConjugateGradient routine should work in parallel.

I also set the number of threads in bash by export OMP_NUM_THREADS=2

But still I get no performance gain at all. What am I doing wrong??

zodiac
  • 291
  • 2
  • 15
  • Make sure you compile with OpenMP support, e.g., `-fopenmp` with gcc or clang. Don't expect a x2 with 2 threads though. – ggael May 29 '18 at 13:08
  • I did compile with -fopenmp. I am not expecting a 2 times faster code. But at least it should be slightly faster than the serial version – zodiac May 29 '18 at 14:52
  • 1
    how large is your test matrix? additional threads come with an additional overhead. if your test matrix is too small you might not see a speed up. – Bort May 30 '18 at 13:00
  • I made tests with several sizes N=10,20,50,100,150 but could not observe a speed up – zodiac Jun 04 '18 at 06:29
  • 1
    This is extremely tiny for sparse matrices whose sizes rather range from 10000^2 to 10000000^2. – ggael Jun 07 '18 at 08:37
  • @ggael I agree, but I think at least I should see a number greater than 100% for the CPU usage when looking with top if the code would run in parallel. And this is not the case; or am I wrong? – zodiac Jun 08 '18 at 06:12
  • No because Eigen will explicitly disable multi-threading if there is not enough work to do, see the respective line of [code](https://bitbucket.org/eigen/eigen/src/94a7dc5d6049149ad474e828a07b9e0484c7760f/Eigen/src/SparseCore/SparseDenseProduct.h#lines-49). If you comment this line it will use multiple threads but then expect a slowdown!! – ggael Jun 08 '18 at 13:50

0 Answers0