-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtestSubsets.nim
48 lines (38 loc) · 1.13 KB
/
testSubsets.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import qex
import physics/qcdTypes
proc test =
qexInit()
var lat = [8,8,8,8]
var lo = newLayout(lat)
let vnc = lo.physVol * getDefaultNc()
var v1 = lo.ColorVector()
var v2 = lo.ColorVector()
var v3 = lo.ColorVector()
var v1e = v1.even
# start thread block ("omp parallel")
threads:
v1 := 1
threadBarrier() # required when changing subsets if potential race condition
v1.even := 2
threadBarrier()
# loop over all (vectorized) site indices in v1
for e in v1.all:
v2[e] := 2 * v1[e]
v3[e] += v2[e]
echo v1.norm2, "\t", v2.norm2, "\t", v3.norm2
doAssert v1.norm2 == 2.5*vnc # even: 2, odd: 1
doAssert v2.norm2 == 10.0*vnc # even: 4, odd: 2
doAssert v3.norm2 == 10.0*vnc # even: 4, odd: 2
threadBarrier()
v1e := 3
threadBarrier()
for e in v1.even:
v2[e] := 2 * v1[e]
v3[e] += v2[e]
threadBarrier()
echo v1.norm2, "\t", v2.norm2, "\t", v3.norm2
doAssert v1.norm2 == 5.0*vnc # even: 3, odd: 1
doAssert v2.norm2 == 20.0*vnc # even: 6, odd: 2
doAssert v3.norm2 == 52.0*vnc # even: 10, odd: 2
qexFinalize()
test()