I am trying to solve many different linear systems using gmres, each system has it's own individual matrix, but they all use the same preconditioners. I am also using a function handle to evaluate the preconditioner backsolve. Essentially,
parfor i=1:N X{i} = gmres(A{i}, b{i}, maxit, tol, @(x) mfun(x,M{i}));end
The individual solves take about 9 iterations and take about 0.02 seconds each, I found changing it to essentially
parfor i=1:N for j =1:n X{j} = gmres(A{j}, b{j}, maxit, tol, @(x) mfun(x,M{j})); end Xstore(i) = X;end
was faster and was able to beat doing things in serial for small systems. In this implimentation each worker uses every preconditioner.
I tried implementing both
Mpool = parallel.pool.Constant(@() M);
and
Mpool = parallel.pool.Constant(M);
both slowed down code significantly. CPU utilization was lower and the individual gmres solves were significantly slower, there was some memory improvement.
What am I doing wrong?
Best Answer