[petsc-users] set a Vec as row or column of a Mat

Jed Brown jed at jedbrown.org
Sun Jun 1 18:10:51 CDT 2014


Shriram Srinivasan <shriram at ualberta.ca> writes:

> Hi,
> I have a petsc Vec object ( say length 3). I want to use its entries as 
> the  column of a Petsc Mat (say 3x3).

PETSc Mat and Vec are not really meant for such small sizes.  Some
people like template libraries like Eigen if they have lots of
complicated expressions involving tiny matrices/tensors, otherwise it's
common to write the small loops or even unroll (you want the compiler to
perform aggressive transformations on sizes this small).

If you were thinking of much larger values for "3", the MatDense format
uses column-oriented storage so you can use VecGetArrayRead(), then copy
those columns into the contiguous storage used by MatDense.

> Is there an obvious way to do this ?
> I could only think of first  copying the entries of the Vec into an 
> array with VecGetValues, and then use it to set the values of the column 
> of the Mat.
> In case it is relevant, I am doing a  sweep of a direction splitting 
> method over a square, and I want to store the solution (vector) of each 
> one dimensional problem in a Mat.
>
> Thanks,
> Shriram
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140602/18b90049/attachment.pgp>


More information about the petsc-users mailing list