title: Performance of thrust::count
body: <p>I have the following code as part of a reorganization of data for later use in a CUDA kernel:</p>
  
  <pre><code>thrust::device_ptr&lt;int&gt; dev_ptr = thrust::device_pointer_cast(dev_particle_cell_indices);
  int total = 0;
  for(int i = 0; i &lt; num_cells; i++) {
      particle_offsets[i] = total;
      // int num = 0;
      int num = thrust::count(dev_ptr, dev_ptr + num_particles, i);
      particle_counts[i] = num;
      total += num;
  }
  </code></pre>
  
  <p>Now, if I set <code>num</code> to 0 (uncomment the 5th line, and comment out the 6th), the application runs at over 30 fps, which is my goal.  However, when I set <code>num</code> equal to the <code>thrust::count</code> call, the framerate drops to about 1-2 fps.  Why would that happen?</p>
  
  <p>My understanding is that thrust is supposed to be a collection of highly optimized algorithms which harness the power of the GPU, so I'm surprised that it would have that kind of impact on the performance of my program.  This is my first time using thrust though, so I may be unaware of some important details.</p>
  
  <p>Is there something about using <code>thrust::count</code> in a loop which is causing it to run so slowly?  How can I optimize my usage of it?</p>
  
  <p>To give some figures, in my current test case, <code>num_particles</code> is about 2000, and <code>num_cells</code> is about 1500.</p>