[petsc-users] How to get Matrix from MatGetArray()
Matthew Knepley
knepley at gmail.com
Sat Oct 1 10:56:06 CDT 2011
On Sat, Oct 1, 2011 at 10:44 AM, behzad baghapour <
behzad.baghapour at gmail.com> wrote:
> OK. All I am concering is:
>
> 1- define matrix A in sparse format AIJ.
> 2- Get the content of A.
> 3- change the content of A for some elements
> 4- Restore the changed matrix back into origin.
>
> I test MatGetArray( Mat A, PetscScalar* a ) but I couldnt find the correct
> content of matrix by using a[i*n+j]. I need to know how to access the
> elements of an assembled sparse matrix.
>
> Am I clear now?
>
No, definitely do not do that. The whole point of PETSc matrices is that you
do not do this. This is what
is wrong with 90% of numerical software. You want *interfaces*, not data
structures. That allows you
to seamlessly
- work in parallel
- work on GPUs
- optimize for different architectures
What you want to do is use MatSetValues() (or MatZeroRows, etc.) to change
your entries.
Matt
>
> Thanks
> Behzad
>
> On Sat, Oct 1, 2011 at 6:56 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>
>> On Sat, Oct 1, 2011 at 10:23, behzad baghapour <
>> behzad.baghapour at gmail.com> wrote:
>>
>>> I meant by MatAssembly, the global indices of matrix elements (related to
>>> a dense format) which is changed into sparse one.
>>
>>
>> I don't understand what you mean. It doesn't make sense to convert "dense"
>> indices into sparse ones.
>>
>>
>>> So what would be right pattern to read the content of the Matrix from
>>> MatGetArray if I know that the original matrix is created by AIJ?
>>
>>
>> Use MatGetRow() if you need access to this. (The internal data structures
>> are different in parallel and serial, so accessing them directly is bad.)
>>
>
>
>
> --
> ==================================
> Behzad Baghapour
> Ph.D. Candidate, Mechecanical Engineering
> University of Tehran, Tehran, Iran
> https://sites.google.com/site/behzadbaghapour
> Fax: 0098-21-88020741
> ==================================
>
>
--
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/20111001/32089361/attachment.htm>
More information about the petsc-users
mailing list