I found the source of the error - though I have no solution yet.
The problem is the following: In my class NewtonSolver I initialise some help-Vectors of the following form with a init-list
SemiSmoothNewtonSolver(... int len):
help(MPI_COMM_WORLD, len)
{
....
}
where len is the (global) number of DOFs. I though this was a good idea to avoid reinitialisation of my help-vectors in each iteration. Here is a minimal working example (taken from the Poisson example file) to reconstruct the error. Works fine in serial, fails in parallel:
class mySolver
{
public:
Matrix* K;
void sol(GenericVector& u, int len)
{
Vector b(MPI_COMM_WORLD, len);
b = 1;
//each of the following lines produces some errors
K->mult(b,u);
solve(*K, u, b, "bicgstab", "hypre_amg");
}
};
int main()
{
// Create mesh and function space
UnitSquareMesh mesh(32, 32);
Poisson::FunctionSpace V(mesh);
// Define boundary condition
Constant u0(0.0);
DirichletBoundary boundary;
DirichletBC bc(V, u0, boundary);
// Define variational forms
Poisson::BilinearForm a(V, V);
Poisson::LinearForm L(V);
Source f;
dUdN g;
L.f = f;
L.g = g;
// Compute solution
Function u(V);
Matrix K;
Vector b;
assemble(K, a);
assemble(b,L);
bc.apply(K,b);
mySolver NewtonSolver;
NewtonSolver.K = &K;
NewtonSolver.sol(*u.vector(), b.size());
//solve(K, *u.vector(), b, "bicgstab", "hypre_amg");
// Plot solution
plot(u);
interactive();
return 0;
}
How can i create a vector in each thread with 1s in of the correct size, such that the above multiplication and solve command is working?