deepmodeling / abacus-develop

An electronic structure package based on either plane wave basis or numerical atomic orbitals.
http://abacus.ustc.edu.cn
GNU Lesser General Public License v3.0
174 stars 136 forks source link

Bug: ABACUS requires 1.75922e+13 MB memory on some machine when setting ecutwfc 2000 Ry #5538

Closed kirk0830 closed 14 hours ago

kirk0830 commented 2 days ago

Describe the bug

ecutwfc2000Ry.zip

Expected behavior

No response

To Reproduce

No response

Environment

No response

Additional Context

No response

Task list for Issue attackers (only for developers)

jinzx10 commented 1 day ago

It turns out to be an issue of int overflow. The following boxed code (as well as several other places doing the similar calculation)

Image

may not work as expected, because nks2, nbands, npol & npwx all have type int, whose maximum value is 2^31-1 = 2147483647 on a machine with int defaulted to int32. Although the last term, sizeof(...) will return a size_t, given the evaluation of such arithmetic expression is left-to-right, it will not promote int to size_t until the last multiplication. That is, if the product nks2 nbands npol * npwx exceeds INT_MAX, the result would be wrong.

A quick solution is to move sizeof(...) to the first term in the chained multiplication.