[petsc-users] set a Vec as row or column of a Mat
Barry Smith
bsmith at mcs.anl.gov
Sun Jun 1 20:18:07 CDT 2014
Do you intend to do this in parallel or just sequential? I assume the “solution of each one dimensional problem” involves a tridiagonal (or wider if you several degrees of freedom per point or a wider stencil) linear solve? Are all the linear solves the same or is each one different (nonlinear function of coefficients?)? Perhaps if you provide more details on the overall problem you are solving we may have more suggestions.
A PETSc Mat is really intended as a linear operator, not a way to store 2d arrays, (unlike MATLAB, which is structured for both roles). I would use a DMDACreate2d() and then “fish out” the rows into a Vec with VecPlaceArray() requires no copies of data and then the columns with VecStrideGather() (and put back with VecStrideScatter) requires copying the entries (but there is no avoiding the copy in this case since the columns are not adjacent entries in Vec obtained from DMCreateGlobalVector().
Barry
On Jun 1, 2014, at 6:00 PM, Shriram Srinivasan <shriram at ualberta.ca> wrote:
> 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).
> 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
More information about the petsc-users
mailing list