[petsc-users] Matricize a vector

Jed Brown jedbrown at mcs.anl.gov
Tue Sep 6 06:05:18 CDT 2011


On Tue, Sep 6, 2011 at 12:52, <elam at cs.toronto.edu> wrote:

> Is it possible to reshape a vector into a matrix in PETSc?  I need to do
> this to compute a matrix vector multiplication (Ax) where the matrix A can
> be decomposed into Kronecker tensor format.  For example, A = A1 kron A2
> kron A3, where A1, A2, A3 are smaller sparse matrices.
>
> Essentially, I need to matricize the vector x and perform a series of
> matrix matrix multiplications to compute Ax.  In Matlab the function to
> perform the matricization is reshape.  Is there a similar function in
> PETSc?
>

No, but there are two functions you can use to apply this operator. You
would likely use both strategies, one for the first and one for the last
part of the tensor product.

1. MatCreateMAIJ() creates a matrix that applies the same scalar operation
to every component of a "block" in a normal vector. With an MAIJ matrix,
MatMult() is semantically like reshaping in row-major order, doing a
matrix-matrix multiply, and putting the result back in a flat vector.

2. Use VecGetArray() followed by MatMPIDenseSetPreallocation() to make a
matrix in column-major order out of the same memory. Then you can
MatMatMult() and make the result go back into a similar matrix.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110906/1ea12657/attachment.htm>


More information about the petsc-users mailing list