## Re: [Libmesh-users] SparseMatrix multiplication.

 Re: [Libmesh-users] SparseMatrix multiplication. From: Kirk, Benjamin (JSC-EG311) - 2012-09-17 18:06:23 ```>>> That's good to keep in mind. PETSc performance (at least in the older >>> versions where I've made this mistake) becomes atrocious if it's asked >>> to create new non-zero matrix entries on the fly without >>> preallocation. >> >> Presumably MatMatMult in PETSc (or the equivalent in trilinos) handles >> this in some sensible way though. > > Sensible in the sense that "ask the user to estimate the ratio > nnz(A*B)/(nnz(A)+nnz(B))" is probably the least bad of a bunch of bad > alternatives. > > That's kind of a quirky thing to try and encapsulate in a > non-solver-specific API, though... Yep. Back to the origin of the question then - do you really *need* the product? Since sparse matrix multiplication is not trivial it may be preferable to carry out the action of the sparse matrix - for example a matvec C=A*B y=C*x instead could be carried out as y = (A*B)*x = A*(B*x) which would eliminate the need for explicitly forming C. Similar things can be done with solves, but there I'm not sure you'd gain anything! -Ben ```

 [Libmesh-users] SparseMatrix multiplication. From: Andrew E Slaughter - 2012-09-17 14:42:22 ```I need to multiply two SparseMatrix objects together, in parallel, does libMesh have this functionality? One possible solution is to use the PETSc MatMatMult function, but this requires that I use PetscMatrix objects, which I also cannot figure out how to do. Can someone indicate how I can specify the ImplicitSystem::matrix and a matrix added with ImplicitSystem::add_matrix can be PetscMatrix objects. Thanks, Andrew -- Andrew E. Slaughter, PhD andrew.e.slaughter@... Materials Process Design and Control Laboratory Sibley School of Mechanical and Aerospace Engineering 169 Frank H. T. Rhodes Hall Cornell University Ithaca, NY 14853-3801 (607) 229-1829 http://aeslaughter.github.com/ ```
 Re: [Libmesh-users] SparseMatrix multiplication. From: Kirk, Benjamin (JSC-EG311) - 2012-09-17 14:48:33 ```Check the PETSC matrix libmesh documentation - I think there is a method to return the raw PETSC object. I know there is for vectors anyway! -Ben On Sep 17, 2012, at 9:42 AM, "Andrew E Slaughter" wrote: > I need to multiply two SparseMatrix objects together, in parallel, does > libMesh have this functionality? > > One possible solution is to use the PETSc MatMatMult function, but this > requires that I use PetscMatrix objects, which I also cannot figure out how > to do. Can someone indicate how I can specify the ImplicitSystem::matrix > and a matrix added with ImplicitSystem::add_matrix can be PetscMatrix > objects. > > Thanks, > Andrew > > -- > Andrew E. Slaughter, PhD > andrew.e.slaughter@... > > Materials Process Design and Control Laboratory > Sibley School of Mechanical and Aerospace Engineering > 169 Frank H. T. Rhodes Hall > Cornell University > Ithaca, NY 14853-3801 > (607) 229-1829 > http://aeslaughter.github.com/ > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Libmesh-users mailing list > Libmesh-users@... > https://lists.sourceforge.net/lists/listinfo/libmesh-users ```
 Re: [Libmesh-users] SparseMatrix multiplication. From: Derek Gaston - 2012-09-17 16:15:32 ```While that is probably true... we should probably enhance the SparseMatrix interface to handle mat*mat cases... maybe Andrew would be willing to supply a patch?! ;-) Derek On Mon, Sep 17, 2012 at 8:48 AM, Kirk, Benjamin (JSC-EG311) < benjamin.kirk-1@...> wrote: > Check the PETSC matrix libmesh documentation - I think there is a method > to return the raw PETSC object. > > I know there is for vectors anyway! > > -Ben > > > > On Sep 17, 2012, at 9:42 AM, "Andrew E Slaughter" < > andrew.e.slaughter@...> wrote: > > > I need to multiply two SparseMatrix objects together, in parallel, does > > libMesh have this functionality? > > > > One possible solution is to use the PETSc MatMatMult function, but this > > requires that I use PetscMatrix objects, which I also cannot figure out > how > > to do. Can someone indicate how I can specify the ImplicitSystem::matrix > > and a matrix added with ImplicitSystem::add_matrix can be PetscMatrix > > objects. > > > > Thanks, > > Andrew > > > > -- > > Andrew E. Slaughter, PhD > > andrew.e.slaughter@... > > > > Materials Process Design and Control Laboratory > > Sibley School of Mechanical and Aerospace Engineering > > 169 Frank H. T. Rhodes Hall > > Cornell University > > Ithaca, NY 14853-3801 > > (607) 229-1829 > > http://aeslaughter.github.com/ > > > ------------------------------------------------------------------------------ > > Live Security Virtual Conference > > Exclusive live event will cover all the ways today's security and > > threat landscape has changed and how IT managers can respond. Discussions > > will include endpoint security, mobile security and the latest in malware > > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > _______________________________________________ > > Libmesh-users mailing list > > Libmesh-users@... > > https://lists.sourceforge.net/lists/listinfo/libmesh-users > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Libmesh-users mailing list > Libmesh-users@... > https://lists.sourceforge.net/lists/listinfo/libmesh-users > ```
 Re: [Libmesh-users] SparseMatrix multiplication. From: Roy Stogner - 2012-09-17 16:25:42 ``` On Mon, 17 Sep 2012, Derek Gaston wrote: > While that is probably true... we should probably enhance the SparseMatrix > interface to handle mat*mat cases... maybe Andrew would be willing to > supply a patch?! ;-) I'd be thrilled to see that. PetscMatrix does give easy access to the PETSc Mat, but it's better to write nominally solver-indpendent code, even if it's just libmesh_not_implemented() in the other solvers, simply because the next thing you know some OCD person comes around and says "hey, why isn't that new example working in Trilinos and Lapack; let me fix that" and the next thing you know you're actually solver-independent again. --- Roy ```
 Re: [Libmesh-users] SparseMatrix multiplication. From: John Peterson - 2012-09-17 16:57:00 ```On Mon, Sep 17, 2012 at 8:42 AM, Andrew E Slaughter wrote: > I need to multiply two SparseMatrix objects together, in parallel, does > libMesh have this functionality? > > One possible solution is to use the PETSc MatMatMult function, but this > requires that I use PetscMatrix objects, which I also cannot figure out how > to do. Can someone indicate how I can specify the ImplicitSystem::matrix > and a matrix added with ImplicitSystem::add_matrix can be PetscMatrix > objects. I guess one question is what are you planning to do with the resulting matrix? In general it will have different sparsity than either of the two operands. -- John ```
 Re: [Libmesh-users] SparseMatrix multiplication. From: Roy Stogner - 2012-09-17 17:33:35 ```On Mon, 17 Sep 2012, John Peterson wrote: > On Mon, Sep 17, 2012 at 8:42 AM, Andrew E Slaughter > wrote: >> I need to multiply two SparseMatrix objects together, in parallel, does >> libMesh have this functionality? >> >> One possible solution is to use the PETSc MatMatMult function, but this >> requires that I use PetscMatrix objects, which I also cannot figure out how >> to do. Can someone indicate how I can specify the ImplicitSystem::matrix >> and a matrix added with ImplicitSystem::add_matrix can be PetscMatrix >> objects. > > I guess one question is what are you planning to do with the resulting matrix? > > In general it will have different sparsity than either of the two operands. That's good to keep in mind. PETSc performance (at least in the older versions where I've made this mistake) becomes atrocious if it's asked to create new non-zero matrix entries on the fly without preallocation. --- Roy ```
 Re: [Libmesh-users] SparseMatrix multiplication. From: David Knezevic - 2012-09-17 17:36:58 ```On 09/17/2012 01:33 PM, Roy Stogner wrote: > On Mon, 17 Sep 2012, John Peterson wrote: > >> On Mon, Sep 17, 2012 at 8:42 AM, Andrew E Slaughter >> wrote: >>> I need to multiply two SparseMatrix objects together, in parallel, does >>> libMesh have this functionality? >>> >>> One possible solution is to use the PETSc MatMatMult function, but this >>> requires that I use PetscMatrix objects, which I also cannot figure out how >>> to do. Can someone indicate how I can specify the ImplicitSystem::matrix >>> and a matrix added with ImplicitSystem::add_matrix can be PetscMatrix >>> objects. >> I guess one question is what are you planning to do with the resulting matrix? >> >> In general it will have different sparsity than either of the two operands. > That's good to keep in mind. PETSc performance (at least in the older > versions where I've made this mistake) becomes atrocious if it's asked > to create new non-zero matrix entries on the fly without > preallocation. Presumably MatMatMult in PETSc (or the equivalent in trilinos) handles this in some sensible way though. ```
 Re: [Libmesh-users] SparseMatrix multiplication. From: Roy Stogner - 2012-09-17 17:55:25 ```On Mon, 17 Sep 2012, David Knezevic wrote: > On 09/17/2012 01:33 PM, Roy Stogner wrote: >> That's good to keep in mind. PETSc performance (at least in the older >> versions where I've made this mistake) becomes atrocious if it's asked >> to create new non-zero matrix entries on the fly without >> preallocation. > > Presumably MatMatMult in PETSc (or the equivalent in trilinos) handles > this in some sensible way though. Sensible in the sense that "ask the user to estimate the ratio nnz(A*B)/(nnz(A)+nnz(B))" is probably the least bad of a bunch of bad alternatives. That's kind of a quirky thing to try and encapsulate in a non-solver-specific API, though... --- Roy ```
 Re: [Libmesh-users] SparseMatrix multiplication. From: Kirk, Benjamin (JSC-EG311) - 2012-09-17 18:06:23 ```>>> That's good to keep in mind. PETSc performance (at least in the older >>> versions where I've made this mistake) becomes atrocious if it's asked >>> to create new non-zero matrix entries on the fly without >>> preallocation. >> >> Presumably MatMatMult in PETSc (or the equivalent in trilinos) handles >> this in some sensible way though. > > Sensible in the sense that "ask the user to estimate the ratio > nnz(A*B)/(nnz(A)+nnz(B))" is probably the least bad of a bunch of bad > alternatives. > > That's kind of a quirky thing to try and encapsulate in a > non-solver-specific API, though... Yep. Back to the origin of the question then - do you really *need* the product? Since sparse matrix multiplication is not trivial it may be preferable to carry out the action of the sparse matrix - for example a matvec C=A*B y=C*x instead could be carried out as y = (A*B)*x = A*(B*x) which would eliminate the need for explicitly forming C. Similar things can be done with solves, but there I'm not sure you'd gain anything! -Ben ```