From b07013a0030d3b3f537974ee2bc82d3d2d89e179 Mon Sep 17 00:00:00 2001 From: Youmu Liu <105042599+Nitload-NSI@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:01:28 +0800 Subject: [PATCH] find a way to create Thread binded to LogicalCore properly --- .../ProcessorAbstraction/Numa.cs | 19 +++++++++++++++++++ .../Numeric/Runtime/MatrixParallel.Numa.cs | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/StgSharp.Common/HighPerformance/ProcessorAbstraction/Numa.cs b/StgSharp.Common/HighPerformance/ProcessorAbstraction/Numa.cs index d4e6be0d..cad7f59f 100644 --- a/StgSharp.Common/HighPerformance/ProcessorAbstraction/Numa.cs +++ b/StgSharp.Common/HighPerformance/ProcessorAbstraction/Numa.cs @@ -59,6 +59,25 @@ namespace StgSharp.Common.HighPerformance.ProcessorAbstraction return NumaAllocNative(size, numaId); } + public static T[][] CreateForeachThread( + Func factory + ) + { + if (factory is null) { + return []; + } + T[][] arr = new T[_numaNodes.Length][]; + foreach (NumaNode node in _numaNodes) + { + T[] values = new T[node.LogicalCoreCount]; + ReadOnlySpan cores = node.LogicalCores; + for (int i = 0; i < cores.Length; i++) { + values[i] = factory(cores[i]); + } + } + return arr; + } + public static unsafe void Free( void* address, int numaId, diff --git a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.Numa.cs b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.Numa.cs index 73cc78fe..33b03ef4 100644 --- a/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.Numa.cs +++ b/StgSharp.Mathematics/Numeric/Runtime/MatrixParallel.Numa.cs @@ -37,7 +37,7 @@ namespace StgSharp.Mathematics.Numeric { private static int[] NumaPayload; - private static MatrixParallelThread[,] NumaThreads; + private static MatrixParallelThread[][] NumaThreads; private static void UpdateThreadPayload() {