PDA

View Full Version : kernel function for cartesian product of two sets A and B



shahsaurabh1990
01-29-2013, 05:28 AM
I have written the kernel for computing the cartesian product of A and B
So my cartesian product will have elements where each element is a pair; first element of the pair i am storing in C and other i am storing in

A={0,1,2,3,4,5}
B={6,5,4,3,2,1}
_kernel void cartesian(__global int *A, __global int *B, __global int *C, __global int *D,int k)
{

// Get the index of the current element
int i = get_global_id(0); //this will get you the index
int j = get_global_id(1); //this will get you the other index

// Do the operation for producing the cartesian product
C[i]=A[i];
D[i]=B[j];

}
I am getting this
A Cartesian B ->
(0 , 0)
(1 , 1)
(2 , 2)
(3 , 3)
(4 , 4)
(5 , 5)
(6 , 6)
(7 , 7)
(8 , 8)
(9 , 9)
(10 , 10)
(11 , 11)
(12 , 12)
(13 , 13)
(14 , 14)
(15 , 15)
(16 , 16)
(17 , 17)
(18 , 18)
(19 , 19)
(20 , 20)
(21 , 21)
(22 , 22)
(23 , 23)
(24 , 24)
(25 , 25)
(26 , 26)
(27 , 27)
(28 , 28)
(29 , 29)
(30 , 30)
(31 , 31)
(32 , 32)
(33 , 33)
(34 , 34)
(35 , 35)

But the result should be
(0,1)
(0,2)
(0,3)
|
|
|

|
(5,6)

shahsaurabh1990
01-29-2013, 05:45 AM
what is the significance of 0 inside the brackets

utnapishtim
01-30-2013, 03:07 AM
Shouldn't it be something like:

C[i*n+j]=A[i]
D[i*n+j]=B[j]