[petsc-users] VecGetSubVector

Emmanuel Ayala juaneah at gmail.com
Thu May 7 22:32:44 CDT 2020


Thanks Matt and Zhang for the answers.

That is right, VecScatter will be the solution to my problem. And
MPI_Exscan is the function that I was looking for.

The only thing that I though, very inefficient, was get the subvector using
the IS that I need, and the scatter it with VecScatterCreateToAll. In this
way I got all the elements in sequential form and then apply scatter
operations based on the ranges of the final Vector ( created to contain the
selected elements), it works.

For suer I will try MPI_Exscan.

Kind regards!

El jue., 7 de may. de 2020 a la(s) 21:57, Junchao Zhang (
junchao.zhang at gmail.com) escribió:

> You have to compute the length of the new vector (i.e., total number of
> selected elements), and then create a VecMPI  with this length. PETSc will
> compute a balanced layout for the vector. Then you create a vecscatter that
> scatters selected elements from the old vector to the new vector. You may
> need MPI_Exscan to build correct index mapping.
>
> --Junchao Zhang
>
>
> On Thu, May 7, 2020 at 3:37 PM Emmanuel Ayala <juaneah at gmail.com> wrote:
>
>> Hi, I hope everyone is well.
>>
>> I have a MPI vector, I selected some elements of this vector and for some
>> processes there is not selected elements (I stored the indices elements
>> into an array). So, I wan to to create a MPI vector using these selected
>> elements, the selected elements must be fully distributed in a MPI vector,
>> but I do not figure out how to do it properly.
>>
>> If I use VecGetSubVector, it creates a MPI vector, but in those processes
>> where there is not selected elements, the subvector portion is empty, this
>> means that the resultant vector is unbalanced.
>>
>> If I use:
>>
>> VecScatterCreate(Vec x,IS ix,Vec y,IS iy,VecScatter *ctx);
>> VecScatterBegin(VecScatter ctx,Vec x,Vec y,INSERT VALUES,SCATTER FORWARD);
>> VecScatterEnd(VecScatter ctx,Vec x,Vec y,INSERT VALUES,SCATTER FORWARD);
>>
>> The vector is still unbalanced.
>>
>> Any suggestion?
>>
>> Kind regards.
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200507/8b34ed6c/attachment.html>


More information about the petsc-users mailing list