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