[petsc-users] about VecGetArray()

Barry Smith bsmith at mcs.anl.gov
Sat Jun 7 10:45:58 CDT 2014


  It looks like you are trying to access the entire vector on all processes. You cannot do this. VecGetArray() only gives you access to the local values. If you need to access the entire vector on each process (which is not scalable or a good idea) you can use VecScatterCreateToAll() or VecScatterCreateToZero() then scatter the vector then use VecGetArray() on the now new sequential vector.

   Barry

On Jun 7, 2014, at 1:40 AM, LikunTan <tlk0812 at hotmail.com> wrote:

> Hello,
> 
> I defined the partition of Vector, which is not stored contiguously. Here is a part of my code. The total number of nodes is NODE*DOF. Before executing this following code, I defined LEN and an array NODENP[] to store the number of nodes and the list of nodes in each processor. I accessed the element using aM[node*DOF+j] and aM[i*DOF+j], but none of them gave me the correct answer. Your help is well appreciated.
> 
> **************************************************************
> VecCreate(PETSC_COMM_WORLD, &M);
> VecSetSizes(M, LEN*DOF, NODE*DOF);  
> 
> VecGetArray(M, &aM); 
> 
> for(int i=0; i<LEN; i++)
> {
>     node=NODENP[i];
>     for(int j=0; j<DOF; j++)
>     {
>         aM[node*DOF+j] or aM[i*DOF+j] ?  //accessing the elements of M
>         
>     }
> }
> VecRestoreArray(M, &aM); 
> *********************************************************



More information about the petsc-users mailing list