raise concurrency cap for multi-cpu systems
This commit is contained in:
parent
5a34fd8c54
commit
2f1c57e0ae
4 changed files with 34 additions and 19 deletions
|
|
@ -41,6 +41,7 @@ export async function slice(points, options = {}) {
|
||||||
zSum = 0.0, // sanity check that points enclose non-zere volume
|
zSum = 0.0, // sanity check that points enclose non-zere volume
|
||||||
buckets = [], // banded/grouped faces to speed up slice/search
|
buckets = [], // banded/grouped faces to speed up slice/search
|
||||||
overlapMax = options.overlap || 0.75,
|
overlapMax = options.overlap || 0.75,
|
||||||
|
bucketMin = options.bucketMin ?? 1,
|
||||||
bucketMax = options.bucketMax || 100,
|
bucketMax = options.bucketMax || 100,
|
||||||
onupdate = options.onupdate || function() {},
|
onupdate = options.onupdate || function() {},
|
||||||
sliceFn = dval(options.slicer, sliceZ),
|
sliceFn = dval(options.slicer, sliceZ),
|
||||||
|
|
@ -138,7 +139,7 @@ export async function slice(points, options = {}) {
|
||||||
let zSpan = zMax - zMin;
|
let zSpan = zMax - zMin;
|
||||||
let zSpanAvg = zSum / points.length;
|
let zSpanAvg = zSum / points.length;
|
||||||
let bucketCount = options.bucket !== false ?
|
let bucketCount = options.bucket !== false ?
|
||||||
Math.min(bucketMax, Math.max(1, Math.floor(zSpan / zSpanAvg))) : 1;
|
Math.min(bucketMax, Math.max(bucketMin, Math.floor(zSpan / zSpanAvg))) : 1;
|
||||||
|
|
||||||
zScale = 1 / (zMax / bucketCount);
|
zScale = 1 / (zMax / bucketCount);
|
||||||
|
|
||||||
|
|
@ -211,7 +212,6 @@ export async function slice(points, options = {}) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
let opt = { ...options, zMin, zMax, zIndexes };
|
let opt = { ...options, zMin, zMax, zIndexes };
|
||||||
let ps = [];
|
let ps = [];
|
||||||
|
|
||||||
for (let i = 0, l = buckets.length; i < l; i++) {
|
for (let i = 0, l = buckets.length; i < l; i++) {
|
||||||
let bucket = buckets[i];
|
let bucket = buckets[i];
|
||||||
let { points, slices } = bucket;
|
let { points, slices } = bucket;
|
||||||
|
|
|
||||||
|
|
@ -318,6 +318,10 @@ export function sliceOne(settings, widget, onupdate, ondone) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isConcurrent) {
|
||||||
|
minions.setPoints(points);
|
||||||
|
}
|
||||||
|
|
||||||
// create Slice objects for specified list of Z heights
|
// create Slice objects for specified list of Z heights
|
||||||
// zGen() produces the list (or empty for slicer auto-detected)
|
// zGen() produces the list (or empty for slicer auto-detected)
|
||||||
slice(points, {
|
slice(points, {
|
||||||
|
|
@ -326,6 +330,7 @@ export function sliceOne(settings, widget, onupdate, ondone) {
|
||||||
xray: process.xray,
|
xray: process.xray,
|
||||||
zMin: bounds.min.z,
|
zMin: bounds.min.z,
|
||||||
zMax: bounds.max.z - zCut,
|
zMax: bounds.max.z - zCut,
|
||||||
|
bucketMin: minions.concurrent * 5,
|
||||||
union: controller.healMesh,
|
union: controller.healMesh,
|
||||||
indices: process.indices || process.xray,
|
indices: process.indices || process.xray,
|
||||||
useAssembly,
|
useAssembly,
|
||||||
|
|
@ -351,6 +356,9 @@ export function sliceOne(settings, widget, onupdate, ondone) {
|
||||||
})
|
})
|
||||||
.then(decodeSlices)
|
.then(decodeSlices)
|
||||||
.then(processSlices)
|
.then(processSlices)
|
||||||
|
.then(() => {
|
||||||
|
minions.setPoints([]);
|
||||||
|
})
|
||||||
.then(ondone);
|
.then(ondone);
|
||||||
|
|
||||||
// z index generator (bottom up)
|
// z index generator (bottom up)
|
||||||
|
|
|
||||||
|
|
@ -154,14 +154,11 @@ const funcs = self.minion = {
|
||||||
|
|
||||||
sliceZ(data, seq) {
|
sliceZ(data, seq) {
|
||||||
debug('minion.sliceZ', { data, seq });
|
debug('minion.sliceZ', { data, seq });
|
||||||
let { z, points, options } = data;
|
let { z, options } = data;
|
||||||
let i = 0, p = 0, realp = new Array(points.length / 3);
|
let { points } = cache;
|
||||||
while (i < points.length) {
|
|
||||||
realp[p++] = newPoint(points[i++], points[i++], points[i++]).round(3);
|
|
||||||
}
|
|
||||||
let state = { zero: [] };
|
let state = { zero: [] };
|
||||||
let output = [];
|
let output = [];
|
||||||
sliceZ(z, realp, {
|
sliceZ(z, points, {
|
||||||
...options,
|
...options,
|
||||||
each(out) { output.push(out) }
|
each(out) { output.push(out) }
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
|
@ -173,9 +170,17 @@ const funcs = self.minion = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setPoints(data, seq) {
|
||||||
|
let { points } = data;
|
||||||
|
let i = 0, p = 0, realp = new Array(points.length / 3);
|
||||||
|
while (i < points.length) {
|
||||||
|
realp[p++] = newPoint(points[i++], points[i++], points[i++]).round(3);
|
||||||
|
}
|
||||||
|
cache.points = realp;
|
||||||
|
},
|
||||||
|
|
||||||
putCache(msg) {
|
putCache(msg) {
|
||||||
const { key, data } = msg;
|
const { key, data } = msg;
|
||||||
// log({ minion_putCache: key, data });
|
|
||||||
if (data) {
|
if (data) {
|
||||||
cache[key] = data;
|
cache[key] = data;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ let drivers = {
|
||||||
WJET
|
WJET
|
||||||
},
|
},
|
||||||
ccvalue = self.navigator ? self.navigator.hardwareConcurrency || 0 : 0,
|
ccvalue = self.navigator ? self.navigator.hardwareConcurrency || 0 : 0,
|
||||||
concurrent = Math.min(4, self.Worker && ccvalue > 3 ? ccvalue - 1 : 0),
|
concurrent = Math.round(Math.max(4, self.Worker && ccvalue > 3 ? ccvalue * 0.75 : 0)),
|
||||||
current = {
|
current = {
|
||||||
print: null,
|
print: null,
|
||||||
snap: null,
|
snap: null,
|
||||||
|
|
@ -174,6 +174,16 @@ const minwork = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setPoints(points) {
|
||||||
|
let i = 0, floatP = new Float32Array(points.length * 3);
|
||||||
|
for (let p of points) {
|
||||||
|
floatP[i++] = p.x;
|
||||||
|
floatP[i++] = p.y;
|
||||||
|
floatP[i++] = p.z;
|
||||||
|
}
|
||||||
|
minwork.broadcast("setPoints", { points: floatP });
|
||||||
|
},
|
||||||
|
|
||||||
// added functions (should be namespaced)
|
// added functions (should be namespaced)
|
||||||
|
|
||||||
subtract({ a, b, outA, outB, z, area, wasm }) {
|
subtract({ a, b, outA, outB, z, area, wasm }) {
|
||||||
|
|
@ -285,17 +295,9 @@ const minwork = {
|
||||||
reject("concurrent slice unavaiable");
|
reject("concurrent slice unavaiable");
|
||||||
}
|
}
|
||||||
let { each } = options;
|
let { each } = options;
|
||||||
// todo use shared array buffer?
|
|
||||||
let i = 0, floatP = new Float32Array(points.length * 3);
|
|
||||||
for (let p of points) {
|
|
||||||
floatP[i++] = p.x;
|
|
||||||
floatP[i++] = p.y;
|
|
||||||
floatP[i++] = p.z;
|
|
||||||
}
|
|
||||||
minwork.queue({
|
minwork.queue({
|
||||||
cmd: "sliceZ",
|
cmd: "sliceZ",
|
||||||
z,
|
z,
|
||||||
points: floatP,
|
|
||||||
options: codec.toCodable(options)
|
options: codec.toCodable(options)
|
||||||
}, data => {
|
}, data => {
|
||||||
let recs = codec.decode(data.output);
|
let recs = codec.decode(data.output);
|
||||||
|
|
@ -305,7 +307,7 @@ const minwork = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve(recs);
|
resolve(recs);
|
||||||
}, [ floatP.buffer ]);
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue