# Usage of PETSc's 'Mat' type

**URL:** <https://community.freefem.org/t/usage-of-petscs-mat-type/835>\
**Category:** General Discussion\
**Created:** [March 5, 2021, 8:09am UTC](https://community.freefem.org/t/usage-of-petscs-mat-type/835 "2021-03-05T08:09:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [March 6, 2021, 11:32am UTC](https://community.freefem.org/t/usage-of-petscs-mat-type/835/2 "2021-03-06T11:32:55Z")

</div>

1. `J(v, v)` computes a scalar product according to the domain decomposition of `J`. It is basically a weighted local scalar product, followed by a reduction. See line 43 of [this](http://jolivet.perso.enseeiht.fr/FreeFem-tutorial/section_8/example4.edp.html) parallel example vs. line 28 of [this](http://jolivet.perso.enseeiht.fr/FreeFem-tutorial/section_8/example4_seq.edp.html) sequential example.
2. Given one distributed matrix `Mat A`, you can create a new distributed matrix `B` following the same column and row distribution using a local matrix `Loc` with the syntax `Mat B(A, Loc)`. If you have a different column and row distribution, here `A` for the rows, `C` for the columns, and `Loc` is a rectangular matrix, you create a distributed rectangular matrix using the syntax `Mat B(A, C, Loc)`. See [this](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/stokes-block-2d-PETSc.edp#L52) Stokes example where there is a different column and row distribution (for velocity and pressure unknowns).

Here is some more materials if you are interested: [Pierre Jolivet introduction to parallel FreeFEM part 1 - YouTube](https://www.youtube.com/watch?v=-Aw2O46V2bo) + [Pierre Jolivet introduction to parallel FreeFEM part 2 - YouTube](https://www.youtube.com/watch?v=Hx57gxTOnvE).  
Don’t hesitate if you have other questions.

---

_[View the full topic](https://community.freefem.org/t/usage-of-petscs-mat-type/835)._
