[petsc-users] PetscLayout and GetRange

Jed Brown jedbrown at mcs.anl.gov
Wed Jan 16 08:07:51 CST 2013


You can't change the size of the vector after it has been created. You can
reuse the memory if you manage it separately (by calling
VecCreateMPIWithArray()). Don't try to "trick" the Vec.

I'm pretty sure your performance anxiety is premature. Just call
VecDestroy() and create a new Vec for the next iteration.

Note: it's inappropriate to think of a Vec as a dynamic array that you're
using to accumulate an unknown amount of data. The Vec is meant to be used
for linear algebra (including collective semantics). If you're building
something dynamically, build it with a dynamic data structure and then put
into a Vec once the structure is built.


On Wed, Jan 16, 2013 at 8:01 AM, Weston Lowrie <wlowrie at uw.edu> wrote:

> On a related note:
> When using VecGetArray(), it uses the info from VecSetSizes(), which is
> set on Vec creation.  Can this be updated after the Vec has been used?
>
> My issue is that even if I know the proper local size that I want, when I
> call VecGetArray() it's going to use the local size determined on Vec
> creation.
>
> To avoid this problem I could use VecSetValues() for the range I am
> interested in, rather then using the pointer generated from VecGetArray()?
>
> Wes
>
> On Tue, Jan 15, 2013 at 5:31 PM, Weston Lowrie <wlowrie at uw.edu> wrote:
>
>> I don't think there is a inefficiency here.  It will be just one extra
>> empty vector since all the other "real" ones are identical size.  Sounds
>> like a good strategy to me.
>>
>> I'm not quite at the stage where I can profile yet.  I will send if I can
>> get it to a point where it might be significant.
>>
>> Thanks for the help,
>> Wes
>>
>>
>>
>> On Tue, Jan 15, 2013 at 5:26 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>>
>>> On Tue, Jan 15, 2013 at 4:21 PM, Weston Lowrie <wlowrie at u.washington.edu
>>> > wrote:
>>>
>>>> That's interesting.  If I understand you correctly, I would create a
>>>> vector of the size I want specifically for calculating the ownership range,
>>>> then use that on the real vectors.  Sounds like that would work.
>>>>
>>>> In my case, with many vectors, it does not make sense to copy them to a
>>>> resized vector every time I want them to grow leading to many creates and
>>>> destroys.
>>>>
>>>
>>> You can't dynamically resize vectors like that, and the global offsets
>>> change when you resize.
>>>
>>> Please profile before jumping to the conclusion that there is some
>>> terrible inefficiency here. Unless all your loop does is create Vecs of
>>> different sizes, chances are that the VecCreate is insignificant. If you
>>> have a profile in which it's a big deal, please send the profile and
>>> explain what you are doing and why.
>>>
>>>
>>>>
>>>> Wes
>>>>
>>>>
>>>> On Tue, Jan 15, 2013 at 5:15 PM, Jed Brown <jedbrown at mcs.anl.gov>wrote:
>>>>
>>>>> VecGetOwnershipRange()
>>>>>
>>>>> You can use VecCreateMPIWithArray() using your own array preallocated
>>>>> to be as long as you want. If you profile, you'll probably find this is not
>>>>> a meaningful optimization.
>>>>>
>>>>>
>>>>> On Tue, Jan 15, 2013 at 4:12 PM, Weston Lowrie <wlowrie at uw.edu> wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I have a problem where I want to grow the size of a Vec (or Mat) many
>>>>>> times during program execution.  I think for efficiency purposes I would
>>>>>> just want to allocate a maximum size, and then only use the portion that I
>>>>>> need.  In the vector case, it is rather simple, just use the beginning of
>>>>>> the vector, and add values to the end.
>>>>>>
>>>>>> This leads to me to the problem of processor ownership ranges.  From
>>>>>> a previous email I noticed one could use the PetscLayout object and keep
>>>>>> adjusting it as the useful part of the vector grows.  Does this sound like
>>>>>> a good approach?
>>>>>>
>>>>>> I noticed the PetscLayout is not available in Fortran bindings.  Any
>>>>>> workarounds for this?  I suppose I can just manually calculate the
>>>>>> processor ranges?
>>>>>>
>>>>>> Thanks for the help,
>>>>>> Wes
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130116/29c63a96/attachment.html>


More information about the petsc-users mailing list