[petsc-users] Why can't I save a diagonal matrix into a binary file via petsc4py?

Jose E. Roman jroman at dsic.upv.es
Tue Nov 19 10:59:59 CST 2024


The implementation is here:
https://urldefense.us/v3/__https://petsc.org/release/src/mat/impls/diagonal/diagonal.c.html*MatView_Diagonal__;Iw!!G_uCfscf7eWS!ej9LRPwh7-zzKBJDEUfh0gSmHxGO7nitFAZJGu1s7mi0htPg8OUAqyV04o_0YYgqOCkjSAKzvEij27AKN9-3Mzk2$ 

You can see that it only handles the ascii case.
It should also check the case of binary viewer, then call VecView() or convert to MATAIJ and call MatView().
Do you want to contribute a merge request? https://urldefense.us/v3/__https://petsc.org/release/developers/contributing/__;!!G_uCfscf7eWS!ej9LRPwh7-zzKBJDEUfh0gSmHxGO7nitFAZJGu1s7mi0htPg8OUAqyV04o_0YYgqOCkjSAKzvEij27AKN6f4qvXn$ 

Jose


> El 19 nov 2024, a las 10:35, 张峻溪 <zhjx960203 at gmail.com> escribió:
> 
> My version is 3.22.0 from "petsc4py.__version__"
> Here is the code:
> ```python
> from petsc4py import PETSc
> import numpy as np
> 
> vec1 = PETSc.Vec().createWithArray(np.arange(30))
> mat1 = PETSc.Mat().createDiagonal(vec1)
> mat1.assemble()
> viewer = PETSc.Viewer().createBinary("abcde.bin", "w")
> mat1.view(viewer)
> viewer.destroy()
> ```
> 
> I find it runs without any error, but no file generated
> However, if I convert mat1 to AIJ, it can be saved successfully



More information about the petsc-users mailing list