final solution of task public
This commit is contained in:
@@ -56,23 +56,35 @@ namespace StgSharp.Mathematics
|
||||
public static partial class MatrixParallel
|
||||
{
|
||||
|
||||
// TODO
|
||||
/*
|
||||
* 目前认为应当按照如下方式进行调整:
|
||||
* 1. 使用Queue进行线程束池化
|
||||
* 2. 一次只能有一个线程进行发布活动(一次只能由一个线程持有)
|
||||
* 3. 发布任务似乎应当分类进行,分类条件为q = n_task / n_thread
|
||||
* 3.1 q=0时,不是全部任务束可以参与计算
|
||||
* 3.2 q>0时,全部任务束可以参与计算
|
||||
* 4. 后续分为a个q线程,b个q+1线程,然后分到线程束中,同时不保证束内任务同步
|
||||
* 5. 仅可能保证线程间任务数量差异不超过512
|
||||
*/
|
||||
|
||||
private static Thread[] _threads;
|
||||
private static readonly (int a, int b)[] LookupTable = [
|
||||
(1, 1),
|
||||
(0, 2),
|
||||
(3, 0),
|
||||
(2, 1),
|
||||
(1, 2),
|
||||
(0, 3),
|
||||
(3, 1),
|
||||
(2, 2),
|
||||
(1, 3),
|
||||
(0, 4),
|
||||
(3, 2),
|
||||
(2, 3),
|
||||
(1, 4),
|
||||
(0, 5),
|
||||
];
|
||||
private static readonly (int a, int b)[] LookupTable = [ (1, 1), // n=7
|
||||
(0, 2), // n=8
|
||||
(3, 0), // n=9
|
||||
(2, 1), // n=10
|
||||
(1, 2), // n=11
|
||||
(0, 3), // n=12
|
||||
(3, 1), // n=13
|
||||
(2, 2), // n=14
|
||||
(1, 3), // n=15
|
||||
(4, 1), // n=16
|
||||
(3, 2), // n=17
|
||||
(2, 3), // n=18
|
||||
(1, 4), // n=19
|
||||
(4, 2), // n=20
|
||||
];
|
||||
|
||||
private static bool _meaningful;
|
||||
|
||||
private static volatile int RemainThreadCount = 0;
|
||||
@@ -139,17 +151,14 @@ namespace StgSharp.Mathematics
|
||||
}
|
||||
} else if (count == 6)
|
||||
{
|
||||
SmallWraps = [
|
||||
new MatrixParallelWrap(0, 3, true),
|
||||
new MatrixParallelWrap(3, 3, false)
|
||||
];
|
||||
SmallWraps = [ new MatrixParallelWrap(0, 3, true), new MatrixParallelWrap(3, 3, false) ];
|
||||
LargeWraps = [];
|
||||
(LargeWrapCount, SmallWrapCount) = (0, 2);
|
||||
} else
|
||||
{
|
||||
(int _3wrap, int _4wrap) = FastDecompose(count);
|
||||
LargeWraps = new MatrixParallelWrap[ _4wrap];
|
||||
SmallWraps = new MatrixParallelWrap[ _3wrap];
|
||||
LargeWraps = new MatrixParallelWrap[_4wrap];
|
||||
SmallWraps = new MatrixParallelWrap[_3wrap];
|
||||
int id = 0;
|
||||
for (int idx = 0; idx < _3wrap; idx++, id += 3) {
|
||||
SmallWraps[idx] = new MatrixParallelWrap(idx, 3, id == 0);
|
||||
@@ -158,7 +167,6 @@ namespace StgSharp.Mathematics
|
||||
LargeWraps[idx] = new MatrixParallelWrap(id, 4, id == 0);
|
||||
}
|
||||
}
|
||||
LeaderHandle = new MatrixParallelWrap.Handle(0, _wraps[0]);
|
||||
LeaderTask = LeaderHandle.Wrap.GetWorkerTaskQueue(0);
|
||||
IsInitialized = true;
|
||||
}
|
||||
@@ -192,7 +200,10 @@ namespace StgSharp.Mathematics
|
||||
public static void SetAllWrap()
|
||||
{
|
||||
ResetThreadCount();
|
||||
foreach (MatrixParallelWrap item in _wraps) {
|
||||
foreach (MatrixParallelWrap item in LargeWraps) {
|
||||
item.SchedulerReset.Set();
|
||||
}
|
||||
foreach (MatrixParallelWrap item in SmallWraps) {
|
||||
item.SchedulerReset.Set();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user