title: Nested loops in OpenCl Kernel
body: <p>I have recently started trying to study OpenCl and am trying to convert the following code into an efficient OpenCl kernel:</p>
  
  <pre><code>for(int i = 0; i &lt; VECTOR_SIZE; i++)
  {
      for(int j = 0; j &lt; 100; j++)
      {
          C[i] = sqrt(A[i] + sqrt(A[i] * B[i])) * sqrt(A[i] + sqrt(A[i] * B[i]));
      }
  }
  </code></pre>
  
  <p>This is what I have come up with so far using different tutorials. My question is, can I somehow get rid of the outer loop in my kernel. Would you say that this is an okey implementation of the above C++ code and no further thing can be done to make it more efficient or close to how an openCL program is supposed to be like.</p>
  
  <p>Also, all the tutorials that I have read so far have the kernels written in a const char *. What is reason behind this and is this the only way OPenCL kernels are written or usually we code them in some other file and then include it in our regular code or something. </p>
  
  <p>Thanks</p>
  
  <pre><code>     const char *RandomComputation =
  "__kernel                                   \n"
  "void RandomComputation(                              "
  "                  __global float *A,       \n"
  "                  __global float *B,       \n"
  "                  __global float *C)       \n"
  "{                                          \n"
  "    //Get the index of the work-item       \n"
  "    int index = get_global_id(0);          \n"
  "   for (int j = 0; j &lt; 100 ; j++)          \n"
  "   {                                       \n"
  "    C[index] = sqrt(A[index] + sqrt(A[index] * B[index])) * sqrt(A[index] + sqrt(A[index] * B[index])); \n"
  "}                                          \n"
  "}                                          \n";
  </code></pre>