-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |