title: scalar and vector kernels in OpenCl
body: <p>I'm reading this paper <a href="http://eprints.dcs.warwick.ac.uk/1694/1/miniMD_opencl.pdf" rel="nofollow">http://eprints.dcs.warwick.ac.uk/1694/1/miniMD_opencl.pdf</a> about a mini molecular dynamics application using OpenCl. The code is located here.<br>
  I got stuck with how kernels are implemented. What I don't understand is this</p>
  
  <pre><code>#if defined(SCALAR_KERNELS)
  __kernel void f_clear(
      __global float* f,
      __const int nall) {
  
      for (unsigned i = get_global_id(0)+1; i &lt;= nall; i += get_global_size(0)) {
          const int i4 = i &lt;&lt; 2;
          f[i4+0] = 0.0f;
          f[i4+1] = 0.0f;
          f[i4+2] = 0.0f;
          f[i4+3] = 0.0f;
      }
  
  }
  #elif defined(VECTOR_KERNELS)
  __kernel __attribute__((vec_type_hint(float4)))
  void f_clear(
      __global float4* f,
      __const int nall) {
  
      const float4 zeroes = (float4) (0.0f, 0.0f, 0.0f, 0.0f);
      for (unsigned i = get_global_id(0)+1; i &lt;= nall; i += get_global_size(0)) {
          f[i] = zeroes;
      }
  
  }
  #endif
  </code></pre>
  
  <p>Is suppose <code>VECTOR_KERNELS</code> and <code>SCALAR_KERNELS</code> correspond to GPU and MIC devices but not sure.<br>
  Does that have something to do with MIMD SIMD instructions or multi-core and vector programming?<br>
  Also is there a real advantage of using vector type now days?<br>
  Finaly, I really can't figure what the two for loops do and the purpose of them.<br>
  Why not just do <code>f[get_global_id(0)]</code> ?<br>
  Thanks,<br>
  Éric.  </p>