# FreeFem PETSc matrix operations

**URL:** <https://community.freefem.org/t/freefem-petsc-matrix-operations/1109>\
**Category:** General Discussion\
**Created:** [July 20, 2021, 2:17pm UTC](https://community.freefem.org/t/freefem-petsc-matrix-operations/1109 "2021-07-20T14:17:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [July 20, 2021, 2:17pm UTC](https://community.freefem.org/t/freefem-petsc-matrix-operations/1109/1 "2021-07-20T14:17:46Z")

</div>

Is there a list of all the PETSc matrix operations implemented in FreeFem? such as, addition, minus, times by a constant, copy a matrix, and so on?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [July 20, 2021, 2:27pm UTC](https://community.freefem.org/t/freefem-petsc-matrix-operations/1109/2 "2021-07-20T14:27:56Z")

</div>

It’s in `plugin/mpi/PETSc-code.hpp`.

---

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [July 20, 2021, 5:44pm UTC](https://community.freefem.org/t/freefem-petsc-matrix-operations/1109/3 "2021-07-20T17:44:59Z")

</div>

I have now found the right one for me. Thank you very much Prof. Jolivet!

---

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [July 25, 2021, 11:26pm UTC](https://community.freefem.org/t/freefem-petsc-matrix-operations/1109/4 "2021-07-25T23:26:12Z")

</div>

Dear Prof. Jolivet,

How can I copy a PETSc Mat?  
I tried A=B, it complains “ **PETSc has generated inconsistent data** ”.  
I have found from PETSc-code.hpp that [MatConvert](https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatConvert.html)() has been implemeted but it seems [MatCopy](https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCopy.html) has not.  
Do you have a method to do this ?

Best,  
Yongxing.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [July 26, 2021, 6:23am UTC](https://community.freefem.org/t/freefem-petsc-matrix-operations/1109/5 "2021-07-26T06:23:38Z")

</div>

Have you tried `Mat A(B)`?

---

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [July 26, 2021, 7:29am UTC](https://community.freefem.org/t/freefem-petsc-matrix-operations/1109/6 "2021-07-26T07:29:05Z")

</div>

it works, thank you very much!
