I ran into an issue when solving multiple linear systems sequentially with a single instance of DMumpsContext
. I do not know if this is an issue with Mumps or PyMumps, so I apologize if this is not an issue with PyMumps.
from scipy.sparse import coo_matrix, tril
import mumps
mats = list()
row = [0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 5, 8, 6, 8, 7, 8, 7]
col = [0, 1, 2, 3, 0, 0, 0, 5, 6, 7, 5, 8, 6, 8, 7, 8, 7, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4]
data = [2.e+00, 1.e-16, 1.e-16, 1.e-16, 1.e-16, 1.e-16, 1.e-16, 0.e+00, 0.e+00,
0.e+00, 0.e+00, 1.e+00, 0.e+00, 1.e+00, 0.e+00, 1.e+00, -1.e+00, 0.e+00,
0.e+00, 0.e+00, 0.e+00, 1.e+00, 0.e+00, 1.e+00, 0.e+00, 1.e+00, -1.e+00]
mat = tril(coo_matrix((data, (row, col)), shape=(9, 9)))
mats.append(mat)
row = [0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 5, 8, 6, 8, 7, 8, 7]
col = [0, 1, 2, 3, 0, 0, 0, 5, 6, 7, 5, 8, 6, 8, 7, 8, 7, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4]
data = [2.e+00, 1.e-16, 1.e-16, 1.e-16, 1.e-16, 1.e-16, 1.e-16, 0.e+00, 0.e+00,
0.e+00, 0.e+00, 1.e+00, 0.e+00, 1.e+00, 0.e+00, 1.e+00, -1.e+00, 0.e+00,
0.e+00, 0.e+00, 0.e+00, 1.e+00, 0.e+00, 1.e+00, 0.e+00, 1.e+00, -1.e+00]
mat = tril(coo_matrix((data, (row, col)), shape=(9, 9)))
mats.append(mat)
row = [0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 5, 8, 6, 8, 7, 8, 7, 5, 6, 7, 8]
col =[0, 1, 2, 3, 0, 0, 0, 5, 6, 7, 5, 8, 6, 8, 7, 8, 7, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8]
data = [2.00000000e+00, 1.00000000e-16, 1.00000000e-16, 1.00000000e-16,
1.00000000e-16, 1.00000000e-16, 1.00000000e-16, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
0.00000000e+00, 1.00000000e+00, 0.00000000e+00, 1.00000000e+00,
-1.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 1.00000000e+00, 0.00000000e+00, 1.00000000e+00,
0.00000000e+00, 1.00000000e+00, -1.00000000e+00, -5.62341325e-09,
-5.62341325e-09, -5.62341325e-09, -5.62341325e-09]
mat = tril(coo_matrix((data, (row, col)), shape=(9, 9)))
mats.append(mat)
row = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 5, 8, 6, 8, 7, 8, 7, 5, 6, 7, 8]
col = [0, 1, 2, 3, 0, 1, 0, 2, 0, 3, 4, 5, 6, 7, 5, 8, 6, 8, 7, 8, 7, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8]
data = [2.00010000e+00, 1.00000000e-16, 1.00000000e-16, 1.00000000e-16,
1.00000000e-16, 1.00000000e-04, 1.00000000e-16, 1.00000000e-04,
1.00000000e-16, 1.00000000e-04, 1.00000000e-04, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
0.00000000e+00, 1.00000000e+00, 0.00000000e+00, 1.00000000e+00,
-1.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 1.00000000e+00, 0.00000000e+00, 1.00000000e+00,
0.00000000e+00, 1.00000000e+00, -1.00000000e+00, -5.62341325e-09,
-5.62341325e-09, -5.62341325e-09, -5.62341325e-09]
mat = tril(coo_matrix((data, (row, col)), shape=(9, 9)))
mats.append(mat)
solver = mumps.DMumpsContext(sym=2, par=1, comm=None)
solver.set_silent()
solver.set_icntl(13, 1)
solver.set_icntl(24, 0)
final_status = None
for i, mat in enumerate(mats):
solver.set_shape(9)
solver.set_centralized_assembled_rows_cols(mat.row + 1, mat.col + 1)
try:
solver.run(job=1)
except RuntimeError:
pass
sym_status = solver.id.infog[0]
if sym_status == 0:
solver.set_centralized_assembled_values(mat.data)
try:
solver.run(job=2)
except RuntimeError:
pass
num_status = solver.id.infog[0]
else:
num_status = None
final_status = num_status
solver.destroy()
print(final_status)
If I run the above script multiple times, I get different results. Sometimes the status for the last factorization is 0 and sometimes it is 10. Sometimes the analysis phase is not successful for the last matrix. Note that if I include solver.run(job=-1)
inside the for loop, I get deterministic behavior. Additionally, if I only factorize the last matrix (and exclude the first three), the results are deterministic and the factorization status is always 0.
Any guidance is appreciated.