diff --git a/nqueens_chpl.chpl b/nqueens_chpl.chpl index 2ea9cbe1ff07d61b7afc814aa6e0109464d60bf6..05d96da40009d337cae49ef0359d14bddf77e400 100644 --- a/nqueens_chpl.chpl +++ b/nqueens_chpl.chpl @@ -6,7 +6,6 @@ use Time; use util; use Pool; - use NQueens_node; /******************************************************************************* @@ -68,22 +67,23 @@ proc isSafe(const board, const queen_num, const row_pos): uint(8) } // Evaluate and generate children nodes on CPU. -proc decompose(const parent: Node, ref tree_loc: uint, ref num_sol: uint, ref pool: SinglePool(Node)) +proc decompose(const parent: Node, ref tree_loc: uint, ref num_sol: uint, ref pool) { const depth = parent.depth; if (depth == N) { num_sol += 1; } - for j in depth..(N-1) { - if isSafe(parent.board, depth, parent.board[j]) { - var child = new Node(); - child.depth = parent.depth; - child.board = parent.board; - child.board[depth] <=> child.board[j]; - child.depth += 1; - pool.pushBack(child); - tree_loc += 1; + else { + for j in depth..(N-1) { + if isSafe(parent.board, depth, parent.board[j]) { + var child = new Node(); + child.depth = depth + 1; + child.board = parent.board; + child.board[depth] <=> child.board[j]; + pool.pushBack(child); + tree_loc += 1; + } } } } @@ -94,7 +94,6 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi var root = new Node(N); var pool = new SinglePool(Node); - pool.pushBack(root); var timer: stopwatch; diff --git a/nqueens_multigpu_chpl.chpl b/nqueens_multigpu_chpl.chpl index 2932def0eea65244f6d6382362c869407393bf00..70cfd1781733a1fc7700e6fb93dc906e44f49169 100644 --- a/nqueens_multigpu_chpl.chpl +++ b/nqueens_multigpu_chpl.chpl @@ -88,7 +88,7 @@ proc decompose(const parent: Node, ref tree_loc: uint, ref num_sol: uint, ref po child.depth = depth + 1; child.board = parent.board; child.board[depth] <=> child.board[j]; - pool.pushBack(child); + pool.pushBackFree(child); tree_loc += 1; } } @@ -162,9 +162,6 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi var pool = new SinglePool_par(Node); pool.pushBack(root); - var allTasksIdleFlag: atomic bool = false; - var eachTaskState: [0..#D] atomic bool = BUSY; // one task per GPU - var timer: stopwatch; /* @@ -196,12 +193,13 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi timer.start(); var eachExploredTree, eachExploredSol: [0..#D] uint; + var eachTaskState: [0..#D] atomic bool = BUSY; // one task per GPU + var allTasksIdleFlag: atomic bool = false; const poolSize = pool.size; const c = poolSize / D; const l = poolSize - (D-1)*c; const f = pool.front; - var lock: atomic bool; pool.front = 0; pool.size = 0; @@ -254,7 +252,7 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi generate_children(parents, poolSize, labels, tree, sol, pool_loc); } else { - // work stealing + // work stealing attempts var tries = 0; var steal = false; const victims = permute(0..#D); @@ -296,6 +294,7 @@ proc nqueens_search(ref exploredTree: uint, ref exploredSol: uint, ref elapsedTi } tries += 1; } + if (steal == false) { // termination if (taskState == BUSY) {