[petsc-dev] PETSc Sorting with duplicate entries

Bisht, Gautam bishtg at ornl.gov
Thu Mar 31 10:00:40 CDT 2011


Hi,

I'm was sorting an array which that has duplicate entries: (x = [39 9 19 39 29]). I noticed that for duplicate entries after sorting, the index returned are not in ascending. The example below will explain this further.

Here is the code snippet:

============================================
do ii=1,5
index(ii) = ii
endo

index = index -1
call PetscSortIntWithPermutation( 5, x, index, ierr)
index = index + 1

do ii=1,5
write(*,*), x(ii), index(ii), x(index(ii))
enddo
============================================


Output:
          39           2           9
            9           3          19
          19           5          29
          39           4          39
          29           1          39

Output (Expected by me, similar to MATLAB output): Note the difference in the index(4) and index(5) values
          39           2           9
            9           3          19
          19           5          29
          39           1          39
          29           4          39


I tired using PetscSortIntWithArray and go similar result. I was wondering if there is a sorting option that can get me the output which I'm expecting. The only way around I came up for this was to look at the index(:) entries that correspond to duplicate values and sort them again.


-Gautam.



More information about the petsc-dev mailing list