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).
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 throughsw_neutron
; so to save memory the user should chunk the combinedspinwave
/sw_neutron
calculations over Q points, or use the relatedspinwavefast
function which returns the perpendicular component only but does not support some features ofspinwave
such as twinning).