From f58b4e442ccc71e1928fb54c275f058783c1d7df Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 21 Jun 2022 11:03:45 +0100 Subject: [PATCH] first version of parallel reduce demo, must remove MV --- openpower/sv/preduce.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 openpower/sv/preduce.py diff --git a/openpower/sv/preduce.py b/openpower/sv/preduce.py new file mode 100644 index 000000000..242b3ab6b --- /dev/null +++ b/openpower/sv/preduce.py @@ -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 () + -- 2.30.2