Wrong with the PETSc

I want to test PETSc and parallelization, so test the code:

load "PETSc"
macro dimension()2// EOM
include "macro_ddm.idp"

macro grad(u)[dx(u), dy(u)]// EOM
func Pk = P1;

border upper(t=0, pi)    { x=cos(t); y=sin(t); label=1; }
border lower(t=pi, 2*pi) { x=cos(t); y=sin(t); label=2; }
mesh Th = buildmesh(upper(100) + lower(100));
Mat A;
MatCreate(Th, A, Pk);

fespace Vh(Th, Pk);
varf vPb(u, v) = intN(Th)(grad(u)' * grad(v)) + intN(Th)(v) + on(2, u = 0);
matrix Loc = vPb(Vh, Vh, tgv = -2);
real[int] b = vPb(0, Vh, tgv = -1);

A = Loc;

Vh u;
set(A, sparams = "-pc_type lu");
u[] = A^-1 * b;
plotD(Th, u, cmm = "Solution");

real[int] r = A * u[];
exchange(A, b, scaled = true);
r -= b;
r *= -1;
Vh v;
v[] = r;
plotD(Th, v, cmm = "Residual");

r = A' * u[];
r -= b;
r *= -1;
v[] = r;
plotD(Th, v, cmm = "Residual computed with A'");

real[int] bPETSc, xPETSc;
ChangeNumbering(A, b, bPETSc);
xPETSc.resize(bPETSc.n);
KSPSolve(A, bPETSc, xPETSc);
ChangeNumbering(A, u[], xPETSc, inverse = true, exchange = true);
plotD(Th, u, cmm = "Solution with KSPSolve");

But get this wrong information :

-- FreeFem++ v4.15 (Wed Dec 11 16:48:56 CET 2024 - git v4.15-7-gb1e524c8c)                                              
   file : .\E1.edp                                                                                                      
 Load: lg_fem lg_mesh lg_mesh3 eigenvalue parallelempi                                                                  
(load: loadLibary D:\MathTool\FreeFem++\\.\PETSc = 0)(load: loadLibary D:\MathTool\FreeFem++\\.\metis = 0) load: init metis (v  5 )                                                                                                             
 sizestack + 1024 =12400  ( 11376 )                                                                                     
                                                                                                                        
  --  mesh:  Nb of Triangles =   6982, Nb of Vertices 3592                                                              
  --  mesh:  Nb of Triangles =   6982, Nb of Vertices 3592                                                              
  --  mesh:  Nb of Triangles =   6982, Nb of Vertices 3592                                                              
  --  mesh:  Nb of Triangles =   6982, Nb of Vertices 3592                                                              
 --- global mesh of 6982 elements (prior to refinement) partitioned with metis  --metisA: 4-way Edge-Cut:       3, Balance:  1.00 Nodal=0/Dual 1                                                                                                
 (in 4.471700e-03)                                                                                                      
 --- partition of unity built (in 6.910000e-03)                                                                         
 --- global numbering created (in 6.967000e-04)                                                                         
 --- global CSR created (in 1.900000e-04)
Warning: -- Your set of boundary condition is incompatible with the mesh label.                                        
 Warning: -- Your set of boundary condition is incompatible with the mesh label.                                        
 Warning: -- Your set of boundary condition is incompatible with the mesh label.                                        
 Warning: -- Your set of boundary condition is incompatible with the mesh label.                                                                               
[1]PETSC ERROR: ------------------------------------------------------------------------                                
[1]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range               
[1]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger                                              
[1]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind and https://petsc.org/release/faq/                       
[1]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run                                          
[1]PETSC ERROR: to get more information on the crash.                                                                   
[1]PETSC ERROR: Run with -malloc_debug to check if memory corruption is causing the crash.                              
                                                                                                                        
job aborted:                                                                                                            
[ranks] message                                                                                                         
                                                                                                                        
[0] terminated                                                                                                          
                                                                                                                        
[1] application aborted                                                                                                 
aborting MPI_COMM_WORLD (comm=0x44000000), error 59, comm rank 1                                                        
                                                                                                                        
[2-3] terminated                                                                                                        
                                                                                                                        
---- error analysis -----                                                                                               
                                                                                                                        
[1] on Z-Z-M                                                                                                            
FreeFem++-mpi.exe aborted the job. abort code 59                                                                        
                                                                                                                        
---- error analysis -----

So How can I deal this problem? I use the windows Powershell:

mpiexec.exe -np 4 FreeFem++-mpi.exe .\E1.edp -wg -ns

The code runs fine on my machine. It may be due to an issue with Fortran with the master branch of FreeFEM (that you are using with version 4.15). If you don’t want to recompile from the sources (which may be tedious on Windows), could you please try to replace -pc_type lu by -pc_type hypre and see if the code runs to completion?

It run successfully!:

-- FreeFem++ v4.15 (Wed Dec 11 16:48:56 CET 2024 - git v4.15-7-gb1e524c8c)                                              
   file : .\E1.edp                                                                                                      
 Load: lg_fem lg_mesh lg_mesh3 eigenvalue parallelempi                                                                  
(load: loadLibary D:\MathTool\FreeFem++\\.\PETSc = 0)(load: loadLibary D:\MathTool\FreeFem++\\.\metis = 0) load: init metis (v  5 )                                                                                                             
 sizestack + 1024 =12400  ( 11376 )                                                                                     
                                                                                                                        
  --  mesh:  Nb of Triangles =   6982, Nb of Vertices 3592                                                              
  --  mesh:  Nb of Triangles =   6982, Nb of Vertices 3592                                                              
  --  mesh:  Nb of Triangles =   6982, Nb of Vertices 3592                                                              
  --  mesh:  Nb of Triangles =   6982, Nb of Vertices 3592                                                              
 --- global mesh of 6982 elements (prior to refinement) partitioned with metis  --metisA: 4-way Edge-Cut:       3, Balance:  1.00 Nodal=0/Dual 1                                                                                                
 (in 5.723800e-03)                                                                                                      
 --- partition of unity built (in 6.983900e-03)                                                                         
 --- global numbering created (in 6.053000e-04)                                                                         
 --- global CSR created (in 2.196000e-03)                                                                               
 Warning: -- Your set of boundary condition is incompatible with the mesh label.                                        
 Warning: -- Your set of boundary condition is incompatible with the mesh label.                                        
 Warning: -- Your set of boundary condition is incompatible with the mesh label.                                        
 Warning: -- Your set of boundary condition is incompatible with the mesh label.                                        
 --- system solved with PETSc (in 1.876550e-02)                                                                         
times: compile 0.08s, execution 10.286s,  mpirank:2                                                                     
times: compile 0.08s, execution 10.286s,  mpirank:3                                                                     
times: compile 0.08s, execution 10.286s,  mpirank:1                                                                     
 ######## unfreed pointers   405 Nb pointer,   0Bytes  ,  mpirank 2, memory leak =0                                     
 ######## unfreed pointers   437 Nb pointer,   0Bytes  ,  mpirank 3, memory leak =0                                     
 ######## unfreed pointers   405 Nb pointer,   0Bytes  ,  mpirank 1, memory leak =0                                     
 CodeAlloc : nb ptr  8243,  size :721528 mpirank: 2                                                                     
 CodeAlloc : nb ptr  8243,  size :721528 mpirank: 3                                                                     
 CodeAlloc : nb ptr  8243,  size :721528 mpirank: 1                                                                     
times: compile 8.000000e-02s, execution 1.032200e+01s,  mpirank:0                                                       
 ######## unfreed pointers   630 Nb pointer,   0Bytes  ,  mpirank 0, memory leak =0                                     
 CodeAlloc : nb ptr  8243,  size :721528 mpirank: 0                                                                     
Ok: Normal End                                                                                                          
WARNING! There are options you set that were not used!                                                                  
WARNING! could be spelling mistake, etc!                                                                                
There are 2 unused database options. They are:                                                                          
Option left: name:-ns (no value) source: command line                                                                   
Option left: name:-wg (no value) source: command line

This will be fixed for -pc_type lu in the next release (hopefully soon).