Using MatGetRow() to extract matrix values.

Stephen R Ball Stephen.R.Ball at awe.co.uk
Fri Jun 13 10:23:17 CDT 2008


Hi

I am now using MatGetRow() to extract the matrix values and column
numbers for each row. However, I have noticed that the ordering of the
matrix values is sometimes different to that which was originally
inserted. For example below are the matrix values for one row.

Original row:

Column no.            Matrix Value
0                     185693206.9234681
1                     4.3135145491066673E-002
2                    -1.5858782157409282E-010
3                     8.5489320680905649E-002
4                    -7.5011130237855266E-011
5                    -3.7505565118927637E-011
6                    -4.3135145489119342E-002
7                    -8.6270290978446909E-002


After matrix assembly, extracted via MatGetRow():-

Column no.            Matrix Value
0                    -7.5011130237855266E-011
1                    -3.7505565118927637E-011
2                     4.3135145491066673E-002      
3                    -8.6270290978446909E-002       
4                     185693206.9234681
5                    -4.3135145489119342E-002
6                    -1.5858782157409282E-010
7                     8.5489320680905649E-002


Is this what I should expect to happen?

As I mentioned in an earlier email, my purpose for extracting the matrix
values is so that I can output the locally owned values to file in the
format I want rather than via use of the MatView() routine. I would
prefer to output the values in their original ordering.

The reason I extract the values after matrix assembly rather than just
output the original CSR matrix array is because, in parallel, some
matrix entries are partial contributions to the true values and it is
these true values that I wish to output. I get these true values after
inserting them via MatSetValues() using the ADD_VALUES flag and then
using MatGetRow().

Can I obtain the matrix values in their original row and column ordering
after matrix assembly? Doesn't MatView() output the matrix with its
original ordering?

Regards

Stephen









-----Original Message-----
From: owner-petsc-users at mcs.anl.gov
[mailto:owner-petsc-users at mcs.anl.gov] On Behalf Of Barry Smith
Sent: 04 June 2008 15:30
To: petsc-users at mcs.anl.gov
Subject: EXTERNAL: Re: EXTERNAL: Re: MatGetArray() not supporting Mat
type mpiaij.


    Stephan,

    For all built in PETSc matrix types, the rows are stored  
contiguously so
you can use MatGetOwnershipRange() to get the global indices for the  
local
rows and thus call MatGetRow().

    Barry


On Jun 4, 2008, at 6:33 AM, Stephen R Ball wrote:

> Ok, I am looking into using MatGetRow(). However this requires the
> global row number for input. I was looking to use  
> MatGetOwnershipRange()
> to obtain the range of global row numbers owned by each processor but
> the documentation states that this routine assumes that the matrix is
> laid out with the first n1 rows on the first processor, the next n2  
> rows
> on the second, etc and that for certain parallel layouts this range  
> may
> not be well defined.
>
> This is the case for me. Do you have a routine where I can specify a
> global row number and it will tell me the rank of the processor that
> owns it? This is to ensure that MatGetRow() only gets called by the
> owner processor for each global row number.
>
> Regards
>
> Stephen
>
>
> -----Original Message-----
> From: owner-petsc-users at mcs.anl.gov
> [mailto:owner-petsc-users at mcs.anl.gov] On Behalf Of Matthew Knepley
> Sent: 03 June 2008 15:29
> To: petsc-users at mcs.anl.gov
> Subject: EXTERNAL: Re: MatGetArray() not supporting Mat type mpiaij.
>
> On Tue, Jun 3, 2008 at 8:11 AM, Stephen R Ball
> <Stephen.R.Ball at awe.co.uk> wrote:
>> Hi
>>
>> I have been trying to extract an array containing the local matrix
>> values using MatGetArray() via the Fortran interface but get the  
>> error
>> message that Mat type mpiaij is not supported with this routine.  
>> All I
>> want to do is to extract the local matrix values so that I can output
>> them to file in the format I want rather than via use of the  
>> MatView()
>> routine. Can you suggest a way of how I can go about extracting the
>> local matrix values?
>
> This is no "local matrix". The Mat interface is supposed to be data
> structure
> neutral so we can optimize for different architectures. If you want  
> the
> values
> directly, I would use MatGetRow() for each row.
>
>  Matt
>
>> Thanks
>>
>> Stephen
>>
>>
>
>
>
> -- 
> 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
>
>




More information about the petsc-users mailing list