Put thread pool to individual type define as thread resource manager.
This commit is contained in:
@@ -820,27 +820,27 @@ namespace StgSharp.Mathematics.Numeric
|
||||
int tileWidth = (1024 / secCount) + 1;
|
||||
int tileCount = (primCount / tileWidth) + 1;
|
||||
|
||||
CapacityFixedStack<MatrixParallelWrap> wraps = LeadParallel();
|
||||
MatrixParallelPool pool = LeadParallel();
|
||||
|
||||
int tilePerThreadLess = tileCount / wraps.Count;
|
||||
int tileToSlice = tileCount % wraps.Count;
|
||||
int slicingPerWrap = tileToSlice / wraps.Count;
|
||||
int extraTiles = tileToSlice % wraps.Count;
|
||||
int tilePerThreadLess = tileCount / pool.SpareThreadCount;
|
||||
int tileToSlice = tileCount % pool.SpareThreadCount;
|
||||
int slicingPerWrap = tileToSlice / pool.SpareThreadCount;
|
||||
int extraTiles = tileToSlice % pool.SpareThreadCount;
|
||||
|
||||
int total = tileCount;
|
||||
int begin = 0;
|
||||
Stack<MatrixParallelWrap> taskBunch = new Stack<MatrixParallelWrap>(wraps.Count);
|
||||
Stack<MatrixParallelWrap> taskBunch = new Stack<MatrixParallelWrap>(pool.SpareThreadCount);
|
||||
while (tileCount > 0)
|
||||
{
|
||||
MatrixParallelWrap wrap = wraps.Pop();
|
||||
_ = pool.TryRequestWrap(out MatrixParallelWrap? wrap);
|
||||
bool hasSlice = tileToSlice > 0;
|
||||
bool isLargeSlice = extraTiles > 0;
|
||||
|
||||
// count tiles for wrap
|
||||
// TODO 此处应该是线程数量而不是线程束数量
|
||||
// TODO 需要想办法正确同步线程数量信息
|
||||
int toSlice = hasSlice ? wrap.WrapTaskCapacity * slicingPerWrap : 0;
|
||||
int baseTile = wrap.WrapTaskCapacity * tilePerThreadLess;
|
||||
int toSlice = hasSlice ? wrap!.WrapTaskCapacity * slicingPerWrap : 0;
|
||||
int baseTile = wrap!.WrapTaskCapacity * tilePerThreadLess;
|
||||
int tileInWrap = baseTile + toSlice + (isLargeSlice ? 1 : 0);
|
||||
int columnInWrap = tileInWrap * tileWidth;
|
||||
|
||||
@@ -857,7 +857,7 @@ namespace StgSharp.Mathematics.Numeric
|
||||
begin += tileInWrap;
|
||||
taskBunch.Push(wrap);
|
||||
}
|
||||
ReleaseParallelLeadership(ref wraps);
|
||||
ReleaseParallelLeadership(ref pool);
|
||||
|
||||
return taskBunch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user