no progress in matrix parallel
This commit is contained in:
@@ -45,23 +45,24 @@ namespace StgSharp.Mathematics
|
||||
internal static class MatrixParallel
|
||||
{
|
||||
|
||||
private static Thread[] _threads;
|
||||
private static Channel<IntPtr> _taskChannel = Channel.CreateUnbounded<IntPtr>();
|
||||
private static readonly Channel<IntPtr> _taskChannel = Channel.CreateUnbounded<IntPtr>();
|
||||
private static int _paraState;
|
||||
|
||||
private static IReadOnlyList<Thread> _threads;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
int count = Environment.ProcessorCount - 4;
|
||||
count = count < 0 ? 1 : count;
|
||||
_threads = new Thread[count];
|
||||
Interlocked.Exchange(ref _paraState, 1);
|
||||
List<Thread> _t = new(count);
|
||||
_threads = _t;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
_threads[i] = new(MatrixParallelCycle)
|
||||
{
|
||||
IsBackground = true
|
||||
};
|
||||
_threads[i].Start();
|
||||
_t.Add(new(MatrixParallelCycle)
|
||||
{
|
||||
IsBackground = true
|
||||
});
|
||||
_t[i].Start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,13 +76,8 @@ namespace StgSharp.Mathematics
|
||||
private static unsafe void MatrixParallelCycle()
|
||||
{
|
||||
Thread t_cur = Thread.CurrentThread;
|
||||
while (_taskChannel.Reader.TryRead(out IntPtr ptr))
|
||||
{
|
||||
MatrixParallelTask* taskHandle = (MatrixParallelTask*)ptr;
|
||||
|
||||
// Execute the task directly
|
||||
taskHandle->Execute();
|
||||
}
|
||||
int index = _threads.ToList().IndexOf(t_cur);
|
||||
while (_taskChannel.Reader.TryRead(out IntPtr ptr)) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user