buffer op and parallel framework is now on full complete

This commit is contained in:
Youmu Liu
2025-11-20 17:50:06 +08:00
parent c595076005
commit 28bdc42982
6 changed files with 88 additions and 51 deletions
@@ -67,7 +67,8 @@ namespace StgSharp.Mathematics.Numeric
int primCount = package->PrimCount;
int secCount = package->SecCount;
long count = (long)primCount * secCount;
Console.WriteLine($"amount of kernels is {count}");
// Console.WriteLine($"amount of kernels is {count}");
long recommendCount = count / 1024;
MatrixParallelThread[] pool = LeadParallel((int)recommendCount);
@@ -103,9 +104,9 @@ namespace StgSharp.Mathematics.Numeric
lengthRef = length;
wrap.WrapTask.Enqueue((nint) current);
Console.WriteLine($"Offset is {offset}");
Console.WriteLine($"Scheduling {length} kernels into {wrap.WrapTaskCapacity} threads");
Console.WriteLine();
// Console.WriteLine($"Offset is {offset}");
// Console.WriteLine($"Scheduling {length} kernels into {wrap.WrapTaskCapacity} threads");
// Console.WriteLine();
current = MatrixParallelFactory.FromExistPackage(current);
offset += length;
}
@@ -253,11 +253,11 @@ namespace StgSharp.Mathematics.Numeric
// Console.WriteLine("worker end");
break;
case RoleType.Scheduler://scheduler
Console.WriteLine("scheduler start");
// Console.WriteLine("scheduler start");
BindedWrap.PublishTaskToWorkers();
BindedWrap.SetAllWorker();
Console.WriteLine("scheduler done");
// Console.WriteLine("scheduler done");
ExecuteTaskPackage(Tasks);
BindedWrap.ReportThreadAccomplished();
BindedWrap.WaitAllWorker();
@@ -416,7 +416,15 @@ namespace StgSharp.Mathematics.Numeric
internal Queue<IntPtr> Tasks { get; } = [];
public RoleType Role { get; internal set; }
public RoleType Role
{
get;
internal set
{
// Console.WriteLine($"Thread {_managedThread.ManagedThreadId} set to {value}, from thread {Environment.CurrentManagedThreadId}");
field = value;
}
}
public enum RoleType : int
{
@@ -141,9 +141,11 @@ namespace StgSharp.Mathematics.Numeric
long offset = 0;
MatrixParallelTaskPackage* current = package;
/*
string msg = $"""
Total: count={count}, length={Threads.Length}{Environment.NewLine}
""";
/**/
foreach (MatrixParallelThread thread in pool)
{
long wrapTaskLength = actual;
@@ -155,14 +157,16 @@ namespace StgSharp.Mathematics.Numeric
ref long lengthRef = ref Unsafe.As<int, long>(ref current->PrimCount);
lengthRef = length;
thread.Tasks.Enqueue((nint)current);
/*
msg += $"""
Slice to thread: total offset={offsetRef} local offset={offset}, length={lengthRef}{Environment.NewLine}
""";
/**/
current = MatrixParallelFactory.FromExistPackage(current);
offset = length;
}
Console.WriteLine(msg);
// Console.WriteLine(msg);
}
private void PublishKernelTaskToWorkers(MatrixParallelTaskPackage* package)