lion03 / thrust

Automatically exported from code.google.com/p/thrust
Apache License 2.0
0 stars 0 forks source link

gather_if example contains incorrect comment #368

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please post a short, self-contained code sample which reproduces the
problem:
The example with gather_if does not produce the results it claims.

#include <iostream>
#include <thrust/gather.h>
#include <thrust/device_vector.h>

struct is_even
{
    __host__ __device__
        bool operator()(const int x)
        {   
            return (x % 2) == 0;
        }   
};
int main(){
    int values[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 
    thrust::device_vector<int> d_values(values, values + 10);

    // we will select an element when our stencil is even
    int stencil[10] = {0, 3, 4, 1, 4, 1, 2, 7, 8, 9}; 
    thrust::device_vector<int> d_stencil(stencil, stencil + 10);

    // map all even indices into the first half of the range
    // and odd indices to the last half of the range
    int map[10]   = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; 
    thrust::device_vector<int> d_map(map, map + 10);

    thrust::device_vector<int> d_output(10, 7); 
    thrust::gather_if(d_map.begin(), d_map.end(),
            d_stencil.begin(),
            d_values.begin(),
            d_output.begin(),
            is_even());
    // d_output is now {0, 2, 4, 6, 8, 7, 7, 7, 7, 7}

    thrust::host_vector<int> v = d_output;

    for(int i =0; i < v.size(); i++)
        std::cout << v[i] << " ";
    std::cout << std::endl;
}

What is the expected output? What do you see instead?

d_output is 
0 7 4 7 8 7 3 7 7 7 
not
0 2 4 6 8 7 7 7 7 7

What version of Thrust are you using? Which version of nvcc?  Which host
compiler?  On what operating system?  Which GPU?
Thrust 1.4

nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2011 NVIDIA Corporation
Built on Thu_May_12_11:09:45_PDT_2011
Cuda compilation tools, release 4.0, V0.2.1221

uname -a
Linux hypnotoad 3.0-ARCH #1 SMP PREEMPT Wed Aug 17 21:55:57 CEST 2011 x86_64 
Intel(R) Core(TM)2 Duo CPU T7500 @ 2.20GHz GenuineIntel GNU/Linux

nvidia-smi -L
GPU 0: Quadro FX 570M

Please provide any additional information below.

Original issue reported on code.google.com by jdmundra...@gmail.com on 31 Aug 2011 at 1:44

GoogleCodeExporter commented 8 years ago

Original comment by jaredhoberock on 31 Aug 2011 at 1:47

GoogleCodeExporter commented 8 years ago
This issue was closed by revision ba527e443875.

Original comment by jaredhoberock on 31 Aug 2011 at 5:44