Brief solution for publishing, debuging
This commit is contained in:
@@ -1,30 +1,27 @@
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel.Execute.cs"
|
// file="MatrixParallel.Execute"
|
||||||
// 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
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// obtaining a copy of this software and associated documentation
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
// files (the “Software”), to deal in the Software without restriction,
|
// in the Software without restriction, including without limitation the rights
|
||||||
// including without limitation the rights to use, copy, modify, merge,
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
// and to permit persons to whom the Software is furnished to do so,
|
// furnished to do so, subject to the following conditions:
|
||||||
// subject to the following conditions:
|
|
||||||
//
|
//
|
||||||
// The above copyright notice and
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
// this permission notice shall be included in all copies
|
// copies or substantial portions of the Software.
|
||||||
// or substantial portions of the Software.
|
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
// SOFTWARE.
|
||||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
//
|
//
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// file="MatrixParallel.Publish"
|
// file="MatrixParallel.Publish"
|
||||||
// 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
|
||||||
@@ -812,7 +812,7 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
PublicTaskPrivate<T>(package);
|
PublicTaskPrivate<T>(package);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static unsafe void PublicTaskPrivate<T>(MatrixParallelTaskPackage<T>* package)
|
private static unsafe Stack<MatrixParallelWrap> PublicTaskPrivate<T>(MatrixParallelTaskPackage<T>* package)
|
||||||
where T: unmanaged, INumber<T>
|
where T: unmanaged, INumber<T>
|
||||||
{
|
{
|
||||||
int primCount = package->PrimCount;
|
int primCount = package->PrimCount;
|
||||||
@@ -822,25 +822,42 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
CapacityFixedStack<MatrixParallelWrap> wraps = LeadParallel();
|
CapacityFixedStack<MatrixParallelWrap> wraps = LeadParallel();
|
||||||
|
|
||||||
int tilePerThreadLess = tileCount / Wraps.Count;
|
int tilePerThreadLess = tileCount / wraps.Count;
|
||||||
int tileToSlice = tileCount % Wraps.Count;
|
int tileToSlice = tileCount % wraps.Count;
|
||||||
int slicingPerWrap = tileToSlice / Wraps.Count;
|
int slicingPerWrap = tileToSlice / wraps.Count;
|
||||||
int extraTiles = tileToSlice % Wraps.Count;
|
int extraTiles = tileToSlice % wraps.Count;
|
||||||
|
|
||||||
int total = tileCount;
|
int total = tileCount;
|
||||||
List<MatrixParallelWrap> w = new List<MatrixParallelWrap>(Wraps.Count);
|
int begin = 0;
|
||||||
|
Stack<MatrixParallelWrap> taskBunch = new Stack<MatrixParallelWrap>(wraps.Count);
|
||||||
int baseTile = 0;
|
while (tileCount > 0)
|
||||||
|
|
||||||
// TODO 干脆用四个掩码分别表示各种部分算了。
|
|
||||||
for (int i = 0; i < Wraps.Count; i++)
|
|
||||||
{
|
{
|
||||||
MatrixParallelWrap wrap = Wraps.Pop();
|
MatrixParallelWrap wrap = wraps.Pop();
|
||||||
wrap.WrapTask = (MatrixParallelTaskPackageNonGeneric*)package;
|
bool hasSlice = tileToSlice > 0;
|
||||||
wrap.WrapTaskCapacity = tilePerThreadLess + (i < extraTiles ? 1 : 0);
|
bool isLargeSlice = extraTiles > 0;
|
||||||
wrap.WrapTaskSliceCount = (i * tilePerThreadLess) + Math.Min(i, extraTiles);
|
|
||||||
w.Add(wrap);
|
// count tiles for wrap
|
||||||
|
int toSlice = wrap.WrapTaskCapacity * slicingPerWrap;
|
||||||
|
int baseTile = wrap.WrapTaskCapacity * tilePerThreadLess;
|
||||||
|
int tileInWrap = baseTile + toSlice + (isLargeSlice ? 1 : 0);
|
||||||
|
int columnInWrap = tileInWrap * tileWidth;
|
||||||
|
|
||||||
|
// set tasks
|
||||||
|
MatrixParallelTaskPackage<T>* task = MatrixParallelFactory.FromExistPackage(package);
|
||||||
|
wrap.WrapTask = (MatrixParallelTaskPackageNonGeneric*)task;
|
||||||
|
task->LeftPrimOffset += columnInWrap;
|
||||||
|
task->PrimCount = columnInWrap;
|
||||||
|
|
||||||
|
// remove tiles count
|
||||||
|
extraTiles--;
|
||||||
|
tileToSlice -= toSlice;
|
||||||
|
tileCount -= tileInWrap;
|
||||||
|
begin += tileInWrap;
|
||||||
|
taskBunch.Push(wrap);
|
||||||
}
|
}
|
||||||
|
ReleaseParallelLeadership(ref wraps);
|
||||||
|
|
||||||
|
return taskBunch;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,7 +269,11 @@ namespace StgSharp.Mathematics.Numeric
|
|||||||
|
|
||||||
internal int WrapTaskSliceCount { get; set; }
|
internal int WrapTaskSliceCount { get; set; }
|
||||||
|
|
||||||
internal int WrapTaskCapacity { get; set; }
|
internal int WrapTaskCapacity
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => _threads.Length;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user