假设我想使用GPU在大小为2 ^ L的未排序1D数组中搜索特定值,其中L是正整数。数组中的所有值都是唯一。 是否可以使用并行缩减(乒乓技术)将搜索结果减少为单个数字?
我的直觉告诉我这是可能的,但我不知道如何开始。谁能帮我吗?我坚持了几天!欢迎提出任何建议,谢谢!
答案 0 :(得分:1)
If each one of your threads write either 0 or their (1D index + 1) to the output buffer depending on whether or not they found the searched value, you can run a prefix sum later and find the (1D index + 1) that corresponds to the searched value in the output buffer in O(log n) instead of O(n), which would be the alternative where you simply iterate over the entire thing.