use a awaiting handle to wrap all resource from task publish
This commit is contained in:
@@ -65,6 +65,8 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
Stack<MatrixParallelWrap> taskGroup = MatrixParallel.PublicTask(left.GetColumnEnumeration(), right.GetColumnEnumeration(), ans.GetColumnEnumeration(),
|
Stack<MatrixParallelWrap> taskGroup = MatrixParallel.PublicTask(left.GetColumnEnumeration(), right.GetColumnEnumeration(), ans.GetColumnEnumeration(),
|
||||||
(delegate*<MatrixKernel<float>*, MatrixKernel<float>*, MatrixKernel<float>*, void>)NativeIntrinsic.Intrinsic.f32_add);
|
(delegate*<MatrixKernel<float>*, MatrixKernel<float>*, MatrixKernel<float>*, void>)NativeIntrinsic.Intrinsic.f32_add);
|
||||||
|
|
||||||
|
MatrixParallel.LaunchParallel(taskGroup, SleepMode.DeepSleep);
|
||||||
/*
|
/*
|
||||||
* run parallel
|
* run parallel
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel"
|
// file="MatrixParallel"
|
||||||
// Project: StgSharp
|
// Project: StgSharp
|
||||||
// AuthorGroup: Nitload Space
|
// AuthorGroup: Nitload
|
||||||
// Copyright (c) Nitload Space. All rights reserved.
|
// Copyright (c) Nitload. All rights reserved.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -55,7 +55,8 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
{
|
{
|
||||||
|
|
||||||
private static Thread[] _threads;
|
private static Thread[] _threads;
|
||||||
private static readonly (int a, int b)[] LookupTable = [ (1, 1), // 7
|
private static readonly (int a, int b)[] LookupTable = [
|
||||||
|
(1, 1), // 7
|
||||||
(0, 2), // 8 (no non-zero solution)
|
(0, 2), // 8 (no non-zero solution)
|
||||||
(3, 0), // 9 (no non-zero solution)
|
(3, 0), // 9 (no non-zero solution)
|
||||||
(2, 1), // 10
|
(2, 1), // 10
|
||||||
@@ -133,7 +134,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
}
|
}
|
||||||
} else if (count == 6)
|
} else if (count == 6)
|
||||||
{
|
{
|
||||||
Pool = new(6, [ new MatrixParallelWrap(0, 3), new MatrixParallelWrap(3, 3) ]);
|
Pool = new(6, [
|
||||||
|
new MatrixParallelWrap(0, 3),
|
||||||
|
new MatrixParallelWrap(3, 3)
|
||||||
|
]);
|
||||||
(LargeWrapCount, SmallWrapCount) = (0, 2);
|
(LargeWrapCount, SmallWrapCount) = (0, 2);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@@ -155,7 +159,10 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
{
|
{
|
||||||
RemainThreadCount = _threads.Length;
|
RemainThreadCount = _threads.Length;
|
||||||
_AfterWork = (ThreadPriority)afterWork;
|
_AfterWork = (ThreadPriority)afterWork;
|
||||||
SetAllWrap(wraps);
|
ResetThreadCount();
|
||||||
|
foreach (MatrixParallelWrap w in wraps) {
|
||||||
|
w.SchedulerReset.Set();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -171,14 +178,6 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
RemainThreadCount = _threads.Length;
|
RemainThreadCount = _threads.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetAllWrap(IEnumerable<MatrixParallelWrap> wraps)
|
|
||||||
{
|
|
||||||
ResetThreadCount();
|
|
||||||
foreach (MatrixParallelWrap item in wraps) {
|
|
||||||
item.SchedulerReset.Set();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region wrap field
|
#region wrap field
|
||||||
|
|
||||||
private static MatrixParallelPool Pool;
|
private static MatrixParallelPool Pool;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
using StgSharp.HighPerformance;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -216,4 +217,18 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
DeepSleep = ThreadPriority.Lowest,
|
DeepSleep = ThreadPriority.Lowest,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MatrixComputeResource
|
||||||
|
{
|
||||||
|
|
||||||
|
public IEnumerable<MatrixParallelWrap> Wraps { get; set; }
|
||||||
|
|
||||||
|
public int WorkingThreadCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closure task leader should do to collect results.
|
||||||
|
/// </summary>
|
||||||
|
public unsafe IntPtr LeaderClosurePackage { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user