Matrix multiplication by vector slow with uBLAS

Asked by Nuno Lopes

Hi,

I was digging in my code to try to find some reason for the slowdown I get using the updated(>0.9.5) versions of dolfin,
(since the dolfin demos do not reproduce the huge time differences I have in my code).
I've found that the main issue is the matrix by vector multiplication that I use in some methods .
When using uBLAS backend I get a huge slowdown compared with PETSc

In the simple dolfin code below PETSc is at least 40 times faster.

Is this an expected behavior?

I reproduced the problem in a simple code:

main.cpp:
------------------------------------------------------------------------------
#include <dolfin.h>
#include "TestForm.h"

using namespace dolfin;

int main(int argc, char *argv[])
{
  parameters["linear_algebra_backend"]=argv[1];

  Timer maintimer(argv[1]);
  maintimer.start();

  UnitSquare mesh(100,100);
  TestForm::FunctionSpace V(mesh);
  TestForm::BilinearForm a(V,V);
  TestForm::LinearForm L(V);
  Constant f(1.0);
  L.f=f;

  Matrix A;
  assemble(A,a);

  Vector x;
  assemble(x,L);

  Vector y(x);
  y.zero();

  A.mult(x,y);

  maintimer.stop();
  summary();
}
-----------------------------------------------------------------
with
TestForm.ufl:
----------------------------------------------------------------
scalar = FiniteElement("Lagrange", "triangle", 1)
v = TestFunction(scalar)
u1 = TrialFunction(scalar)

f= Coefficient(scalar);

a = v*u1*dx
L = f*v*dx
------------------------------------------------------------------

using uBLAS approx 2.5s and with PETSc approx 0.06s.
Could someone please test the code...

Thanks in advance.
Nuno Lopes.

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Kristian B. Ølgaard (k.b.oelgaard) said :
#1

Confirmed, I got around a factor of 50 in favour of PETSc with the
development version of DOLFIN.

Kristian

On 16 July 2010 16:51, Nuno Lopes <email address hidden> wrote:
> New question #117960 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/117960
>
> Hi,
>
> I was digging in my code to try to find some  reason  for the  slowdown  I get using  the updated(>0.9.5) versions of dolfin,
> (since the dolfin demos do not reproduce the huge time differences I have in my code).
> I've found that the main issue is the matrix by vector multiplication that I use in some methods .
> When using uBLAS backend  I get a huge slowdown compared with PETSc
>
> In the simple dolfin code below PETSc is at least 40 times faster.
>
> Is this an expected behavior?
>
> I reproduced the problem in a simple code:
>
> main.cpp:
> ------------------------------------------------------------------------------
> #include <dolfin.h>
> #include "TestForm.h"
>
> using namespace dolfin;
>
> int main(int argc, char *argv[])
> {
>  parameters["linear_algebra_backend"]=argv[1];
>
>  Timer maintimer(argv[1]);
>  maintimer.start();
>
>  UnitSquare mesh(100,100);
>  TestForm::FunctionSpace V(mesh);
>  TestForm::BilinearForm  a(V,V);
>  TestForm::LinearForm L(V);
>  Constant f(1.0);
>  L.f=f;
>
>  Matrix A;
>  assemble(A,a);
>
>  Vector x;
>  assemble(x,L);
>
>  Vector y(x);
>  y.zero();
>
>  A.mult(x,y);
>
>  maintimer.stop();
>  summary();
> }
> -----------------------------------------------------------------
> with
> TestForm.ufl:
> ----------------------------------------------------------------
> scalar = FiniteElement("Lagrange", "triangle", 1)
> v  = TestFunction(scalar)
> u1 = TrialFunction(scalar)
>
> f= Coefficient(scalar);
>
> a = v*u1*dx
> L =  f*v*dx
> ------------------------------------------------------------------
>
> using uBLAS approx 2.5s and with PETSc approx 0.06s.
> Could someone please test the code...
>
> Thanks in advance.
> Nuno Lopes.
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp
>

Revision history for this message
Garth Wells (garth-wells) said :
#2

I have noticed some *major* slow downs in uBLAS lately. I'd say that there isn't much that we can do about. uBLAS as a project appears rudderless and not bothered about performance.

We should seriously consider removing support for uBLAS. We now have Armadillo available for dense linear algebra, and PETSc can be installed as package or via Dorsal. The motivations for adding uBLAS now longer hold.

Revision history for this message
Anders Logg (logg) said :
#3

On Fri, Jul 16, 2010 at 04:51:28PM -0000, Garth Wells wrote:
> Question #117960 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/117960
>
> Garth Wells proposed the following answer:
> I have noticed some *major* slow downs in uBLAS lately. I'd say that
> there isn't much that we can do about. uBLAS as a project appears
> rudderless and not bothered about performance.
>
> We should seriously consider removing support for uBLAS. We now have
> Armadillo available for dense linear algebra, and PETSc can be installed
> as package or via Dorsal. The motivations for adding uBLAS now longer
> hold.

I don't mind removing uBLAS, but perhaps we should wait a little while
longer. I remember that we considered removing MTL4 a while back but
then it started improving.

--
Anders

Revision history for this message
Garth Wells (garth-wells) said :
#4

On 18/07/10 19:56, Anders Logg wrote:
> On Fri, Jul 16, 2010 at 04:51:28PM -0000, Garth Wells wrote:
>> Question #117960 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/117960
>>
>> Garth Wells proposed the following answer:
>> I have noticed some *major* slow downs in uBLAS lately. I'd say that
>> there isn't much that we can do about. uBLAS as a project appears
>> rudderless and not bothered about performance.
>>
>> We should seriously consider removing support for uBLAS. We now have
>> Armadillo available for dense linear algebra, and PETSc can be installed
>> as package or via Dorsal. The motivations for adding uBLAS now longer
>> hold.
>
> I don't mind removing uBLAS, but perhaps we should wait a little while
> longer. I remember that we considered removing MTL4 a while back but
> then it started improving.
>

True. A difference is that MTL4 is actively mainatined and worries about
performance. Peter Gottschling responded to our concerns, which is why
we still support MTL4.

Garth

> --
> Anders
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Anders Logg (logg) said :
#5

On Sun, Jul 18, 2010 at 07:00:42PM -0000, Garth Wells wrote:
> Question #117960 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/117960
>
> Garth Wells proposed the following answer:
>
> On 18/07/10 19:56, Anders Logg wrote:
> > On Fri, Jul 16, 2010 at 04:51:28PM -0000, Garth Wells wrote:
> >> Question #117960 on DOLFIN changed:
> >> https://answers.launchpad.net/dolfin/+question/117960
> >>
> >> Garth Wells proposed the following answer:
> >> I have noticed some *major* slow downs in uBLAS lately. I'd say that
> >> there isn't much that we can do about. uBLAS as a project appears
> >> rudderless and not bothered about performance.
> >>
> >> We should seriously consider removing support for uBLAS. We now have
> >> Armadillo available for dense linear algebra, and PETSc can be installed
> >> as package or via Dorsal. The motivations for adding uBLAS now longer
> >> hold.
> >
> > I don't mind removing uBLAS, but perhaps we should wait a little while
> > longer. I remember that we considered removing MTL4 a while back but
> > then it started improving.
> >
>
> True. A difference is that MTL4 is actively mainatined and worries about
> performance. Peter Gottschling responded to our concerns, which is why
> we still support MTL4.
>
> Garth

True, but perhaps uBLAS will shape up. My impression is the Boost
libraries aim for high performance.

--
Anders

Can you help with this problem?

Provide an answer of your own, or ask Nuno Lopes for more information if necessary.

To post a message you must log in.