how do you access the nonzero elements in SeqAIJ matrices

Barry Smith bsmith at mcs.anl.gov
Mon Aug 4 11:14:14 CDT 2008


On Aug 4, 2008, at 11:01 AM, Ahmed El Zein wrote:

>>
> Shouldn't that be the opposite? Isn't the whole idea of an  
> interface, to
> have a set of functions that will work on all matrix types, regardless
> of implementation.

   Yes. However GetIJ and GetArray are NOT in any way natural for
all matrix types so these are not real methods on the matrices.

    Barry

Examples: for dense matrices i and j are nonsense. Some kind of  
hierarchical
storage of the matrix data means the numerical values are not simply
stored in an array.

>
>
> Thanks for the info though. If I can't get direct access I will used
> MatGetRowIJ() + MatGetArray() and hope that the matrices I come across
> will support them.
>
> Ahmed
>>
>>   Matt
>>
>>> Thanks,
>>> Ahmed
>>>>
>>>>  Matt
>>>>
>>>>> and finally I attempted to access the arrays directly like this:
>>>>> Mat_SeqAIJ  *a = (Mat_SeqAIJ*)A->data;
>>>>> MatScalar *val = a->a;
>>>>> PetscInt  *ptr = a->i;
>>>>> PetscInt  *ind = a->j;
>>>>>
>>>>> However when accessing directly I get different values for ptr and
>>>>> SIGSEGV when accessing val or ind.
>>>>>
>>>>> also I get a bogus number for a->nz (134630032 instead of 21)
>>> What is the correct way to get the number of nonzeros?
>>>
>>>>>
>>>>> Can someone please explain when I am doing wrong?
>>>>>
>>>>> Ahmed
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>




More information about the petsc-dev mailing list