mpl going on good process

This commit is contained in:
Youmu Liu
2025-09-24 20:38:15 +08:00
parent 8abc82ae08
commit 0cafe9fd4d
15 changed files with 179 additions and 104 deletions
@@ -69,15 +69,33 @@ namespace StgSharp.Mathematics
private static Thread[] _threads;
private static MatrixParallelWrap[] _wraps;
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 volatile int RemainThreadCount = 0;
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 bool _meaningful;
private static int LargeWrapCount;
private static volatile int RemainThreadCount = 0;
private static int SmallWrapCount;
private static readonly object _lock = new();
private static ThreadPriority _AfterWork = ThreadPriority.Lowest;
public static bool SupportParallel { get; } = Environment.ProcessorCount > 6;
public static bool IsParallelMeaningful { get; } = Environment.ProcessorCount > 6 && IsInitialized;
public static bool IsParallelMeaningful => Environment.ProcessorCount > 6 && IsInitialized;
public static MatrixParallelWrap.Handle LeaderHandle { get; private/**/ set; }
@@ -91,7 +109,7 @@ namespace StgSharp.Mathematics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (int a, int b) FastDecompose(int c)
public static (int count_3, int count_4) FastDecompose(int c)
{
if (c < 7) {
return (0, 0);
@@ -111,15 +129,25 @@ namespace StgSharp.Mathematics
return;
}
MatrixParallelFactory.Init();
if (!SupportParallel)
{
IsInitialized = true;
return;
}
int count = Environment.ProcessorCount - 4;
count = count == 5 ? 4 : count;
_threads = new Thread[count];
if (count < 6)
{
count = count == 3 ? 3 : 4;
_wraps = [ new MatrixParallelWrap(0, count, true) ];
(LargeWrapCount, SmallWrapCount) = count == 3 ? (1,0) : (0,1);
} else if (count == 6)
{
_wraps = [ new MatrixParallelWrap(0, 3, true), new MatrixParallelWrap(3, 3, false) ];
_wraps = [
new MatrixParallelWrap(0, 3, true),
new MatrixParallelWrap(3, 3, false)
];
} else
{
(int _3wrap, int _4wrap) = FastDecompose(count);