zoukankan      html  css  js  c++  java
  • CUDA--Thrust(3)--List

    CUDA List 实现:

      尽管Thrust没有提供像C++中的List容器,但是Thrust却和C++兼容。

    代码:

    #include "cuda_runtime.h"
    #include "device_launch_parameters.h"
    
    #include <stdio.h>
    
    #include <thrust/host_vector.h>
    #include <thrust/device_vector.h>
    #include <thrust/copy.h>
    #include <thrust/fill.h>
    #include <thrust/sequence.h>
    #include <iostream>
    #include <list>
    #include <vector>
    
    int main(void) {
    
        int i = 0,j=0;
    
        // create an STL list with 4 values
        std::list<int> stl_list;
        std::list<int>::iterator it_1;
        stl_list.push_back(10);
        stl_list.push_back(20);
        stl_list.push_back(30);
        stl_list.push_back(40);
    
        //show the sequence stl_list
        std::cout << "show the original stl_list" << std::endl;
        for (it_1 =stl_list.begin(); it_1 !=stl_list.end(); it_1++)
            std::cout << "stl_list[" << (++i) << "]=" << *it_1 << std::endl;
    
        // initialize a device_vector with the list
        thrust::device_vector<int> D(stl_list.begin(), stl_list.end());
        
        //show the sequence D
        std::cout << "show the original D" << std::endl;
        for (int i = 0; i < D.size(); ++i)
            std::cout << "D[" << i << "]=" << D[i] << std::endl;
    
        // copy a device_vector into an STL vector
        std::vector<int> stl_vector(D.size());
        std::vector<int>::iterator it_2;
        thrust::copy(D.begin(), D.end(), stl_vector.begin());
    
        //show the sequence STL vector
        std::cout << "show the original STL vector" << std::endl;
        for (it_2 = stl_vector.begin(); it_2 != stl_vector.end(); it_2++)
            std::cout << "STL_vector[" << (++j) << "]=" << *it_2 << std::endl;
    
    
        
        
        return 0;
    }
    View Code

  • 相关阅读:
    给入坑前端的新人的建议
    浅析js闭包
    mongoose之操作mongoDB数据库
    input模拟输入下拉框
    浅析AngularJS自定义指令之嵌入(transclude)
    vue-cli之打包多入口配置
    Node.js之图片上传
    移动端之模态框滚动穿透问题
    浅谈vue之动态路由匹配
    vuex数据持久化存储
  • 原文地址:https://www.cnblogs.com/xuelanga000/p/13186399.html
Copyright © 2011-2022 走看看