working on dynamic wrapping, a good awaiting is on way

This commit is contained in:
Youmu Liu
2025-11-07 18:22:50 +08:00
parent ec1b8dbd51
commit f959339e18
16 changed files with 447 additions and 355 deletions
@@ -78,6 +78,17 @@ namespace StgSharp.Mathematics.Numeric
}
}
internal IEnumerable<MatrixParallelWrap> Wraps
{
get
{
if (_disposed) {
throw new ObjectDisposedException(typeof(MatrixParallelHandle).Name);
}
return _wraps;
}
}
internal ReadOnlySpan<MatrixParallelThread> ThreadsUnsafe
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -91,10 +102,16 @@ namespace StgSharp.Mathematics.Numeric
if (_disposed) {
return;
}
MatrixParallel.ReleaseParallelLeadership(ref _threads);
MatrixParallel.ReturnParallelResources(ref _threads);
_disposed = true;
}
public MatrixParallelThread GetLeader()
{
Threads[0].Role = 2;
return Threads[0];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static (int count_3, int count_4) FastDecompose(int c)
{
@@ -139,11 +156,22 @@ namespace StgSharp.Mathematics.Numeric
int count = _threads.Length;
if (count < 6)
{
MatrixParallelWrap wrap = new MatrixParallelWrap(_threads);
MatrixParallelWrap wrap = new MatrixParallelWrap(_threads, 0, count);
_wraps = [ wrap ];
}
(int c3,int c4) = FastDecompose(_threads.Length);
_wraps = new(c3 + c4);
int begin = 0;
for (int i = 0; i < c3; i++)
{
_wraps.Push(new MatrixParallelWrap(_threads, begin, 3));
begin += 3;
}
for (int i = 0; i < c4; i++)
{
_wraps.Push(new MatrixParallelWrap(_threads, begin, 4));
begin += 4;
}
}
}