decomposition in parfor failure
Mostrar comentarios más antiguos
Hi there,
I need to solve multiple linear systems for multiple times:
for
. Due to this problem strcure, I realize that the decomposition routine will be very efficient, and since all linear systems are independent of each other, I use parfor to further speed up the time.
However decomposition + parfor does work in matlab. I attach a piece of toy code where I synthesize the matrices
and show case my idea:
d = 1000; % size of matrix A
n = 10; % number of linear systems
% get two random sparse PSD matrices in sparse form: (I, J, VA1) and (I, J, VA2)
I = horzcat(1:d, randi(d, 1, 2*d));
J = horzcat(1:d, randi(d, 1, 2*d));
V1 = rand(3*d, 1);
V2 = rand(3*d, 1);
T1 = sparse(I, J, V1);
T2 = sparse(I, J, V2);
[~, ~, VA1] = find(T1*T1');
[I, J, VA2] = find(T2*T2');
A = cell(1, n);
pool = parpool(2);
% construct A_i and decompose
parfor i = 1 : n
A{i} = decomposition(sparse(I, J, VA1 + i^2 * VA2));
end
b = rand(d, n);
x = rand(d, n);
% solve all linear systems for one RHS
parfor i = 1 : n
x(:, i) = A{i}\b(:, i);
end
delete(pool);
The problem is, matlab will give error at the second parfor loop:
Error using \ (line 391)
Matrix dimensions must agree.
It seems that A{i} are still empty. I found a previous post https://www.mathworks.com/matlabcentral/answers/401212-decomposition-object-saveobj-method-not-supported that points me to https://merzba.ch/dw/blg:matlab_decomposition_parfor where the author explained that it is the (un)serialization steps of the decomposition object in parfor that caused the trouble.
I followed the suggestions in the post to modify decomposition.m. However, Matlab still reports warnings and error. The warning is
Warning: Decomposition built-in error: CHOLMODWrapper object does not support saving to file.
Loaded file will not be usable.
> In parallel.internal.pool.serialize (line 10)
In distcomp/remoteparfor/serialize (line 279)
In distcomp/remoteparfor/addInterval (line 329)
In parallel_function>distributed_execution (line 704)
In parallel_function (line 573)
In untitled (line 24)
Warning: Decomposition built-in error: CHOLMODWrapper object not initialized correctly. Save and load are not supported for this object.
> In parallel.internal.pool.deserialize (line 33)
In remoteParallelFunction (line 66)
and the error reads
Error using matlab.internal.decomposition.SparseCholesky/solve (line 34)
Decomposition built-in error: Error: Cholesky decomposition is in invalid state.
Error in \ (line 394)
x = solve(f.Underlying, b, transp);
Error in untitled (line 24)
parfor i = 1 : m
Any idea on how to fix this? I would appreciate it a lot!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Distributed Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!