PDA

View Full Version : reg sudoku problem



paviraj_1989
04-25-2011, 11:19 PM
Hello,

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))"\
"{"\
"res[0]=0;"\
"return;"\
"}"\
"res[0]=1;"\
"return;"\
"}"

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

HolyGeneralK
04-26-2011, 12:17 PM
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.