I am modelling a Klein-Gordon equation (similar to a wave equation), by mode decomposition, i.e. I need to solve the eigenvalue problem y_n'' = - omega_n ** 2 * y
(This is of course a vast simplification).
This procedure involves many steps, but the main ones are
- Calculate the solution for each of the modes (identified with an index
n
) up to a maximum indexmax_n
. Save it to the nth element of a solution array of the class I am using to do all this (as this is all part of a bigger project).
for n in range(-max_n, max_n+1):
self.solution_array[n+max_n] = scipy.integrate.solve_bvp(
Klein_Gordon_differential_equation,
boundary_conditions,
...,
p=(eigenvalue_guess(n),),
)
This is suboptimal as I am not doing any parallelization.
-
When all these modes are calculated, calculate some physical quantity regarding the full family of solutions, which changes the context of the problem.
-
With this new context, repeat step 1.
-
If some convergence is achieved, stop.
When trying to solve for the eigenvalue, SciPy raises a MemoryError: Not enough memory to perform factorization
.
Is there anyway I change my method so that I do not get a MemoryError
? For example, is it possible that since I am not using parallelization, SciPy ‘sees’ less memory than what it should be seeing? i.e. will parallelization solve something more than just runtime?
Note: Please tell me if I need to add more details. The process in itself its pretty simple, but the calculations I am doing involve a lot of subcalculations that I do not think are relevant for the question.
Edit: The traceback of the error:
Traceback (most recent call last):
File "main.py", line 45, in <module>
smoothing=smoothing,
File "/home/sanz/MasterArbeit/computation/calculations/increase_lambda.py", line 84, in main
plt.show()
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 254, in show
return _show(*args, **kw)
File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 3266, in show
cls.mainloop()
File "/usr/lib/python3/dist-packages/matplotlib/backends/_backend_tk.py", line 1039, in mainloop
managers[0].window.mainloop()
File "/usr/lib/python3.7/tkinter/__init__.py", line 1283, in mainloop
self.tk.mainloop(n)
KeyboardInterrupt
Edit: Other probably relevant information: The code breaks down due to physical reasons (when the eigenvalue of some mode goes to 0, due to the external electric field being too strong). When that happens, I understand that scipy tries to increase the number of nodes used with each iteration. I guess that is where the memory error is
6