[petsc-users] Matricize a vector
elam at cs.toronto.edu
elam at cs.toronto.edu
Tue Sep 6 08:07:06 CDT 2011
Thank you, the two functions described below are what I need. Are there
more examples available on how to use the MAIJ matrix? The MatCreateMAIJ
page is very brief. Also, are there example codes for computing a
kronecker product in PETSc?
> 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.
>
More information about the petsc-users
mailing list