Skip to content
Snippets Groups Projects
Commit 29b58696 authored by Guillaume-Helbecque's avatar Guillaume-Helbecque
Browse files

lock pool once for all children

parent a3947840
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,18 @@ module Pool_par
this.lock = false;
}
proc ref acquireLock() {
while true {
if this.lock.compareAndSwap(false, true) {
return;
}
}
}
proc ref releaseLock() {
this.lock.write(false);
}
// Parallel-safe insertion to the end of the deque.
proc ref pushBack(node: eltType) {
while true {
......@@ -44,6 +56,16 @@ module Pool_par
}
}
proc ref pushBackFree(node: eltType) {
if (this.front + this.size >= this.capacity) {
this.capacity *= 2;
this.dom = {0..#this.capacity};
}
this.elements[this.front + this.size] = node;
this.size += 1;
}
// Insertion to the end of the deque. Parallel-safety is not guaranteed.
proc ref pushBackFree(node: eltType) {
if (this.front + this.size >= this.capacity) {
......
......@@ -126,6 +126,8 @@ proc evaluate_gpu(const parents_d: [] Node, const size, ref labels_d)
proc generate_children(const ref parents: [] Node, const size: int, const ref labels: [] uint(8),
ref exploredTree: uint, ref exploredSol: uint, ref pool)
{
pool.acquireLock();
for i in 0..#size {
const parent = parents[i];
const depth = parent.depth;
......@@ -139,11 +141,13 @@ proc generate_children(const ref parents: [] Node, const size: int, const ref la
child.depth = depth + 1;
child.board = parent.board;
child.board[depth] <=> child.board[j];
pool.pushBack(child);
pool.pushBackFree(child);
exploredTree += 1;
}
}
}
pool.releaseLock();
}
// Multi-GPU N-Queens search.
......@@ -318,15 +322,12 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi
}
}
if lock.compareAndSwap(false, true) {
const poolLocSize = pool_loc.size;
for p in 0..#poolLocSize {
var hasWork = 0;
pool.pushBack(pool_loc.popBack(hasWork));
if !hasWork then break;
}
lock.write(false);
}
eachExploredTree[gpuID] = tree;
eachExploredSol[gpuID] = sol;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment