[petsc-users] Inverse local to global mapping?

Jed Brown jed at jedbrown.org
Tue Feb 16 16:49:33 CST 2016


Florian Lindner <mailinglists at xgm.de> writes:

> Hello,
>
> I want to build a global vector (and matrix) from local data. The local data has a global index, which can be non-contiguous i.e. global index (0, 5, 2) is on rank 0, (1, 4, 3) is on rank 1. To keep all local data on the local part of vector I need a mapping:
>
> Application -> PETSc
> (0, 5, 2)   -> (0, 1, 2)
> (1, 4, 3)   -> (3, 4, 5)
>
> It can happen that rank 1 also need to touch vector[5] (application ordering) i.e. vector[1] (petsc ordering) on rank 0.
>
> I can produce a mapping using index sets:
>
> ierr = ISCreateGeneral(PETSC_COMM_WORLD, indizes.size(), indizes.data(), PETSC_COPY_VALUES, &ISlocal); CHKERRV(ierr);
> ierr = ISAllGather(ISlocal, &ISglobal); CHKERRV(ierr); // Gather the IS from all processors
> ierr = ISLocalToGlobalMappingCreateIS(ISglobal, &ISmapping); CHKERRV(ierr); // Make it a mapping
>
> I construct std::vector indizes by walking though all local indizes. This way I have a mapping ISmapping that looks like that:
>
> 0 0
> 1 5
> 2 2
> 3 1
> 4 4
> 5 3
>
> Now I can use that mapping: VecSetLocalToGlobalMapping(vec, mapping);
>
> but this does not work like it should (for me). If I use VecSetValueLocal to set element 5 it gets mapped to 3, element 1 gets mapped to 5.
> I want to have it reversed, accessing element 3 gets mapped to 5, element 1 to 3.

ISInvertPermutation would do what you're asking for, but beware that
this is not memory scalable.

I recommend fixing your algorithm so you don't need this inverse mapping.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160216/6fe8a452/attachment-0001.pgp>


More information about the petsc-users mailing list