[petsc-users] about VecGetArray()

Matthew Knepley knepley at gmail.com
Sat Jun 7 07:53:11 CDT 2014


On Sat, 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.
>

We cannot know what you mean by "the correct answer". Vec is just a 1D
array of memory. You decide on the organization inside.

   Matt


> **************************************************************
> 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);
> *********************************************************
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140607/3dfbbf53/attachment.html>


More information about the petsc-users mailing list