Hi all,

I am computing prefix sum using ScanLargeArrays sample in SDK of a large array containing 1s and 0s lets say {1,0,0,1,1,0,0,0,0,0,1,1,0,1,1,1} so after prefix sum, output is {0,1,1,1,2,3,3,3,3,3,3,4,5,5,6,7}. Is there a way to determine the number of distinct elements in this prefixed sum array inside any of the 3 kernels in this sample? either counting 1s in input array (somehow in scanLargeArray kernel) or distinct elements in final array (somehow in blockAddition kernel)?

Lets assume that number of 1s and 0s are not known beforehand in cpu and these distinct elements are to be determined inside kernel as the array size is in millions.

Thank you.

>> Is there a way to determine the number of distinct elements in this prefixed sum array inside any of the 3 kernels in this sample?

Just check the last number in the array... Say it is N..

Then you have 0, 1, 2, until N.

Thats all it is.

Create another kernel with N+1 threads which will write the global_id() into the same location in another buffer.

So, that buffer would contain all the distinct elements in the prefixed-sum array.

So simple.... (or) Did I misread your question?