From 678e60fa4e96575ec74e8032cd00cd9224eaaa6b Mon Sep 17 00:00:00 2001 From: Growl Date: Tue, 21 Jul 2026 14:50:06 +0800 Subject: [PATCH] Drop toolchain patch for tblite - No evidence shows these patches actually affect the tblite code path, and calculation settings should not be controlled through environment variables. - Spack recipe doesn't contain them, needs to keep dependency behavior consistent. --- .../stage8/dftd4-4.2.0-gradient-fixes.patch | 574 -------- .../scripts/stage8/install_tblite.sh | 10 +- .../simple-dftd3-1.4.0-gradient-fixes.patch | 1210 ----------------- 3 files changed, 1 insertion(+), 1793 deletions(-) delete mode 100644 tools/toolchain/scripts/stage8/dftd4-4.2.0-gradient-fixes.patch delete mode 100644 tools/toolchain/scripts/stage8/simple-dftd3-1.4.0-gradient-fixes.patch diff --git a/tools/toolchain/scripts/stage8/dftd4-4.2.0-gradient-fixes.patch b/tools/toolchain/scripts/stage8/dftd4-4.2.0-gradient-fixes.patch deleted file mode 100644 index e467cf852e..0000000000 --- a/tools/toolchain/scripts/stage8/dftd4-4.2.0-gradient-fixes.patch +++ /dev/null @@ -1,574 +0,0 @@ -diff --git a/src/dftd4/cutoff.f90 b/src/dftd4/cutoff.f90 -index 86a856b..40f299f 100644 ---- a/src/dftd4/cutoff.f90 -+++ b/src/dftd4/cutoff.f90 -@@ -20,7 +20,7 @@ module dftd4_cutoff - implicit none - private - -- public :: realspace_cutoff, get_lattice_points, smooth_cutoff -+ public :: realspace_cutoff, get_lattice_points, smooth_cutoff, apply_smooth_width_env - - - !> Coordination number cutoff -@@ -53,7 +53,7 @@ module dftd4_cutoff - real(wp) :: disp3 = disp3_default - - !> Width of smooth two-body interaction cutoff -- real(wp) :: width2 = 0.0_wp -+ real(wp) :: width2 = 0.05_wp - - !> Width of smooth three-body interaction cutoff - real(wp) :: width3 = 0.0_wp -@@ -70,6 +70,46 @@ module dftd4_cutoff - contains - - -+subroutine apply_smooth_width_env(cutoff) -+ -+ type(realspace_cutoff), intent(inout) :: cutoff -+ -+ call get_smooth_width("DFTD4_DISP2_SMOOTH_WIDTH", "TBLITE_D4_DISP2_SMOOTH_WIDTH", & -+ & cutoff%disp2, cutoff%width2) -+ call get_smooth_width("DFTD4_DISP3_SMOOTH_WIDTH", "TBLITE_D4_DISP3_SMOOTH_WIDTH", & -+ & cutoff%disp3, cutoff%width3) -+ -+end subroutine apply_smooth_width_env -+ -+ -+subroutine get_smooth_width(env1, env2, cutoff, width) -+ -+ character(len=*), intent(in) :: env1, env2 -+ real(wp), intent(in) :: cutoff -+ real(wp), intent(inout) :: width -+ -+ character(len=64) :: env -+ integer :: stat, io -+ real(wp) :: env_width -+ -+ call get_environment_variable(env1, env, status=stat) -+ if (stat /= 0 .or. len_trim(env) == 0) then -+ call get_environment_variable(env2, env, status=stat) -+ end if -+ if (stat == 0 .and. len_trim(env) > 0) then -+ read(env, *, iostat=io) env_width -+ if (io == 0) then -+ if (env_width > 0.0_wp .and. env_width < cutoff) then -+ width = env_width -+ else -+ width = 0.0_wp -+ end if -+ end if -+ end if -+ -+end subroutine get_smooth_width -+ -+ - !> Smooth polynomial switch for realspace cutoffs - pure subroutine smooth_cutoff(r, cutoff, width, sw, dswdr) - -diff --git a/src/dftd4/damping/atm.f90 b/src/dftd4/damping/atm.f90 -index c6162c9..3f4f46a 100644 ---- a/src/dftd4/damping/atm.f90 -+++ b/src/dftd4/damping/atm.f90 -@@ -145,23 +145,16 @@ subroutine get_atm_dispersion_energy(mol, trans, cutoff, width, s9, a1, a2, alp, - real(wp) :: r0ij, r0jk, r0ik, r0, r1, r2, r3, r5, rr, fdmp, ang - real(wp) :: cutoff2, c9, dE, alp3, swij, swjk, swik, dswdr, sw - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) - - cutoff2 = cutoff*cutoff - alp3 = alp / 3.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(dynamic) default(none) reduction(+:energy) & - !$omp shared(mol, trans, c6, s9, a1, a2, alp3, r4r2, cutoff2, cutoff, width) & - !$omp private(iat, jat, kat, izp, jzp, kzp, jtr, ktr, vij, vjk, vik, & - !$omp& r2ij, r2jk, r2ik, rij, rjk, rik, c6ij, c6jk, c6ik, triple, & - !$omp& r0ij, r0jk, r0ik, r0, r1, r2, r3, r5, rr, fdmp, ang, c9, dE, & -- !$omp& swij, swjk, swik, dswdr, sw) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- !$omp do schedule(dynamic) -+ !$omp& swij, swjk, swik, dswdr, sw) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -212,20 +205,15 @@ subroutine get_atm_dispersion_energy(mol, trans, cutoff, width, s9, a1, a2, alp, - rr = ang*fdmp - - dE = rr * c9 * triple * third * sw -- energy_local(iat) = energy_local(iat) - dE -- energy_local(jat) = energy_local(jat) - dE -- energy_local(kat) = energy_local(kat) - dE -+ energy(iat) = energy(iat) - dE -+ energy(jat) = energy(jat) - dE -+ energy(kat) = energy(kat) - dE - end do - end do - end do - end do - end do -- !$omp end do -- !$omp critical (get_atm_dispersion_energy_) -- energy(:) = energy(:) + energy_local(:) -- !$omp end critical (get_atm_dispersion_energy_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_atm_dispersion_energy - -@@ -293,34 +281,19 @@ subroutine get_atm_dispersion_derivs(mol, trans, cutoff, width, s9, a1, a2, alp, - real(wp) :: dGij(3), dGjk(3), dGik(3), dS(3, 3) - real(wp) :: swij, swjk, swik, dswijdr, dswjkdr, dswikdr, sw - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) -- real(wp), allocatable :: dEdcn_local(:) -- real(wp), allocatable :: dEdq_local(:) -- real(wp), allocatable :: gradient_local(:, :) -- real(wp), allocatable :: sigma_local(:, :) - - cutoff2 = cutoff*cutoff - alp3 = alp / 3.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(dynamic) default(none) & -+ !$omp reduction(+:energy, gradient, sigma, dEdcn, dEdq) & - !$omp shared(mol, trans, c6, s9, a1, a2, alp, alp3, r4r2, cutoff2, & - !$omp& cutoff, width, dc6dcn, dc6dq) & - !$omp private(iat, jat, kat, izp, jzp, kzp, jtr, ktr, vij, vjk, vik, & - !$omp& r2ij, r2jk, r2ik, rij, rjk, rik, c6ij, c6jk, c6ik, triple, & - !$omp& r0ij, r0jk, r0ik, r0, r1, r2, r3, r5, rr, fdmp, dfdmp, ang, dang, & - !$omp& c9, dE, dE0, dE_third, dGij, dGjk, dGik, dS, swij, swjk, swik, & -- !$omp& dswijdr, dswjkdr, dswikdr, sw) & -- !$omp shared(energy, gradient, sigma, dEdcn, dEdq) & -- !$omp private(energy_local, gradient_local, sigma_local, dEdcn_local, & -- !$omp& dEdq_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- allocate(dEdcn_local(size(dEdcn, 1)), source=0.0_wp) -- allocate(dEdq_local(size(dEdq, 1)), source=0.0_wp) -- allocate(gradient_local(size(gradient, 1), size(gradient, 2)), source=0.0_wp) -- allocate(sigma_local(size(sigma, 1), size(sigma, 2)), source=0.0_wp) -- !$omp do schedule(dynamic) -+ !$omp& dswijdr, dswjkdr, dswikdr, sw) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -399,55 +372,42 @@ subroutine get_atm_dispersion_derivs(mol, trans, cutoff, width, s9, a1, a2, alp, - - dE = dE0 * triple * sw - dE_third = dE * third -- energy_local(iat) = energy_local(iat) - dE_third -- energy_local(jat) = energy_local(jat) - dE_third -- energy_local(kat) = energy_local(kat) - dE_third -+ energy(iat) = energy(iat) - dE_third -+ energy(jat) = energy(jat) - dE_third -+ energy(kat) = energy(kat) - dE_third - -- gradient_local(:, iat) = gradient_local(:, iat) & -+ gradient(:, iat) = gradient(:, iat) & - & - (dGij + dGik) * triple -- gradient_local(:, jat) = gradient_local(:, jat) & -+ gradient(:, jat) = gradient(:, jat) & - & + (dGij - dGjk) * triple -- gradient_local(:, kat) = gradient_local(:, kat) & -+ gradient(:, kat) = gradient(:, kat) & - & + (dGik + dGjk) * triple - - dS(:, :) = spread(dGij, 1, 3) * spread(vij, 2, 3)& - & + spread(dGik, 1, 3) * spread(vik, 2, 3)& - & + spread(dGjk, 1, 3) * spread(vjk, 2, 3) - -- sigma_local(:, :) = sigma_local + dS * triple -+ sigma(:, :) = sigma(:, :) + dS * triple - -- dEdcn_local(iat) = dEdcn_local(iat) - dE * 0.5_wp & -+ dEdcn(iat) = dEdcn(iat) - dE * 0.5_wp & - & * (dc6dcn(iat, jat) / c6ij + dc6dcn(iat, kat) / c6ik) -- dEdcn_local(jat) = dEdcn_local(jat) - dE * 0.5_wp & -+ dEdcn(jat) = dEdcn(jat) - dE * 0.5_wp & - & * (dc6dcn(jat, iat) / c6ij + dc6dcn(jat, kat) / c6jk) -- dEdcn_local(kat) = dEdcn_local(kat) - dE * 0.5_wp & -+ dEdcn(kat) = dEdcn(kat) - dE * 0.5_wp & - & * (dc6dcn(kat, iat) / c6ik + dc6dcn(kat, jat) / c6jk) - -- dEdq_local(iat) = dEdq_local(iat) - dE * 0.5_wp & -+ dEdq(iat) = dEdq(iat) - dE * 0.5_wp & - & * (dc6dq(iat, jat) / c6ij + dc6dq(iat, kat) / c6ik) -- dEdq_local(jat) = dEdq_local(jat) - dE * 0.5_wp & -+ dEdq(jat) = dEdq(jat) - dE * 0.5_wp & - & * (dc6dq(jat, iat) / c6ij + dc6dq(jat, kat) / c6jk) -- dEdq_local(kat) = dEdq_local(kat) - dE * 0.5_wp & -+ dEdq(kat) = dEdq(kat) - dE * 0.5_wp & - & * (dc6dq(kat, iat) / c6ik + dc6dq(kat, jat) / c6jk) - end do - end do - end do - end do - end do -- !$omp end do -- !$omp critical (get_atm_dispersion_derivs_) -- energy(:) = energy(:) + energy_local(:) -- dEdcn(:) = dEdcn(:) + dEdcn_local(:) -- dEdq(:) = dEdq(:) + dEdq_local(:) -- gradient(:, :) = gradient(:, :) + gradient_local(:, :) -- sigma(:, :) = sigma(:, :) + sigma_local(:, :) -- !$omp end critical (get_atm_dispersion_derivs_) -- deallocate(energy_local) -- deallocate(dEdcn_local) -- deallocate(dEdq_local) -- deallocate(gradient_local) -- deallocate(sigma_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_atm_dispersion_derivs - -diff --git a/src/dftd4/damping/rational.f90 b/src/dftd4/damping/rational.f90 -index 9d359c9..87e8f6b 100644 ---- a/src/dftd4/damping/rational.f90 -+++ b/src/dftd4/damping/rational.f90 -@@ -152,20 +152,13 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, r4r2, c6, ener - real(wp) :: vec(3), r2, r, cutoff2, r0ij, rrij, c6ij, t6, t8, edisp, dE - real(wp) :: sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r0ij, rrij, c6ij, & -- !$omp& t6, t8, edisp, dE, r, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& t6, t8, edisp, dE, r, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -188,19 +181,14 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, r4r2, c6, ener - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(iat) = energy_local(iat) + dE -+ energy(iat) = energy(iat) + dE - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -+ energy(jat) = energy(jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_energy_) -- energy(:) = energy(:) + energy_local(:) -- !$omp end critical (get_dispersion_energy_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_energy - -@@ -256,29 +244,14 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, r4r2, c6, dc6d - real(wp) :: edisp0, gdisp0, edisp, gdisp, sw, dswdr - real(wp) :: dE, dG(3), dS(3, 3) - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) -- real(wp), allocatable :: dEdcn_local(:) -- real(wp), allocatable :: dEdq_local(:) -- real(wp), allocatable :: gradient_local(:, :) -- real(wp), allocatable :: sigma_local(:, :) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) & -+ !$omp reduction(+:energy, gradient, sigma, dEdcn, dEdq) & - !$omp shared(mol, self, c6, dc6dcn, dc6dq, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r0ij, rrij, c6ij, t6, t8, & -- !$omp& d6, d8, edisp0, gdisp0, edisp, gdisp, dE, dG, dS, r, sw, dswdr) & -- !$omp shared(energy, gradient, sigma, dEdcn, dEdq) & -- !$omp private(energy_local, gradient_local, sigma_local, dEdcn_local, & -- !$omp& dEdq_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- allocate(dEdcn_local(size(dEdcn, 1)), source=0.0_wp) -- allocate(dEdq_local(size(dEdq, 1)), source=0.0_wp) -- allocate(gradient_local(size(gradient, 1), size(gradient, 2)), source=0.0_wp) -- allocate(sigma_local(size(sigma, 1), size(sigma, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& d6, d8, edisp0, gdisp0, edisp, gdisp, dE, dG, dS, r, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -310,35 +283,22 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, r4r2, c6, dc6d - dG(:) = -c6ij*gdisp*vec - dS(:, :) = spread(dG, 1, 3) * spread(vec, 2, 3) * 0.5_wp - -- energy_local(iat) = energy_local(iat) + dE -- dEdcn_local(iat) = dEdcn_local(iat) - dc6dcn(iat, jat) * edisp -- dEdq_local(iat) = dEdq_local(iat) - dc6dq(iat, jat) * edisp -- sigma_local(:, :) = sigma_local + dS -+ energy(iat) = energy(iat) + dE -+ dEdcn(iat) = dEdcn(iat) - dc6dcn(iat, jat) * edisp -+ dEdq(iat) = dEdq(iat) - dc6dq(iat, jat) * edisp -+ sigma(:, :) = sigma(:, :) + dS - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -- dEdcn_local(jat) = dEdcn_local(jat) - dc6dcn(jat, iat) * edisp -- dEdq_local(jat) = dEdq_local(jat) - dc6dq(jat, iat) * edisp -- gradient_local(:, iat) = gradient_local(:, iat) + dG -- gradient_local(:, jat) = gradient_local(:, jat) - dG -- sigma_local(:, :) = sigma_local + dS -+ energy(jat) = energy(jat) + dE -+ dEdcn(jat) = dEdcn(jat) - dc6dcn(jat, iat) * edisp -+ dEdq(jat) = dEdq(jat) - dc6dq(jat, iat) * edisp -+ gradient(:, iat) = gradient(:, iat) + dG -+ gradient(:, jat) = gradient(:, jat) - dG -+ sigma(:, :) = sigma(:, :) + dS - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_derivs_) -- energy(:) = energy(:) + energy_local(:) -- dEdcn(:) = dEdcn(:) + dEdcn_local(:) -- dEdq(:) = dEdq(:) + dEdq_local(:) -- gradient(:, :) = gradient(:, :) + gradient_local(:, :) -- sigma(:, :) = sigma(:, :) + sigma_local(:, :) -- !$omp end critical (get_dispersion_derivs_) -- deallocate(energy_local) -- deallocate(dEdcn_local) -- deallocate(dEdq_local) -- deallocate(gradient_local) -- deallocate(sigma_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_derivs - -@@ -429,21 +389,14 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, r4r2, c6, e - real(wp) :: vec(3), r2, r, cutoff2, r0ij, rrij, c6ij, t6, t8, edisp, dE - real(wp) :: sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:, :) - - if (abs(self%s6) < epsilon(1.0_wp) .and. abs(self%s8) < epsilon(1.0_wp)) return - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r0ij, rrij, c6ij, & -- !$omp& t6, t8, edisp, dE, r, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1), size(energy, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& t6, t8, edisp, dE, r, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -466,19 +419,14 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, r4r2, c6, e - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(jat, iat) = energy_local(jat, iat) + dE -+ energy(jat, iat) = energy(jat, iat) + dE - if (iat /= jat) then -- energy_local(iat, jat) = energy_local(iat, jat) + dE -+ energy(iat, jat) = energy(iat, jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_pairwise_dispersion2_) -- energy(:, :) = energy(:, :) + energy_local(:, :) -- !$omp end critical (get_pairwise_dispersion2_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_pairwise_dispersion2 - -@@ -517,24 +465,17 @@ subroutine get_pairwise_dispersion3(self, mol, trans, cutoff, width, r4r2, c6, e - real(wp) :: r0ij, r0jk, r0ik, r0, r1, r2, r3, r5, rr, fdmp, ang - real(wp) :: cutoff2, c9, dE, alp3, swij, swjk, swik, dswdr, sw - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:, :) - - if (abs(self%s9) < epsilon(1.0_wp)) return - cutoff2 = cutoff*cutoff - alp3 = self%alp / 3.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, trans, c6, r4r2, cutoff2, cutoff, width, alp3, self) & - !$omp private(iat, jat, kat, izp, jzp, kzp, jtr, ktr, vij, vjk, vik, & - !$omp& r2ij, r2jk, r2ik, rij, rjk, rik, c6ij, c6jk, c6ik, triple, & - !$omp& r0ij, r0jk, r0ik, r0, r1, r2, r3, r5, rr, fdmp, ang, c9, dE, & -- !$omp& swij, swjk, swik, dswdr, sw) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1), size(energy, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& swij, swjk, swik, dswdr, sw) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -585,23 +526,18 @@ subroutine get_pairwise_dispersion3(self, mol, trans, cutoff, width, r4r2, c6, e - rr = ang*fdmp - - dE = rr * c9 * triple * sixth * sw -- energy_local(jat, iat) = energy_local(jat, iat) - dE -- energy_local(kat, iat) = energy_local(kat, iat) - dE -- energy_local(iat, jat) = energy_local(iat, jat) - dE -- energy_local(kat, jat) = energy_local(kat, jat) - dE -- energy_local(iat, kat) = energy_local(iat, kat) - dE -- energy_local(jat, kat) = energy_local(jat, kat) - dE -+ energy(jat, iat) = energy(jat, iat) - dE -+ energy(kat, iat) = energy(kat, iat) - dE -+ energy(iat, jat) = energy(iat, jat) - dE -+ energy(kat, jat) = energy(kat, jat) - dE -+ energy(iat, kat) = energy(iat, kat) - dE -+ energy(jat, kat) = energy(jat, kat) - dE - end do - end do - end do - end do - end do -- !$omp end do -- !$omp critical (get_pairwise_dispersion3_) -- energy(:, :) = energy(:, :) + energy_local(:, :) -- !$omp end critical (get_pairwise_dispersion3_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_pairwise_dispersion3 - -diff --git a/src/dftd4/disp.f90 b/src/dftd4/disp.f90 -index 73253ce..8524cef 100644 ---- a/src/dftd4/disp.f90 -+++ b/src/dftd4/disp.f90 -@@ -18,7 +18,7 @@ - module dftd4_disp - use, intrinsic :: iso_fortran_env, only : error_unit - use dftd4_blas, only : d4_gemv -- use dftd4_cutoff, only : realspace_cutoff, get_lattice_points -+ use dftd4_cutoff, only : realspace_cutoff, get_lattice_points, apply_smooth_width_env - use dftd4_damping, only : damping_param - use dftd4_data, only : get_covalent_rad - use dftd4_model, only : dispersion_model -@@ -70,9 +70,12 @@ subroutine get_dispersion(mol, disp, param, cutoff, energy, gradient, sigma) - real(wp), allocatable :: dEdcn(:), dEdq(:), energies(:) - real(wp), allocatable :: lattr(:, :) - type(error_type), allocatable :: error -+ type(realspace_cutoff) :: cutoff_eff - - mref = maxval(disp%ref) - grad = present(gradient).or.present(sigma) -+ cutoff_eff = cutoff -+ call apply_smooth_width_env(cutoff_eff) - - if (.not. allocated(disp%mchrg)) then - write(error_unit, '("[Error]:", 1x, a)') "Not supported for non-self-consistent D4 version" -@@ -80,8 +83,8 @@ subroutine get_dispersion(mol, disp, param, cutoff, energy, gradient, sigma) - end if - - allocate(cn(mol%nat)) -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%cn, lattr) -- call get_coordination_number(mol, lattr, cutoff%cn, disp%rcov, disp%en, cn) -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%cn, lattr) -+ call get_coordination_number(mol, lattr, cutoff_eff%cn, disp%rcov, disp%en, cn) - - allocate(q(mol%nat)) - if (grad) allocate(dqdr(3, mol%nat, mol%nat), dqdL(3, 3, mol%nat)) -@@ -109,8 +112,8 @@ subroutine get_dispersion(mol, disp, param, cutoff, energy, gradient, sigma) - sigma(:, :) = 0.0_wp - end if - -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp2, lattr) -- call param%get_dispersion2(mol, lattr, cutoff%disp2, cutoff%width2, disp%r4r2, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%disp2, lattr) -+ call param%get_dispersion2(mol, lattr, cutoff_eff%disp2, cutoff_eff%width2, disp%r4r2, & - & c6, dc6dcn, dc6dq, energies, dEdcn, dEdq, gradient, sigma) - if (grad) then - call d4_gemv(dqdr, dEdq, gradient, beta=1.0_wp) -@@ -121,11 +124,11 @@ subroutine get_dispersion(mol, disp, param, cutoff, energy, gradient, sigma) - call disp%weight_references(mol, cn, q, gwvec, gwdcn, gwdq) - call disp%get_atomic_c6(mol, gwvec, gwdcn, gwdq, c6, dc6dcn, dc6dq) - -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp3, lattr) -- call param%get_dispersion3(mol, lattr, cutoff%disp3, cutoff%width3, disp%r4r2, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%disp3, lattr) -+ call param%get_dispersion3(mol, lattr, cutoff_eff%disp3, cutoff_eff%width3, disp%r4r2, & - & c6, dc6dcn, dc6dq, energies, dEdcn, dEdq, gradient, sigma) - if (grad) then -- call add_coordination_number_derivs(mol, lattr, cutoff%cn, & -+ call add_coordination_number_derivs(mol, lattr, cutoff_eff%cn, & - & disp%rcov, disp%en, dEdcn, gradient, sigma) - end if - -@@ -213,6 +216,7 @@ subroutine get_pairwise_dispersion(mol, disp, param, cutoff, energy2, energy3) - integer :: mref - real(wp), allocatable :: cn(:), q(:), gwvec(:, :, :), c6(:, :), lattr(:, :) - type(error_type), allocatable :: error -+ type(realspace_cutoff) :: cutoff_eff - - if (.not. allocated(disp%mchrg)) then - write(error_unit, '("[Error]:", 1x, a)') "Not supported for non-self-consistent D4 version" -@@ -220,10 +224,12 @@ subroutine get_pairwise_dispersion(mol, disp, param, cutoff, energy2, energy3) - end if - - mref = maxval(disp%ref) -+ cutoff_eff = cutoff -+ call apply_smooth_width_env(cutoff_eff) - - allocate(cn(mol%nat)) -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%cn, lattr) -- call get_coordination_number(mol, lattr, cutoff%cn, disp%rcov, disp%en, cn) -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%cn, lattr) -+ call get_coordination_number(mol, lattr, cutoff_eff%cn, disp%rcov, disp%en, cn) - - allocate(q(mol%nat)) - call get_charges(disp%mchrg, mol, error, q) -@@ -240,16 +246,16 @@ subroutine get_pairwise_dispersion(mol, disp, param, cutoff, energy2, energy3) - - energy2(:, :) = 0.0_wp - energy3(:, :) = 0.0_wp -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp2, lattr) -- call param%get_pairwise_dispersion2(mol, lattr, cutoff%disp2, cutoff%width2, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%disp2, lattr) -+ call param%get_pairwise_dispersion2(mol, lattr, cutoff_eff%disp2, cutoff_eff%width2, & - & disp%r4r2, c6, energy2) - - q(:) = 0.0_wp - call disp%weight_references(mol, cn, q, gwvec) - call disp%get_atomic_c6(mol, gwvec, c6=c6) - -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp3, lattr) -- call param%get_pairwise_dispersion3(mol, lattr, cutoff%disp3, cutoff%width3, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%disp3, lattr) -+ call param%get_pairwise_dispersion3(mol, lattr, cutoff_eff%disp3, cutoff_eff%width3, & - & disp%r4r2, c6, energy3) - - end subroutine get_pairwise_dispersion diff --git a/tools/toolchain/scripts/stage8/install_tblite.sh b/tools/toolchain/scripts/stage8/install_tblite.sh index 6bc055de9e..2383e04bf6 100755 --- a/tools/toolchain/scripts/stage8/install_tblite.sh +++ b/tools/toolchain/scripts/stage8/install_tblite.sh @@ -36,12 +36,6 @@ case "$with_tblite" in [ -d tblite-${tblite_ver} ] && rm -rf tblite-${tblite_ver} tar -xJf tblite-${tblite_ver}.tar.xz cd tblite-${tblite_ver} - - patch -l -d subprojects/s-dftd3 -p1 < "${SCRIPT_DIR}/stage8/simple-dftd3-${tblite_sdftd3_ver}-gradient-fixes.patch" \ - > simple_dftd3_gradient_fixes.patch.log 2>&1 || tail_excerpt simple_dftd3_gradient_fixes.patch.log - patch -l -d subprojects/dftd4 -p1 < "${SCRIPT_DIR}/stage8/dftd4-${tblite_dftd4_ver}-gradient-fixes.patch" \ - > dftd4_gradient_fixes.patch.log 2>&1 || tail_excerpt dftd4_gradient_fixes.patch.log - mkdir -p build && cd build cmake \ -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ @@ -52,9 +46,7 @@ case "$with_tblite" in .. \ > cmake.log 2>&1 || tail_excerpt cmake.log make install -j $(get_nprocs) > make.log 2>&1 || tail_excerpt make.log - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage8/$(basename ${SCRIPT_NAME})" \ - "${SCRIPT_DIR}/stage8/simple-dftd3-${tblite_sdftd3_ver}-gradient-fixes.patch" \ - "${SCRIPT_DIR}/stage8/dftd4-${tblite_dftd4_ver}-gradient-fixes.patch" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage8/$(basename ${SCRIPT_NAME})" cd .. fi ;; diff --git a/tools/toolchain/scripts/stage8/simple-dftd3-1.4.0-gradient-fixes.patch b/tools/toolchain/scripts/stage8/simple-dftd3-1.4.0-gradient-fixes.patch deleted file mode 100644 index 05fa3542f9..0000000000 --- a/tools/toolchain/scripts/stage8/simple-dftd3-1.4.0-gradient-fixes.patch +++ /dev/null @@ -1,1210 +0,0 @@ -diff --git a/src/dftd3/cutoff.f90 b/src/dftd3/cutoff.f90 -index 743774e..da2a0df 100644 ---- a/src/dftd3/cutoff.f90 -+++ b/src/dftd3/cutoff.f90 -@@ -18,7 +18,7 @@ module dftd3_cutoff - use mctc_env, only : wp - implicit none - -- public :: realspace_cutoff, get_lattice_points, smooth_cutoff -+ public :: realspace_cutoff, get_lattice_points, smooth_cutoff, apply_smooth_width_env - - - !> Coordination number cutoff -@@ -51,7 +51,7 @@ module dftd3_cutoff - real(wp) :: disp3 = disp3_default - - !> Width of smooth two-body interaction cutoff -- real(wp) :: width2 = 0.0_wp -+ real(wp) :: width2 = 0.05_wp - - !> Width of smooth three-body interaction cutoff - real(wp) :: width3 = 0.0_wp -@@ -68,6 +68,47 @@ module dftd3_cutoff - contains - - -+subroutine apply_smooth_width_env(cutoff) -+ type(realspace_cutoff), intent(inout) :: cutoff -+ -+ call get_smooth_width("SDFTD3_DISP2_SMOOTH_WIDTH", "DFTD3_DISP2_SMOOTH_WIDTH", & -+ & "TBLITE_D3_DISP2_SMOOTH_WIDTH", cutoff%disp2, cutoff%width2) -+ call get_smooth_width("SDFTD3_DISP3_SMOOTH_WIDTH", "DFTD3_DISP3_SMOOTH_WIDTH", & -+ & "TBLITE_D3_DISP3_SMOOTH_WIDTH", cutoff%disp3, cutoff%width3) -+ -+end subroutine apply_smooth_width_env -+ -+ -+subroutine get_smooth_width(env1, env2, env3, cutoff, width) -+ character(len=*), intent(in) :: env1, env2, env3 -+ real(wp), intent(in) :: cutoff -+ real(wp), intent(inout) :: width -+ -+ character(len=64) :: env -+ integer :: stat, io -+ real(wp) :: env_width -+ -+ call get_environment_variable(env1, env, status=stat) -+ if (stat /= 0 .or. len_trim(env) == 0) then -+ call get_environment_variable(env2, env, status=stat) -+ end if -+ if (stat /= 0 .or. len_trim(env) == 0) then -+ call get_environment_variable(env3, env, status=stat) -+ end if -+ if (stat == 0 .and. len_trim(env) > 0) then -+ read(env, *, iostat=io) env_width -+ if (io == 0) then -+ if (env_width > 0.0_wp .and. env_width < cutoff) then -+ width = env_width -+ else -+ width = 0.0_wp -+ end if -+ end if -+ end if -+ -+end subroutine get_smooth_width -+ -+ - !> Smooth polynomial switch for realspace cutoffs - pure subroutine smooth_cutoff(r, cutoff, width, sw, dswdr) - real(wp), intent(in) :: r -diff --git a/src/dftd3/damping/atm.f90 b/src/dftd3/damping/atm.f90 -index 419561a..9ce6521 100644 ---- a/src/dftd3/damping/atm.f90 -+++ b/src/dftd3/damping/atm.f90 -@@ -128,23 +128,16 @@ subroutine get_atm_dispersion_energy(mol, trans, cutoff, width, s9, rs9, alp, rv - real(wp) :: cutoff2, c9, dE, alp3 - real(wp) :: swij, swjk, swik, dswdr, sw - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) - - cutoff2 = cutoff*cutoff - alp3 = alp / 3.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, trans, c6, s9, rs9, alp3, rvdw, cutoff2, cutoff, width) & - !$omp private(iat, jat, kat, izp, jzp, kzp, jtr, ktr, vij, vjk, vik, & - !$omp& r2ij, r2jk, r2ik, rij, rjk, rik, c6ij, c6jk, c6ik, triple, & - !$omp& r0ij, r0jk, r0ik, r0, r1, r2, r3, r5, rr, fdmp, ang, c9, dE, & -- !$omp& swij, swjk, swik, dswdr, sw) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& swij, swjk, swik, dswdr, sw) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -190,20 +183,15 @@ subroutine get_atm_dispersion_energy(mol, trans, cutoff, width, s9, rs9, alp, rv - rr = ang*fdmp - - dE = rr * c9 * triple * sw / 3.0_wp -- energy_local(iat) = energy_local(iat) - dE -- energy_local(jat) = energy_local(jat) - dE -- energy_local(kat) = energy_local(kat) - dE -+ energy(iat) = energy(iat) - dE -+ energy(jat) = energy(jat) - dE -+ energy(kat) = energy(kat) - dE - end do - end do - end do - end do - end do -- !$omp end do -- !$omp critical (get_atm_dispersion_energy_) -- energy(:) = energy(:) + energy_local(:) -- !$omp end critical (get_atm_dispersion_energy_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_atm_dispersion_energy - -@@ -262,30 +250,17 @@ subroutine get_atm_dispersion_derivs(mol, trans, cutoff, width, s9, rs9, alp, rv - real(wp) :: alp3, r0r1alp3 - real(wp) :: swij, swjk, swik, dswijdr, dswjkdr, dswikdr, sw - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) -- real(wp), allocatable :: dEdcn_local(:) -- real(wp), allocatable :: gradient_local(:, :) -- real(wp), allocatable :: sigma_local(:, :) - - cutoff2 = cutoff*cutoff - alp3 = alp / 3.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy, gradient, sigma, dEdcn) & - !$omp shared(mol, trans, c6, s9, rs9, alp, alp3, rvdw, cutoff2, cutoff, width, dc6dcn) & - !$omp private(iat, jat, kat, izp, jzp, kzp, jtr, ktr, ic, jc, vij, vjk, vik, & - !$omp& r2ij, r2jk, r2ik, rij, rjk, rik, c6ij, c6jk, c6ik, triple, & - !$omp& r0ij, r0jk, r0ik, r0, r1, r2, r3, r5, rr, fdmp, dfdmp, ang, & - !$omp& dang, c9, dE, dE0, dGij, dGjk, dGik, dS, r0r1alp3, swij, & -- !$omp& swjk, swik, dswijdr, dswjkdr, dswikdr, sw) & -- !$omp shared(energy, gradient, sigma, dEdcn) & -- !$omp private(energy_local, gradient_local, sigma_local, dEdcn_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- allocate(dEdcn_local(size(dEdcn, 1)), source=0.0_wp) -- allocate(gradient_local(size(gradient, 1), size(gradient, 2)), source=0.0_wp) -- allocate(sigma_local(size(sigma, 1), size(sigma, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& swjk, swik, dswijdr, dswjkdr, dswikdr, sw) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -359,13 +334,13 @@ subroutine get_atm_dispersion_derivs(mol, trans, cutoff, width, s9, rs9, alp, rv - & - dE0 * dswjkdr / rjk * swij * swik * vjk - - dE = dE0 * triple * sw -- energy_local(iat) = energy_local(iat) - dE/3.0_wp -- energy_local(jat) = energy_local(jat) - dE/3.0_wp -- energy_local(kat) = energy_local(kat) - dE/3.0_wp -+ energy(iat) = energy(iat) - dE/3.0_wp -+ energy(jat) = energy(jat) - dE/3.0_wp -+ energy(kat) = energy(kat) - dE/3.0_wp - -- gradient_local(:, iat) = gradient_local(:, iat) - (dGij + dGik) * triple -- gradient_local(:, jat) = gradient_local(:, jat) + (dGij - dGjk) * triple -- gradient_local(:, kat) = gradient_local(:, kat) + (dGik + dGjk) * triple -+ gradient(:, iat) = gradient(:, iat) - (dGij + dGik) * triple -+ gradient(:, jat) = gradient(:, jat) + (dGij - dGjk) * triple -+ gradient(:, kat) = gradient(:, kat) + (dGik + dGjk) * triple - - do ic = 1, 3 - do jc = 1, 3 -@@ -374,31 +349,20 @@ subroutine get_atm_dispersion_derivs(mol, trans, cutoff, width, s9, rs9, alp, rv - end do - end do - -- sigma_local(:, :) = sigma_local + dS * triple -+ sigma(:, :) = sigma(:, :) + dS * triple - -- dEdcn_local(iat) = dEdcn_local(iat) - dE * 0.5_wp & -+ dEdcn(iat) = dEdcn(iat) - dE * 0.5_wp & - & * (dc6dcn(iat, jat) / c6ij + dc6dcn(iat, kat) / c6ik) -- dEdcn_local(jat) = dEdcn_local(jat) - dE * 0.5_wp & -+ dEdcn(jat) = dEdcn(jat) - dE * 0.5_wp & - & * (dc6dcn(jat, iat) / c6ij + dc6dcn(jat, kat) / c6jk) -- dEdcn_local(kat) = dEdcn_local(kat) - dE * 0.5_wp & -+ dEdcn(kat) = dEdcn(kat) - dE * 0.5_wp & - & * (dc6dcn(kat, iat) / c6ik + dc6dcn(kat, jat) / c6jk) - end do - end do - end do - end do - end do -- !$omp end do -- !$omp critical (get_atm_dispersion_derivs_) -- energy(:) = energy(:) + energy_local(:) -- dEdcn(:) = dEdcn(:) + dEdcn_local(:) -- gradient(:, :) = gradient(:, :) + gradient_local(:, :) -- sigma(:, :) = sigma(:, :) + sigma_local(:, :) -- !$omp end critical (get_atm_dispersion_derivs_) -- deallocate(energy_local) -- deallocate(dEdcn_local) -- deallocate(gradient_local) -- deallocate(sigma_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_atm_dispersion_derivs - -@@ -444,24 +408,17 @@ subroutine get_atm_pairwise_dispersion(mol, trans, cutoff, width, s9, rs9, alp, - real(wp) :: cutoff2, c9, dE, alp3 - real(wp) :: swij, swjk, swik, dswdr, sw - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:, :) - - if (abs(s9) < epsilon(1.0_wp)) return - cutoff2 = cutoff*cutoff - alp3 = alp / 3.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, trans, c6, cutoff2, cutoff, width, s9, rs9, alp3, rvdw) & - !$omp private(iat, jat, kat, izp, jzp, kzp, jtr, ktr, vij, vjk, vik, & - !$omp& r2ij, r2jk, r2ik, rij, rjk, rik, c6ij, c6jk, c6ik, triple, & - !$omp& r0ij, r0jk, r0ik, r0, r1, r2, r3, r5, rr, fdmp, ang, c9, dE, & -- !$omp& swij, swjk, swik, dswdr, sw) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1), size(energy, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& swij, swjk, swik, dswdr, sw) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -507,23 +464,18 @@ subroutine get_atm_pairwise_dispersion(mol, trans, cutoff, width, s9, rs9, alp, - rr = ang*fdmp - - dE = rr * c9 * triple * sw / 6.0_wp -- energy_local(jat, iat) = energy_local(jat, iat) - dE -- energy_local(kat, iat) = energy_local(kat, iat) - dE -- energy_local(iat, jat) = energy_local(iat, jat) - dE -- energy_local(kat, jat) = energy_local(kat, jat) - dE -- energy_local(iat, kat) = energy_local(iat, kat) - dE -- energy_local(jat, kat) = energy_local(jat, kat) - dE -+ energy(jat, iat) = energy(jat, iat) - dE -+ energy(kat, iat) = energy(kat, iat) - dE -+ energy(iat, jat) = energy(iat, jat) - dE -+ energy(kat, jat) = energy(kat, jat) - dE -+ energy(iat, kat) = energy(iat, kat) - dE -+ energy(jat, kat) = energy(jat, kat) - dE - end do - end do - end do - end do - end do -- !$omp end do -- !$omp critical (get_atm_pairwise_dispersion_) -- energy(:, :) = energy(:, :) + energy_local(:, :) -- !$omp end critical (get_atm_pairwise_dispersion_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_atm_pairwise_dispersion - -diff --git a/src/dftd3/damping/cso.f90 b/src/dftd3/damping/cso.f90 -index 4253577..8fc4032 100644 ---- a/src/dftd3/damping/cso.f90 -+++ b/src/dftd3/damping/cso.f90 -@@ -172,20 +172,13 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: c6ij, edisp, dE, sw, dswdr - real(wp) :: d6_6, a2r0ij, r4 - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, rrij, r0ij, rij, d6, ef, & -- !$omp& sf, sig, t6, c6ij, edisp, dE, d6_6, a2r0ij, r4, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& sf, sig, t6, c6ij, edisp, dE, d6_6, a2r0ij, r4, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -213,19 +206,14 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(iat) = energy_local(iat) + dE -+ energy(iat) = energy(iat) + dE - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -+ energy(jat) = energy(jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_energy_cso_) -- energy(:) = energy(:) + energy_local(:) -- !$omp end critical (get_dispersion_energy_cso_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_energy - -@@ -279,27 +267,14 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: dE, dG(3), dS(3, 3) - real(wp) :: d6_6, a2r0ij, r4 - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) -- real(wp), allocatable :: dEdcn_local(:) -- real(wp), allocatable :: gradient_local(:, :) -- real(wp), allocatable :: sigma_local(:, :) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy, gradient, sigma, dEdcn) & - !$omp shared(mol, self, c6, dc6dcn, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, ic, jc, vec, r2, rrij, r0ij, rij, d6, ef, & - !$omp& sf, sig, t6, c6ij, dsig, dt6, edisp0, gdisp0, edisp, gdisp, dE, & -- !$omp& dG, dS, d6_6, a2r0ij, r4, sw, dswdr) & -- !$omp shared(energy, gradient, sigma, dEdcn) & -- !$omp private(energy_local, gradient_local, sigma_local, dEdcn_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- allocate(dEdcn_local(size(dEdcn, 1)), source=0.0_wp) -- allocate(gradient_local(size(gradient, 1), size(gradient, 2)), source=0.0_wp) -- allocate(sigma_local(size(sigma, 1), size(sigma, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& dG, dS, d6_6, a2r0ij, r4, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -339,31 +314,20 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - end do - end do - -- energy_local(iat) = energy_local(iat) + dE -- dEdcn_local(iat) = dEdcn_local(iat) - dc6dcn(iat, jat) * edisp -- sigma_local(:, :) = sigma_local(:, :) + dS -+ energy(iat) = energy(iat) + dE -+ dEdcn(iat) = dEdcn(iat) - dc6dcn(iat, jat) * edisp -+ sigma(:, :) = sigma(:, :) + dS - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -- dEdcn_local(jat) = dEdcn_local(jat) - dc6dcn(jat, iat) * edisp -- gradient_local(:, iat) = gradient_local(:, iat) + dG -- gradient_local(:, jat) = gradient_local(:, jat) - dG -- sigma_local(:, :) = sigma_local(:, :) + dS -+ energy(jat) = energy(jat) + dE -+ dEdcn(jat) = dEdcn(jat) - dc6dcn(jat, iat) * edisp -+ gradient(:, iat) = gradient(:, iat) + dG -+ gradient(:, jat) = gradient(:, jat) - dG -+ sigma(:, :) = sigma(:, :) + dS - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_derivs_cso_) -- energy(:) = energy(:) + energy_local(:) -- dEdcn(:) = dEdcn(:) + dEdcn_local(:) -- gradient(:, :) = gradient(:, :) + gradient_local(:, :) -- sigma(:, :) = sigma(:, :) + sigma_local(:, :) -- !$omp end critical (get_dispersion_derivs_cso_) -- deallocate(energy_local) -- deallocate(dEdcn_local) -- deallocate(gradient_local) -- deallocate(sigma_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_derivs - -@@ -452,20 +416,13 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - real(wp) :: c6ij, edisp, dE, sw, dswdr - real(wp) :: d6_6, a2r0ij, r4 - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:, :) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, rrij, r0ij, rij, d6, ef, & -- !$omp& sf, sig, t6, c6ij, edisp, dE, d6_6, a2r0ij, r4, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1), size(energy, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& sf, sig, t6, c6ij, edisp, dE, d6_6, a2r0ij, r4, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -493,19 +450,14 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(jat, iat) = energy_local(jat, iat) + dE -+ energy(jat, iat) = energy(jat, iat) + dE - if (iat /= jat) then -- energy_local(iat, jat) = energy_local(iat, jat) + dE -+ energy(iat, jat) = energy(iat, jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_pairwise_dispersion2_cso_) -- energy(:, :) = energy(:, :) + energy_local(:, :) -- !$omp end critical (get_pairwise_dispersion2_cso_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_pairwise_dispersion2 - -diff --git a/src/dftd3/damping/mzero.f90 b/src/dftd3/damping/mzero.f90 -index 301aaf1..230c965 100644 ---- a/src/dftd3/damping/mzero.f90 -+++ b/src/dftd3/damping/mzero.f90 -@@ -172,22 +172,15 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: edisp, cutoff2, r0ij, rrij, c6ij, dE - real(wp) :: irs6r0, irs8r0, betr0, sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) - - cutoff2 = cutoff*cutoff - alp6 = self%alp - alp8 = self%alp + 2.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, alp6, alp8, rvdw, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r1, r6, r8, t6, t8, f6, & -- !$omp& f8, edisp, r0ij, rrij, c6ij, dE, irs6r0, irs8r0, betr0, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& f8, edisp, r0ij, rrij, c6ij, dE, irs6r0, irs8r0, betr0, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -218,19 +211,14 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(iat) = energy_local(iat) + dE -+ energy(iat) = energy(iat) + dE - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -+ energy(jat) = energy(jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_energy_) -- energy(:) = energy(:) + energy_local(:) -- !$omp end critical (get_dispersion_energy_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_energy - -@@ -283,29 +271,16 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: edisp0, gdisp0, edisp, gdisp, cutoff2, r0ij, rrij, c6ij, dE, dG(3), dS(3, 3) - real(wp) :: irs6r0, irs8r0, betr0, betr02rs6, betr02rs8, sw, dswdr - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) -- real(wp), allocatable :: dEdcn_local(:) -- real(wp), allocatable :: gradient_local(:, :) -- real(wp), allocatable :: sigma_local(:, :) - - cutoff2 = cutoff*cutoff - alp6 = self%alp - alp8 = self%alp + 2.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy, gradient, sigma, dEdcn) & - !$omp shared(mol, self, c6, dc6dcn, trans, cutoff2, cutoff, width, alp6, alp8, rvdw, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, ic, jc, vec, r2, r1, r6, r8, t6, t8, d6, & - !$omp& d8, f6, f8, edisp0, gdisp0, edisp, gdisp, r0ij, rrij, c6ij, & -- !$omp& dE, dG, dS, irs6r0, irs8r0, betr0, betr02rs6, betr02rs8, sw, dswdr) & -- !$omp shared(energy, gradient, sigma, dEdcn) & -- !$omp private(energy_local, gradient_local, sigma_local, dEdcn_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- allocate(dEdcn_local(size(dEdcn, 1)), source=0.0_wp) -- allocate(gradient_local(size(gradient, 1), size(gradient, 2)), source=0.0_wp) -- allocate(sigma_local(size(sigma, 1), size(sigma, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& dE, dG, dS, irs6r0, irs8r0, betr0, betr02rs6, betr02rs8, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -352,31 +327,20 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - end do - end do - -- energy_local(iat) = energy_local(iat) + dE -- dEdcn_local(iat) = dEdcn_local(iat) - dc6dcn(iat, jat) * edisp -- sigma_local(:, :) = sigma_local + dS -+ energy(iat) = energy(iat) + dE -+ dEdcn(iat) = dEdcn(iat) - dc6dcn(iat, jat) * edisp -+ sigma(:, :) = sigma(:, :) + dS - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -- dEdcn_local(jat) = dEdcn_local(jat) - dc6dcn(jat, iat) * edisp -- gradient_local(:, iat) = gradient_local(:, iat) + dG -- gradient_local(:, jat) = gradient_local(:, jat) - dG -- sigma_local(:, :) = sigma_local + dS -+ energy(jat) = energy(jat) + dE -+ dEdcn(jat) = dEdcn(jat) - dc6dcn(jat, iat) * edisp -+ gradient(:, iat) = gradient(:, iat) + dG -+ gradient(:, jat) = gradient(:, jat) - dG -+ sigma(:, :) = sigma(:, :) + dS - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_derivs_) -- energy(:) = energy(:) + energy_local(:) -- dEdcn(:) = dEdcn(:) + dEdcn_local(:) -- gradient(:, :) = gradient(:, :) + gradient_local(:, :) -- sigma(:, :) = sigma(:, :) + sigma_local(:, :) -- !$omp end critical (get_dispersion_derivs_) -- deallocate(energy_local) -- deallocate(dEdcn_local) -- deallocate(gradient_local) -- deallocate(sigma_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_derivs - -@@ -464,22 +428,15 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - real(wp) :: vec(3), r2, r1, r6, r8, t6, t8, f6, f8, alp6, alp8 - real(wp) :: edisp, cutoff2, r0ij, rrij, c6ij, dE, sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:, :) - - cutoff2 = cutoff*cutoff - alp6 = self%alp - alp8 = self%alp + 2.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, alp6, alp8, rvdw, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r1, r6, r8, t6, t8, f6, & -- !$omp& f8, edisp, r0ij, rrij, c6ij, dE, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1), size(energy, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& f8, edisp, r0ij, rrij, c6ij, dE, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -507,19 +464,14 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(jat, iat) = energy_local(jat, iat) + dE -+ energy(jat, iat) = energy(jat, iat) + dE - if (iat /= jat) then -- energy_local(iat, jat) = energy_local(iat, jat) + dE -+ energy(iat, jat) = energy(iat, jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_pairwise_dispersion2_) -- energy(:, :) = energy(:, :) + energy_local(:, :) -- !$omp end critical (get_pairwise_dispersion2_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_pairwise_dispersion2 - -diff --git a/src/dftd3/damping/optimizedpower.f90 b/src/dftd3/damping/optimizedpower.f90 -index 9f365ac..0def41c 100644 ---- a/src/dftd3/damping/optimizedpower.f90 -+++ b/src/dftd3/damping/optimizedpower.f90 -@@ -172,21 +172,14 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: r0ij2, r0ij6, r0ij8, abr0ij6, abr0ij8, r4 - real(wp) :: sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r1, r0ij, rrij, c6ij, t6, & - !$omp& t8, edisp, dE, rb, ab, r0ij2, r0ij6, r0ij8, abr0ij6, abr0ij8, & -- !$omp& r4, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& r4, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -216,19 +209,14 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(iat) = energy_local(iat) + dE -+ energy(iat) = energy(iat) + dE - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -+ energy(jat) = energy(jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_energy_) -- energy(:) = energy(:) + energy_local(:) -- !$omp end critical (get_dispersion_energy_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_energy - -@@ -282,27 +270,14 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: dE, dG(3), dS(3, 3), rb, ab - real(wp) :: r0ij2, r0ij6, r0ij8, abr0ij6, abr0ij8, r4 - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) -- real(wp), allocatable :: dEdcn_local(:) -- real(wp), allocatable :: gradient_local(:, :) -- real(wp), allocatable :: sigma_local(:, :) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy, gradient, sigma, dEdcn) & - !$omp shared(mol, self, c6, dc6dcn, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, ic, jc, vec, r2, r1, r0ij, rrij, c6ij, & - !$omp& t6, t8, d6, d8, edisp0, gdisp0, edisp, gdisp, dE, dG, dS, rb, ab, & -- !$omp& r0ij2, r0ij6, r0ij8, abr0ij6, abr0ij8, r4, sw, dswdr) & -- !$omp shared(energy, gradient, sigma, dEdcn) & -- !$omp private(energy_local, gradient_local, sigma_local, dEdcn_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- allocate(dEdcn_local(size(dEdcn, 1)), source=0.0_wp) -- allocate(gradient_local(size(gradient, 1), size(gradient, 2)), source=0.0_wp) -- allocate(sigma_local(size(sigma, 1), size(sigma, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& r0ij2, r0ij6, r0ij8, abr0ij6, abr0ij8, r4, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -344,31 +319,20 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - end do - end do - -- energy_local(iat) = energy_local(iat) + dE -- dEdcn_local(iat) = dEdcn_local(iat) - dc6dcn(iat, jat) * edisp -- sigma_local(:, :) = sigma_local + dS -+ energy(iat) = energy(iat) + dE -+ dEdcn(iat) = dEdcn(iat) - dc6dcn(iat, jat) * edisp -+ sigma(:, :) = sigma(:, :) + dS - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -- dEdcn_local(jat) = dEdcn_local(jat) - dc6dcn(jat, iat) * edisp -- gradient_local(:, iat) = gradient_local(:, iat) + dG -- gradient_local(:, jat) = gradient_local(:, jat) - dG -- sigma_local(:, :) = sigma_local + dS -+ energy(jat) = energy(jat) + dE -+ dEdcn(jat) = dEdcn(jat) - dc6dcn(jat, iat) * edisp -+ gradient(:, iat) = gradient(:, iat) + dG -+ gradient(:, jat) = gradient(:, jat) - dG -+ sigma(:, :) = sigma(:, :) + dS - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_derivs_) -- energy(:) = energy(:) + energy_local(:) -- dEdcn(:) = dEdcn(:) + dEdcn_local(:) -- gradient(:, :) = gradient(:, :) + gradient_local(:, :) -- sigma(:, :) = sigma(:, :) + sigma_local(:, :) -- !$omp end critical (get_dispersion_derivs_) -- deallocate(energy_local) -- deallocate(dEdcn_local) -- deallocate(gradient_local) -- deallocate(sigma_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_derivs - -@@ -456,20 +420,13 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - real(wp) :: vec(3), r2, r1, cutoff2, r0ij, rrij, c6ij, t6, t8, edisp, dE, rb, ab - real(wp) :: sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:, :) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r1, r0ij, rrij, c6ij, t6, & -- !$omp& t8, edisp, dE, rb, ab, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1), size(energy, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& t8, edisp, dE, rb, ab, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -493,19 +450,14 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(jat, iat) = energy_local(jat, iat) + dE -+ energy(jat, iat) = energy(jat, iat) + dE - if (iat /= jat) then -- energy_local(iat, jat) = energy_local(iat, jat) + dE -+ energy(iat, jat) = energy(iat, jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_pairwise_dispersion2_) -- energy(:, :) = energy(:, :) + energy_local(:, :) -- !$omp end critical (get_pairwise_dispersion2_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_pairwise_dispersion2 - -diff --git a/src/dftd3/damping/rational.f90 b/src/dftd3/damping/rational.f90 -index a8edb7c..32aac1e 100644 ---- a/src/dftd3/damping/rational.f90 -+++ b/src/dftd3/damping/rational.f90 -@@ -170,20 +170,13 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: sw, dswdr - real(wp) :: r0ij2, r0ij6, r0ij8, r4 - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r1, r0ij, rrij, c6ij, t6, & -- !$omp& t8, edisp, dE, r0ij2, r0ij6, r0ij8, r4, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& t8, edisp, dE, r0ij2, r0ij6, r0ij8, r4, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -209,19 +202,14 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(iat) = energy_local(iat) + dE -+ energy(iat) = energy(iat) + dE - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -+ energy(jat) = energy(jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_energy_) -- energy(:) = energy(:) + energy_local(:) -- !$omp end critical (get_dispersion_energy_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_energy - -@@ -275,27 +263,14 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: dE, dG(3), dS(3, 3) - real(wp) :: r0ij2, r0ij6, r0ij8, r4 - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) -- real(wp), allocatable :: dEdcn_local(:) -- real(wp), allocatable :: gradient_local(:, :) -- real(wp), allocatable :: sigma_local(:, :) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy, gradient, sigma, dEdcn) & - !$omp shared(mol, self, c6, dc6dcn, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, ic, jc, vec, r2, r1, r0ij, rrij, c6ij, & - !$omp& t6, t8, d6, d8, edisp0, gdisp0, edisp, gdisp, dE, dG, dS, & -- !$omp& r0ij2, r0ij6, r0ij8, r4, sw, dswdr) & -- !$omp shared(energy, gradient, sigma, dEdcn) & -- !$omp private(energy_local, gradient_local, sigma_local, dEdcn_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- allocate(dEdcn_local(size(dEdcn, 1)), source=0.0_wp) -- allocate(gradient_local(size(gradient, 1), size(gradient, 2)), source=0.0_wp) -- allocate(sigma_local(size(sigma, 1), size(sigma, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& r0ij2, r0ij6, r0ij8, r4, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -333,31 +308,20 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - end do - end do - -- energy_local(iat) = energy_local(iat) + dE -- dEdcn_local(iat) = dEdcn_local(iat) - dc6dcn(iat, jat) * edisp -- sigma_local(:, :) = sigma_local + dS -+ energy(iat) = energy(iat) + dE -+ dEdcn(iat) = dEdcn(iat) - dc6dcn(iat, jat) * edisp -+ sigma(:, :) = sigma(:, :) + dS - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -- dEdcn_local(jat) = dEdcn_local(jat) - dc6dcn(jat, iat) * edisp -- gradient_local(:, iat) = gradient_local(:, iat) + dG -- gradient_local(:, jat) = gradient_local(:, jat) - dG -- sigma_local(:, :) = sigma_local + dS -+ energy(jat) = energy(jat) + dE -+ dEdcn(jat) = dEdcn(jat) - dc6dcn(jat, iat) * edisp -+ gradient(:, iat) = gradient(:, iat) + dG -+ gradient(:, jat) = gradient(:, jat) - dG -+ sigma(:, :) = sigma(:, :) + dS - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_derivs_) -- energy(:) = energy(:) + energy_local(:) -- dEdcn(:) = dEdcn(:) + dEdcn_local(:) -- gradient(:, :) = gradient(:, :) + gradient_local(:, :) -- sigma(:, :) = sigma(:, :) + sigma_local(:, :) -- !$omp end critical (get_dispersion_derivs_) -- deallocate(energy_local) -- deallocate(dEdcn_local) -- deallocate(gradient_local) -- deallocate(sigma_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_derivs - -@@ -445,20 +409,13 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - real(wp) :: vec(3), r2, r1, cutoff2, r0ij, rrij, c6ij, t6, t8, edisp, dE - real(wp) :: sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:, :) - - cutoff2 = cutoff*cutoff - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r1, r0ij, rrij, c6ij, t6, & -- !$omp& t8, edisp, dE, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1), size(energy, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& t8, edisp, dE, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -480,19 +437,14 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(jat, iat) = energy_local(jat, iat) + dE -+ energy(jat, iat) = energy(jat, iat) + dE - if (iat /= jat) then -- energy_local(iat, jat) = energy_local(iat, jat) + dE -+ energy(iat, jat) = energy(iat, jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_pairwise_dispersion2_) -- energy(:, :) = energy(:, :) + energy_local(:, :) -- !$omp end critical (get_pairwise_dispersion2_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_pairwise_dispersion2 - -diff --git a/src/dftd3/damping/zero.f90 b/src/dftd3/damping/zero.f90 -index 2e3ed6e..e5b78ad 100644 ---- a/src/dftd3/damping/zero.f90 -+++ b/src/dftd3/damping/zero.f90 -@@ -170,22 +170,15 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: edisp, cutoff2, r0ij, rrij, c6ij, dE - real(wp) :: rs6r0, rs8r0, sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) - - cutoff2 = cutoff*cutoff - alp6 = self%alp - alp8 = self%alp + 2.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, alp6, alp8, rvdw, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r1, r6, r8, t6, t8, f6, & -- !$omp& f8, edisp, r0ij, rrij, c6ij, dE, rs6r0, rs8r0, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& f8, edisp, r0ij, rrij, c6ij, dE, rs6r0, rs8r0, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -215,19 +208,14 @@ subroutine get_dispersion_energy(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(iat) = energy_local(iat) + dE -+ energy(iat) = energy(iat) + dE - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -+ energy(jat) = energy(jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_energy_) -- energy(:) = energy(:) + energy_local(:) -- !$omp end critical (get_dispersion_energy_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_energy - -@@ -280,29 +268,16 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - real(wp) :: edisp0, gdisp0, edisp, gdisp, cutoff2, r0ij, rrij, c6ij, dE, dG(3), dS(3, 3) - real(wp) :: rs6r0, rs8r0, sw, dswdr - -- ! Thread-private arrays for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:) -- real(wp), allocatable :: dEdcn_local(:) -- real(wp), allocatable :: gradient_local(:, :) -- real(wp), allocatable :: sigma_local(:, :) - - cutoff2 = cutoff*cutoff - alp6 = self%alp - alp8 = self%alp + 2.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy, gradient, sigma, dEdcn) & - !$omp shared(mol, self, c6, dc6dcn, trans, cutoff2, cutoff, width, alp6, alp8, r4r2, rvdw) & - !$omp private(iat, jat, izp, jzp, jtr, ic, jc, vec, r2, r1, r6, r8, t6, t8, d6, & - !$omp& d8, f6, f8, edisp0, gdisp0, edisp, gdisp, r0ij, rrij, c6ij, dE, & -- !$omp& dG, dS, rs6r0, rs8r0, sw, dswdr) & -- !$omp shared(energy, gradient, sigma, dEdcn) & -- !$omp private(energy_local, gradient_local, sigma_local, dEdcn_local) -- allocate(energy_local(size(energy, 1)), source=0.0_wp) -- allocate(dEdcn_local(size(dEdcn, 1)), source=0.0_wp) -- allocate(gradient_local(size(gradient, 1), size(gradient, 2)), source=0.0_wp) -- allocate(sigma_local(size(sigma, 1), size(sigma, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& dG, dS, rs6r0, rs8r0, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -346,31 +321,20 @@ subroutine get_dispersion_derivs(self, mol, trans, cutoff, width, rvdw, r4r2, c6 - end do - end do - -- energy_local(iat) = energy_local(iat) + dE -- dEdcn_local(iat) = dEdcn_local(iat) - dc6dcn(iat, jat) * edisp -- sigma_local(:, :) = sigma_local + dS -+ energy(iat) = energy(iat) + dE -+ dEdcn(iat) = dEdcn(iat) - dc6dcn(iat, jat) * edisp -+ sigma(:, :) = sigma(:, :) + dS - if (iat /= jat) then -- energy_local(jat) = energy_local(jat) + dE -- dEdcn_local(jat) = dEdcn_local(jat) - dc6dcn(jat, iat) * edisp -- gradient_local(:, iat) = gradient_local(:, iat) + dG -- gradient_local(:, jat) = gradient_local(:, jat) - dG -- sigma_local(:, :) = sigma_local + dS -+ energy(jat) = energy(jat) + dE -+ dEdcn(jat) = dEdcn(jat) - dc6dcn(jat, iat) * edisp -+ gradient(:, iat) = gradient(:, iat) + dG -+ gradient(:, jat) = gradient(:, jat) - dG -+ sigma(:, :) = sigma(:, :) + dS - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_dispersion_derivs_) -- energy(:) = energy(:) + energy_local(:) -- dEdcn(:) = dEdcn(:) + dEdcn_local(:) -- gradient(:, :) = gradient(:, :) + gradient_local(:, :) -- sigma(:, :) = sigma(:, :) + sigma_local(:, :) -- !$omp end critical (get_dispersion_derivs_) -- deallocate(energy_local) -- deallocate(dEdcn_local) -- deallocate(gradient_local) -- deallocate(sigma_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_dispersion_derivs - -@@ -459,22 +423,15 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - real(wp) :: edisp, cutoff2, r0ij, rrij, c6ij, dE - real(wp) :: rs6r0, rs8r0, sw, dswdr - -- ! Thread-private array for reduction -- ! Set to 0 explicitly as the shared variants are potentially non-zero (inout) -- real(wp), allocatable :: energy_local(:, :) - - cutoff2 = cutoff*cutoff - alp6 = self%alp - alp8 = self%alp + 2.0_wp - -- !$omp parallel default(none) & -+ !$omp parallel do schedule(runtime) default(none) reduction(+:energy) & - !$omp shared(mol, self, c6, trans, cutoff2, cutoff, width, alp6, alp8, rvdw, r4r2) & - !$omp private(iat, jat, izp, jzp, jtr, vec, r2, r1, r6, r8, t6, t8, f6, & -- !$omp& f8, edisp, r0ij, rrij, c6ij, dE, rs6r0, rs8r0, sw, dswdr) & -- !$omp shared(energy) & -- !$omp private(energy_local) -- allocate(energy_local(size(energy, 1), size(energy, 2)), source=0.0_wp) -- !$omp do schedule(runtime) -+ !$omp& f8, edisp, r0ij, rrij, c6ij, dE, rs6r0, rs8r0, sw, dswdr) - do iat = 1, mol%nat - izp = mol%id(iat) - do jat = 1, iat -@@ -504,19 +461,14 @@ subroutine get_pairwise_dispersion2(self, mol, trans, cutoff, width, rvdw, r4r2, - - dE = -c6ij*edisp * 0.5_wp - -- energy_local(jat, iat) = energy_local(jat, iat) + dE -+ energy(jat, iat) = energy(jat, iat) + dE - if (iat /= jat) then -- energy_local(iat, jat) = energy_local(iat, jat) + dE -+ energy(iat, jat) = energy(iat, jat) + dE - end if - end do - end do - end do -- !$omp end do -- !$omp critical (get_pairwise_dispersion2_) -- energy(:, :) = energy(:, :) + energy_local(:, :) -- !$omp end critical (get_pairwise_dispersion2_) -- deallocate(energy_local) -- !$omp end parallel -+ !$omp end parallel do - - end subroutine get_pairwise_dispersion2 - -diff --git a/src/dftd3/disp.f90 b/src/dftd3/disp.f90 -index 413683f..c75fec8 100644 ---- a/src/dftd3/disp.f90 -+++ b/src/dftd3/disp.f90 -@@ -15,7 +15,7 @@ - ! along with s-dftd3. If not, see . - - module dftd3_disp -- use dftd3_cutoff, only : realspace_cutoff, get_lattice_points -+ use dftd3_cutoff, only : realspace_cutoff, get_lattice_points, apply_smooth_width_env - use dftd3_damping, only : damping_param - use dftd3_model, only : d3_model - use dftd3_ncoord, only : get_coordination_number, add_coordination_number_derivs -@@ -69,13 +69,16 @@ subroutine get_dispersion_atomic(mol, disp, param, cutoff, energies, gradient, s - real(wp), allocatable :: c6(:, :), dc6dcn(:, :) - real(wp), allocatable :: dEdcn(:) - real(wp), allocatable :: lattr(:, :) -+ type(realspace_cutoff) :: cutoff_eff - - mref = maxval(disp%ref) - grad = present(gradient).and.present(sigma) -+ cutoff_eff = cutoff -+ call apply_smooth_width_env(cutoff_eff) - - allocate(cn(mol%nat)) -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%cn, lattr) -- call get_coordination_number(mol, lattr, cutoff%cn, disp%rcov, cn) -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%cn, lattr) -+ call get_coordination_number(mol, lattr, cutoff_eff%cn, disp%rcov, cn) - - allocate(gwvec(mref, mol%nat)) - if (grad) allocate(gwdcn(mref, mol%nat)) -@@ -92,15 +95,15 @@ subroutine get_dispersion_atomic(mol, disp, param, cutoff, energies, gradient, s - gradient(:, :) = 0.0_wp - sigma(:, :) = 0.0_wp - end if -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp2, lattr) -- call param%get_dispersion2(mol, lattr, cutoff%disp2, cutoff%width2, disp%rvdw, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%disp2, lattr) -+ call param%get_dispersion2(mol, lattr, cutoff_eff%disp2, cutoff_eff%width2, disp%rvdw, & - & disp%r4r2, c6, dc6dcn, energies, dEdcn, gradient, sigma) -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp3, lattr) -- call param%get_dispersion3(mol, lattr, cutoff%disp3, cutoff%width3, disp%rvdw, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%disp3, lattr) -+ call param%get_dispersion3(mol, lattr, cutoff_eff%disp3, cutoff_eff%width3, disp%rvdw, & - & disp%r4r2, c6, dc6dcn, energies, dEdcn, gradient, sigma) - if (grad) then -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%cn, lattr) -- call add_coordination_number_derivs(mol, lattr, cutoff%cn, disp%rcov, dEdcn, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%cn, lattr) -+ call add_coordination_number_derivs(mol, lattr, cutoff_eff%cn, disp%rcov, dEdcn, & - & gradient, sigma) - end if - -@@ -165,12 +168,15 @@ subroutine get_pairwise_dispersion(mol, disp, param, cutoff, energy2, energy3) - - integer :: mref - real(wp), allocatable :: cn(:), gwvec(:, :), c6(:, :), lattr(:, :) -+ type(realspace_cutoff) :: cutoff_eff - - mref = maxval(disp%ref) -+ cutoff_eff = cutoff -+ call apply_smooth_width_env(cutoff_eff) - - allocate(cn(mol%nat)) -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%cn, lattr) -- call get_coordination_number(mol, lattr, cutoff%cn, disp%rcov, cn) -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%cn, lattr) -+ call get_coordination_number(mol, lattr, cutoff_eff%cn, disp%rcov, cn) - - allocate(gwvec(mref, mol%nat)) - call disp%weight_references(mol, cn, gwvec) -@@ -180,12 +186,12 @@ subroutine get_pairwise_dispersion(mol, disp, param, cutoff, energy2, energy3) - - energy2(:, :) = 0.0_wp - energy3(:, :) = 0.0_wp -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp2, lattr) -- call param%get_pairwise_dispersion2(mol, lattr, cutoff%disp2, cutoff%width2, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%disp2, lattr) -+ call param%get_pairwise_dispersion2(mol, lattr, cutoff_eff%disp2, cutoff_eff%width2, & - & disp%rvdw, disp%r4r2, c6, energy2) - -- call get_lattice_points(mol%periodic, mol%lattice, cutoff%disp3, lattr) -- call param%get_pairwise_dispersion3(mol, lattr, cutoff%disp3, cutoff%width3, & -+ call get_lattice_points(mol%periodic, mol%lattice, cutoff_eff%disp3, lattr) -+ call param%get_pairwise_dispersion3(mol, lattr, cutoff_eff%disp3, cutoff_eff%width3, & - & disp%rvdw, disp%r4r2, c6, energy3) - - end subroutine get_pairwise_dispersion