# Creata a 'Mat' with all componets are zero PETSc

**URL:** <https://community.freefem.org/t/creata-a-mat-with-all-componets-are-zero-petsc/2374>\
**Category:** General Discussion\
**Created:** [April 3, 2023, 2:30pm UTC](https://community.freefem.org/t/creata-a-mat-with-all-componets-are-zero-petsc/2374 "2023-04-03T14:30:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@Stone](https://community.freefem.org/u/Stone)\
**Post date:** [April 3, 2023, 2:30pm UTC](https://community.freefem.org/t/creata-a-mat-with-all-componets-are-zero-petsc/2374/1 "2023-04-03T14:30:49Z")

</div>

Hi,  
I am leanring to develop a code using FreeFEM with PETSc. I just met a problem that is to create a ‘Mat’ type matrix with all components being zero. My solution is

> **int** N = 200;  
> **real** [int, int] A(N, N);  
> A = 0.; **matrix** empA = A;  
> Mat empAm = empA;

However, this solution is not efficient since A is not sparse despite empA is sparse.

I checked the FreeFEM-PETSc tutorial [(here)](https://joliv.et/FreeFem-tutorial/main.html) but didn’t find an efficient solution. Does FreeFEM provide a function resembling ‘ **MatZeroEntries** ’ in PETSc?  
Can this function extend to a matrix with different rows and columns?

A little personal suggestion: I suggest the developers put the link of the FreeFEM-PETSc tutorial on the documentation page ([here](https://doc.freefem.org/introduction/index.html)) since this is a really good material to learn FreeFEM with PETSc.

I really appreciate any help you can provide.

---

<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:** [April 3, 2023, 3:12pm UTC](https://community.freefem.org/t/creata-a-mat-with-all-componets-are-zero-petsc/2374/2 "2023-04-03T15:12:45Z")

</div>

I’m not sure I understand what you want to achieve. Just a matrix full of zeros?

```auto
$ cat empty.edp 
load "PETSc"
matrix A(20, 20);
Mat B(A);
ObjectView(B);
$ ff-mpirun -n 1 empty.edp -v 0
Mat Object: 1 MPI process
  type: seqaij
row 0:
row 1:
row 2:
row 3:
row 4:
row 5:
row 6:
row 7:
row 8:
row 9:
row 10:
row 11:
row 12:
row 13:
row 14:
row 15:
row 16:
row 17:
row 18:
row 19:

```

---

<div class="post-metadata">

**Author:** ![Stone](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@Stone](https://community.freefem.org/u/Stone)\
**Post date:** [April 3, 2023, 4:21pm UTC](https://community.freefem.org/t/creata-a-mat-with-all-componets-are-zero-petsc/2374/3 "2023-04-03T16:21:41Z")

</div>

Thank you, prj. This is exactly what I want.
