5

I'm new to using Thrust and there is one thing I don't understand. Is Thrust asynchronous or synchronous?

If I write the following code, the time taken isn't 0. But in the other tags, other users report a result of 0. What is the truth?

clock_t start,end;

start=clock(); 
thrust::sort_by_key(vettore.begin(), vettore.end(), counter.begin()); 

end=clock();

double time=((double)(end-start))/CLOCKS_PER_SEC; 

cout<<"execution time"<<time<<endl;// the result is 0.327
Bart
  • 19,692
  • 7
  • 68
  • 77
user1413067
  • 61
  • 1
  • 4
  • Note: related question on the NVIDIA forum [here](https://devtalk.nvidia.com/default/topic/864759/is-thrust-copy-synchrous-or-asynchronus-/). – BenC Sep 07 '15 at 04:38

3 Answers3

3

Kernel launches have always been asynchronous - even in CUDA 1.0 - so any Thrust call that results only in a kernel launch will be asynchronous.

Any Thrust code that implicitly triggers memcpy's will be synchronous due to the lack of stream support, as alluded to by marina.k.

ArchaeaSoftware
  • 4,332
  • 16
  • 21
  • 4
    For example, thrust::reduce() is definitely synchronous since it reads back the result and returns it to the calling thread via the return value. I make some comments about these limitations in my recent blog post on Thrust: http://developer.nvidia.com/content/expressive-algorithmic-programming-thrust – harrism Jun 21 '12 at 04:24
0

clock() function's granularity is not good as you think in Windows. And in Windows XP its granularity is as high as 16msec.

Instead of using clock() use a high resolution timer or Cutil library's timing functions (which is generally preferred).

Discussion about High resolution timer in Windows: C++ high precision time measurement in Windows

Discussion about CUtil library's usage for timing: CUDA: CUtil timer - confusion on elapsed time

Community
  • 1
  • 1
phoad
  • 1,801
  • 2
  • 20
  • 31
0

you can do it manually add the time.h to the indexer, go to Preferences -> C/C++ -> Indexer and put it in front of the existing "Files to be indexed up-front" like this:

time.h, cstdarg, stdarg.h, .....

it going to work

Alamin
  • 65
  • 1
  • 5