• CUDA--Thrust--数学运算(5)


      Thrust有一个Transformations. 这个方法为我们进行数学运算提供了方便其中 thrust/functional.h 

    包含大部分内建的算法和比较操作。代码如下:

    #include <thrust/device_vector.h>
    #include <thrust/transform.h>
    #include <thrust/sequence.h>
    #include <thrust/copy.h>
    #include <thrust/fill.h>
    #include <thrust/replace.h>
    #include <thrust/functional.h>
    #include <iostream>
    
    int main(void) {
    
        //allocate three device vectors with 10 elements
        thrust::device_vector<int>X(10);
        thrust::device_vector<int>Y(10);
        thrust::device_vector<int>Z(10);
    
        //initialize X to 0,1,2,3.
        thrust::sequence(X.begin(), X.end());
    
        //compute Y=-X
        thrust::transform(X.begin(), X.end(), Y.begin(), thrust::negate<int>());
    
        //fill Z with twos
        thrust::fill(Z.begin(), Z.end(), 2);
    
        //compute Y=X mod 2
        thrust::transform(X.begin(), X.end(), Z.begin(), Y.begin(), thrust::modulus<int>());
    
        //replace all the ones in Y with tens
    
        thrust::replace(Y.begin(), Y.end(), 1, 10);
    
        //print Y
        thrust::copy(Y.begin(), Y.end(), std::ostream_iterator<int>(std::cout, "
    "));
    
        
    
    
        return 0;
    }
    operatoins
  • 相关阅读:
    C#处理json实战
    HDU3994(Folyd + 期望概率)
    POJ1270 Following Orders (拓扑排序)
    HDU 3634 City Planning (离散化)
    HDU4762(JAVA大数)
    POJ3026(BFS + prim)
    POJ1679(次小生成树)
    UVA10487(二分)
    ZOJ 2048(Prim 或者 Kruskal)
    FZU 1856 The Troop (JAVA高精度)
  • 原文地址:https://www.cnblogs.com/xuelanga000/p/13358442.html
Copyright © 2020-2023  润新知