[petsc-users] Doubt on how to copy a Mat into another (Fortran)

Matthew Knepley knepley at gmail.com
Mon Feb 4 10:46:16 CST 2019


On Mon, Feb 4, 2019 at 11:16 AM Marco Tiberga via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Dear PETSc developers,
>
>
>
> Since I am learning how to use MatCreateNest, I was looking at example
> ex73f90t.F90
> <https://www.mcs.anl.gov/petsc/petsc-current/src/snes/examples/tutorials/ex73f90t.F90.html>
> (I am using Fortran).
>
>
>
> At line 297, the array of matrices to be passed to MatCreateNest is
> initialized with code lines as “matArray(1) = Amat”.
>

That is a pointer. It does not create a replica in memory, as the calls
below do. Fortran is not explicit about this distinction
which can lead to confusion.

  Thanks,

    Matt


>
>
> I was surprised to find such a simple command, I thought a matrix copy
> should be done by a sequence like
>
> “ call MatDuplicate(Amat, MAT_SHARE_NONZERO_PATTERN,matArray(1),ierr);
> CHKERRA(ierr)
>
>   call MatCopy(Amat,matArray(1), SAME_NONZERO_PATTERN,ierr); CHKERRA(ierr)
>>
>
>
> So, I was wondering: are the two ways completely equivalent, and therefore
> the second unnecessarily more complex? or is the latter more robust and
> therefore preferable?
>
> Is there any difference in terms of performance?
>
>
>
> Thanks a lot for the clarification.
>
>
>
> Best regards,
>
> Marco Tiberga
>
> PhD candidate
>
> Delft University of Technology
>
> Faculty of Applied Sciences
>
> Radiation Science & Technology Department
>
> Mekelweg 15, 2629 JB Delft, The Netherlands
>
> E-Mail: *m.tiberga at tudelft.nl <m.tiberga at tudelft.nl>*
>
> Website: http://www.nera.rst.tudelft.nl/
>
>
>
>
>
>
>


-- 
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

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190204/c763e39d/attachment.html>


More information about the petsc-users mailing list