行业知识
[CUDA] 使用thrust::sort()函数排序
2026-11-18 14:04:34
来源:互联网转载
一、简介
���文介绍了如何使用thrust::sort()函数对device_vector容器,或者int*指针表示的内存(显存)处的数据进行排序。
()二、示例代码
1. 排序 device_vector中的数据
main.cu文件内容:
#include #include #include #include #include #include #include #include #include using namespace std;int main(){ int min = 0, max = 100; random_device seed; // 硬件生成随机数种子 ranlux48 engine(seed()); // 利用种子生成随机数引擎 uniform_int_distribution distrib(min, max); // 设置随机数范围,并为均匀分布 int n = 10; thrust::host_vector data_host(n); thrust::device_vector data_device(n); /* 在host_vector上生成随机数 */ for (int i = 0; i
上一篇:安居房备案回执编号怎么查看的
下一篇:电脑有服务器怎么删除文件?