Changes

Jump to: navigation, search

The parallelizing Express

1,254 bytes added, 16:43, 18 February 2017
SudokuMP by Marko R
0.00 7.43 0.00 24 0.00 0.00 std::__deque_buf_size(unsigned long)
==== Analysis / Code Snippet ====
 
The two functions which dominate the runtime of this program are create_copy_board which accounts for roughly 60% or more of the exceution time and choose_cell_bf which accounts for another 20% generally.
<pre>
Board* create_copy_board(Board* b){
Board* copy_board = new Board(b->dim);
for(int row = 0; row < b->dim; row++) {
for(int col = 0; col < b->dim; col++) {
copy_board->solution[row][col] = b->solution[row][col];
for(int index = 0; index < b->dim; index++) {
copy_board->cells[row][col][index] = b->cells[row][col][index];
}
}
}
copy_board->cells_solved = b->cells_solved;
return copy_board;
}
 
/* Choose cell with the least number of possible values
* Return 0 if that cell has 0 values
*/
bool choose_cell_bf(Board* b, int &row, int &col) {
int least = b->dim+1, counter;
for(int r = 0; r < b->dim; r++) {
for(int c = 0; c < b->dim; c++) {
counter = 0;
if(!b->solution[r][c]) {
for(int num = 0; num < b->dim; num++) {
if(b->cells[r][c][num]) {
counter++;
}
}
if(counter < least) {
least = counter;
row = r;
col = c;
}
}
}
}
return (least != 0);
}
</pre>
----
94
edits

Navigation menu