<div dir="ltr"><div dir="ltr">On Fri, Dec 9, 2022 at 6:50 PM Karthikeyan Chockalingam - STFC UKRI via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg5272059809090504813">
<div lang="EN-GB" style="overflow-wrap: break-word;">
<div class="m_9063915685637258561WordSection1">
<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_9063915685637258561OWAAM3F9AFB4C861F014AACA86D8A70231CD5" 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?<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".<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Compute number of local nonzeros in Q, call it n.<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_9063915685637258561p1">VecCreate(PETSC_COMM_WORLD, &R); </p>
<p class="m_9063915685637258561p1">VecSetType(R, VECMPI); </p>
<p class="m_9063915685637258561p1">VecSetSizes(R, <b>n</b>, PETSC_DECIDE); </p>
<p class="m_9063915685637258561p1"><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_9063915685637258561p1">VecGetOwnershipRange(R, &istart, &iend); </p>
<p class="m_9063915685637258561p1">local_size = iend - istart; //The local_size should be ‘<b>n</b>’ right?</p>
<p class="m_9063915685637258561p1">VecGetArray(R, &values); </p>
<p class="m_9063915685637258561p1"><span class="m_9063915685637258561apple-converted-space"> </span><span class="m_9063915685637258561s1"><b>for</b></span> (i =
<span class="m_9063915685637258561s2">0</span>; i < local_size; i++) {</p>
<p class="m_9063915685637258561p1"><span class="m_9063915685637258561apple-converted-space"> </span>values[i] = Vec[i];</p>
<p class="m_9063915685637258561p1"><span class="m_9063915685637258561apple-converted-space"> </span>}</p>
<p class="m_9063915685637258561p1">VecRestoreArray(R, &values); </p>
<p class="m_9063915685637258561p1"><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_9063915685637258561p1"><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> <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>1) Blaise is right you should use an IS, not a Vec, to hold node indices. His solution is only a few lines, so I would use it.</div><div><br></div><div>2) I would not recommend doing things this way in the first place. PETSc can manage parallel meshes scalably, marking boundaries using DMLabel objects.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</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="msg5272059809090504813"><div lang="EN-GB" style="overflow-wrap: break-word;"><div class="m_9063915685637258561WordSection1">
<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_9063915685637258561p1"><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_9063915685637258561m5796220908723221417apple-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><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>