working on dynamic wrapping
This commit is contained in:
@@ -820,9 +820,15 @@ namespace StgSharp.Mathematics.Numeric
|
||||
int tileWidth = (1024 / secCount) + 1;
|
||||
int tileCount = (primCount + tileWidth - 1) / tileWidth;
|
||||
|
||||
CapacityFixedStack<MatrixParallelThread> pool = LeadParallel();
|
||||
ReadOnlySpan<MatrixParallelThread> pool = LeadParallel(tileCount);
|
||||
|
||||
int threadCount = pool.Count;
|
||||
int threadCount = pool.Length;
|
||||
if (pool.Length == 0)
|
||||
{
|
||||
/*
|
||||
* wait until has enough threads
|
||||
*/
|
||||
}
|
||||
int tilePerThreadLess = tileCount / threadCount; // tiles per thread without extra slice
|
||||
int columnAfterBaseTile = tileCount % threadCount * tileWidth; // tile sliced into columns
|
||||
int extraColumnPerThread = columnAfterBaseTile / threadCount;
|
||||
@@ -831,17 +837,8 @@ namespace StgSharp.Mathematics.Numeric
|
||||
int total = primCount;
|
||||
Stack<MatrixParallelWrap> taskBunch = new Stack<MatrixParallelWrap>(threadCount);
|
||||
MatrixParallelTaskPackage<T>* current = package;
|
||||
while (true)
|
||||
foreach (MatrixParallelThread thread in pool)
|
||||
{
|
||||
if (!pool.TryPop(out MatrixParallelThread? wrap) || wrap is null)
|
||||
{
|
||||
#if DEBUG
|
||||
throw new InvalidOperationException("Someone steal parallel wraps from the pool.");
|
||||
#else
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool hasSlice = columnAfterBaseTile > 0;
|
||||
bool isLargeSlice = extraColumnCount > 0;
|
||||
|
||||
@@ -872,7 +869,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
total -= columnInWrap;
|
||||
|
||||
// set to wrap and push
|
||||
wrap.Tasks.Enqueue((IntPtr)current);
|
||||
// wrap.Tasks.Enqueue((IntPtr)current);
|
||||
|
||||
// taskBunch.Push(wrap);
|
||||
|
||||
@@ -884,7 +881,6 @@ namespace StgSharp.Mathematics.Numeric
|
||||
current = MatrixParallelFactory.FromExistPackage(current);
|
||||
current->PrimTileOffset += columnInWrap;
|
||||
}
|
||||
ReleaseParallelLeadership(ref pool);
|
||||
|
||||
return taskBunch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user