diff --git a/StgSharp.Common/Mathematics/Linear/MatrixParallel.Publish.cs b/StgSharp.Common/Mathematics/Linear/MatrixParallel.Publish.cs index 2bc26ebf..0338c129 100644 --- a/StgSharp.Common/Mathematics/Linear/MatrixParallel.Publish.cs +++ b/StgSharp.Common/Mathematics/Linear/MatrixParallel.Publish.cs @@ -1,6 +1,6 @@ //----------------------------------------------------------------------- // ----------------------------------------------------------------------- -// file="MatrixParallel.TaskPublic.cs" +// file="MatrixParallel.Publish.cs" // Project: StgSharp // AuthorGroup: Nitload Space // Copyright (c) Nitload Space. All rights reserved. @@ -76,22 +76,9 @@ namespace StgSharp.Mathematics package->ElementSize = sizeof(T); package->ComputeMode = 3; - if ((c3 | c4) > 0) { } else - { - int - small_4_size = c4 / LargeWrapCount, - large_4_size = small_4_size + 1, - small_3_size = c3 / LargeWrapCount, - large_3_size = small_3_size + 1; - int - large_4_count = c4 % LargeWrapCount, - small_4_count = LargeWrapCount - large_4_count, - large_3_count = c3 % LargeWrapCount, - small_3_count = LargeWrapCount - large_3_count; - for (int i = 0; i < large_4_count; i++) { } - - // TODO maybe a task slice method is good? - } + int baseCount = columnCount / length, + rem = columnCount % length; + if (baseCount == 0) { } } } diff --git a/StgSharp.Common/Mathematics/Linear/MatrixParallel.cs b/StgSharp.Common/Mathematics/Linear/MatrixParallel.cs index 69ee58fa..03b29548 100644 --- a/StgSharp.Common/Mathematics/Linear/MatrixParallel.cs +++ b/StgSharp.Common/Mathematics/Linear/MatrixParallel.cs @@ -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(); } }