[petsc-users] Scatter parallel Vec to sequential Vec on non-zeroth process

Junchao Zhang junchao.zhang at gmail.com
Wed Jun 30 09:34:38 CDT 2021


OK, then we should optimize this case.  VecScatterCreateToZero() uses
MPI_Gather/Gatherv.  But in your case, petsc will use individual MPI
send/recvs, though it is possible to use Gather/Gatherv.
I created a follow-up issue https://gitlab.com/petsc/petsc/-/issues/950

Thanks.
--Junchao Zhang


On Wed, Jun 30, 2021 at 9:07 AM Peder Jørgensgaard Olesen <pjool at mek.dtu.dk>
wrote:

> Dear Junchao Zhang
>
>
> I'm distributing a set of independent tasks over different processes, so
> I'm afraid sending everything to the zeroth process would rather
> thoroughly defeat the purpose of what I'm doing.
>
>
> Med venlig hilsen / Best regards
>
> Peder
> ------------------------------
> *Fra:* Junchao Zhang <junchao.zhang at gmail.com>
> *Sendt:* 30. juni 2021 16:00:25
> *Til:* Peder Jørgensgaard Olesen
> *Cc:* Matthew Knepley; petsc-users at mcs.anl.gov
> *Emne:* Re: [petsc-users] Scatter parallel Vec to sequential Vec on
> non-zeroth process
>
> That should work. But VecScatterCreateToZero() is more efficient. So if
> possible, better refactor your code in such a way.
>
> --Junchao Zhang
>
> On Wed, Jun 30, 2021 at 7:13 AM Peder Jørgensgaard Olesen via petsc-users <
> petsc-users at mcs.anl.gov> wrote:
>
>> Dear Matt
>>
>>
>> Thank you for your reply. I'm guessing that the line
>>
>> if (rank) N = 0;
>>
>> should be changed to something like
>>
>> if (rank != target_rank) N = 0;
>>
>> such that an empty SEQVEC and scatter are created on each rank other than
>> target_rank.
>>
>>
>> Med venlig hilsen / Best regards
>>
>> Peder
>> ------------------------------
>> *Fra:* Matthew Knepley <knepley at gmail.com>
>> *Sendt:* 30. juni 2021 13:58:49
>> *Til:* Peder Jørgensgaard Olesen
>> *Cc:* petsc-users at mcs.anl.gov
>> *Emne:* Re: [petsc-users] Scatter parallel Vec to sequential Vec on
>> non-zeroth process
>>
>> On Wed, Jun 30, 2021 at 6:49 AM Peder Jørgensgaard Olesen via petsc-users
>> <petsc-users at mcs.anl.gov> wrote:
>>
>>> Hello
>>>
>>>
>>> I have a parallel vector, and I'd like to copy its data to a sequential
>>> vector located on a given process that is not necessarily the
>>> 0th process, so using VecScatterCreateToZero wouldn't do here.
>>>
>>>
>>> How might one approach this?
>>>
>> The function is very short:
>> https://www.mcs.anl.gov/petsc/petsc-current/src/vec/is/sf/interface/vscat.c.html#VecScatterCreateToZero
>> Just go in and replace '0' by the rank you want.
>>
>>   Thanks,
>>
>>      Matt
>>
>>> Med venlig hilsen / Best Regards
>>>
>>>
>>> Peder Jørgensgaard Olesen
>>>
>>> PhD Student, Turbulence Research Lab
>>>
>>> Dept. of Mechanical Engineering
>>>
>>> Technical University of Denmark
>>>
>>> Koppels Allé
>>>
>>> Bygning 403, Rum 105
>>>
>>> DK-2800 Kgs. Lyngby
>>>
>>
>>
>> --
>> What most experimenters take for granted before they begin their
>> experiments is infinitely more interesting than any results to which their
>> experiments lead.
>> -- Norbert Wiener
>>
>> https://www.cse.buffalo.edu/~knepley/
>> <http://www.cse.buffalo.edu/~knepley/>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20210630/92248679/attachment-0001.html>


More information about the petsc-users mailing list