def sums

bend-parallel@0.1.0.0 · scan.bend:113

import bend-parallel@0.1.0.0/scan.bend as Scan
import Base

113# Pass 1's forks: d levels down to the leaves under leaf index i. fa and
114# fs are two handles each to the data a and the sums s. Leaf i reads only
115# its block of a and writes only s[i], so no two lanes touch one slot.
116def sums(+d: Nat, +i: U32, +e: Nat, fa: Array<U32> & Array<U32>, fs: Array<U32> & Array<U32>) -> Two:
117  match d:
118    case 0n:
119      (a, a2) = fa
120      (s, s2) = fs
121      two.rejoin(a2, s2, sums.leaf(i, e, a, s))
122    case 1n+p:
123      (a0, a1) = fa
124      (s0, s1) = fs
125      +j = (i * 2 : U32)
126      l r = sums(p, j, e, Array.fork(U32, a0), Array.fork(U32, s0))
127        sums(p, (j + 1 : U32), e, Array.fork(U32, a1), Array.fork(U32, s1))
128      two.join(l, r)

Uses (12)

Used by (1)