# HG changeset patch # User Sascha L. Teichmann # Date 1551353687 -3600 # Node ID 930ca9c4e2a794de2624d9bb18aa460fcbfe353e # Parent 9b1f0edf5fdc12c45b958bc0c445b8150698545c Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data. diff -r 9b1f0edf5fdc -r 930ca9c4e2a7 pkg/octree/builder.go --- a/pkg/octree/builder.go Thu Feb 28 12:03:02 2019 +0100 +++ b/pkg/octree/builder.go Thu Feb 28 12:34:47 2019 +0100 @@ -18,6 +18,7 @@ "encoding/binary" "io" "log" + "runtime" "sync" "sync/atomic" @@ -77,38 +78,38 @@ triangles[i] = int32(i) } - /* - n := runtime.NumCPU() + n := runtime.NumCPU() - steps := make(chan buildStep, n) + steps := make(chan buildStep) - var wg sync.WaitGroup - for i := 0; i < n; i++ { - wg.Add(1) - go func() { - defer wg.Done() - for step := range steps { - step(steps) - } - }() - } + var wg sync.WaitGroup + for i := 0; i < n; i++ { + wg.Add(1) + go func() { + defer wg.Done() + for step := range steps { + step(steps) + } + }() + } - tb.index = append(tb.index, 0) + tb.index = append(tb.index, 0) - root := func(int32) { - close(steps) - } + root := func(int32) { + close(steps) + } - steps <- tb.buildConcurrent( - triangles, - tb.t.Min, tb.t.Max, - 0, - root) + steps <- tb.buildConcurrent( + triangles, + tb.t.Min, tb.t.Max, + 0, + root) - wg.Wait() + wg.Wait() + + /* + tb.buildRecursive(triangles, tb.t.Min, tb.t.Max, 0) */ - - tb.buildRecursive(triangles, tb.t.Min, tb.t.Max, 0) tb.index[0] = int32(len(tb.index)) log.Printf("info: num nodes: %d\n", tb.index[0]) log.Printf("info: nodes: %d leaves: %d index %d\n", @@ -125,7 +126,7 @@ return func(steps chan buildStep) { // none concurrent for small parts. - if len(triangles) < 1024 || depth > 8 { + if len(triangles) <= 1024 || depth > 8 { parent(tb.buildRecursive(triangles, min, max, depth)) return } @@ -164,10 +165,10 @@ } } - var used int32 + used := new(int32) for i := range quandrants { if len(quandrants[i]) > 0 { - used++ + *used++ } } @@ -175,16 +176,16 @@ for i := range quandrants { if len(quandrants[i]) > 0 { - j := i + j := int32(i) parent := func(v int32) { - tb.index[j] = v - if atomic.AddInt32(&used, -1) == 0 { + tb.index[pos+j] = v + if atomic.AddInt32(used, -1) == 0 { parent(pos) } } step := tb.buildConcurrent( - quandrants[j], - bboxes[j][0], bboxes[j][1], + quandrants[i], + bboxes[i][0], bboxes[i][1], depth+1, parent) select {