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

Multithreading and matrix-vector product

Tags: None
(comma "," separated)
matriza
Registered Member
Posts
17
Karma
0
Hi,

I've got two versions of code that essentially do the power iterations for SVD of 5000x120,000 matrices, one that first computes the 5000x5000 covariance and then uses that and another that multiplies alternately by X and X^T and uses less memory but is about 6x slower even taking into account computation of the covariance. Both running with 16 openmp threads with NDEBUG.

Am I right in understanding that matrix-matrix products are multi-threaded but matrix-vector products are not?

Since a vector is pretty much a matrix, is there way to "hack" it so that matrix-vector products are run by the matrix-matrix code?

Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Yes, for instance:
Code: Select all
VectorXd v;
MatrixXd M;
M * v; // detected as matrix-vector
M * MatrixXd::Map(v.data(), v.rows(), v.cols()); // detected as matrix-matrix

however don't expect any gain from this hack as multi-threading is not very efficient on matrix-vector problems (memory bound). The overall performance might even be slower.
You might also try:
Code: Select all
#pragma omp parallel for
for(int k=0; k<16; ++k)
{
  int start = (r.size()/16)*i;
  int count = k==15 ? r.size()-start : r.size()/16;
  r.segment(start,count) = M.middleRows(start,count) * v;
}

Please let us know whether you get any speedup from this. Also, make sure that you have 16 hardware cores, not 8 multi-threaded ones. In the later case, use 8 threads instead of 16.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]