问题描述
我有几个块,每个块在整数数组的单独部分上执行。作为示例:将一个从阵列[0]到阵列[9]和块二从阵列[10]到阵列[20]。
每个区块的数组最大值的最佳索引是什么?
示例块a [0]到a [10]具有以下值:
5 10 2 3 4 34 56 3 9 10
p>
所以56是索引6处的最大值。
我不能使用共享内存,因为数组的大小可能非常大。因此它不适合。有没有任何库允许我这么快?
我知道减少算法,但我认为我的情况是不同的,因为我想得到的索引最大的元素。
这不会对原始海报有好处,但对于那些谁来到这个网页寻找答案,我会第二推荐使用已经有一个函数thrust :: max_element的thrust,返回最大元素的索引。还提供了min_element和minmax_element函数。有关详情,请参阅推荐文档。
I have several blocks were each block executes on separate part of an integer array. As an example: block one from array[0] to array[9] and block two from array[10] to array[20].
What is the best way i can get the index of the max value of the array for each block?
Example block one a[0] to a[10] have the following values:5 10 2 3 4 34 56 3 9 10
So 56 is the largest value at index 6.
I cannot use the shared memory because the size of the array may be very big. Therefore it won't fit. Are there any libraries that allows me to do so fast?
I know about the reduction algorithm, but i think my case is different because i want to get the index of the largest element.
This will not benefit the original poster but for those who came to this page looking for an answer I would second the recommendation to use thrust that already has a function thrust::max_element that does exactly that - returns an index of the largest element. min_element and minmax_element functions are also provided. See thrust documentation for details here.
这篇关于CUDA:在数组中获取最大值及其索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!