How to get the address of an element in the matrix

Matthew Knepley knepley at gmail.com
Thu Aug 10 15:50:34 CDT 2006


On 8/10/06, Julian <julvar at tamu.edu> wrote:
> Hi,
>
> Is there any way to get the address/location of a particular element in the
> matrix, say mat[i,j]

This would defeat the purpose of the interface. NO sparse matrix format
supports this access. In fact, they all have individual access routines. We
present the interface so that you never hav to rewrite your code if the matrix
storage format changes. Furthermore, this works equally well in parallel. If you
need mat[i,j], your algorithm is probably wrong.

    Matt

> So I can use that address later on to change the value of that element
> rather than using MatSetValues.
> I am currently using MatGetValues to get the value as such...
>         PetscScalar val;
>         MatGetValues(mat, 1, &i, 1, &j, &val);
>
> But I would like something where I can pass a pointer and then the pointer
> will be pointing to mat[i,j] such as
>         PetscScalar *val;
>         MatGetReference(mat, i, j, val);
>
> Is there something like this already in place ? Or is it not allowed because
> of the way the matrix is implemented internally?
>
> Thanks,
> Julian.
>
>


-- 
"Failure has a thousand explanations. Success doesn't need one" -- Sir
Alec Guiness




More information about the petsc-users mailing list