[petsc-users] Parallel sort in Petsc

Jed Brown jed at jedbrown.org
Tue Jul 7 09:49:36 CDT 2020


Matthew Knepley <knepley at gmail.com> writes:

> On Tue, Jul 7, 2020 at 9:14 AM Antoine Côté <Antoine.Cote3 at usherbrooke.ca>
> wrote:
>
>> Hi,
>>
>> I need to compute the permutations to sort scalar values of a Vec object
>> in decreasing order. I've been developing on a single process for now,
>> using VecGetArrayRead() to extract the values
>> and PetscSortRealWithPermutation() to get the permutations.
>>
>> I would like to run the code on multiple processes. From these links, I
>> can see it's an issue :
>> https://lists.mcs.anl.gov/pipermail/petsc-users/2013-November/019628.html
>> https://lists.mcs.anl.gov/pipermail/petsc-users/2009-June/004621.html
>>
>> One work around I've been considering : get the max scalar value using
>> VecMax() ; compute a scaling factor that makes this max value equals the
>> largest integer value tolerated by PetscInt ; scale all values of Vec and
>> convert them to integers ; use PetscParallelSortInt() ; inverse the scaling
>> on (now sorted) integers values and convert them back to scalars.
>>
>> This is only a patch really, the main issues being : (1) I would get a
>> sorted Vec, not the permutations and (2) there would be a lost of
>> information when converting scalars to int values.
>>
>> Isn't there a way to parallel sort real values using Petsc?
>>
>
> I looked at the code. It does not depend on the value type do you could
> just copy it and replace all the Int types with Real. It would be nice to
> abstract the type and comparator away, but that is more work in C.

It can be done with a comparison function like with qsort/qsort_r from
libc.  It'll get inlined at reasonable optimization and would still be
useful for sorting user objects.


More information about the petsc-users mailing list