[petsc-users] From CSR format to MatSetValues

Matthew Knepley knepley at gmail.com
Fri Jun 15 06:25:24 CDT 2012


On Fri, Jun 15, 2012 at 11:18 AM, w_ang_temp <w_ang_temp at 163.com> wrote:

> Hello, Matt
>
>     After my careful testing, I get some findings.
>
>     Firstly, considering the approach of setting one row at a time. I
> change my codes
> from setting one data per time to one row per time (codes attached). I
> find that both
> of the times are almost equal and cannot be ignored . In my opinion, the
> latter should
> take less time than the former. the codes have been proved to have the
> right results
> and I think my testing datas are enough to show that they almost have the
> same time
> for setting the matrix.
>

I do not believe you analysis. Send the output of -log_summary -info to
petsc-maint at mcs.anl.gov

    Matt


>
>     Secondly, as you said in a previous post('CSR Sparse Matrix Query',
> 2007), there
> is no Fortran interface for the function 'MatCreateMPIAIJWithArrays'. I am
> not sure
> if it is true now because the docs do not specify this and I connot
> compile with
> it atfer a simple test. In my opinion, you prefer to do the thing of
> setting values from
> CSR format using the way of setting values with MatSetValus for each row
> rather than
> using MatCreateMPIAIJWithArrays. am I right?
>
>     Thanks again.
>                                        Jim
> -----coding:per row(you can compare it with the first page int this post
> of one data per time )-----
>
>       !NROWIN,NNZIJ,values:the CSR variables of the main function
>       !NROWIN,NNZIJ:one-based,so get zero-based variables rowIndex,columns
>        do 10,II=Istart+1,Iend
>         !no-zero numbers of this row
>         rowNum=NROWIN(II+1)-NROWIN(II)
>
>         allocate(nColPerRow(rowNum))
>         allocate(valuePerRow(rowNum))
>
>         kValStart=NROWIN(II)+1-1
>         kValEnd=NROWIN(II)+rowNum-1
>
>         !column index
>         nColPerRow=NNZIJ(kValStart:kValEnd)-1
>         valuePerRow=values(kValStart:kValEnd)
>         nRow=II-1
>         call MatSetValues(A,ione,nRow,rowNum,nColPerRow,valuePerRow,
>      &       INSERT_VALUES,ierr)
>        deallocate(nColPerRow)
>        deallocate(valuePerRow)
>   10  continue
> ---------------------coding-----------------------------
>
>
> >在 2012-06-10 20:49:13,"Matthew Knepley" <knepley at gmail.com> 写道:
>
> >On Sun, Jun 10, 2012 at 4:48 PM, w_ang_temp <w_ang_temp at 163.com> wrote:
>
>>  >Hello, Barry
>>
>> >    I try to use MatCreateSeqAIJWithArrays to deal with my problem.
>> Since
>> >there is no example in the doc, I find some examples in the web and use
>> it.
>> >And I get some errors.
>>
>> >    When the processor is 1(mpiexec -n 1 ./ex4f), the results are ok.
>> While
>> >it is more than one, I get the errors. So I think I miss some piece of
>> >information about MatCreateSeqAIJWithArrays.
>>
>
> >1) Check the error codes. Always!
>
>
>>  >    Thanks.
>> >                                          Jim
>>
>>
>> >----------------------------code-------------------------------------------
>> >      call MatCreate(PETSC_COMM_WORLD,A,ierr)
>> >      call MatSetType(A,MATAIJ,ierr)
>> >      call MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,n,ierr)
>> >      call MatSetFromOptions(A,ierr)
>> >      call MatGetOwnershipRange(A,Istart,Iend,ierr)
>>
>
>
>>  >      !NROWIN,NNZIJ,values:the CSR variables of the main function
>> >      !NROWIN,NNZIJ:one-based,so get zero-based variables
>> rowIndex,columns
>> >      allocate(rowIndex(JFLNG+1))
>> >      allocate(columns(MAXNNZ))
>> >      rowIndex=NROWIN-1
>> >      columns=NNZIJ-1
>>
>> >      call MatCreateSeqAIJWithArrays(MPI_COMM_WORLD,m,n,rowIndex,columns,
>> >     &       values,A, ierr)
>>
>
> >2) This can only be called in serial. In parallel, you need
> MatCreateMPIAIJWithArrays()
>
> >3) I still believe you are really doing the wrong thing. The right
> solution is to set one row at
> >    a time. I will bet dollars to doughnuts that the assembly time is not
> noticeable in your program.
>
> >     Matt
>
>
>>
>> >      call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)
>> >      call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)
>>
>> >----------------------------code-------------------------------------------
>>
>> >----------------------------Error
>> Message----------------------------------
>> >.........
>>
>
>
>


-- 
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/20120615/436a1fde/attachment.html>


More information about the petsc-users mailing list