Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
o-morikawa authored Dec 18, 2024
1 parent d22f460 commit cd86b51
Showing 1 changed file with 253 additions and 30 deletions.
283 changes: 253 additions & 30 deletions src/output/bridge_format.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module Bridge_format
using Requires

import ..AbstractGaugefields_module: set_wing_U!
#=
Bridge++ Text file format
Expand All @@ -21,53 +23,225 @@ Re of U(0,0,0,0;mu=1)_00 # mu=1, site (x,y,z,t)=(0,0,0,0)
Im of U(0,0,0,0;mu=1)_00
=#
import ..AbstractGaugefields_module: AbstractGaugefields, set_wing_U!
update!(U) = set_wing!(U)
update!(U::Array{T,1}) where {T<:AbstractGaugefields} = set_wing_U!(U)

function save_textdata(U, filename)
function __init__()
@require MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" begin
import ..AbstractGaugefields_module:
Gaugefields_4D_wing_mpi, Gaugefields_4D_nowing_mpi
import ..AbstractGaugefields_module:
identityGaugefields_4D_wing_mpi,
Gaugefields_4D_wing_mpi,
calc_rank_and_indices,
barrier,
comm,
setvalue!,
getvalue

NX = U[1].NX
NY = U[1].NY
NZ = U[1].NZ
NT = U[1].NT
NC = U[1].NC
function load_BridgeText!(initial, U::Array{T,1}, L, NC) where {T<:Gaugefields_4D_nowing_mpi}
NX = L[1]
NY = L[2]
NZ = L[3]
NT = L[4]
@assert U[1].NX == NX "NX mismatch"
@assert U[1].NY == NY "NY mismatch"
@assert U[1].NZ == NZ "NZ mismatch"
@assert U[1].NT == NT "NT mismatch"
@assert U[1].NC == NC "NC mismatch"
fp = open(initial, "r")
numdata = countlines(initial)
@assert numdata == 4 * NX * NY * NT * NZ * NC * NC * 2 "data shape is wrong"

data = zeros(ComplexF64, NC, NC, 4, prod(U[1].PN), U[1].nprocs)
counts = zeros(Int64, U[1].nprocs)
totalnum = NX * NY * NZ * NT * NC * NC * 2 * 4
PN = U[1].PN
barrier(U[1])

#li = LIME_header((NX,NY,NZ,NT),"su3gauge",1,64)
#print(li.doc)
#write("test.xml", li.doc)
N = NC * NC * 4

send_mesg1 = Array{ComplexF64}(undef, 1)
recv_mesg1 = Array{ComplexF64}(undef, 1)

fp = open(filename, "w")
#fp = open("testbin.dat","w")
i = 0
i = 0
#for μ=1:4
for it = 1:NT
for iz = 1:NZ
for iy = 1:NY
for ix = 1:NX
for μ = 1:4
for a = 1:NC
for b = 1:NC
i += 1
#rvalue = read(fp, floattype)
rvalue = real(U[μ][a, b, ix, iy, iz, it])
println(fp, rvalue)
ivalue = imag(U[μ][a, b, ix, iy, iz, it])
println(fp, ivalue)
send_mesg = Array{ComplexF64}(undef, N)
recv_mesg = Array{ComplexF64}(undef, N)

i = 0
counttotal = 0
for it = 1:NT
for iz = 1:NZ
for iy = 1:NY
for ix = 1:NX
rank, ix_local, iy_local, iz_local, it_local =
calc_rank_and_indices(U[1], ix, iy, iz, it)
#counts[rank+1] += 1
counttotal += 1

#=
if U[1].myrank == 0
println("rank = $rank")
println("$ix $(ix_local)")
println("$iy $(iy_local)")
println("$iz $(iz_local)")
println("$it $(it_local)")
end
=#
barrier(U[1])
if U[1].myrank == 0
count = 0
for μ = 1:4
for a = 1:NC
for b = 1:NC
count += 1
u = split(readline(fp))
#println(u)
rvalue = parse(Float64, u[1])
u = split(readline(fp))
ivalue = parse(Float64, u[1])
send_mesg[count] = rvalue + im * ivalue
#U[μ][b,a,ix,iy,iz,it] = rvalue + im*ivalue
end
end
#u = U[μ][:,:,ix,iy,iz,it]
#println(u'*u)
end

sreq =
MPI.Isend(send_mesg, rank, counttotal, comm)
end
if U[1].myrank == rank
rreq =
MPI.Irecv!(recv_mesg, 0, counttotal, comm)
MPI.Wait!(rreq)
count = 0
for μ = 1:4
for a = 1:NC
for b = 1:NC
count += 1
v = recv_mesg[count]
#U[μ][a, b, ix, iy, iz, it]
setvalue!(
U[μ],
v,
a,
b,
ix_local,
iy_local,
iz_local,
it_local,
)
end
end
end
end
barrier(U[1])
end
end
end
end
#end

barrier(U[1])
update!(U)

end
end
close(fp)

function save_textdata(U::Array{T,1}, filename) where {T<:Gaugefields_4D_nowing_mpi}
NX = U[1].NX
NY = U[1].NY
NZ = U[1].NZ
NT = U[1].NT
NC = U[1].NC

barrier(U[1])

N = NC * NC * 4
send_mesg1 = Array{ComplexF64}(undef, 1)
recv_mesg1 = Array{ComplexF64}(undef, 1)

return
send_mesg = Array{ComplexF64}(undef, N)
recv_mesg = Array{ComplexF64}(undef, N)


#li = LIME_header((NX,NY,NZ,NT),"su3gauge",1,64)
#print(li.doc)
#write("test.xml", li.doc)

if U[1].myrank == 0
fp = open(filename, "w")
end


i = 0
counttotal = 0
for it = 1:NT
for iz = 1:NZ
for iy = 1:NY
for ix = 1:NX
rank, ix_local, iy_local, iz_local, it_local =
calc_rank_and_indices(U[1], ix, iy, iz, it)
#counts[rank+1] += 1
counttotal += 1

barrier(U[1])
if U[1].myrank == rank
count = 0
for μ = 1:4
for a = 1:NC
for b = 1:NC
count += 1
send_mesg[count] = getvalue(
U[μ],
a,
b,
ix_local,
iy_local,
iz_local,
it_local,
)
#send_mesg[count] = U[μ][ic2,ic1,ix_local,iy_local,iz_local,it_local]
end
end
end
sreq = MPI.Isend(send_mesg, rank, counttotal, U[1].comm)
end
if U[1].myrank == 0
rreq = MPI.Irecv!(recv_mesg, 0, counttotal, U[1].comm)
MPI.Wait!(rreq)
count = 0
for μ = 1:4
for a = 1:NC
for b = 1:NC
count += 1
v = recv_mesg[count]
rvalue = real(v)
println(fp, rvalue)
ivalue = imag(v)
println(fp, ivalue)

#write(fp, hton(real(v)))
#write(fp, hton(imag(v)))
#Gaugefields.setvalue!(U[μ],v,ic2,ic1,ix_local,iy_local,iz_local,it_local)
end
end
end
end
barrier(U[1])
end
end
end
end
if U[1].myrank == 0
close(fp)
end
barrier(U[1])



end
end
end

function load_BridgeText!(initial, U, L, NC)
Expand Down Expand Up @@ -118,4 +292,53 @@ function load_BridgeText!(initial, U, L, NC)


end

function save_textdata(U, filename)

NX = U[1].NX
NY = U[1].NY
NZ = U[1].NZ
NT = U[1].NT
NC = U[1].NC


#li = LIME_header((NX,NY,NZ,NT),"su3gauge",1,64)
#print(li.doc)
#write("test.xml", li.doc)


fp = open(filename, "w")
#fp = open("testbin.dat","w")
i = 0
i = 0
#for μ=1:4
for it = 1:NT
for iz = 1:NZ
for iy = 1:NY
for ix = 1:NX
for μ = 1:4
for a = 1:NC
for b = 1:NC
i += 1
#rvalue = read(fp, floattype)
rvalue = real(U[μ][a, b, ix, iy, iz, it])
println(fp, rvalue)
ivalue = imag(U[μ][a, b, ix, iy, iz, it])
println(fp, ivalue)
end
end
end
end
end
end
end
close(fp)




return

end

end

0 comments on commit cd86b51

Please sign in to comment.