ForSCF: Portable Multicore and Multi-GPU Fock Builds for Electronic Structure Calculations
The construction of the Fock matrix from electron repulsion integrals dominates the cost of Hartree--Fock calculations and limits the performance of the self-consistent field (SCF) step of density functional and post-Hartree--Fock methods. This work discusses opt-UM and opt-Brc, two integral schemes of Palethorpe et al.\ for graphics processing units (GPUs), based on the McMurchie--Davidson and Head-Gordon--Pople algorithms and defined from recurrence graphs. Whereas the original implementation uses CUDA, the schemes are expressed here in Fortran with compiler directives, so that one source builds with OpenACC for NVIDIA and AMD GPUs and with OpenMP for multicore CPUs. They are adapted to the directive model and to GPUs with smaller caches, and a mixed scheme is introduced that builds the Coulomb matrix with opt-UM and the exchange matrix with opt-Brc. The resulting code, ForSCF, can also serve as the Fock-build engine of other quantum chemistry programs. At a matched per-build error below $10^{-5} E_h$, for polyglycine chains and water clusters on one V100 GPU, ForSCF builds the Fock matrix on average 2.4-3.3 times as fast as GPU4PySCF with STO-3G and the Pople basis sets and 1.2-1-6 times as fast with cc-pVDZ and cc-pVTZ, although GPU4PySCF is faster for the larger water clusters with the latter two. At the largest systems that NWChem completed, ForSCF on one GPU converges RHF calculations 22-207 times as fast as NWChem, PySCF and ORCA on all 32 CPU cores of the same node, and as the Fock-build engine of NWChem it makes direct SCF calculations 13-35 times faster.