Daily update on 20251023-010006 by Nitload Youmu. Additional Message : Put matrix parallel pool and other supporting methods into individual classes.

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-10-23 01:00:06 +08:00
parent affaf03845
commit 3b23272f38
2 changed files with 34 additions and 34 deletions
+9 -13
View File
@@ -2,8 +2,8 @@
// -----------------------------------------------------------------------
// file="MatrixParallel"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -35,13 +35,13 @@ using System.Threading;
namespace StgSharp.Mathematics.Numeric
{
/*
* Thread wrapping to accelerate matrix operations by dividing threads into groups (wraps).
* For M wraps, each containing an average of N threads, we satisfy the condition M * N = T - 4,
* Thread wrapping to accelerate matrix operations by dividing threads into groups (pool).
* For M pool, each containing an average of N threads, we satisfy the condition M * N = T - 4,
* where T is the total thread count of the CPU. Typically, for modern consumer CPUs, T is around 16.
* For simplicity, let M * N = 16.
*
* The total time complexity for publishing tasks is O(M + N):
* - O(M) accounts for distributing tasks across M wraps.
* - O(M) accounts for distributing tasks across M pool.
* - O(N) accounts for threads within each wrap fetching tasks from the wrap queue.
*
* Using the inequality Sqrt(M * N) <= (M + N) / 2 (derived from the arithmetic-geometric mean inequality),
@@ -55,8 +55,7 @@ namespace StgSharp.Mathematics.Numeric
{
private static Thread[] _threads;
private static readonly (int a, int b)[] LookupTable = [
(1, 1), // 7
private static readonly (int a, int b)[] LookupTable = [ (1, 1), // 7
(0, 2), // 8 (no non-zero solution)
(3, 0), // 9 (no non-zero solution)
(2, 1), // 10
@@ -134,10 +133,7 @@ namespace StgSharp.Mathematics.Numeric
}
} else if (count == 6)
{
Pool = new(6, [
new MatrixParallelWrap(0, 3),
new MatrixParallelWrap(3, 3)
]);
Pool = new(6, [ new MatrixParallelWrap(0, 3), new MatrixParallelWrap(3, 3) ]);
(LargeWrapCount, SmallWrapCount) = (0, 2);
} else
{
@@ -199,13 +195,13 @@ namespace StgSharp.Mathematics.Numeric
return Pool;
}
public static void ReleaseParallelLeadership(ref CapacityFixedStack<MatrixParallelWrap> wraps)
public static void ReleaseParallelLeadership(ref MatrixParallelPool pool)
{
#if NET9_0_OR_GREATER
#else
Monitor.Exit(_lock);
#endif
wraps = null!;
pool = null!;
}
#endregion