title: Can someone Vectorize the diffusion() function
body: <p>I am unable to vectorize this code </p>
  
  <p>the Given Information to do is 
  vectorizing diffusion()</p>
  
  <p>The diffusion workload has a true vector dependency over timesteps, so this workload can not be vectorized over timesteps. One solution to this issue is to implement loop-interchange to make the particle loop to the inner loop.</p>
  
  <p>In order to implement the interchange, you must create a temporary buffer to store the positions of the particles. Furthermore, the random number generator can't be in the vectorized loop. So you must generate and store multiple random numbers before the vectorized loop. You can generate n_particles random numbers with:</p>
  
  <pre><code>float rn[n_particles];
  vsRngUniform(VSL_RNG_METHOD_UNIFORM_STD,
               rnStream, n_particles, rn, -1.0, 1.0);
  </code></pre>
  
  <p>The given Code to vectorize is </p>
  
  <pre><code>int diffusion(
       const int n_particles,     // num of particles
       const int n_steps,         // num of timesteps
       const float x_threshold,   // x cutoff
       const float alpha,         // for dist_func
       VSLStreamStatePtr rnStream // RNG
      ) {
    int n_escaped=0;
    for (int i = 0; i &lt; n_particles; i++) {
      float x = 0.0f;
      for (int j = 0; j &lt; n_steps; j++) {
        float rn;
        // Intel(R) MKL RNG
        vsRngUniform(VSL_RNG_METHOD_UNIFORM_STD,
                     rnStream, 1, &amp;rn, -1.0, 1.0);
        x += dist_func(alpha, rn); 
      }
      if (x &gt; x_threshold) n_escaped++;
    }
    return n_escaped; 
  }
  </code></pre>