<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 9, 2022 at 6:50 PM Karthikeyan Chockalingam - STFC UKRI <<a href="mailto:karthikeyan.chockalingam@stfc.ac.uk">karthikeyan.chockalingam@stfc.ac.uk</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 class="msg2834509638292777242">
<div lang="EN-GB" style="overflow-wrap: break-word;">
<div class="m_-1095046491910575780WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">Thank you Mark and Barry.
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><a id="m_-1095046491910575780OWAAM3F9AFB4C861F014AACA86D8A70231CD5" href="mailto:mfadams@lbl.gov" target="_blank"><span style="font-family:Calibri,sans-serif;text-decoration:none">@Mark Adams</span></a> I follow you
for the most part. Shouldn’t R be an MPI Vector?</span></p></div></div></div></blockquote><div><br></div><div>yes, "R, with local size n" implies an MPI vector.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1"><p class="MsoNormal"><span style="font-size:11pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Here it goes:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Q[Vec[i]] for all "i" in my local (sequential) "Vec".</span></p></div></div></div></blockquote><div><br></div><div>OK, you are calling VecSetValue(Q,... <a href="https://petsc.org/main/docs/manualpages/Sys/ADD_VALUES/" style="box-sizing:border-box;background-color:rgb(245,245,245);text-decoration-line:none;font-family:SFMono-Regular,Menlo,Consolas,Monaco,"Liberation Mono","Lucida Console",monospace;font-size:13.125px;white-space:nowrap">ADD_VALUES</a>)</div><div>VecAsseemblyBegin/End needs to be called and that will do communication.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1"><p class="MsoNormal"><span style="font-size:11pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Compute number of local nonzeros in Q, call it n.</span></p></div></div></div></blockquote><div><br></div><div>You would use VecGetArray like below to do this count.</div><div><br></div><div>You could cache the indices in Q that are non-zero, or redo the loop below. </div><div><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 class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1"><p class="MsoNormal"><span style="font-size:11pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">//Create a MPI Vector R, with local size n<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="m_-1095046491910575780p1">VecCreate(PETSC_COMM_WORLD, &R); </p>
<p class="m_-1095046491910575780p1">VecSetType(R, VECMPI); </p>
<p class="m_-1095046491910575780p1">VecSetSizes(R, <b>n</b>, PETSC_DECIDE); </p>
<p class="m_-1095046491910575780p1"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:11pt">//Populate MPI Vector R with local (sequential) "Vec".<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="m_-1095046491910575780p1">VecGetOwnershipRange(R, &istart, &iend); </p>
<p class="m_-1095046491910575780p1">local_size = iend - istart; //The local_size should be ‘<b>n</b>’ right?</p></div></div></div></blockquote><div><br></div><div>Well yes, but you are going to need to get the "istart" from Q, not R, to get the global index in a loop.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1">
<p class="m_-1095046491910575780p1">VecGetArray(R, &values);</p></div></div></div></blockquote><div><br></div><div>No, you want to get the values from Q and use VecSetValue(R,...</div><div><br></div><div>VecGetArray(Q, &values_Q);<br></div><div><br></div><div>VecGetOwnershipRange(R, &istart_R, NULL);<br></div><div>idx = istart_R</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1"><p class="m_-1095046491910575780p1"> </p>
<p class="m_-1095046491910575780p1"><span class="m_-1095046491910575780apple-converted-space"> </span><span class="m_-1095046491910575780s1"><b>for</b></span> (i =
<span class="m_-1095046491910575780s2">0</span>; i < local_size_Q; i++) {</p></div></div></div></blockquote><div><br></div><div>No, redo the loop above that you used to count. You skipped this so I can put it here.</div><div>(simpler to just run this loop twice, first count and then set)</div><div><br></div><div>If (values_Q[i] != 0) [</div><div> VecSetValue(R, idx++, (PetscScalar) istart_Q+i, <a href="https://petsc.org/main/docs/manualpages/Sys/INSERT_VALUES/" style="box-sizing:border-box;background-color:rgb(245,245,245);text-decoration-line:none;font-family:SFMono-Regular,Menlo,Consolas,Monaco,"Liberation Mono","Lucida Console",monospace;font-size:13.125px;white-space:nowrap">INSERT_VALUES</a>)<br></div><div>} <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 class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1">
<p class="m_-1095046491910575780p1"><span class="m_-1095046491910575780apple-converted-space"> </span>values[i] = Vec[i];</p></div></div></div></blockquote><div> <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 class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1">
<p class="m_-1095046491910575780p1"><span class="m_-1095046491910575780apple-converted-space"> </span>}</p>
<p class="m_-1095046491910575780p1">VecRestoreArray(R, &values);</p></div></div></div></blockquote><div>VecRestoreArray(Q, &values_Q);<br></div><div><br></div><div>You don't really need a VecAsseemblyBegin/End (R) here but you can add it to be clear.</div><div><br></div><div><div>I'm not sure this is correct so you need to debug this and the scatter can be figured out later.</div><br class="gmail-Apple-interchange-newline"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1"><p class="m_-1095046491910575780p1"> </p>
<p class="m_-1095046491910575780p1"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:11pt">//Scatter R to all processors
<u></u><u></u></span></p>
<p class="m_-1095046491910575780p1"><u></u> <u></u></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">Vec V_SEQ;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">VecScatter ctx;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black"> <u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">VecScatterCreateToAll(R,&ctx,&V_SEQ);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black"><u></u> </span></p></div></div></div></blockquote><div><br></div><div>I'm not sure how to best do this. Look in the docs or ask in a separate thread. This thread is busy figuring the first part out.</div><div><br></div><div> <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 class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1"><p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black"><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">//Remove duplicates in V_SEQ<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">How can I use PetscSortRemoveDupsInt to remove duplicates in V_SEQ?<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">Physics behind:<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">I am reading a parallel mesh, and want to mark all the boundary nodes. I use a local (sequential) Vec to store the boundary nodes for each parallel partition.
Hence, local Vecs can end up with duplicate node index among them, which I would like to get rid of when I combine all of them together.</span></p></div></div></div></blockquote><div><br></div><div>Humm, OK, I'm not sure I get this exactly but yes this is intended to get each process a global list of (boundary) vertices.</div><div>Not super scalable, but if it gets you started then that's great.</div><div><br></div><div>Good luck,</div><div>Mark</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg2834509638292777242"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_-1095046491910575780WordSection1"><p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">Best,<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black">Karthik.<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9pt;font-family:Menlo;color:black"><u></u> <u></u></span></p>
<p class="m_-1095046491910575780p1"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size:12pt;color:black">From:
</span></b><span style="font-size:12pt;color:black">Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank">mfadams@lbl.gov</a>><br>
<b>Date: </b>Friday, 9 December 2022 at 21:08<br>
<b>To: </b>Chockalingam, Karthikeyan (STFC,DL,HC) <<a href="mailto:karthikeyan.chockalingam@stfc.ac.uk" target="_blank">karthikeyan.chockalingam@stfc.ac.uk</a>><br>
<b>Cc: </b>Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>>, <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a> <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject: </b>Re: [petsc-users] Union of sequential vecs<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">If your space is pretty compact, eg, (0,12), you could create an MPI vector Q of size 13, say, and each processor can add 1.0 to Q[Vec[i]], for all "i" in my local "Vec".<u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Then each processor can count the number of local nonzeros in Q, call it n, create a new vector, R, with local size n, then set R[i] = global index of the nonzero for each nonzero in Q, i=0:n.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Do some sort of vec-scatter-to-all with R to get what you want.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Does that work?<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Mark<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
</div>
</div>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">On Fri, Dec 9, 2022 at 3:25 PM Karthikeyan Chockalingam - STFC UKRI via petsc-users <</span><a href="mailto:petsc-users@mcs.anl.gov" target="_blank"><span style="font-size:11pt">petsc-users@mcs.anl.gov</span></a><span style="font-size:11pt">>
wrote:<u></u><u></u></span></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">That is where I am stuck,
<u>I don’t know</u> who to combine them to get Vec = {2,5,7,8,10,11,12}.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">I just want them in an MPI vector.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">I finally plan to call VecScatterCreateToAll so that all processor gets a copy.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Thank you.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Kind regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Karthik.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size:12pt;color:black">From:
</span></b><span style="font-size:12pt;color:black">Barry Smith <</span><a href="mailto:bsmith@petsc.dev" target="_blank"><span style="font-size:12pt">bsmith@petsc.dev</span></a><span style="font-size:12pt;color:black">><br>
<b>Date: </b>Friday, 9 December 2022 at 20:04<br>
<b>To: </b>Chockalingam, Karthikeyan (STFC,DL,HC) <</span><a href="mailto:karthikeyan.chockalingam@stfc.ac.uk" target="_blank"><span style="font-size:12pt">karthikeyan.chockalingam@stfc.ac.uk</span></a><span style="font-size:12pt;color:black">><br>
<b>Cc: </b></span><a href="mailto:petsc-users@mcs.anl.gov" target="_blank"><span style="font-size:12pt">petsc-users@mcs.anl.gov</span></a><span style="font-size:12pt;color:black"> <</span><a href="mailto:petsc-users@mcs.anl.gov" target="_blank"><span style="font-size:12pt">petsc-users@mcs.anl.gov</span></a><span style="font-size:12pt;color:black">><br>
<b>Subject: </b>Re: [petsc-users] Union of sequential vecs</span><span style="font-size:11pt"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:11pt"> How are you combining them to get Vec = {2,5,7,8,10,11,12}?<u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> Do you want the values to remain on the same MPI rank as before, just in an MPI vector?<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="font-size:11pt"><u></u> <u></u></span></p>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<p class="MsoNormal"><span style="font-size:11pt">On Dec 9, 2022, at 2:28 PM, Karthikeyan Chockalingam - STFC UKRI via petsc-users <</span><a href="mailto:petsc-users@mcs.anl.gov" target="_blank"><span style="font-size:11pt">petsc-users@mcs.anl.gov</span></a><span style="font-size:11pt">>
wrote:<u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Hi,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">I want to take the union of a set of sequential vectors, each living in a different processor.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Say,<span class="m_-1095046491910575780m5796220908723221417apple-converted-space"> </span><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Vec_Seq1 = {2,5,7}<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Vec_Seq2 = {5,8,10,11}<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Vec_Seq3 = {5,2,12}.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Finally, get the union of all them Vec = {2,5,7,8,10,11,12}.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">I initially wanted to create a parallel vector and insert the (sequential vector) values but I do not know, to which index to insert the values to.
But I do know the total size of Vec (which in this case is 7).<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Any help is much appreciated.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Kind regards,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Karthik.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
<p style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span style="font-size:6pt;font-family:Helvetica">This email and any attachments are intended solely for the use of the named recipients. If you are not the intended recipient you must
not use, disclose, copy or distribute this email or any of its attachments and should notify the sender immediately and delete this email from your system. UK Research and Innovation (UKRI) has taken every reasonable precaution to minimise risk of this email
or any attachments containing viruses or malware but the recipient should carry out its own virus and malware checks before opening the attachments. UKRI does not accept any liability for any losses or damages which the recipient may sustain due to presence
of any viruses. </span></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><span style="font-size:11pt"> <u></u><u></u></span></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div></blockquote></div></div>