Remove all concurrency code

Muddled the code too much, and only gave a marginal performance improvement in the grand scheme of things. Other ways to parallelize MCTS will be nicer to implement and could yield better results.
This commit is contained in:
Asriel Camora
2023-07-07 20:17:35 +02:00
parent 3ab50d389e
commit 636501ab86
11 changed files with 153 additions and 431 deletions
+6 -27
View File
@@ -11,41 +11,20 @@ public struct ArenaBuffer<T> where T : struct
// The benchmark reaches 20 at most, but here we have a little leeway just in case.
private const int MaxSize = 24;
private static int BatchSize = Vector<float>.Count;
private static int BatchSizeBits = int.Log2(BatchSize);
private static int BatchSizeMask = BatchSize - 1;
private static readonly int BatchSize = Vector<float>.Count;
private static readonly int BatchSizeBits = int.Log2(BatchSize);
private static readonly int BatchSizeMask = BatchSize - 1;
private static int BatchCount = MaxSize / BatchSize;
private static readonly int BatchCount = MaxSize / BatchSize;
public ArenaNode<T>[][] Data;
private int index; // Unused in single threaded workload
private int count;
public readonly int Count => count;
public void AddConcurrent(ArenaNode<T> node)
{
if (Data == null)
Interlocked.CompareExchange(ref Data, new ArenaNode<T>[BatchCount][], null);
var idx = Interlocked.Increment(ref index) - 1;
var (arrayIdx, subIdx) = GetArrayIndex(idx);
if (Data[arrayIdx] == null)
Interlocked.CompareExchange(ref Data[arrayIdx], new ArenaNode<T>[BatchSize], null);
node.ChildIdx = (arrayIdx, subIdx);
Data[arrayIdx][subIdx] = node;
Interlocked.Increment(ref count);
}
public int Count { get; private set; }
public void Add(ArenaNode<T> node)
{
Data ??= new ArenaNode<T>[BatchCount][];
var idx = count++;
var idx = Count++;
var (arrayIdx, subIdx) = GetArrayIndex(idx);