如何使用Thrust库对键进行精确排序 [英] How to sort with less precision on keys with Thrust library

查看:316
本文介绍了如何使用Thrust库对键进行精确排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组整数值,我想使用Thrust对它们进行排序。在这种排序中只使用一些高位/低位有可能。如果可能,我不想使用用户定义的比较器,因为它将使用的算法从radix-sort更改为merge-sort,并增加了很多时间。

I have a set of integer values and I want to sort them using Thrust. Is there a possiblity for using only some high bits/low bits in this sorting. If possible I do not want to use user defined comparator, because it changes the used algorithm from radix-sort to merge-sort and increases elapsed time quite much.

当所有数字在位上具有相同的值时,在排序时该位被跳过,因此使用最低可能的位数并且希望它是足够的是可行的。 (即:使用具有8位的char和将高3位设置为0的5位)

I think when all the numbers have the same value on a bit, the bit is skipped while sorting, so is it feasible to use the lowest possible bit number and hope it will be sufficient. (ie: for 5 bits using char with 8 bits and setting upper 3 bits to 0)

示例:

sort<4, 0>(myvector.begin(), myvector.end())
sort<4, 1>(myvector.begin(), myvector.end())

只使用4位,高或低进行排序..

sort using only 4 bits, high or low..

类似于
的东西 http://www.moderngpu.com /sort/mgpusort.html

推荐答案

Thrust的界面抽象出了算法实现细节,当前排序策略是基数排序。由于底层排序实现可能从版本到版本,后端到后端,甚至调用到调用都可能发生变化,因此用户无法传递要排序的位数。

Thrust's interface abstracts away algorithm implementation details such as the fact that one of the current sorting strategies is a radix sort. Due to the possibility that the underlying sort implementation could change from version to version, backend to backend, or even invocation to invocation, there is no way for the user to communicate the number of bits to sort.

幸运的是,这样的显式信息通常不是必需的。适当时,Thrust的当前排序实现将检查排序键,并在置零位中省略多余的计算。

Fortunately, such explicit information generally isn't necessary. When appropriate, Thrust's current sorting implementation will inspect the sorting keys and omit superfluous computation amidst zeroed bits.

这篇关于如何使用Thrust库对键进行精确排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆