<div dir="ltr">I don't care the little extra overhead. I just feel the avoidable loop in the user code a bit ugly.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">--Junchao Zhang</div></div></div>
<br><div class="gmail_quote">On Fri, Apr 20, 2018 at 4:11 PM, Smith, Barry F. <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
  I would just use VecSetValues() since almost all values are local it will be scalable and a little extra time in setting values is not a big deal for this test code.<br>
<span class="HOEnZb"><font color="#888888"><br>
   Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
> On Apr 20, 2018, at 4:09 PM, Jed Brown <<a href="mailto:jed@jedbrown.org">jed@jedbrown.org</a>> wrote:<br>
> <br>
> Junchao Zhang <<a href="mailto:jczhang@mcs.anl.gov">jczhang@mcs.anl.gov</a>> writes:<br>
> <br>
>> VecScatter is too heavy (in both coding and runtime) for this simple task.<br>
>> I just want to pad a vector loaded from a PetscViewer to match an MPIBAIJ<br>
>> matrix. Thus the majority is memcpy, with few neighborhood off-processor<br>
>> puts.<br>
> <br>
> At what address do those puts go, how do you avoid race conditions from<br>
> multiple processors having overlapping neighborhoods, and how does the<br>
> recipient know that the put has completed?  Just use VecScatter.  It<br>
> could be optimized to recognize contiguous runs above a certain size and<br>
> convert to memcpy.<br>
> <br>
>> --Junchao Zhang<br>
>> <br>
>> On Fri, Apr 20, 2018 at 3:57 PM, Jed Brown <<a href="mailto:jed@jedbrown.org">jed@jedbrown.org</a>> wrote:<br>
>> <br>
>>> Junchao, If you need to access off-process values and put them into a<br>
>>> new vector, you should use VecScatter.<br>
>>> <br>
>>> "Smith, Barry F." <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> writes:<br>
>>> <br>
>>>>  Setting large contiguous blocks of values is not a common use case. In<br>
>>> finite elements the values are not contiguous.<br>
>>>> <br>
>>>>> On Apr 20, 2018, at 3:45 PM, Zhang, Junchao <<a href="mailto:jczhang@mcs.anl.gov">jczhang@mcs.anl.gov</a>><br>
>>> wrote:<br>
>>>>> <br>
>>>>> I agree the extra overhead can be small, but users are forced to write<br>
>>> a loop where one single line gives the best.<br>
>>>>> <br>
>>>>> --Junchao Zhang<br>
>>>>> <br>
>>>>> On Fri, Apr 20, 2018 at 3:36 PM, Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>><br>
>>> wrote:<br>
>>>>> <br>
>>>>>   When setting values into matrices and vectors we consider the<br>
>>> "extra" overhead of needing to pass in the indices for all the values<br>
>>> (instead of being able to set an arbitrary block of values without using<br>
>>> indices for each one) to be a minimal overhead that we can live with.<br>
>>>>> <br>
>>>>>   Barry<br>
>>>>> <br>
>>>>> <br>
>>>>>> On Apr 20, 2018, at 3:33 PM, Junchao Zhang <<a href="mailto:jczhang@mcs.anl.gov">jczhang@mcs.anl.gov</a>><br>
>>> wrote:<br>
>>>>>> <br>
>>>>>> <br>
>>>>>> On Fri, Apr 20, 2018 at 3:18 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>><br>
>>> wrote:<br>
>>>>>> On Fri, Apr 20, 2018 at 4:10 PM, Junchao Zhang <<a href="mailto:jczhang@mcs.anl.gov">jczhang@mcs.anl.gov</a>><br>
>>> wrote:<br>
>>>>>> To pad a vector, i.e., copy a vector to a new one, I have to call<br>
>>> VecSetValue(newb,1,&idx,...) for each element. But to be efficient, what I<br>
>>> really needs is to set a block of values in one call. It looks PETSc does<br>
>>> not have a routine for that(?). I looked at VecSetValuesBlocked, but it<br>
>>> looks it is not for that purpose.<br>
>>>>>> Should we have something like VecSetValuesBlock(Vec v,PetscInt<br>
>>> i,PetscInt cnt,PetscScalar *value, InsertMode mode) to set cnt values<br>
>>> starting at index i?<br>
>>>>>> <br>
>>>>>> Use VecGetArray().<br>
>>>>>> Did you mean VecGetArray b and newb, do a memcpy from b to new and<br>
>>> then restore them? If yes, it does not work since some of the values I want<br>
>>> to set might be remote.<br>
>>>>>> E.g, I have 4 processors. b's size is 181 and is distributed as 46,<br>
>>> 45,45,45, newb is distributed as 48,45,45,45 to match a matrix of block<br>
>>> size 3.<br>
>>>>>> <br>
>>>>>> <br>
>>>>>>  Matt<br>
>>>>>> <br>
>>>>>> --Junchao Zhang<br>
>>>>>> <br>
>>>>>> <br>
>>>>>> <br>
>>>>>> --<br>
>>>>>> What most experimenters take for granted before they begin their<br>
>>> experiments is infinitely more interesting than any results to which their<br>
>>> experiments lead.<br>
>>>>>> -- Norbert Wiener<br>
>>>>>> <br>
>>>>>> <a href="https://www.cse.buffalo.edu/~knepley/" rel="noreferrer" target="_blank">https://www.cse.buffalo.edu/~<wbr>knepley/</a><br>
>>>>>> <br>
>>>>> <br>
>>>>> <br>
>>> <br>
<br>
</div></div></blockquote></div><br></div>