mirror of
https://igit.ific.uv.es/alramos/latticegpu.jl.git
synced 2025-05-15 03:33:42 +02:00
Work in scalar observables
This commit is contained in:
parent
38c861e042
commit
0654f15564
4 changed files with 117 additions and 87 deletions
|
@ -3,45 +3,33 @@
|
|||
### Alberto Ramos wrote this file. As long as you retain this
|
||||
### notice you can do whatever you want with this stuff. If we meet some
|
||||
### day, and you think this stuff is worth it, you can buy me a beer in
|
||||
### return. <alberto.ramos@cern.ch>
|
||||
### return. <>
|
||||
###
|
||||
### file: YMact.jl
|
||||
### created: Mon Jul 12 18:31:19 2021
|
||||
###
|
||||
|
||||
"""
|
||||
each instance defines fields to store observables in each lattice point
|
||||
"""
|
||||
|
||||
struct Obs{T}
|
||||
rho2 #ρ^2
|
||||
lphi #L_\phi
|
||||
lalpha #L_\alpha
|
||||
function Obs(::Type{T}, lp::SpaceParm, sp::ScalarParm, gp::GaugeParm) where {T <: AbstractFloat}
|
||||
|
||||
rho2n = nscalar_field(Complex{T}, length(sp.kap), lp)
|
||||
lphin = nscalar_field(Complex{T}, length(sp.kap), lp)
|
||||
lalphan = nscalar_field(Complex{T}, length(sp.kap), lp)
|
||||
return new{T}(rho2n, lphin, lalphan)
|
||||
end
|
||||
end
|
||||
|
||||
"""
|
||||
computes global observables by calling krnl_obs! and summing
|
||||
for all lattice points
|
||||
"""
|
||||
|
||||
function updt_obs!(obs::Obs{T}, U, Phi, sp::ScalarParm, lp::SpaceParm) where {T <: AbstractFloat}
|
||||
function scalar_obs(U, Phi, sp::ScalarParm, lp::SpaceParm, ymws::YMworkspace)
|
||||
|
||||
CUDA.@sync begin
|
||||
CUDA.@cuda threads=lp.bsz blocks=lp.rsz krnl_obs!(obs, U, Phi, sp, lp)
|
||||
@timeit "Scalar observables" begin
|
||||
CUDA.@sync begin
|
||||
CUDA.@cuda threads=lp.bsz blocks=lp.rsz krnl_obs!(ymws.rm, ymws.cm, U, Phi, sp, lp)
|
||||
end
|
||||
|
||||
V = prod(lp.iL)
|
||||
#summation of global observables
|
||||
rho2 = CUDA.mapreduce(norm2, +, Phi)/V
|
||||
lphi = CUDA.reduce(+, ymws.rm)/(lp.ndim*V)
|
||||
lalpha = CUDA.mapreduce(real, +, ymws.cm)/(lp.ndim*V)
|
||||
end
|
||||
|
||||
#summation of global observables
|
||||
rho2 = CUDA.reduce(+, obs.rho2)
|
||||
lphi = CUDA.reduce(+, obs.lphi)
|
||||
lalpha = CUDA.reduce(+, obs.lalpha)
|
||||
return (rho2,lphi,lalpha)
|
||||
|
||||
return rho2, lphi, lalpha
|
||||
end
|
||||
|
||||
"""
|
||||
|
@ -49,14 +37,13 @@ end
|
|||
for each lattice point
|
||||
"""
|
||||
|
||||
function krnl_obs!(obs::Obs{T}, U::AbstractArray{TG}, Phi::AbstractArray{TS}, sp::ScalarParm{NP,T}, lp::SpaceParm{N,M,D}) where {TG,TS,NP,T,N,M,D}
|
||||
function krnl_obs!(rm, cm, U::AbstractArray{TG}, Phi::AbstractArray{TS}, sp::ScalarParm{NP,T}, lp::SpaceParm{N,M,D}) where {TG,TS,NP,T,N,M,D}
|
||||
|
||||
#thread/block coordinate
|
||||
b, r = CUDA.threadIdx().x, CUDA.blockIdx().x
|
||||
|
||||
Ush = @cuStaticSharedMem(TG, (D,N)) #Links - array (lattice points)x(spacetime dimension)
|
||||
Psh = @cuStaticSharedMem(TS, (D,NP)) #Phield - array (lattice points)x(scalalr dimension)
|
||||
|
||||
Ush = @cuStaticSharedMem(TG, (D,N))
|
||||
Psh = @cuStaticSharedMem(TS, (D,NP))
|
||||
|
||||
for id in 1:N
|
||||
Ush[b,id] = U[b,id,r]
|
||||
|
@ -66,16 +53,14 @@ function krnl_obs!(obs::Obs{T}, U::AbstractArray{TG}, Phi::AbstractArray{TS}, sp
|
|||
end
|
||||
sync_threads()
|
||||
|
||||
IX = point_coord((b,r), lp)
|
||||
|
||||
rm[IX] = zero(eltype(rm))
|
||||
cm[IX] = zero(eltype(cm))
|
||||
#compute obs
|
||||
for i in 1:NP
|
||||
obs.rho2[b,i,r] = norm2( Psh[b,i] )
|
||||
obs.lphi[b,i,r] = zero( obs.lphi[b,i,r] )
|
||||
obs.lalpha[b,i,r] = zero( obs.lalpha[b,i,r] )
|
||||
norm = norm( Psh[b,i] )
|
||||
|
||||
for mu in 1:N
|
||||
|
||||
#up fields
|
||||
psq = norm( Psh[b,i] )
|
||||
for id in 1:N
|
||||
bu, ru = up((b, r), id, lp) #thread/block coordinate of up point
|
||||
if (ru == r)
|
||||
phiup = Psh[bu,i]
|
||||
|
@ -83,10 +68,10 @@ function krnl_obs!(obs::Obs{T}, U::AbstractArray{TG}, Phi::AbstractArray{TS}, sp
|
|||
phiup = Phi[bu,i,ru]
|
||||
end
|
||||
|
||||
normup = norm(phiup)
|
||||
psqup = norm(phiup)
|
||||
|
||||
obs.lphi[b,i,r] += tr( Psh[b,i], Ush[b,i]*phiup )
|
||||
obs.lalpha[b,i,r] += tr( Psh[b,i]/norm, Ush[b,i]*phiup/normup )
|
||||
rm[IX] += dot( Psh[b,i], Ush[b,id]*phiup )
|
||||
cm[IX] += complex(rm[IX])/(psq*psqup)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue