Skip to content

Commit

Permalink
Made it so that mrg32k3a RNG fields can be written/saved to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
Curtis Peterson committed Jan 3, 2023
1 parent 4415493 commit 3a6a38c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/io/qioInternal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ template IOtype*(x:typedesc[DComplexV]):untyped = DComplex
template IOtype*(x:typedesc[SColorMatrixV]):untyped = SColorMatrix
template IOtype*(x:typedesc[DColorMatrixV]):untyped = DColorMatrix
template IOtype*(x:typedesc[RngMilc6]):untyped = RngMilc6
template IOtype*(x:typedesc[MRG32k3a]):untyped = MRG32k3a

# For IO with mis-matching types; see read[T]/write[T]
template IOtypeP*(x:typedesc[SVec0]):untyped = float64
Expand All @@ -20,3 +21,4 @@ template IOtypeP*(x:typedesc[DComplexV]):untyped = SComplex
template IOtypeP*(x:typedesc[SColorMatrixV]):untyped = DColorMatrix
template IOtypeP*(x:typedesc[DColorMatrixV]):untyped = SColorMatrix
template IOtypeP*(x:typedesc[RngMilc6]):untyped = RngMilc6
template IOtypeP*(x:typedesc[MRG32k3a]):untyped = MRG32k3a
14 changes: 14 additions & 0 deletions src/rng/mrg32k3a.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Operations Research, 47, 1 (1999), 159-164.

import math
import comms/comms
import maths/types
import simd/simdWrap

type
State = array[3,uint32]
Expand Down Expand Up @@ -76,6 +78,18 @@ when a2sq[76]!=[[1511326704u32, 3759209742u32, 1610795712u32], [4292754251u32, 1
{.error:"a2sq[76] wrong!".}

template isWrapper*(x: MRG32k3a): untyped = false
template numberType*(x: MRG32k3a): typedesc = uint32
template numberType*(x: typedesc[MRG32k3a]): typedesc = uint32
template simdLength*(x: typedesc[MRG32k3a]): untyped = 1
template getNc*(x: MRG32k3a): untyped = 0
template getNs*(x: MRG32k3a): untyped = 0
template `:=`*(x: MRG32k3a, y: MRG32k3a) =
x = y
template `:=`*(x: MRG32k3a, y: Indexed) =
x := y[]
template `[]`*(x: MRG32k3a, y: Simd): untyped = x
template `[]=`*(x: MRG32k3a, y: Simd, z: typed) =
x := z

proc `$`*(x:MRG32k3a):string =
"MRG32k3a(" & $x.s1 & " " & $x.s2 & ")"
Expand Down
37 changes: 26 additions & 11 deletions src/stagg_pv_hmc/staghmc_spv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ var seed_prms = {"parallel_seed" : intParam("seed", int(1000 * epochTime())).uin

# Define string parameters
var str_prms = {"bc" : "pppa", "start" : "hot",
"gauge_int_alg" : "2MN",
"ferm_int_alg" : "2MN",
"pv_int_alg" : "2MN"}.toTable
"gauge_int_alg" : "2MN", "ferm_int_alg" : "2MN",
"pv_int_alg" : "2MN", "rng_type" : "MRG32k3a"}.toTable

# Define options
var options = {"verbose_cg_stats" : false, "verbose_timer" : false,
Expand Down Expand Up @@ -330,16 +329,21 @@ proc ploop(g: auto) =

#[ ~~~~ Functions for IO ~~~~ ]#

#[ For reading RngMilc6 ]#
#[ For reading RNG object ]#
proc read_rng_milc6(filename: string): auto =
# Get iniial time
let t0 = ticc()

# Tell user what you're doing
echo "loading global rng file: " & filename

# Create RngMilc6 object
var rng: RngMilc6
# Initialize RNG
var rng: MRG32k3a

# Check type of rng
if str_prms["rng_type"] == "RngMilc6":
# Create RngMilc6 object
var rng: RngMilc6

# Create new file stream
var file = newFileStream(filename, fmRead)
Expand All @@ -356,7 +360,7 @@ proc read_rng_milc6(filename: string): auto =
# Return rng
result = rng

#[ For reading RngMilc6 ]#
#[ For reading RNG object ]#
proc write_rng_milc6(filename: string, rng: auto) =
# Get initial time
let t0 = ticc()
Expand All @@ -369,7 +373,7 @@ proc write_rng_milc6(filename: string, rng: auto) =

# Check if nil
if not file.isNil:
# Write RngMilc6 object to file
# Write RNG object to file
file.write rng

# Flush
Expand Down Expand Up @@ -570,13 +574,24 @@ proc initialize_params_fields_and_rngs(): auto =
let field_rng_file = io_path & def_fn & "_" & intToStr(start_config) & ".rng"

# Define new RNG field for pbp
var r_pbp = lo.newRNGField(RngMilc6, seed_prms["pbp_seed"])
var r_pbp = lo.newRNGField(MRG32k3a, seed_prms["pbp_seed"])

# Define new RNG field for fermions
var r = lo.newRNGField(RngMilc6, seed_prms["parallel_seed"])
var r = lo.newRNGField(MRG32k3a, seed_prms["parallel_seed"])

# Create global RNG for HMC
var R: RngMilc6
var R: MRG32k3a

# Check type of rng
if str_prms["rng_type"] == "RngMilc6":
# Define new RNG field for pbp
var r_pbp = lo.newRNGField(RngMilc6, seed_prms["pbp_seed"])

# Define new RNG field for fermions
var r = lo.newRNGField(RngMilc6, seed_prms["parallel_seed"])

# Create global RNG for HMC
var R: RngMilc6

# Seed RNG
R.seed(seed_prms["serial_seed"], 987654321)
Expand Down

0 comments on commit 3a6a38c

Please sign in to comment.