东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 1449|回复: 0
打印 上一主题 下一主题

[C/C++] thrust例子:stl_list与stl_vector与device_vector

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14451
QQ
跳转到指定楼层
楼主
发表于 2021-6-16 11:07:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式



thrust例子:stl_list与stl_vector与device_vector


  1. #include <thrust/device_vector.h>
  2. #include <thrust/copy.h>
  3. #include <list>
  4. #include <vector>

  5. //thrust例子:stl_list与stl_vector与device_vector

  6. int main(void)
  7. {
  8.     //C ++标准库提供了一个链表list(std::list),它提供了双向(但不是随机访问)迭代器。
  9.     //尽管Thrust不提供此类容器的设备实现,但它与它们兼容
  10.   // create an STL list with 4 values
  11.   std::list<int> stl_list;

  12.   stl_list.push_back(10);
  13.   stl_list.push_back(20);
  14.   stl_list.push_back(30);
  15.   stl_list.push_back(40);


  16.   // 直接用list初始化一个设备向量D
  17.   thrust::device_vector<int> D(stl_list.begin(), stl_list.end());

  18.   // 拷贝一个设备向量 到 标准库的向量
  19.   std::vector<int> stl_vector(D.size());
  20.   thrust::copy(D.begin(), D.end(), stl_vector.begin());


  21.   for(int i=0;i<stl_vector.size();i++){
  22.       printf("stl_vector:%d\n", stl_vector[i]);
  23.   }

  24.   return 0;
  25. }




复制代码


让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-6-18 21:45 , Processed in 0.180428 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表