~/bend-docscommunity

parallel.bend relies on unsafe/foreign

raw source on the hub · import bend-visgraph@2.0.0.0/parallel.bend as Parallel

ts2vg's visibility graphs of time series, in Bend2, on every CPU thread.

import bend-visgraph@2.0.0.0/visgraph.bend as VG import bend-visgraph@2.0.0.0/parallel.bend as Par

Par.build and Par.degrees are VG.build and VG.degrees on every thread. Each def here that hands one array to two tasks relies on Base's @unsafe Array.fork: the tasks that share an array read it, write cells no other task writes, or add to cells atomically.

2 imports
import Base
import ./visgraph.bend as VG

Types

type Blocks source · line 25 · raw

Data

The stack runs on blocks in parallel; a merge then walks the blocks in order.

type Chunks source · line 60 · raw

Data

type Cut source · line 71 · raw

Type

type Halves source · line 100 · raw

Data

Definitions

def fork3 source · line 13 · raw

@a:Pair(Array<F32>, Array<F32>) -> @b:Pair(Array<U32>, Array<U32>) -> @c:Pair(Array<U32>, Array<U32>) -> Pair(0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols, 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols)

def fork_cols source · line 19 · raw

@c:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols -> Pair(0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols, 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols)

def block_of source · line 29 · raw

@l:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Local -> Blocks

def block_leaf source · line 36 · raw

@+s:U32 -> @+e:U32 -> @c:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols -> Blocks

It forks nothing, so the runtime runs it once the tree has grown, on any idle thread; work done before a fork runs while the tree grows, on a few threads.

def block_tree source · line 40 · raw

@depth:Nat -> @+s:U32 -> @+e:U32 -> @cc:Pair(0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols, 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols) -> Blocks

def merge source · line 53 · raw

@bs:Blocks -> @m:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Merged -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Merged

def close source · line 64 · raw

@full:Bool -> @+start:U32 -> @+end:U32 -> @cs:Chunks -> Chunks

def cut source · line 74 · raw

@count:Nat -> @+i:U32 -> @lr:Pair(Array<U32>, U32) -> @rr:Pair(Array<U32>, U32) -> @+start:U32 -> @+acc:U32 -> @+target:U32 -> @cs:Chunks -> @+m:U32 -> Cut

def fork_depth source · line 89 · raw

Nat

def block_depth source · line 93 · raw

@+n:U32 -> Nat

At most 512 blocks, and at least 32 points in each unless n is below 64.

def target source · line 97 · raw

@+visits:F32 -> U32

About two chunks for each of the tree's leaves.

def halve source · line 103 · raw

@k:Nat -> @cs:Chunks -> @+na:U32 -> @+total:U32 -> @acc:Chunks -> Halves

def halves source · line 110 · raw

@cs:Chunks -> @+m:U32 -> Halves

def chunks source · line 113 · raw

@cs:Chunks -> @o:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Out -> @+index:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Out

def leaf source · line 122 · raw

@cs:Chunks -> @c:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols -> @xs:Array<F32> -> @+index:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

def tree source · line 125 · raw

@depth:Nat -> @h:Halves -> @cc:Pair(0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols, 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols) -> @xx:Pair(Array<F32>, Array<F32>) -> @+index:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

def split source · line 138 · raw

@+index:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> @ys:Array<F32> -> @xs:Array<F32> -> @c:Cut -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

def cut_all source · line 142 · raw

@+index:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> @+n:U32 -> @ys:Array<F32> -> @xs:Array<F32> -> @lefts:Array<U32> -> @r:Pair(Array<U32>, F32) -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

def merged source · line 146 · raw

@+index:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> @+n:U32 -> @ys:Array<F32> -> @xs:Array<F32> -> @m:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Merged -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

def passed source · line 150 · raw

@+index:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> @+n:U32 -> @xs:Array<F32> -> @cc:Pair(0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols, 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Cols) -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

def built source · line 155 · raw

@+index:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> @ys:Array<F32> -> @xs:Array<F32> -> @+n:U32 -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

def visibility source · line 160 · raw

@+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> @ys:Array<F32> -> @xs:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Xs -> @+n:U32 -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

VG.build on every thread: the stack runs on blocks, then the sweeps on chunks of equal work.

def chosen source · line 167 · raw

@is_visibility:Bool -> @+g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Visibility -> @+dir:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Direction -> @+k:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Weight -> @+lo:F32 -> @+hi:F32 -> @+limit:U32 -> @ys:Array<F32> -> @xs:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Xs -> @+n:U32 -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges

def build source · line 175 · raw

@o:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Options -> @s:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Series -> 0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Graph

VG.build on every thread.

def degrees_tree source · line 182 · raw

@depth:Nat -> @es:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Edges -> @dd:Pair(Array<U32>, Array<U32>) -> Array<U32>

Forks down the build's tree of EJoin into VG.degrees.into, which forks nothing, so the runtime spreads the tallies over every thread.

def degrees source · line 197 · raw

@g:0xe3a7f78ee5245da17fe27e3556f94e74/visgraph.Graph -> Array<U32>

VG.degrees on every thread.