Skip to content

Fix missing OpenACC copy-back in non-MPI3 calc_uVpsi_rdivided - #1283

Merged
syamada0 merged 2 commits into
SALMON-TDDFT:develop-2.0.0from
william-dawson:fix/openacc-uVpsibox-copyback
Aug 28, 2026
Merged

syamada0 merged 2 commits into
SALMON-TDDFT:develop-2.0.0from
william-dawson:fix/openacc-uVpsibox-copyback

Conversation

@william-dawson

Copy link
Copy Markdown
Contributor

This is a small fix: when MPI3 is disabled in a GPU build, the #else branch of calc_uVpsi_rdivided computes pseudo-potential projections on the device (dev_uVpsibox) but never copies them back to the host arrays before comm_summation. That silently reduces stale data and gives wrong energies in multi-rank runs.

The MPI3 branch (#ifdef) right above already does this copy-back (uVpsibox = dev_uVpsibox). This PR adds the same #ifdef USE_OPENACC copy-back to the #else branch so both paths behave correctly.

Verification

SiO₂ 3×3×3 (486 atoms, 1944 states), Rikyu GB200, nvhpc/26.3, 4 GPUs / 4 ranks:

  • Without fix: energy off by ~+22,000 eV.
  • With fix: exact match to single-rank reference.

…ion fallback

In calc_uVpsi_rdivided (nonlocal_potential.f90), the compute loop writes
the projected nonlocal-PP integrals into dev_uVpsibox (the OpenACC device
array), while the host array uVpsibox stays uninitialized. The
MPI_VERSION3 path copies the device data back to the host
(uVpsibox = dev_uVpsibox) before use, but that copy-back is inside
"#ifdef FORTRAN_COMPILER_HAS_MPI_VERSION3" -- so under the non-MPI3
fallback path (FORTRAN_COMPILER_HAS_MPI_VERSION3=OFF) the subsequent
comm_summation(uVpsibox, ...) sums uninitialized host memory, yielding
uVpsibox2 = 0 and dropping the nonlocal pseudopotential contribution
from the Hamiltonian entirely.

This produces a silently wrong total energy whenever the real-space grid
is MPI-divided (nproc_rgrid>1, the only code path that calls
calc_uVpsi_rdivided) on a GPU/OpenACC build with the non-MPI3 fallback:
the missing E_ion_nloc term inflates the total energy by |E_ion_nloc|
(~22,325 eV on a 486-atom SiO2 3x3x3x3 system), and the matter current
density diverges from the correct trajectory from the first timestep.

Mirror the existing MPI_VERSION3 copy-back into the #else branch so the
host arrays are populated from device before comm_summation reads them.

Verified on RIKYU (GB200, nvhpc/26.3, FORTRAN_COMPILER_HAS_MPI_VERSION3=OFF):
the patched nproc_rgrid=2,1,1 run is now bit-for-bit identical to the
nproc_rgrid=1,1,1 reference (Eall = -164707.165382338 eV at t=0, matching
to 15 significant figures), where the unpatched run gave -142382.23 eV.
@jenkins-diana

Copy link
Copy Markdown

Can one of the admins verify this patch?

@syamada0
syamada0 merged commit 9f1d8bb into SALMON-TDDFT:develop-2.0.0 Aug 28, 2026
1 check passed
@syamada0

Copy link
Copy Markdown
Contributor

Thank you @william-dawson san, I have merged this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants