From 20710187a3074979001d1a43eb41e05b8196da8d Mon Sep 17 00:00:00 2001 From: ctpeterson Date: Tue, 17 Dec 2024 11:00:08 -0500 Subject: [PATCH] Added HISQ force test --- src/examples/hisq_force.nim | 178 ++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 src/examples/hisq_force.nim diff --git a/src/examples/hisq_force.nim b/src/examples/hisq_force.nim new file mode 100644 index 0000000..9479eb5 --- /dev/null +++ b/src/examples/hisq_force.nim @@ -0,0 +1,178 @@ +# C.T. Peterson: force test inspired from conversation with Peter Boyle +# See Grid implementation here: +# -https://github.com/paboyle/Grid/blob/develop/tests/forces/Test_bdy.cc +import qex +import gauge/[hisqsmear] +import physics/[stagD,stagSolve] + +qexInit() + +defaultSetup() +var + sg = lo.newGauge() + sgl = lo.newGauge() + f = lo.newGauge() + ff = lo.newGauge() + p = lo.newGauge() + phi = lo.ColorVector() + psi = lo.ColorVector() + r = lo.newRNGField(RngMilc6,123456789) + mass = 0.1 + eps = 0.001 + spa = initSolverParams() + spf = initSolverParams() + info: PerfInfo +let + hisq = newHisq() + stag = newStag3(sg,sgl) + arsq = 1e-20 + frsq = 1e-12 + +spa.r2req = arsq +spa.maxits = 10000 +spf.r2req = frsq +spf.maxits = 10000 +spf.verbosity = 1 + +# -- Generic + +proc smearRephase(g: auto, sg,sgl: auto): auto {.discardable.} = + tic() + let smearedForce = hisq.smearGetForce(g,sg,sgl) + threads: + sg.setBC; sgl.setBC; + threadBarrier() + sg.stagPhase; sgl.stagPhase; + smearedForce + +proc reTrMul(x,y:auto):auto = + var d: type(eval(toDouble(redot(x[0],y[0])))) + for ir in x: d += redot(x[ir].adj, y[ir]) + result = simdSum(d) + x.l.threadRankSum(result) + +# -- Action calculation + +proc action(): float = + var s: float + stag.solve(psi, phi, -mass, spa) + threads: + var st = psi.norm2 + threadMaster: s = st + result = 0.5*s + +# -- Force calculation & momentum update + +proc smearedOneAndThreeLinkForce(f: auto, smearedForce: proc, p: auto, g:auto) = + # reverse accumulation of the derivative + # 1. Dslash + var + f1 = f.newOneOf() + f3 = f.newOneOf() + ff = f.newOneOf() + t,t3: array[4,Shifter[typeof(p),typeof(p[0])]] + for mu in 0..