[petsc-users] Questions about creation of matrix and setting its values

Cong Li solvercorleone at gmail.com
Wed Aug 5 21:00:37 CDT 2015


Barry,

Thanks. I think I understood.

Cong Li

On Thu, Aug 6, 2015 at 3:01 AM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
> > On Aug 5, 2015, at 4:47 AM, Cong Li <solvercorleone at gmail.com> wrote:
> >
> >> Hi,
> >>
> >> I am wondering if it is necessary to call
> >> MatAssemblyBegin() and MatAssemblyEnd() after MatDuplicate() with the
> option of MAT_DO_NOT_COPY_VALUES.
> >> For example, if I have an assembled matrix A, and I call MatDuplicate()
> to create B, which is a duplication of A.
> >> Do I need to call MatAssemblyBegin() and MatAssemblyEnd() for B.
>
>   You should not need to. But note if you use the flag
> MAT_DO_NOT_COPY_VALUES the new matrix will have zero for all the numerical
> entries.
> >
> >>
> >> And 2nd question is :
> >> just after the MatCreateDense() call and before MatAssemblyBegin() and
> MatAssemblyEnd() calls, can I use MatGetArray() ?
>
>    Dense matrices are a special case because room is always allocated for
> all the matrix entries and one can use MatDenseGetArray() to either access
> or set any local value. So if you are only setting/accessing local values
> you don't actually need to use MatSetValues() (though you can) you can just
> access the locations directly after using MatDenseGetArray().  There is no
> harm in calling the MatAssemblyBegin/End() "extra" times for dense matrices.
>
> >>
> >> The 3rd question is:
> >> before the MatAssemblyBegin() and MatAssemblyEnd() calls, should I use
> INSERT_VALUES or ADD_VALUES for MatSetValues call? And why ?
> >> Actually I have read the manual, but I still feel confused about the
> means of INSERT_VALUES and ADD_VALUES.
> > There are a couple of reasons that you need to make these
> MatAssemblyBegin/End calls:
> > - entries can be set which should be stored on a different process, so
> these need to be communicated
> > - for compressed formats like CSR (as used in MATAIJ and others) the
> entries need to be processed into their compressed form
> > In general, the entries of the matrix are not stored in their "usable"
> forms until you make the MatAssembleEnd call. Rather they are kept in some
> easy-to-insert-into intermediate storage. INSERT_VALUES means that old
> values that might be in the matrix are overwritten , and ADD_VALUES means
> that the new entries from intermediate storage are added to the old values.
> >
> >
> >>
> >> Thanks
> >>
> >> Cong Li
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150806/4cf9177f/attachment.html>


More information about the petsc-users mailing list