<div><font>Hi there,</font></div><div><font><br></font></div><div><font>I am a fresh user of Petsc, from Jiangnan University. Now I am trying to use Petsc for FEM and topology optimization.</font></div><div><font>Since I use the background pixel elements, some of elements I don't want them to be calculated, so I have to filter them out. Then after my calculation, I want to have them back.</font></div><div><font><br></font></div><div><font>For example, in the context of "<span style="font-weight: bold;">mpiexec -np 2</span>":</font></div><div><font>I have a Vec xPassive=[<span style="color: rgb(0, 255, 0);">1, 1</span>, <span style="color: rgb(255, 0, 0);">0, 0, 0</span> <span style="font-weight: bold;">|</span> <span style="color: rgb(0, 0, 255);">1, 1, 1, 1, 1</span>] showing the design-able elements (1) and the not-design-able elements (<span style="color: rgb(255, 0, 0);">0</span>) to be filtered out. This vec is auto sliced into 5+5  by the 2 threads.</font></div><div><font>At the same time, I have a Vec density=[<span style="color: rgb(0, 255, 0);">0.0, 0.1</span>,<span style="color: rgb(255, 0, 0);"> 1.0, 1.0, 1.0</span> <span style="font-weight: bold;">|</span> <span style="color: rgb(0, 0, 255);">0.5, 0.6, 0.7, 0.8, 0.9</span>].</font></div><div><font>In order to narrow down the density, I make an array and count, like resarray=[<span style="color: rgb(0, 255, 0);">0.0, 0.1</span>] with count=2 and resarray=[<span style="color: rgb(0, 0, 255);">0.5, 0.6, 0.7, 0.8, 0.9</span>] with count=5, then by the method <span style="font-weight: bold;">VecCreateMPIWithArray</span>(PETSC_COMM_WORLD, 1, count, PETSC_DECIDE, resarray, &</font><font>density_new</font><font>),  I get Vec density_new = [<span style="color: rgb(0, 255, 0);">0.0, 0.1</span>, <span style="color: rgb(0, 0, 255);">0.5, 0.6, 0.7, 0.8, 0.9</span>] successfully.</font></div><div><font>Next, I put the density_new into some methods to get the new values like density_new=[<span style="color: rgb(0, 255, 0);">0.01, 0.11</span>, <span style="color: rgb(0, 0, 255);">0.51, 0.61</span> <span style="font-weight: bold;">|</span> <span style="color: rgb(0, 0, 255);">0.71, 0.81, 0.91</span>], note that since the density_new is of size 7, it becomes 4+3 for the 2 threads.<br></font></div><div><font>Finally, I have to recover them as Vec density_recover=[<span style="color: rgb(0, 255, 0);">0.01, 0.11</span>, <span style="color: rgb(255, 0, 0);">1.0, 1.0, 1.0</span> <span style="font-weight: bold;">|</span> <span style="color: rgb(0, 0, 255);">0.51, 0.61, 0.71, 0.81, 0.91</span>], in this process I fill the default 1.0 for the place where xPassive value</font><font>=0</font><font>.</font></div><div><font><br></font></div><div><font>In the last step, when I try to recover the density vector, I tried to use <span style="font-weight: bold;">VecGetValues</span> but it seems can only get local values, cannot cross threads. <br></font></div><div><font>I tried also to use <span style="font-weight: bold;">VecScatterCreate</span>(</font><font>density_new</font><font>, NULL, </font><font>density_recover</font><font>, idx_to, &scatter), however, my idx_to=[0, 1 <span style="font-weight: bold;">|</span> 5, 6, 7, 8, 9] and not works well like normal </font><font>[0, 1, 5, 6, 7, 8, 9].</font></div><div><font>Could you help me with this please? Thank you soooooo much for your time!</font></div><div><font><br></font></div><div><font>Best regards,</font></div><div><font>Qingyuan HU</font></div><div><font>School of Science, Jiangnan University<br></font></div><div><includetail><!--<![endif]--></includetail></div>