From 3b23272f38b5595b0ec340599843bd7f34848277 Mon Sep 17 00:00:00 2001 From: Nitload Date: Thu, 23 Oct 2025 01:00:06 +0800 Subject: [PATCH] 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 --- .../Numeric/MatrixParallel.cs | 22 ++++----- .../Numeric/MatrixParallelPool.cs | 46 ++++++++++--------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/StgSharp.Mathematics/Numeric/MatrixParallel.cs b/StgSharp.Mathematics/Numeric/MatrixParallel.cs index 1f97cbf8..76d3834b 100644 --- a/StgSharp.Mathematics/Numeric/MatrixParallel.cs +++ b/StgSharp.Mathematics/Numeric/MatrixParallel.cs @@ -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 wraps) + public static void ReleaseParallelLeadership(ref MatrixParallelPool pool) { #if NET9_0_OR_GREATER #else Monitor.Exit(_lock); #endif - wraps = null!; + pool = null!; } #endregion diff --git a/StgSharp.Mathematics/Numeric/MatrixParallelPool.cs b/StgSharp.Mathematics/Numeric/MatrixParallelPool.cs index e464cf82..95b33973 100644 --- a/StgSharp.Mathematics/Numeric/MatrixParallelPool.cs +++ b/StgSharp.Mathematics/Numeric/MatrixParallelPool.cs @@ -1,27 +1,30 @@ //----------------------------------------------------------------------- // ----------------------------------------------------------------------- -// file="MatrixParallelPool" +// file="MatrixParallelPool.cs" // 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 -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, +// and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and +// this permission notice shall be included in all copies +// or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, +// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH +// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- @@ -42,13 +45,14 @@ namespace StgSharp.Mathematics.Numeric { throw new NotSupportedException(); } - + /* internal MatrixParallelPool(int threadCount, ReadOnlySpan wrapSpan) { SpareWrap = CapacityFixedStackBuilder.Create(wrapSpan); SingleThreadAllocation = new CapacityFixedBag(wrapSpan.Length); SpareThreadCount = threadCount; } + /**/ internal MatrixParallelPool(int threadCount, CapacityFixedStack wrapSpan) {