[petsc-users] Two ways to set Vec values?

Rob Ellis Robert.G.Ellis at Shaw.ca
Tue Dec 22 12:04:12 CST 2009

Hi Petsc'ers

Can someone please let me know if I can set MPI vector values using either
of the following methods? I wish to set the values of 'x' from the values in
'work'. Both methods operate correctly, but I would like to know which is
more efficient, and/or recommended and why.

1. GetArray/RestoreArray Method:

call VecGetOwnershipRange(x,imin,imax,ierr)
call VecGetArray(x,x_local_v,x_local_i,ierr)
do i=imin,imax-1
call VecRestoreArray(x,x_local_v,x_local_i,ierr)

2. SetValues/VecAssembly Method:

call VecGetOwnershipRange(x,imin,imax,ierr)
nx_local = imax-imin
do i=imin,imax-1
call VecSetValues(x,nx_local,icol,work(imin+1),INSERT_VALUES,ierr)
call VecAssemblyBegin(x,ierr)
call VecAssemblyEnd(x,ierr)

Method 1 is more compact and does not require the auxiliary column number
vector, nor does it require the VecAssembly, however, it seems to be what is
suggested by the examples. Also, is it recommended to use VecGetArrayF90? 

Thanks for your help,

More information about the petsc-users mailing list