<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=utf-8"> <META content="MSHTML 6.00.2900.3132" name=GENERATOR></HEAD> <BODY> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007>Hi Markus,</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007>First off, I think it might be a good idea to turn off debugging by defining:</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007>#define NDEBUG</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007>next, if you can assume no shared memory between the left and right side of the equation, then you can use noalias</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007>noalias(v) = prod(u,M);</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007>What are the time results with these changes?</SPAN></FONT></DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007></SPAN></FONT> </DIV> <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=531201115-29062007>Ian</SPAN></FONT></DIV> <BLOCKQUOTE> <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> ublas-bounces@lists.boost.org [mailto:ublas-bounces@lists.boost.org]<B>On Behalf Of </B>Markus Weimer<BR><B>Sent:</B> Friday, June 29, 2007 3:53 AM<BR><B>To:</B> ublas mailing list<BR><B>Subject:</B> [ublas] vector * Matrix is slow compared to hand written code<BR><BR></FONT></DIV>Hi,<BR><BR>we just did some experiments on the following case, which occurs often in our code:<BR><BR>v = prod(u,M)<BR><SPAN class=531201115-29062007><FONT face=Arial color=#0000ff size=2> </FONT></SPAN><BR>where v and u are dense vectors and M is a sparse matrix in compressed row major format.<BR><BR>We also did an alternative implementatio of prod called ourProd in the attached code. It follows the following algorithm: <BR><BR>for i in M.size1():<BR> v += u[i] * M[i,*]<BR><BR>where M[i,*] equals row i of M.<BR><BR>This version often is 10-20 times faster than the prod in uBLAS on sparse M. While this is all good, the implementation in test_fast() in the attached source is sometimes 1000 times faster on very sparse matrices, for example when running the code with the following parameters: <BR><BR> executable 100000 10000 1 0.001<BR><BR>The parameters are as follows:<BR><BR> executable ROWS COLS HOWOFTEN NONZEROPROBABILITY<BR><BR>where HOWOFTEN controls how often the experiments are run.<BR><BR>Do you see any way to achieve better performance within uBLAS for prod(u,M) with M being very sparse, as in 1 out of 1000 entries are set. <BR><BR>Thanks in advance,<BR><BR>Markus<BR></BLOCKQUOTE></BODY></HTML>