
Ublas : 
Subject: Re: [ublas] Matrix multiplication performance
From: Michael Lehn (michael.lehn_at_[hidden])
Date: 20160118 08:04:29
Hi Palik and Oswin,
I attached a simple implementation of a matrixmatrix product (gemm.hpp) which has less
then 250 lines of code. I also attached a simple test programm (matprod.cc). The test
Programm has a simple wrapper for the implementation in gemm.hpp. For a real applications
you should use traits like for the BLAS bindings. You can compile it with
g++ O3 Wall std=c++11 I $BOOST_PATH matprod.cc
where BOOST_PATH contains your boost implementation. Let me know if this works
for you.
Cheers,
Michael

Dr. Michael Lehn
University of Ulm, Institute for Numerical Mathematics
Helmholtzstr. 20
D89069 Ulm, Germany
Phone: (+49) 731 5023534, Fax: (+49) 731 5023548

On 18 Jan 2016, at 09:25, Oswin Krause <Oswin.Krause_at_[hidden]> wrote:
> Hi Palik,
>
> this is a known problem. In your case you should already get better performance when using axpy_prod instead of prod. There are currently moves towards a ublas 2.0 which should make this a nonproblem in the future.
>
>
> On 20160117 21:23, palik imre wrote:
>> Hi all,
>> It seems that the matrix multiplication in ublas ends up with the
>> trivial algorithm. On my machine, even the following function
>> outperforms it for square matrices bigger than 173*173 (by a huge
>> margin for matrices bigger than 190*190), while not performing
>> considerably worse for smaller matrices:
>> matrix<double>
>> matmul_byrow(const matrix<double> &lhs, const matrix<double> &rhs)
>> {
>> assert(lhs.size2() == rhs.size1());
>> matrix<double> rv(lhs.size1(), rhs.size2());
>> matrix<double> r = trans(rhs);
>> for (unsigned c = 0; c < rhs.size2(); c++)
>> {
>> matrix_column<matrix<double> > out(rv, c);
>> matrix_row<matrix<double> > in(r, c);
>> out = prod(lhs, in);
>> }
>> return rv;
>> }
>> Is there anybody working on improving the matrix multiplication performance?
>> If not, then I can try to find some spare cycles ...
>> Cheers,
>> Imre Palik
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>> Sent to: Oswin.Krause_at_[hidden]
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: michael.lehn_at_[hidden]