[petsc-users] DMCreateGlobalVector and DMGetGlobalVector

Dave May dave.mayhem23 at gmail.com
Wed Feb 4 03:25:28 CST 2015


On Wednesday, 4 February 2015, bichinhoverde <
bichinhoverde at spwinternet.com.br> wrote:

> Ok, but from a PETSc user perspective, what is the difference between
> create and get?
>
> When should I use get and when should I use create?
>

It's a memory saving optimization.
It's a cache of vectors you can use. It's clever as it lets you reuse data
rather always create/destroying objects.

>
> Can I call create several times to create several vectors? Is it the same
> as creating one and then duplicating?
>
> Yes to both


> Can I call get several times to get several vectors? Is it the same as
> getting one and then duplicating?
>
>
Functionally, both approaches are equivalent. However duplicating always
allocated new memory thus the total memory footprint will increase.



> If I replace all gets with creates, or all creates with gets in my code,
> what will change?
>

If you change all creates to gets, probably the most notable difference
would be the memory usage.  Plus whatever extra time is required for
creating which isn't incurred when you re use vectors.

Note that the DMGetVec will NOT initialize the entries to zero (unlike the
Create variants). The user is responsible for that task.


>
>
>
>
> On Wed, Feb 4, 2015 at 5:16 AM, Jed Brown <jed at jedbrown.org
> <javascript:_e(%7B%7D,'cvml','jed at jedbrown.org');>> wrote:
>
>> bichinhoverde <bichinhoverde at spwinternet.com.br
>> <javascript:_e(%7B%7D,'cvml','bichinhoverde at spwinternet.com.br');>>
>> writes:
>>
>> > Hi. I have some questions.
>> >
>> > What is the difference between DMCreateGlobalVector and
>> DMGetGlobalVector
>> > (and the local counterparts)?
>>
>> Create creates a vector that the caller owns.  Get merely gets access to
>> a vector from a managed pool (creating it if necessary), to be returned
>> via DMRestoreGlobalVector().
>>
>> > What happens when one calls SNESSolve with NULL for the solution
>> vector, as
>> > in src/snes/examples/tutorials/ex7.c:158? SNESSolve(snes,NULL,NULL);
>>
>> A vector is created automatically.  You can get access to it with
>> SNESGetSolution.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150204/758ff757/attachment.html>


More information about the petsc-users mailing list