[petsc-users] Push Back in Vector

Jed Brown jed at 59A2.org
Thu Feb 25 10:45:18 CST 2010


On Thu, 25 Feb 2010 13:37:21 -0300, Pedro Torres <torres.pedrozpk at gmail.com> wrote:
> Well, in my case I have a sequential vector and I'm trying to append one
> element at the end of the array, without the need of destroy this.

PETSc Vec doesn't work this way.  Use whatever data structure you like
to put this thing together, then give it to PETSc once you know what you
have.

> - Create a new vector with size+1
> - copy old array in the new array and append the element,

This is what dynamically sized array containers (e.g. std::vector) do
internally, but they guess at how much extra will be needed (usually
increasing the allocated size by a geometric factor).

(When I asked what you are trying to do, I was looking for a higher
level description of what you wanted to achieve, and why you thought
appending to a Vec was a desirable thing.)

Jed


More information about the petsc-users mailing list