i have the next task: write opencl program, which will sort massive using odd-even sort method. i wrote it, but have some troubles and i don't know how to solve it because i'm new in opencl
here is my kernel code:
const char* kernelSource =
"__kernel void odd_even_sort(__global ulong * arr, const unsigned int n) {\n"
" unsigned int id = get_global_id(0);\n"
" for (unsigned int phase = 0; phase < n; phase++) {\n"
" unsigned int swap_idx;\n"
" if (phase % 2 == 0) {\n"
" swap_idx = id * 2;\n"
" }\n"
" else {\n"
" swap_idx = id * 2 + 1;\n"
" }\n"
" if (swap_idx + 1 < n) {\n"
" if (arr[swap_idx] > arr[swap_idx + 1]) {\n"
" ulong temp = arr[swap_idx];\n"
" arr[swap_idx] = arr[swap_idx + 1];\n"
" arr[swap_idx + 1] = temp;\n"
" }\n"
" }\n"
" barrier(CLK_GLOBAL_MEM_FENCE);\n"
" }\n"
"}\n";
and here is how i run it:
clSetKernelArg(kernel, 0, sizeof(cl_mem), (cl_ulong*)&A_mem);
clSetKernelArg(kernel, 1, sizeof(unsigned int), &nums);
size_t global_work_size = nums / 2;
ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, NULL, 0, NULL, NULL);
nums is the length of massive, it is a power of 2
i don't know why, but when i try to print sorted massive, i can't find some numbers from the unsorted. instead of these numbers there can be dublicates of random numbers, here is the example:
the unsorted massive is guaranteed to contain no duplicate numbers.
there may also be a problem that the number is out of place (example with another array):
i hope for someone's help