# Combinatorics?

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

Wah!
My array was actually a char array. It was given to the kernel as int*, so a[1] would actually access the fifth byte instead of the second one. D’oh.
I happened to test this with n == 4 so I thought it would access indexes at multiples of n, but they were always multiples of four of course, regardless of n.

Thanks and regards,
Sebastian Mecklenburg