c++ - CUDA - thrust::sort on device returns only 0's -
I have run the following emphasis for sorting. The problem is that after Please, tell me what is wrong here. You are seeing all the reasons As Robert Kowlow mentioned on a Windows machine (working on OP windows), I have personally certified that it is for both Windows, Then, as mentioned by Robert, this effect will show on the Linux As suggested by Robert, any direction can change to to avoid the show of all thrust :: sort , the output contains all
0 s
#include & lt; Emphasis / host_worker. H> #include & lt; Thrust / device_vector.h & gt; # Include & lt; Emphasis / Copy H & gt; # Include & lt; Emphasis / order & Gt; # Include & lt; Cstdlib & gt; # Include & lt; Iostream & gt; using namespace std; Int main (zero) {emphasis: host_ector & lt; Int & gt; H_vec (32 <20; & lt; 20); Emphasis: generated (h_vec.begin (), h_vec.end (), rand); Emphasis: device_vector & lt; Int & gt; D_vec = h_vec; For (Int i = 0; I <32; i ++) Cot & lt; & Lt; D_vec [i] & lt; & Lt; Endl; The court's & lt; & Lt; Endl & lt; & Lt; Endl & lt; & Lt; Endl; Thrust: sort (d_vec.begin (), d_vec.end ()); For (Int i = 0; I <32; i ++) Cot & lt; & Lt; D_vec [i] & lt; & Lt; Endl; The court's & lt; & Lt; endl & lt; & Lt; Endl & lt; & Lt; Endl; Emphasis :: copy (d_vec.begin (), d_vec.end (), h_vec.begin ()); For (Int i = 0; I <32; i ++) COAT & LT; & Lt; HIVIC [I] & lt; & Lt; Andal; Return 0; }
0 s That is that you are generating a large number of random numbers, that is,
32 & lt; & Lt; Between 20 = 33554432 ,
0 and
RAND_MAX , you are ordering them, but you can only display
32 Are there.
RAND_MAX = 2 ^ 15-1 = 32767 . Accordingly, you are creating between
33554432 integer
0 and
32767 , which means that you have a large number of
0 < / Code is> in the original array and hence the number of numbers
32 in the order of all
0 .
32 and
64 bit machines, which are both windows
32 and
64 are on bit system
RAND_MAX = 32767 .
32 bit machines, but not on Linux
64 bit machine, for which
RAND_MAX = 2 ^ 31-1 , for that matter,
RAND_MAX
32
thrust :: host_vector < Int & gt; H_vec (32 <20; & lt; 20);
thrust :: host_vector & lt; Int & gt; H_vec (Min (32 <-20; RAND_MAX));
0 .
Comments
Post a Comment