optimize para performance of buffered stack
This commit is contained in:
@@ -820,9 +820,9 @@ namespace StgSharp.Mathematics.Numeric
|
||||
int tileWidth = (1024 / secCount) + 1;
|
||||
int tileCount = (primCount + tileWidth - 1) / tileWidth;
|
||||
|
||||
MatrixParallelPool pool = LeadParallel();
|
||||
CapacityFixedStack<MatrixParallelThread> pool = LeadParallel();
|
||||
|
||||
int threadCount = pool.SpareThreadCount;
|
||||
int threadCount = pool.Count;
|
||||
int tilePerThreadLess = tileCount / threadCount; // tiles per thread without extra slice
|
||||
int columnAfterBaseTile = tileCount % threadCount * tileWidth; // tile sliced into columns
|
||||
int extraColumnPerThread = columnAfterBaseTile / threadCount;
|
||||
@@ -833,7 +833,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
MatrixParallelTaskPackage<T>* current = package;
|
||||
while (true)
|
||||
{
|
||||
if (!pool.TryRequestWrap(out MatrixParallelWrap? wrap) || wrap is null)
|
||||
if (!pool.TryPop(out MatrixParallelThread? wrap) || wrap is null)
|
||||
{
|
||||
#if DEBUG
|
||||
throw new InvalidOperationException("Someone steal parallel wraps from the pool.");
|
||||
@@ -846,7 +846,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
bool isLargeSlice = extraColumnCount > 0;
|
||||
|
||||
// count tiles for wrap
|
||||
int wrapWidth = wrap!.WrapTaskCapacity;
|
||||
int wrapWidth =/**/ 3/* wrap!.WrapTaskCapacity/**/;
|
||||
int columnFromSlicingCount = (hasSlice ? extraColumnPerThread : 0) * wrapWidth;
|
||||
int baseColumn = wrapWidth * tilePerThreadLess * tileWidth;
|
||||
int columnInWrap = baseColumn + columnFromSlicingCount + (isLargeSlice ? 1 : 0);
|
||||
@@ -872,8 +872,9 @@ namespace StgSharp.Mathematics.Numeric
|
||||
total -= columnInWrap;
|
||||
|
||||
// set to wrap and push
|
||||
wrap.WrapTask = (MatrixParallelTaskPackageNonGeneric*)current;
|
||||
taskBunch.Push(wrap);
|
||||
wrap.Tasks.Enqueue((IntPtr)current);
|
||||
|
||||
// taskBunch.Push(wrap);
|
||||
|
||||
|
||||
if (total <= 0)
|
||||
|
||||
Reference in New Issue
Block a user