SpinW / spinw

SpinW Matlab library for spin wave calculation
http://www.spinw.org
GNU General Public License v3.0
36 stars 15 forks source link

Out-of-memory error in spinwave #40

Closed mducle closed 2 years ago

mducle commented 4 years ago

The calculation of the structure factor in spinwave (lines 869-908) uses several large temporary matrices (of size 3 x 3 x nExt x nExt x nHKL) which increases the required memory for the calculations by about 4-5 times the minimum necessary for the outputs.

This could be reduced to twice the minimum necessary memory for outputs if these temporary matrices are removed - at the cost of the code becoming hard to read (less like the mathematics).

A further reduction to just the necessary amount of memory could be achieved by casting the eigenvector array down to single-precision for the calculations and then up-casting the structure factor array Sab back to double-precision at the end of the calculation, for a small loss of accuracy. This could be made an option, for users who need to simulate large numbers of Q points at once without external chunking (spinwave already chunks the internal loop over Q points. However it returns the full structure factor tensor, whilst for neutron scattering uses only the component perpendicular to Q is needed which uses 9 times less memory, after passing through sw_neutron; so to save memory the user should chunk the combined spinwave/sw_neutron calculations over Q points, or use the related spinwavefast function which returns the perpendicular component only but does not support some features of spinwave such as twinning).

mducle commented 2 years ago

50 is a duplicate of this issue but it has more details and a patch, so closing this issue instead.