<div dir="ltr">Yes, I got the right Vector local size using the code below and I am also sure all processes entered that function by printing out a message, which shows up the number of processes times.<div>But the hanging problem is still there. I need to spend more time and do more tests. <br><div><div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)"> int</span> vec_local_size;</div><div><span style="color:rgb(106,153,85)"> // vec_local_size = new int[world_size];</span></div><div> <span style="color:rgb(220,220,170)">VecGetLocalSize</span>(sol_vector_rp1, <span style="color:rgb(212,212,212)">&</span>vec_local_size);</div><div> <span style="color:rgb(78,201,176)">std</span>::cout <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(206,145,120)">"process "</span> <span style="color:rgb(212,212,212)"><<</span> world_rank <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(206,145,120)">" has "</span> <span style="color:rgb(212,212,212)"><<</span> vec_local_size <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(206,145,120)">" entries."</span> <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(78,201,176)">std</span>::endl;</div></div></div></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, Dec 8, 2024 at 4:40 PM Qiyue Lu <<a href="mailto:qiyuelu1@gmail.com">qiyuelu1@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">Yes, it seems the global_vec has some problems. It is passed by as a function parameter. And the original vector is declared as in the code. However, I got some print-out as below, while I am expecting to get evenly-distributed values. <div>process 0 has 5422 entries.<br>process 1 has 0 entries.<br>process 2 has 0 entries.<br>process 3 has 0 entries.<br>process 4 has 0 entries.<br>process 5 has 0 entries.<br>process 6 has 0 entries.<br>process 7 has 0 entries.<br>process 8 has 0 entries.<br>process 9 has 0 entries.<br>process 10 has 0 entries.<br>process 11 has 0 entries.<br>process 12 has 0 entries.<br><div><div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div> Vec sol_vector_rp1;</div><div> <span style="color:rgb(220,220,170)">VecCreate</span>(MPI_COMM_WORLD, <span style="color:rgb(212,212,212)">&</span>sol_vector_rp1);</div><div> <span style="color:rgb(220,220,170)">VecSetType</span>(sol_vector_rp1, VECMPI);</div><div> <span style="color:rgb(220,220,170)">VecSetSizes</span>(sol_vector_rp1, PETSC_DECIDE, numNodesTotal<span style="color:rgb(212,212,212)">*</span>numDOFs); </div><div> <span style="color:rgb(220,220,170)">VecSet</span>(sol_vector_rp1, <span style="color:rgb(181,206,168)">0.0</span>);</div><div> <span style="color:rgb(220,220,170)">VecAssemblyBegin</span>(sol_vector_rp1);</div><div> <span style="color:rgb(220,220,170)">VecAssemblyEnd</span>(sol_vector_rp1);</div><div> </div><div> <span style="color:rgb(86,156,214)">int</span> <span style="color:rgb(212,212,212)">*</span>vec_local_size <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(86,156,214)">nullptr</span>;</div><div> vec_local_size <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(86,156,214)">new</span> <span style="color:rgb(86,156,214)">int</span>[world_size];</div><div> <span style="color:rgb(220,220,170)">VecGetLocalSize</span>(sol_vector_rp1, vec_local_size);</div><div> <span style="color:rgb(197,134,192)">for</span> (<span style="color:rgb(86,156,214)">int</span> i <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(181,206,168)">0</span>; i <span style="color:rgb(212,212,212)"><</span> world_size; i<span style="color:rgb(212,212,212)">++</span>){</div><div> <span style="color:rgb(78,201,176)">std</span>::cout <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(206,145,120)">"process "</span> <span style="color:rgb(212,212,212)"><<</span> i <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(206,145,120)">" has "</span> <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(156,220,254)">vec_local_size</span>[i] <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(206,145,120)">" entries."</span> <span style="color:rgb(212,212,212)"><<</span> <span style="color:rgb(78,201,176)">std</span>::endl;</div><div> }</div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 8, 2024 at 4:00 PM Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</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><div><br></div> Where does global_vec come from, and are you sure that all MPI processes that share global_vec enter this code region?<div><br></div><div><br id="m_4578038538749361977m_158529018849766561lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Dec 8, 2024, at 4:52 PM, Qiyue Lu <<a href="mailto:qiyuelu1@gmail.com" target="_blank">qiyuelu1@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Thank you all for the reply. Here is the code. Since I need to fetch data from the local_vec, so I set the type as VECSEQ, so I can use VecGetValues(). <div><div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(78,201,176)"> std</span>::vector<span style="color:rgb(212,212,212)"><</span><span style="color:rgb(78,201,176)">std</span>::vector<span style="color:rgb(212,212,212)"><</span><span style="color:rgb(86,156,214)">double</span><span style="color:rgb(212,212,212)">>></span> <span style="color:rgb(220,220,170)">vc</span>(numNodesSurface, <span style="color:rgb(78,201,176)">std</span>::<span style="color:rgb(220,220,170)">vector</span><<span style="color:rgb(86,156,214)">double</span>>(numDimsProb));<span style="color:rgb(106,153,85)"> // 2-D matrix storing velocity u, v.</span></div><div> PetscScalar <span style="color:rgb(212,212,212)">*</span>ptr_vc <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(86,156,214)">NULL</span>;<span style="color:rgb(106,153,85)"> // memory storing the fetched values</span></div><div> ptr_vc <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(86,156,214)">new</span> <span style="color:rgb(86,156,214)">double</span>[numNodesSurface<span style="color:rgb(212,212,212)">*</span>numDimsProb];<span style="color:rgb(106,153,85)"> // numNodesSurfac = 6, numDimsProb = 2, are number of nodes per element and problem dimension</span></div><div> PetscInt <span style="color:rgb(156,220,254)">idx_global</span>[numNodesSurface<span style="color:rgb(212,212,212)">*</span>numDimsProb];<span style="color:rgb(106,153,85)"> // for creating global Index Set</span></div><div> PetscInt <span style="color:rgb(156,220,254)">idx_local</span>[numNodesSurface<span style="color:rgb(212,212,212)">*</span>numDimsProb];<span style="color:rgb(106,153,85)"> // for creating local Index Set</span></div><div> <span style="color:rgb(197,134,192)">for</span> (<span style="color:rgb(86,156,214)">int</span> i <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(181,206,168)">0</span>; i <span style="color:rgb(212,212,212)"><</span> numNodesSurface; i<span style="color:rgb(212,212,212)">++</span>){</div><div> <span style="color:rgb(197,134,192)">for</span> (<span style="color:rgb(86,156,214)">int</span> j <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(181,206,168)">0</span>; j <span style="color:rgb(212,212,212)"><</span> numDimsProb; j<span style="color:rgb(212,212,212)">++</span>){</div><div> <span style="color:rgb(156,220,254)">idx_local</span>[i<span style="color:rgb(212,212,212)">*</span>numDimsProb <span style="color:rgb(212,212,212)">+</span> j] <span style="color:rgb(212,212,212)">=</span> i<span style="color:rgb(212,212,212)">*</span>numDimsProb <span style="color:rgb(212,212,212)">+</span> j;<span style="color:rgb(106,153,85)"> // local index</span></div><div> <span style="color:rgb(156,220,254)">idx_global</span>[i<span style="color:rgb(212,212,212)">*</span>numDimsProb <span style="color:rgb(212,212,212)">+</span> j] <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(156,220,254)">node_el</span>[i]<span style="color:rgb(212,212,212)">*</span>numDOFs <span style="color:rgb(212,212,212)">+</span> j;<span style="color:rgb(106,153,85)"> // global index</span></div><div> }</div><div> }</div><div><span style="color:rgb(106,153,85)"> // global_vec is distributed, and uses MPI_COMM_WORLD as a communicator which includes all processes. </span></div><div><span style="color:rgb(106,153,85)"> // I want to fetch 12 (numNodesSurface*numDimsProb) values from global_vec and put them in a local vector,</span></div><div><span style="color:rgb(106,153,85)"> // Therefore, I set up this local_vec as VECSEQ and using PETSC_COMM_SELF.</span></div><div> IS is_source, is_dest;</div><div> <span style="color:rgb(220,220,170)">ISCreateGeneral</span>(PETSC_COMM_SELF, numNodesSurface<span style="color:rgb(212,212,212)">*</span>numDimsProb, idx_global, PETSC_COPY_VALUES, <span style="color:rgb(212,212,212)">&</span>is_source);</div><div> <span style="color:rgb(220,220,170)">ISCreateGeneral</span>(PETSC_COMM_SELF, numNodesSurface<span style="color:rgb(212,212,212)">*</span>numDimsProb, idx_local, PETSC_COPY_VALUES, <span style="color:rgb(212,212,212)">&</span>is_dest);</div><div> Vec local_vec;</div><div> <span style="color:rgb(220,220,170)">VecCreate</span>(PETSC_COMM_SELF, <span style="color:rgb(212,212,212)">&</span>local_vec);</div><div> <span style="color:rgb(220,220,170)">VecSetSizes</span>(local_vec, PETSC_DECIDE, numNodesSurface<span style="color:rgb(212,212,212)">*</span>numDimsProb); </div><div> <span style="color:rgb(220,220,170)">VecSetType</span>(local_vec, VECSEQ);</div><div> VecScatter scat;</div><div> <span style="color:rgb(220,220,170)">VecScatterCreate</span>(global_vec, is_source, local_vec, is_dest, <span style="color:rgb(212,212,212)">&</span>scat);<span style="color:rgb(106,153,85)"> // Got Stuck here</span></div><div> <span style="color:rgb(220,220,170)">VecScatterBegin</span>(scat, global_vec, local_vec, INSERT_VALUES, SCATTER_FORWARD);</div><div> <span style="color:rgb(220,220,170)">VecScatterEnd</span>(scat, global_vec, local_vec, INSERT_VALUES, SCATTER_FORWARD);</div><div> <span style="color:rgb(220,220,170)">VecGetValues</span>(local_vec, numNodesSurface<span style="color:rgb(212,212,212)">*</span>numDimsProb, idx_local, ptr_vc);</div><div> <span style="color:rgb(197,134,192)">for</span> (<span style="color:rgb(86,156,214)">int</span> i <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(181,206,168)">0</span>; i <span style="color:rgb(212,212,212)"><</span> numNodesSurface; i<span style="color:rgb(212,212,212)">++</span>){</div><div> <span style="color:rgb(197,134,192)">for</span> (<span style="color:rgb(86,156,214)">int</span> j <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(181,206,168)">0</span>; j <span style="color:rgb(212,212,212)"><</span> numDimsProb; j<span style="color:rgb(212,212,212)">++</span>){</div><div> <span style="color:rgb(156,220,254)">vc</span>[i][j] <span style="color:rgb(212,212,212)">=</span> <span style="color:rgb(156,220,254)">ptr_vc</span>[i<span style="color:rgb(212,212,212)">*</span>numDimsProb <span style="color:rgb(212,212,212)">+</span> j];<span style="color:rgb(106,153,85)"> // From 1-D to 2-D</span></div><div> }</div><div> }</div><div> <span style="color:rgb(220,220,170)">ISDestroy</span>(<span style="color:rgb(212,212,212)">&</span>is_source);</div><div> <span style="color:rgb(220,220,170)">ISDestroy</span>(<span style="color:rgb(212,212,212)">&</span>is_dest);</div><div> <span style="color:rgb(220,220,170)">VecDestroy</span>(<span style="color:rgb(212,212,212)">&</span>local_vec);</div><div> <span style="color:rgb(220,220,170)">VecScatterDestroy</span>(<span style="color:rgb(212,212,212)">&</span>scat);</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 8, 2024 at 11:12 AM Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</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><div><br></div> You can scatter from a global vector to a local vector; numerous PETSc examples demonstrate this. So hanging here is surprising. Please display the entire code so we can see the context of the VecScatterCreate() usage. Perhaps not all the MPI process that are in the global_vec communicator are involved in the call to VecScatterCreate(). <div><br></div><div> To determine where the hang occurs you can run with -start_in_debugger use c for continue in each debugger window and then after a long time of hanging do control d in the hanging windows and then type bt to see where the code is hanging.</div><div><br></div><div> Barry</div><div> <br id="m_4578038538749361977m_158529018849766561m_354643477798547113lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Dec 7, 2024, at 9:47 PM, Qiyue Lu <<a href="mailto:qiyuelu1@gmail.com" target="_blank">qiyuelu1@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Hello,<br><div>I am trying to fetch 12 entries from a distributed vector global_vec and put them into a local vector on each process. </div><div><br></div><div><div style="background-color:rgb(31,31,31);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div style="color:rgb(204,204,204)"><span style="color:rgb(78,201,176)"> IS</span> <span style="color:rgb(156,220,254)">is_source</span>, <span style="color:rgb(156,220,254)">is_dest</span>;</div><div><font color="#cccccc"> </font><span style="color:rgb(220,220,170)">ISCreateGeneral</span><font color="#cccccc">(</font><span style="color:rgb(86,156,214)">PETSC_COMM_SELF</span><font color="#cccccc">, </font><font color="#9cdcfe">12</font><font color="#cccccc">, </font><span style="color:rgb(156,220,254)">idx_global</span><font color="#cccccc">, </font><span style="color:rgb(79,193,255)">PETSC_COPY_VALUES</span><font color="#cccccc">, </font><span style="color:rgb(212,212,212)">&</span><span style="color:rgb(156,220,254)">is_source</span><font color="#cccccc">);</font></div><div><span style="color:rgb(204,204,204)"> <span style="color:rgb(220,220,170)">ISCreateGeneral</span>(<span style="color:rgb(86,156,214)">PETSC_COMM_SELF</span>, </span><font color="#9cdcfe">12</font><font color="#cccccc">, </font><span style="color:rgb(156,220,254)">idx_local</span><font color="#cccccc">, </font><span style="color:rgb(79,193,255)">PETSC_COPY_VALUES</span><font color="#cccccc">, </font><span style="color:rgb(212,212,212)">&</span><span style="color:rgb(156,220,254)">is_dest</span><font color="#cccccc">);</font></div><div style="color:rgb(204,204,204)"> <span style="color:rgb(78,201,176)">Vec</span> <span style="color:rgb(156,220,254)">local_vec</span>;</div><div style="color:rgb(204,204,204)"> <span style="color:rgb(220,220,170)">VecCreate</span>(<span style="color:rgb(86,156,214)">PETSC_COMM_SELF</span>, <span style="color:rgb(212,212,212)">&</span><span style="color:rgb(156,220,254)">local_vec</span>);</div><div><span style="color:rgb(204,204,204)"> <span style="color:rgb(220,220,170)">VecSetSizes</span>(<span style="color:rgb(156,220,254)">local_vec</span>, <span style="color:rgb(86,156,214)">PETSC_DECIDE</span>, </span><font color="#9cdcfe">12</font><font color="#cccccc">); </font></div><div style="color:rgb(204,204,204)"> <span style="color:rgb(220,220,170)">VecSetType</span>(<span style="color:rgb(156,220,254)">local_vec</span>, <span style="color:rgb(86,156,214)">VECSEQ</span>);</div><div style="color:rgb(204,204,204)"> <span style="color:rgb(78,201,176)">VecScatter</span> <span style="color:rgb(156,220,254)">scat</span>;</div><div style="color:rgb(204,204,204)"> <span style="color:rgb(220,220,170)">VecScatterCreate</span>(<span style="color:rgb(156,220,254)">global_vec</span>, <span style="color:rgb(156,220,254)">is_source</span>, <span style="color:rgb(156,220,254)">local_vec</span>, <span style="color:rgb(156,220,254)">is_dest</span>, <span style="color:rgb(212,212,212)">&</span><span style="color:rgb(156,220,254)">scat</span>);</div></div></div><div><br></div><div><br></div><div>I create the local vector as sequential. However, the last two lines which create a scatter object, will cause more than half processes to hang and no error pops out. </div><div><br></div><div>Does the scatter have to be VECMPI to VECMPI and cannot VECMPI to VECSEQ?</div><div><br></div><div>Thanks,</div><div>Qiyue Lu</div></div>
</div></blockquote></div><br></div></div></blockquote></div>
</div></blockquote></div><br></div></div></blockquote></div>
</blockquote></div>