title: In CUDA / Thrust, how can I access a vector element's neighbor during a for-each operation?
body: <p>I am trying to do some scientific simulation using Thrust library in CUDA, but I got stuck in the following operation which is basically a for-each loop:</p>
  
  <pre><code>device_vector&lt;float&gt; In(N);
  
  for-each In(x) in In
        Out(x) = some_calculation(In(x-1),In(x),In(x+1));
  end
  </code></pre>
  
  <p>I have already looked up stackoverflow.com and find some similar questions:
  <a href="https://stackoverflow.com/questions/14616066/thrust-vector-transformation-involving-neighbor-elements">Similar questions 1</a></p>
  
  <p>But it seems using a transform iterator is only possible when the some_calculation function is done between 2 parameters, for transform iterator passes two parameters at most.</p>
  
  <p>Then, for question 2:
  <a href="https://stackoverflow.com/questions/12727225/thrust-accessing-neighbors">Similar questions 2</a></p>
  
  <p>The discussion just ended without a conclusion.</p>
  
  <p>I believe this is a simple problem because it's a natural requirements for parallel calculation. Anyone could tell me what to do?</p>