0

Possible Duplicate:
BOOST uBLAS matrix product extremely slow

I am trying to use uBlas library (in boost).

I wrote a simple code to multiple two large matrices. The result is too slow, when I compared the performance with Matlab and Octave, it was extremely slower. Would you please help me to solve the problem

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/operation.hpp>
int main () {
   using namespace boost::numeric::ublas;
   const int D = 1000;
   matrix<double> a (D, D);
   matrix<double> b (D, D);
   matrix<double> c (D, D);
   for (unsigned i = 0; i < a.size1 (); ++ i)
      for (unsigned j = 0; j < a.size2 (); ++ j){
         a (i, j) = ((i-j)<150)?1:0;   
         b (i, j) = 3 * i + j;
      }
    std::cout <<"Hi\n";
    axpy_prod(a, b,c, false);  // C = A * B
    //noalias(c) = prod(a,b);
    return 0;
}
Community
  • 1
  • 1
iampat
  • 1,062
  • 1
  • 11
  • 23
  • *how* slow, how fast would you expect it to be, what computer are you running it on, which compiler, and which compiler flags? – jalf Dec 06 '11 at 20:44
  • What was the MATLAB code, how did you do the timings, what were the timings? – David Heffernan Dec 06 '11 at 20:44
  • You might do better using a BLAS tailored to your hardware. For example, for Intel processor's use MKL. – Codie CodeMonkey Dec 06 '11 at 20:46
  • The only scenario where uBLAS will be _fast_ is if you use it with LAPACK bindings. – ildjarn Dec 06 '11 at 20:47
  • In matlab, I simply wrote c=a*b and matlab return the result in about one second. But, in uBlas, it took more then 20min! – iampat Dec 07 '11 at 00:24
  • My main reason for using uBlas/boost is its portability. – iampat Dec 07 '11 at 00:26
  • Now 20 min is really beyond any reason and there might be some other error. Oh, let me guess it didn't take 20 mins and you just aborted it after 20 mins? Are you sure `unsigned` is an `unsigned int` and not an `unsigned char`, so you get an infinite loop? – Christian Rau Dec 07 '11 at 18:44
  • @Christian : `unsigned` is definitely an alias for `unsigned int`, just as `long` is an alias for `long int`, and `short` for `short int`, etc. – ildjarn Dec 07 '11 at 21:14

0 Answers0