Hello,
maybe this is too obvious, but I don’t see it:
I want to iterate over a single array and process all possible combinations of pairs from it.
In C I would do it with a nested loop:
int* a = someArray();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int num1 = a[i];
int num2 = a[j];
doComputation(num1, num2);
}
}
Now I want to simulate this using OpenCL.
My first naive assumption was that could enqueue my kernel using n as size and 2 as dimension like:
queue.enqueueNDRangeKernel(kernel, cl::NullRange, cl::NDRange(n, n), cl::NullRange, NULL, &event);
and then do this in my kernel
__kernel void
doComputation(__global int* a) {
int id1 = get_global_id(0);
int id2 = get_global_id(1);
int num1 = a[id1];
int num2 = a[id2];
//do the actual computation
}
However, I get unexpected results since id1 and id2 seem to be multiples of n instead of iterating over the range [1,n].
What did I not understand?
Thanks and regards,
Sebastian Mecklenburg