Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This introduces a new keyword, precond, that turns on preconditioning of the SD/CG algorithm to optimize the spread. It is based on the same idea as the Tetter-Payne-Allan preconditioner of DFT: the functional is nearly diagonal in R-space, and the gradients put too much emphasis on the large-R contributions (plotting the gradients as a function of k shows a characteristic checkerboard pattern). Using this preconditioner speeds up the iteration for fine k-point grids. In my tests I got about x2 on 8x8x8 Silicon and x3 on 14x14 Arsenene, (exact speedups are sensitive to other input parameters such as tolerance, trial step, CG parameters...). I have not observed any slowdown for coarser grids.
In terms of implementation, I use a slow Fourier transform: I really should be using a FFT, but this requires a lot more code than this barebone implementation, that reuses the machinery in hamiltonian.F90 to construct a R-space grid (thanks to G. Pizzi for the idea!). On the systems I tried, the additional cost of preconditioning is nearly zero. It does require more RAM (sizeof(complex double) times the number of kpoints squared, independently of the number of Wannier functions), although modestly so: at 10k kpoints (22 x 22 x 22), it's 1.6 GB. When the "optimisation" flag is < 3, I turn off the GEMM-based implementation to save RAM: this is slow, but still yields a speedup it because of the gain in iterations.
There are a number of tunable parameters in the algorithm, which I do not expose: the default values seem good enough not to bother.
Any comments welcome!