reg sudoku problem


This my serial code.
bool NumberFits(int sudoku[], int i, int j) {
/* place number j in sudoku-field i /
int x, y;
int line;
int squareX, squareY; /
coordinates of subsquare */

x = i % cCount;//col
y = i / cCount;//row

/* checks for equals in rows and columns */
for (line = 0; line < cCount; line ++)// want to parallelise this loop
if (sudoku[x + line * cCount] == j) return false;
if (sudoku[line + y * cCount] == j) return false;

Here is my kernel function for serial code above

“__kernel void NumberFits(int i, int j,int cCount,__global const int *sudoku,__global int *res){”
“int x, y, squareX, squareY,k;”
“x = i % cCount;”
“y = i / cCount;”
“int line=get_global_id(0);”
“if((sudoku[line + y * cCount] == j) || (sudoku[x + line * cCount]==j))”

But res[0] is getting overwritten
is there any bug in this kernel function??

Your code is not buggy - it’s just not written correctly.
Each work item is writing to the same location in res. Thus, the last work item to finish will be writing the last value to it.

What I’d suggest is to use get_local_id() or get_global_id() to give yourself your correct location and make your write of res[] to be dependent on this.