<div dir="ltr"><div><br></div>Antoine,<br> See the attached example. It does sort on rank 0 but puts the permutation results in parallel. Run it with mpirun -n 3 ./ex2 for a demo.<div><span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px"></span></div> Thanks.<br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">--Junchao Zhang</div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 9, 2020 at 1:24 PM Antoine Côté <<a href="mailto:Antoine.Cote3@usherbrooke.ca">Antoine.Cote3@usherbrooke.ca</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">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
The Vec containing the scalars represents stresses at nodes points of a DMDA. My program sorts stresses, and makes calculations according to their rank. This needs to be done <span style="font-family:Calibri,Arial,Helvetica,sans-serif">while keeping track of
the original positions of stresses in Vec. Using permutations, I can access the node of my choice and get its associated rank, without changing the original Vec.</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif"><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif">Regards,</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif"><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif">Antoine</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div id="gmail-m_-2092248979562482186appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-2092248979562482186divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>De :</b> Junchao Zhang <<a href="mailto:junchao.zhang@gmail.com" target="_blank">junchao.zhang@gmail.com</a>><br>
<b>Envoyé :</b> 9 juillet 2020 12:42<br>
<b>À :</b> Antoine Côté <Antoine.Cote3@USherbrooke.ca><br>
<b>Objet :</b> Re: [petsc-users] Parallel sort in Petsc</font>
<div> </div>
</div>
<div>
<div dir="ltr">It is easier without permutations. So let me ask first do you need the permutations or just a (parallel) sorted vector?<br>
<div><font color="#000000" face="Calibri, Arial, Helvetica, sans-serif"><span style="font-size:16px"><br clear="all">
</span></font>
<div>
<div dir="ltr">
<div dir="ltr">--Junchao Zhang</div>
</div>
</div>
<br>
</div>
</div>
<br>
<div>
<div dir="ltr">On Thu, Jul 9, 2020 at 11:21 AM Antoine Côté <<a href="mailto:Antoine.Cote3@usherbrooke.ca" target="_blank">Antoine.Cote3@usherbrooke.ca</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
That is worth trying!</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Say I gather to process 0 as proposed here : <a href="https://can01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.mcs.anl.gov%2Fpetsc%2Fdocumentation%2Ffaq.html%23mpi-vec-to-mpi-vec&data=02%7C01%7CAntoine.Cote3%40usherbrooke.ca%7C5b19e2103f434ddd79a308d824270a5c%7C3a5a8744593545f99423b32c3a5de082%7C0%7C0%7C637299097387394607&sdata=4qRikFqiT7IavQKuVjS6rs9L9KsPPIHC23Ekfov1Jvg%3D&reserved=0" target="_blank">https://www.mcs.anl.gov/petsc/documentation/faq.html#mpi-vec-to-mpi-vec</a></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Let Vec A be the vector containing the scalars. If I compute the permutations I'm looking for, how do I :</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
- tell the code to run PetscSortRealWithPermutation() <u>only </u>on process 0 ?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
- distribute back the permutations on all process (that is, send only the permutations concerning the local portion of Vec A stored by a given process) ?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
- make sure other processes wait until they receive the permutations prior proceeding with the rest of the code ?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Thank you very much!</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Antoine</div>
<div id="gmail-m_-2092248979562482186x_gmail-m_4248000772018166989appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-2092248979562482186x_gmail-m_4248000772018166989divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>De :</b> Junchao Zhang <<a href="mailto:junchao.zhang@gmail.com" target="_blank">junchao.zhang@gmail.com</a>><br>
<b>Envoyé :</b> 7 juillet 2020 10:52<br>
<b>À :</b> Antoine Côté <Antoine.Cote3@USherbrooke.ca><br>
<b>Cc :</b> <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>Objet :</b> Re: [petsc-users] Parallel sort in Petsc</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>Gather all values to rank 0 and do a sequential sort there, then profile to see whether it is a performance bottleneck in your code.</div>
<br clear="all">
<div>
<div dir="ltr">
<div dir="ltr">--Junchao Zhang</div>
</div>
</div>
<br>
</div>
<br>
<div>
<div dir="ltr">On Tue, Jul 7, 2020 at 8:14 AM Antoine Côté <<a href="mailto:Antoine.Cote3@usherbrooke.ca" target="_blank">Antoine.Cote3@usherbrooke.ca</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">Hi,</span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="background-color:rgb(255,255,255);color:rgb(0,0,0)"><font face="Calibri, Arial, Helvetica, sans-serif"><span style="font-size:12pt">I need to compute the permutations to sort scalar values of a Vec object in decreasing order. I've been
</span>developing<span style="font-size:12pt"> on a single process for now, using
</span></font><span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">VecGetArrayRead</span><span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">() to extract the values and PetscSortRealWithPermutation() to get
the permutations.</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
I would like to run the code on multiple processes. From these links, I can see it's an issue : </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<a href="https://can01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.mcs.anl.gov%2Fpipermail%2Fpetsc-users%2F2013-November%2F019628.html&data=02%7C01%7CAntoine.Cote3%40usherbrooke.ca%7C5b19e2103f434ddd79a308d824270a5c%7C3a5a8744593545f99423b32c3a5de082%7C0%7C0%7C637299097387404606&sdata=I1XaEkfaCXpIpHOHH3ErtQyoxMLnRwqFysh1v%2BybfSY%3D&reserved=0" target="_blank">https://lists.mcs.anl.gov/pipermail/petsc-users/2013-November/019628.html</a><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<a href="https://can01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.mcs.anl.gov%2Fpipermail%2Fpetsc-users%2F2009-June%2F004621.html&data=02%7C01%7CAntoine.Cote3%40usherbrooke.ca%7C5b19e2103f434ddd79a308d824270a5c%7C3a5a8744593545f99423b32c3a5de082%7C0%7C0%7C637299097387404606&sdata=A9i3R3enHTQjWXLY2yiDNSesporutJPUobU1%2F3Nvk9s%3D&reserved=0" target="_blank">https://lists.mcs.anl.gov/pipermail/petsc-users/2009-June/004621.html</a></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
One work around I've been considering : get the max scalar value using VecMax() ; compute a scaling factor that makes this max value equals the largest integer value tolerated by PetscInt ; scale all values of Vec and convert them to integers ; use PetscParallelSortInt()
; inverse the scaling on (now sorted) integers values and convert them back to scalars.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
This is only a patch really, the main issues being : <span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">(1) I would get a sorted Vec, not the permutations and (2) there would be a lost of information when converting scalars to int
values.</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt"><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">Isn't there a way to parallel sort real values using Petsc?<br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt"><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">Thank you very much!</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt"><br>
</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt">Antoine Côté</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote></div>