Sorting a vector

Matthew Knepley knepley at
Tue Jun 16 07:56:11 CDT 2009

On Tue, Jun 16, 2009 at 5:38 AM, tog <guillaume.alleon at> wrote:

> Hi there
> This is a kind of newbie question :)
> I have a vector which is the solution of my simulation, I want then to
> extract the p indices corresponding to the p biggest values in my vector. Is
> there a way to do this with PETSc ?

You can get p=1 with VecMax().

> What if I want to sort my vector to get the indices in ascending order of
> their values ?

The p=2+ and permutation cases are sophisticated in parallel and not
present. In serial, you can use
VecGetArray() and PetscSortReal()/SortRealWithPermutation().


> Thanks
> Guillaume
What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the petsc-users mailing list