This commit is contained in:
Youmu Liu
2025-09-26 20:45:28 +08:00
parent 0cafe9fd4d
commit 003f9d272e
3 changed files with 46 additions and 35 deletions
@@ -28,22 +28,11 @@
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.HighPerformance.Memory;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO.Pipes;
using System.Linq;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace StgSharp.Mathematics
{
@@ -68,7 +57,6 @@ namespace StgSharp.Mathematics
{
private static Thread[] _threads;
private static MatrixParallelWrap[] _wraps;
private static readonly (int a, int b)[] LookupTable = [
(1, 1),
(0, 2),
@@ -87,9 +75,7 @@ namespace StgSharp.Mathematics
];
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;
@@ -139,25 +125,37 @@ namespace StgSharp.Mathematics
_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);
if (count == 3)
{
SmallWraps = [ new MatrixParallelWrap(0, count, true) ];
LargeWraps = [];
(LargeWrapCount, SmallWrapCount) = (1, 0);
} else
{
count = 4;
LargeWraps = [ new MatrixParallelWrap(0, count, true) ];
SmallWraps = [];
(LargeWrapCount, SmallWrapCount) = (0, 1);
}
} else if (count == 6)
{
_wraps = [
SmallWraps = [
new MatrixParallelWrap(0, 3, true),
new MatrixParallelWrap(3, 3, false)
];
LargeWraps = [];
(LargeWrapCount, SmallWrapCount) = (0, 2);
} else
{
(int _3wrap, int _4wrap) = FastDecompose(count);
_wraps = new MatrixParallelWrap[_3wrap + _4wrap];
int id = 0, idx = 0;
for (; idx < _3wrap; idx++, id += 3) {
_wraps[idx] = new MatrixParallelWrap(idx, 3, id == 0);
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);
}
for (; idx < _3wrap + _4wrap; idx++, id += 4) {
_wraps[idx] = new MatrixParallelWrap(id, 4, id == 0);
for (int idx = 0; idx < _3wrap + _4wrap; idx++, id += 4) {
LargeWraps[idx] = new MatrixParallelWrap(id, 4, id == 0);
}
}
LeaderHandle = new MatrixParallelWrap.Handle(0, _wraps[0]);
@@ -344,6 +342,14 @@ namespace StgSharp.Mathematics
#endregion
}
#region wrap field
private static MatrixParallelWrap[] LargeWraps;
private static MatrixParallelWrap[] SmallWraps;
private static int LargeWrapCount;
private static int SmallWrapCount;
#endregion
}
public enum SleepMode