<div dir="ltr">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.<div><br></div><div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">--Junchao Zhang</div></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 7, 2020 at 3:37 PM Emmanuel Ayala <<a href="mailto:juaneah@gmail.com">juaneah@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, I hope everyone is well.<br><br>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. <br><br>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.<br><br>If I use:<br><br>VecScatterCreate(Vec x,IS ix,Vec y,IS iy,VecScatter *ctx);<br>VecScatterBegin(VecScatter ctx,Vec x,Vec y,INSERT VALUES,SCATTER FORWARD);<br>VecScatterEnd(VecScatter ctx,Vec x,Vec y,INSERT VALUES,SCATTER FORWARD);<br><br>The vector is still unbalanced.<br><br>Any suggestion?<br><br>Kind regards.</div>
</blockquote></div>