first version of parallel reduce demo, must remove MV
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 21 Jun 2022 10:03:45 +0000 (11:03 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 21 Jun 2022 10:34:49 +0000 (11:34 +0100)
openpower/sv/preduce.py [new file with mode: 0644]

diff --git a/openpower/sv/preduce.py b/openpower/sv/preduce.py
new file mode 100644 (file)
index 0000000..242b3ab
--- /dev/null
@@ -0,0 +1,25 @@
+from copy import copy
+
+def preduce(vl, vec, pred):
+    pred = copy(pred) # must not damage predicate
+    step = 1
+    while step < vl:
+        step *= 2
+        for i in range(0, vl, step):
+            other = i + step // 2
+            other_pred = other < vl and pred[other]
+            if pred[i] and other_pred:
+                vec[i] += vec[other]
+            elif other_pred:
+                vec[i] = vec[other]
+            pred[i] |= other_pred
+        print("   row", step, pred, vec)
+
+if __name__ == '__main__':
+    vec = [1, 2, 3, 4, 9, 5, 6]
+    prd = [1, 1, 1, 1, 0, 1, 1]
+    print (vec)
+    preduce(len(vec), vec, prd)
+    print (vec)
+    print ()
+