Daily update on 20250921-173333 by Nitload Youmu. Additional Message : New design of matrix enumeration, capable for parallel task publication.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -64,7 +64,7 @@ namespace StgSharp.Mathematics
|
||||
* we allow each wrap to contain either 3 or 4 threads, providing flexibility while maintaining efficiency.
|
||||
*/
|
||||
|
||||
internal static partial class MatrixParallel
|
||||
public static partial class MatrixParallel
|
||||
{
|
||||
|
||||
private static Thread[] _threads;
|
||||
@@ -167,7 +167,7 @@ namespace StgSharp.Mathematics
|
||||
{
|
||||
ResetThreadCount();
|
||||
foreach (MatrixParallelWrap item in _wraps) {
|
||||
_ = item.SchedulerReset.Set();
|
||||
item.SchedulerReset.Set();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,17 +176,17 @@ namespace StgSharp.Mathematics
|
||||
|
||||
private readonly Queue<IntPtr>[] _cache;
|
||||
private readonly Thread[] _threads;
|
||||
private readonly AutoResetEvent[] _workerReset;
|
||||
private readonly ManualResetEventSlim[] _workerReset;
|
||||
|
||||
public MatrixParallelWrap(int id, int wrapSize, bool isFirst)
|
||||
{
|
||||
ID = id;
|
||||
int begin = isFirst ? 1 : 0, end = wrapSize - 1;
|
||||
_cache = new Queue<IntPtr>[wrapSize];
|
||||
_workerReset = new AutoResetEvent[end];
|
||||
_workerReset = new ManualResetEventSlim[end];
|
||||
_threads = new Thread[wrapSize];
|
||||
for (int i = 0; i < end; i++) {
|
||||
_workerReset[i] = new AutoResetEvent(false);
|
||||
_workerReset[i] = new ManualResetEventSlim(false);
|
||||
}
|
||||
for (int i = 0; i < _cache.Length; i++) {
|
||||
_cache[i] = new Queue<IntPtr>(8);
|
||||
@@ -212,7 +212,7 @@ namespace StgSharp.Mathematics
|
||||
|
||||
public int ID { get; init; }
|
||||
|
||||
internal AutoResetEvent SchedulerReset { get; } = new(false);
|
||||
internal ManualResetEventSlim SchedulerReset { get; } = new(false);
|
||||
|
||||
public Span<IntPtr> EnqueuePackage(Span<IntPtr> packageSpan)
|
||||
{
|
||||
@@ -224,7 +224,7 @@ namespace StgSharp.Mathematics
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AutoResetEvent GetWorkerResetEvent(int id)
|
||||
public ManualResetEventSlim GetWorkerResetEvent(int id)
|
||||
{
|
||||
return _workerReset[id];
|
||||
}
|
||||
@@ -238,8 +238,8 @@ namespace StgSharp.Mathematics
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetAllWorker()
|
||||
{
|
||||
foreach (AutoResetEvent item in _workerReset) {
|
||||
_ = item.Set();
|
||||
foreach (ManualResetEventSlim item in _workerReset) {
|
||||
item.Set();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,10 +253,11 @@ namespace StgSharp.Mathematics
|
||||
MatrixParallelWrap wrap = handle.Wrap;
|
||||
int inWrapIndex = handle.InWrapIndex;
|
||||
Thread self = Thread.CurrentThread;
|
||||
AutoResetEvent reset = wrap.GetWorkerResetEvent(inWrapIndex);
|
||||
ManualResetEventSlim reset = wrap.GetWorkerResetEvent(inWrapIndex);
|
||||
do
|
||||
{
|
||||
_ = reset.WaitOne();
|
||||
reset.Wait();
|
||||
reset.Reset();
|
||||
self.Priority = ThreadPriority.Highest;
|
||||
ExecuteTaskPackage(wrap.GetWorkerTaskQueue(inWrapIndex));
|
||||
_ = Interlocked.Decrement(ref RemainThreadCount);
|
||||
@@ -270,11 +271,12 @@ namespace StgSharp.Mathematics
|
||||
MatrixParallelWrap wrap = handle.Wrap;
|
||||
int inWrapIndex = handle.InWrapIndex;
|
||||
Queue<IntPtr> taskQueue = wrap.GetWorkerTaskQueue(inWrapIndex);
|
||||
AutoResetEvent resetEvent = wrap.SchedulerReset;
|
||||
ManualResetEventSlim resetEvent = wrap.SchedulerReset;
|
||||
Thread self = Thread.CurrentThread;
|
||||
do
|
||||
{
|
||||
_ = resetEvent.WaitOne();
|
||||
resetEvent.Wait();
|
||||
resetEvent.Reset();
|
||||
self.Priority = ThreadPriority.Highest;
|
||||
|
||||
// TODO task publication to worker in wrap
|
||||
@@ -290,7 +292,7 @@ namespace StgSharp.Mathematics
|
||||
{
|
||||
while (taskQueue.TryDequeue(out nint handle))
|
||||
{
|
||||
MatrixParallelTaskPackage* p = (MatrixParallelTaskPackage*)handle;
|
||||
MatrixParallelTaskPackageNonGeneric* p = (MatrixParallelTaskPackageNonGeneric*)handle;
|
||||
switch (p->ComputeMode)
|
||||
{
|
||||
case 1:
|
||||
|
||||
Reference in New Issue
Block a user