Open main menu

CDOT Wiki β

Changes

TriForce

147 bytes added, 17:10, 15 March 2019
Assignment 2
bool SolveSudoku(int grid[N][N], int* d_a, int row, int col)
{
// If there is no unassigned location, we are done if (!FindUnassignedLocation(grid, row, col)) return true; // success! dim3 block(N, 3); int guess = 0; while (guess <= N) { makeGuess << <1, block >> > (d_a, guess, row, col); cudaMemcpy(&guess, d_a + row * N + col, sizeof(int), cudaMemcpyDeviceToHost); if (guess <= N && SolveSudoku(grid, d_a, row, col + 1)) return true; } //Erase the guess on the host int zero = UNASSIGNED; cudaMemcpy(d_a + row * N + col, &zero, sizeof(int), cudaMemcpyHostToDevice); return false; // this triggers backtracking
}
 
/* Searches the grid to find an entry that is still unassigned. If
found, the reference parameters row, col will be set the location
bool FindUnassignedLocation(int grid[N][N], int &row, int &col)
{
for (; row < N; ++row) { for (; col < N; ++col) if (grid[row][col] == UNASSIGNED) return true; col = 0; } return false;
}
 
/* A utility function to print grid */
void printGrid(int grid[N][N])