<div dir="ltr">Hi, Hannes,<div> It looks your concern is no enough memory to store vector entries needed in SpMV (instead of the performance one might gain by doing computation immediately upon arrival of data from neighbors). Please note in petsc SpMV, it does not need to store the whole vector locally, it only needs some entries (e.g., corresponding to nonzero columns). If storing these sparse entries causes memory consumption problems for you, then I wonder how you would store your matrix, which supposedly needs more memory.</div><div><br></div><div>With that said, petsc vecscatter does not have something like VecScatterWaitAny(). For your experiment, you can leverage info provided by vecscatter, since the communication analysis part is hard. Let's say you created VecScatter <i>sf</i> to scattering MPI Vec x to sequential Vec y (Note PetscSF and Vecscatter are the same type)</div><div><br></div><div>Call <a href="https://petsc.org/release/docs/manualpages/PetscSF/PetscSFGetLeafRanks.html#PetscSFGetLeafRanks">PetscSFGetLeafRanks</a>(<a href="https://petsc.org/release/docs/manualpages/PetscSF/PetscSF.html#PetscSF">PetscSF</a> sf,<a href="https://petsc.org/release/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> *niranks,const <a href="https://petsc.org/release/docs/manualpages/Sys/PetscMPIInt.html#PetscMPIInt">PetscMPIInt</a> **iranks,const <a href="https://petsc.org/release/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> **ioffset,const <a href="https://petsc.org/release/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a> **irootloc) to get send info</div><div><pre>niranks: number of MPI ranks to which this rank wants to send entries of x</pre><pre>iranks[]: of length niranks, storing MPI ranks mentioned above</pre><pre>ioffset[]: of length niranks+1. ioffset[] stores indices to irootloc[].</pre><pre>irootloc[]: irootloc[ioffset[i]..ioffset[i+1]] stores (local) indices of entries of x that should be sent to iranks[i]</pre></div><div><br></div><div>Call <a href="https://petsc.org/release/docs/manualpages/PetscSF/PetscSFGetRootRanks.html#PetscSFGetRootRanks">PetscSFGetRootRanks</a><span style="color:rgb(0,0,0)">(</span><a href="https://petsc.org/release/docs/manualpages/PetscSF/PetscSF.html#PetscSF">PetscSF</a><span style="color:rgb(0,0,0)"> sf,</span><a href="https://petsc.org/release/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a><span style="color:rgb(0,0,0)"> *nranks,const </span><a href="https://petsc.org/release/docs/manualpages/Sys/PetscMPIInt.html#PetscMPIInt">PetscMPIInt</a><span style="color:rgb(0,0,0)"> **ranks,const </span><a href="https://petsc.org/release/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a><span style="color:rgb(0,0,0)"> **roffset,const </span><a href="https://petsc.org/release/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a><span style="color:rgb(0,0,0)"> **rmine,const </span><a href="https://petsc.org/release/docs/manualpages/Sys/PetscInt.html#PetscInt">PetscInt</a><span style="color:rgb(0,0,0)"> **rremote) to get receive info</span><br></div><div><pre style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif">nranks: number of MPI ranks from which this rank will receive entries of x</span><br></pre><pre style="color:rgb(0,0,0)">ranks[]: of length nranks, storing MPI ranks mentioned above</pre><pre style="color:rgb(0,0,0)">roffset[]: of length nranks+1. roffset[] stores indices to rmine[]</pre><pre style="color:rgb(0,0,0)">rmine[]: rmine[roffset[i]..roffset[i+1]] stores (local) indices of entries of y that should receive data from ranks[i]</pre><div></div><pre style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"><br></span></pre><pre style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">Using above info, you can allocate send/recv buffers, post MPI_Isend/Irecv, and do MPI_Waitany() on MPI_Requests returned from MPI_Irecv. You can use </span>PetscCommGetNewTag<span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">(</span>PetscObjectComm<span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">((PetscObject)sf), </span>&newtag<span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">) to get a good MPI tag for your own MPI_Isend/Irecv.</span><br></pre></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><br></div><div dir="ltr">--Junchao Zhang</div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 26, 2021 at 7:41 AM Hannes Phil Niklas Brandt <<a href="mailto:s6hsbran@uni-bonn.de">s6hsbran@uni-bonn.de</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">Hello,<br>
<br>
I<br>
am interested in the non-blocking, collective communication of<br>
Petsc-Vecs.<br>
Right<br>
now I am using VecScatterBegin and<br>
VecScatterEnd to scatter different entries of a parallel distributed<br>
MPI-Vec to local sequential vectors on each process.<br>
After the call to VecScatterEnd I perform<br>
separate<br>
computations on each block of the<br>
sequential Vec<br>
corresponding to a process.<br>
However,<br>
I would prefer to use each block of the local sequential Vec for<br>
those further<br>
computations as soon as I receive it from the<br>
corresponding process (so I do not want to<br>
wait for the whole scattering<br>
to finish). Are there functionalities in Petsc capable<br>
of this?<br>
<br>
I<br>
am trying to compute the matrix-vector-product for a parallel<br>
distributed MPI-Vec and a parallel distributed sparse matrix format I<br>
implemented myself. Each process needs entries from the whole MPI-Vec<br>
for the product, but does not have enough storage capacities to store<br>
those entries all at once, not even in a sparse format. Therefore, I need to<br>
process the entries in small blocks and add the results onto a local<br>
result vector.<br>
<br>
Best<br>
Regards<br>
Hannes<br>
p { margin-bottom: 0.25cm; line-height: 115%; background: transparent }<br>
</blockquote></div>