From 41af8c12d70145320a1f2fd924464802f26cffff Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 16 Jun 2017 16:38:59 +0100 Subject: [PATCH] Code cleaning for conserved current contractions. Will now be easier to implement mobius conserved current. --- lib/qcd/action/fermion/WilsonFermion.cc | 26 ++++---- lib/qcd/action/fermion/WilsonFermion5D.cc | 40 ++++--------- lib/qcd/action/fermion/WilsonKernels.cc | 72 ++++++++++------------- lib/qcd/action/fermion/WilsonKernels.h | 22 +++---- 4 files changed, 64 insertions(+), 96 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonFermion.cc b/lib/qcd/action/fermion/WilsonFermion.cc index 28842cdd..eff7d958 100644 --- a/lib/qcd/action/fermion/WilsonFermion.cc +++ b/lib/qcd/action/fermion/WilsonFermion.cc @@ -361,23 +361,23 @@ void WilsonFermion::ContractConservedCurrent(PropagatorField &q_in_1, conformable(_grid, q_in_1._grid); conformable(_grid, q_in_2._grid); conformable(_grid, q_out._grid); - PropagatorField tmp(_grid); + PropagatorField tmp1(_grid), tmp2(_grid); q_out = zero; - // Forward, need q1(x + mu), q2(x) - tmp = Cshift(q_in_1, mu, 1); + // Forward, need q1(x + mu), q2(x). Backward, need q1(x), q2(x + mu). + // Inefficient comms method but not performance critical. + tmp1 = Cshift(q_in_1, mu, 1); + tmp2 = Cshift(q_in_2, mu, 1); parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) { - Kernels::ContractConservedCurrentSiteFwd(tmp, q_in_2, q_out, Umu, - mu, sU, sU, sU, sU); - } - - // Backward, need q1(x), q2(x + mu) - tmp = Cshift(q_in_2, mu, 1); - parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) - { - Kernels::ContractConservedCurrentSiteBwd(q_in_1, tmp, q_out, Umu, - mu, sU, sU, sU, sU); + Kernels::ContractConservedCurrentSiteFwd(tmp1._odata[sU], + q_in_2._odata[sU], + q_out._odata[sU], + Umu, sU, mu); + Kernels::ContractConservedCurrentSiteBwd(q_in_1._odata[sU], + tmp2._odata[sU], + q_out._odata[sU], + Umu, sU, mu); } } diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index b69a18ba..76218098 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -686,13 +686,13 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, conformable(q_in_1._grid, FermionGrid()); conformable(q_in_1._grid, q_in_2._grid); conformable(_FourDimGrid, q_out._grid); - - PropagatorField tmp(FermionGrid()); + PropagatorField tmp1(FermionGrid()), tmp2(FermionGrid()); q_out = zero; - // Forward, need q1(x + mu, s), q2(x, Ls - 1 - s). 5D lattice so shift - // 4D coordinate mu by one. - tmp = Cshift(q_in_1, mu + 1, 1); + // Forward, need q1(x + mu, s), q2(x, Ls - 1 - s). Backward, need q1(x, s), + // q2(x + mu, Ls - 1 - s). 5D lattice so shift 4D coordinate mu by one. + tmp1 = Cshift(q_in_1, mu + 1, 1); + tmp2 = Cshift(q_in_2, mu + 1, 1); parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) { unsigned int sF1 = sU * Ls; @@ -701,28 +701,14 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, { bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ true : false; - Kernels::ContractConservedCurrentSiteFwd(tmp, q_in_2, q_out, Umu, - mu, sF1, sF2, sU, sU, - axial_sign); - sF1++; - sF2--; - } - } - - // Backward, need q1(x, s), q2(x + mu, Ls - 1 - s). 5D lattice so shift - // 4D coordinate mu by one. - tmp = Cshift(q_in_2, mu + 1, 1); - parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) - { - unsigned int sF1 = sU * Ls; - unsigned int sF2 = (sU + 1) * Ls - 1; - for (int s = 0; s < Ls; ++s) - { - bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ - true : false; - Kernels::ContractConservedCurrentSiteBwd(q_in_1, tmp, q_out, Umu, - mu, sF1, sF2, sU, sU, - axial_sign); + Kernels::ContractConservedCurrentSiteFwd(tmp1._odata[sF1], + q_in_2._odata[sF2], + q_out._odata[sU], + Umu, sU, mu, axial_sign); + Kernels::ContractConservedCurrentSiteBwd(q_in_1._odata[sF1], + tmp2._odata[sF2], + q_out._odata[sU], + Umu, sU, mu, axial_sign); sF1++; sF2--; } diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index c519dc56..6b193766 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -298,28 +298,25 @@ void WilsonKernels::DhopDir( StencilImpl &st, DoubledGaugeField &U,SiteHal ******************************************************************************/ template void WilsonKernels::ContractConservedCurrentSiteFwd( - const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, + const SitePropagator &q_in_1, + const SitePropagator &q_in_2, + SitePropagator &q_out, DoubledGaugeField &U, - unsigned int mu, - unsigned int sF_in_1, - unsigned int sF_in_2, - unsigned int sF_out, unsigned int sU, + unsigned int mu, bool switch_sign) { SitePropagator result, tmp; Gamma g5(Gamma::Algebra::Gamma5); - multLinkProp(tmp, U._odata[sU], q_in_1._odata[sF_in_1], mu); - result = g5 * adj(q_in_2._odata[sF_in_2]) * g5 * WilsonCurrentFwd(tmp, mu); + Impl::multLinkProp(tmp, U._odata[sU], q_in_1, mu); + result = g5 * adj(q_in_2) * g5 * WilsonCurrentFwd(tmp, mu); if (switch_sign) { - q_out._odata[sF_out] -= result; + q_out -= result; } else { - q_out._odata[sF_out] += result; + q_out += result; } } @@ -331,28 +328,25 @@ void WilsonKernels::ContractConservedCurrentSiteFwd( ******************************************************************************/ template void WilsonKernels::ContractConservedCurrentSiteBwd( - const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, + const SitePropagator &q_in_1, + const SitePropagator &q_in_2, + SitePropagator &q_out, DoubledGaugeField &U, - unsigned int mu, - unsigned int sF_in_1, - unsigned int sF_in_2, - unsigned int sF_out, unsigned int sU, + unsigned int mu, bool switch_sign) { SitePropagator result, tmp; Gamma g5(Gamma::Algebra::Gamma5); - multLinkProp(tmp, U._odata[sU], q_in_1._odata[sF_in_1], mu + Nd); - result = g5 * adj(q_in_2._odata[sF_in_2]) * g5 * WilsonCurrentBwd(tmp, mu); + Impl::multLinkProp(tmp, U._odata[sU], q_in_1, mu + Nd); + result = g5 * adj(q_in_2) * g5 * WilsonCurrentBwd(tmp, mu); if (switch_sign) { - q_out._odata[sF_out] += result; + q_out += result; } else { - q_out._odata[sF_out] -= result; + q_out -= result; } } @@ -360,31 +354,25 @@ void WilsonKernels::ContractConservedCurrentSiteBwd( #define NO_CURR_SITE(Impl) \ template <> \ void WilsonKernels::ContractConservedCurrentSiteFwd( \ - const PropagatorField &q_in_1, \ - const PropagatorField &q_in_2, \ - PropagatorField &q_out, \ - DoubledGaugeField &U, \ - unsigned int mu, \ - unsigned int sF_in_1, \ - unsigned int sF_in_2, \ - unsigned int sF_out, \ - unsigned int sU, \ - bool switch_sign) \ + const SitePropagator &q_in_1, \ + const SitePropagator &q_in_2, \ + SitePropagator &q_out, \ + DoubledGaugeField &U, \ + unsigned int sU, \ + unsigned int mu, \ + bool switch_sign) \ { \ assert(0); \ } \ template <> \ void WilsonKernels::ContractConservedCurrentSiteBwd( \ - const PropagatorField &q_in_1, \ - const PropagatorField &q_in_2, \ - PropagatorField &q_out, \ - DoubledGaugeField &U, \ - unsigned int mu, \ - unsigned int sF_in_1, \ - unsigned int sF_in_2, \ - unsigned int sF_out, \ - unsigned int sU, \ - bool switch_sign) \ + const SitePropagator &q_in_1, \ + const SitePropagator &q_in_2, \ + SitePropagator &q_out, \ + DoubledGaugeField &U, \ + unsigned int mu, \ + unsigned int sU, \ + bool switch_sign) \ { \ assert(0); \ } diff --git a/lib/qcd/action/fermion/WilsonKernels.h b/lib/qcd/action/fermion/WilsonKernels.h index 95155ccc..0294c740 100644 --- a/lib/qcd/action/fermion/WilsonKernels.h +++ b/lib/qcd/action/fermion/WilsonKernels.h @@ -183,25 +183,19 @@ public: ////////////////////////////////////////////////////////////////////////////// // Utilities for inserting Wilson conserved current. ////////////////////////////////////////////////////////////////////////////// - void ContractConservedCurrentSiteFwd(const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, + void ContractConservedCurrentSiteFwd(const SitePropagator &q_in_1, + const SitePropagator &q_in_2, + SitePropagator &q_out, DoubledGaugeField &U, - unsigned int mu, - unsigned int sF_in_1, - unsigned int sF_in_2, - unsigned int sF_out, unsigned int sU, + unsigned int mu, bool switch_sign = false); - void ContractConservedCurrentSiteBwd(const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, + void ContractConservedCurrentSiteBwd(const SitePropagator &q_in_1, + const SitePropagator &q_in_2, + SitePropagator &q_out, DoubledGaugeField &U, - unsigned int mu, - unsigned int sF_in_1, - unsigned int sF_in_2, - unsigned int sF_out, unsigned int sU, + unsigned int mu, bool switch_sign = false); void SeqConservedCurrentInternal(const PropagatorField &q_in, PropagatorField &q_out,