setting values in parallel vectors

Khan, Irfan irfan.khan at gatech.edu
Thu Apr 2 14:09:51 CDT 2009


Thank you, that was very helpful. Please do let me know if I understood this right. Generally VecSetValues()+VecGhostUpdateBegin/End() is faster than VecGetArray()+assign_array()+VecRestoreArray()+VecGhostUpdateBegin/End(). Also both these operation would be equivalent.

Thank you
Irfan

----- Original Message -----
From: "Jed Brown" <jed at 59A2.org>
To: petsc-users at mcs.anl.gov
Sent: Thursday, April 2, 2009 2:16:09 PM GMT -05:00 US/Canada Eastern
Subject: Re: setting values in parallel vectors

On Thu 2009-04-02 12:54, Khan, Irfan wrote:
> Hello
> I have a question about setting values in parallel vectors. Which of the following two options is more efficient or does it matter at all.
> 
> Using VecGhostGetLocalForm:
> 
>  - Obtain the local array form of global vector using VeGhostGetLocalForm() and VecGetArray()
>  - Fill in the values 
>  - Use VecGhostRestoreLocalForm() and VecRestoreArray()
>  - Use VecGhostUpdateBegin() and VecGhostUpdateEnd()
> 
> Using VecSetValues:
> 
>  - Fill in the values of the values in the global parallel vector using VecSetValues()
>  - Use VecAssemblyBegin() and VecAssemblyEnd()
> 
> 
> Please note that in both the cases the values being filled are local values to the rank.

These choices are not equivalent.  Assuming you use

  VecGhostUpdateBegin(x,INSERT_VALUES,SCATTER_FORWARD);
  VecGhostUpdateEnd(x,INSERT_VALUES,SCATTER_FORWARD);

the ghosted values will be updated on every process.  In contrast
VecAssemblyBegin/End only updates the owner's copy, it knows nothing
about the ghost values.  If you are only setting owned values,
VecAssembly* does almost nothing, you will still have to update the
ghost values.  Note that if you only need owned values, you can call
VecGetArray on the global form instead of working with the local form.

Setting local values directly after VecGetArray (with or without the
local form) is faster, but it's irrelevant (VecSetValues is plenty
fast).

Jed


More information about the petsc-users mailing list