Dear FreeFem developers and users,

I’m writing you since I’m having some troubles once I am required to pass from local to global solution in my parallel script. I have an algorithm that is fine in sequential and is apparently working also in parallel, but once I want to move from the local to global solution the following error appears:

```
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
```

I’m copying here also my script that I’m developing trying to follow what explained in this lecture

```
load "msh3"
load "mat_edgeP1"
load "Element_Mixte3d"
include "macro_ddm.idp"
lockOrientation = false;
mesh3 Th("team4gmsh.mesh");
lockOrientation = true;
mesh3 ThPlt = Th;
int brickPlt = ThPlt(0.05,0.,0.).region;
plot(Th,cmm = "mesh from gmsh", wait = 1);
load "PETSc"
macro dimension()3// EOM // 2D or 3D
buildDmesh(Th) //now the mesh is local
int brick = Th(0.05,0.,0.).region;
int outside = Th(0.7,0.0,0.0).region;
cout<<"Brick label = "<<brick<<endl;
cout<<"Outside label = "<<outside<<endl;
real mu = 4*pi*1.0e-7;
real nu=1.0/mu;
real rhoAl = 3.94e-8; //Ohm*m
real sigmaAl = 1.0/rhoAl;
func Pk = Edge03d;
fespace vhp(Th,P0);
fespace vh(Th,Pk);
vh [A0x,A0y,A0z] = [-0.05*y,0.05*x,0.];
vhp SSigma = 1+(sigmaAl-1)*(region == brick);
macro Curl(Ax,Ay,Az) [dy(Az)-dz(Ay), dz(Ax)-dx(Az), dx(Ay)-dy(Ax)]//EOM
real tempo;
real tau = 0.0119; //[s]
real dt = 1.0e-4; //[s];
real tend = 0.02; //[s];
int Imax=tend/dt;
func fact = exp(-tempo/tau);
int[int] lati = [17,18,19,20,21,22];
varf lhs([AX,AY,AZ],[Wx,Wy,Wz]) = int3d(Th)(nu*Curl(AX,AY,AZ)'*Curl(Wx,Wy,Wz))+int3d(Th)(SSigma*[Wx,Wy,Wz]'*[AX,AY,AZ]/dt)+on(lati,AX=-0.05*y*fact,AY=0.05*x*fact,AZ=0.);
varf rhs([AX,AY,AZ],[Wx,Wy,Wz]) = int3d(Th)(SSigma*[Wx,Wy,Wz]'*[A0x,A0y,A0z]/dt)+on(lati,AX=-0.05*y*fact,AY=0.05*x*fact,AZ=0.);
Mat AA;
int[int] n2o;
macro ThN2O()n2o// EOM
macro def(i)[i, i#B, i#C]// EOM
macro init(i)[i, i, i]// EOM
createMat(Th, AA, Pk)
fespace VhPlt(ThPlt, Pk); //LINE GENERATING PROBLEMS
int[int] SubIdx = restrict(vh,VhPlt,n2o); //LINE GENERATING PROBLEMS
real[int] rr(vh.ndof);
ofstream fpj("MPI_pj_TEAM4.dat");
for (int ii=1;ii<=Imax;ii++)
{
real tempo = dt*ii;
AA = lhs(vh,vh);
set(AA, sparams = "-pc_type lu");
rr = rhs(0,vh);
vh [Ax,Ay,Az];
Ax[] = AA^-1*rr;
VhPlt [Agx,Agy,Agz];
Agx[](SubIdx) = Ax[]; //LINE GENERATING PROBLEMS
[A0x,A0y,A0z] = [Ax,Ay,Az];
}
```

Here attached also the mesh I’m using.

https://drive.google.com/drive/folders/1zW7m6ir9tQzcvi8_EWUTAVQa8MI7X4l2?usp=sharing

Is someone ablo to understand where the problem is and why introducing the lines marked with the comment LINE GENERATING PROBLEM the error appears?

I’m already thanking so much anyone will try to help me!

yours sincerely,

Marco