Does PETSc have some functions like A.*B, A./B in Matlab?

Jed Brown jed at
Wed Oct 28 11:39:44 CDT 2009

abhyshr at wrote:
> If A and B are vectors, then you can use VecPointwiseMult for A.*B and VecPointwiseDivide for A./B.
> For matrices,pointwise multiplication and division functions are not provided in Petsc. One possible way to do
> A.*B and A./B for matrices is to loop through the columns of the matrices,call MatGetColumnVector for each column of matrix A,B
> and then call VecPointwiseMult/VecPointwiseDivide.

This would be very inefficient because it produces dense output and
PETSc matrices are row-aligned.  I would suggest using MatGetRow which
is much faster and preserves sparsity.


> Shri
> ----- Original Message -----
> From: "Yujie" <recrusader at>
> To: "PETSc users list" <petsc-users at>
> Sent: Wednesday, October 28, 2009 10:21:34 AM GMT -06:00 US/Canada Central
> Subject: Does PETSc have some functions like A.*B, A./B in Matlab?
> Dear PETSc Developers, 
> Does PETSc provide some functions, like A.*B, A./B in Matlab? Thanks a lot. 
> Regards, 
> Yujie 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the petsc-users mailing list