title: Executing same Kernel multiple times in OpenCL
body: <p>I want to run a kernel(same) multiple times( lets say 3 times) in parallel with OpenCL. I read similar title threads but i am still confused. I have already wrote a program that executes it once.I know i need to make changes to clEnqueueNDKernelRangeKernel( ) and i tried but failed. So kindly can someone tell me how can i do it multiple times. Thanks for help.</p>
  
  <pre><code>//Includes
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;iostream&gt;
  
  #ifdef __APPLE__
  #include &lt;OpenCL/opencl.h&gt;
  #else
  #include &lt;CL/cl.h&gt;
  #endif
  
  #define DATA_SIZE 10
  
  using namespace std;
  
  const char *ProgramSource =
  "__kernel void add(__global float *inputA, __global float *inputB, __global 
  float *inputC, __global float *output)\n"\
  "{\n"\
  "  size_t id = get_global_id(0);\n"\
  "float f;\n"\
  "float y1 = 0.0f;\n"\
  "y1 = inputA[id] + inputB[id] + inputC[id];\n"\
  "  output[id] = y1;\n"\
  "}\n";
  
  int main(void)
  {
  cl_context context;
  cl_context_properties properties[3];
  cl_kernel kernel;
  cl_command_queue command_queue;
  cl_program program;
  cl_int err;
  cl_uint num_of_platforms = 0;
  cl_platform_id platform_id;
  cl_device_id device_id;
  cl_uint num_of_devices = 0;
  cl_mem inputA, inputB, inputC, output;
  
  size_t global;
  
  float inputDataA[DATA_SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  float inputDataB[DATA_SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  float inputDataC[DATA_SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };    
  float y1[DATA_SIZE] = { 0 };
  int i;
  
  // retreive a list of platforms avaible
  if (clGetPlatformIDs(1, &amp;platform_id, &amp;num_of_platforms) != CL_SUCCESS)
  {
      printf("Unable to get platform_id\n");
      return 1;
  }
  
  // try to get a supported GPU device
  if (clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &amp;device_id, 
  &amp;num_of_devices) != CL_SUCCESS)
  {
      printf("Unable to get device_id\n");
      return 1;
  }
  
  // context properties list - must be terminated with 0
  properties[0] = CL_CONTEXT_PLATFORM;
  properties[1] = (cl_context_properties)platform_id;
  properties[2] = 0;
  
  // create a context with the GPU device
  context = clCreateContext(properties, 1, &amp;device_id, NULL, NULL, &amp;err);
  
  // create command queue using the context and device
  command_queue = clCreateCommandQueue(context, device_id, 0, &amp;err);
  
  // create a program from the kernel source code
  program = clCreateProgramWithSource(context, 1, (const char 
  **)&amp;ProgramSource, NULL, &amp;err);
  
  // compile the program
  if (clBuildProgram(program, 0, NULL, NULL, NULL, NULL) != CL_SUCCESS)
  {
      printf("Error building program\n");
      return 1;
  }
  
  // specify which kernel from the program to execute
  kernel = clCreateKernel(program, "add", &amp;err);
  
  // create buffers for the input and ouput
  inputA = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * DATA_SIZE, NULL, NULL);
  inputB = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * DATA_SIZE, NULL, NULL);
  inputC = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(float) * DATA_SIZE, NULL, NULL);
  output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(float) * DATA_SIZE, NULL, NULL);
  
  // load data into the input buffer
  clEnqueueWriteBuffer(command_queue, inputA, CL_TRUE, 0, sizeof(float) * DATA_SIZE, inputDataA, 0, NULL, NULL);
  clEnqueueWriteBuffer(command_queue, inputB, CL_TRUE, 0, sizeof(float) * DATA_SIZE, inputDataB, 0, NULL, NULL);
  clEnqueueWriteBuffer(command_queue, inputC, CL_TRUE, 0, sizeof(float) * DATA_SIZE, inputDataC, 0, NULL, NULL);
  // set the argument list for the kernel command
  clSetKernelArg(kernel, 0, sizeof(cl_mem), &amp;inputA);
  clSetKernelArg(kernel, 1, sizeof(cl_mem), &amp;inputB);
  clSetKernelArg(kernel, 2, sizeof(cl_mem), &amp;inputC);
  clSetKernelArg(kernel, 3, sizeof(cl_mem), &amp;output);
  
  global = DATA_SIZE;
  
  clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &amp;global, NULL, 0, NULL, NULL);
  clFinish(command_queue);
  
  // copy the results from out of the output buffer
  clEnqueueReadBuffer(command_queue, output, CL_TRUE, 0, sizeof(float) *DATA_SIZE, y1, 0, NULL, NULL);
  
  // print the results
  printf("y1: ");
  
  for (i = 0; i&lt;DATA_SIZE; i++)
  {
      printf("%f\n ", y1[i]);
  }
  
  // cleanup - release OpenCL resources
  clReleaseMemObject(inputA);
  clReleaseMemObject(inputB);
  clReleaseMemObject(inputC);
  clReleaseMemObject(output);
  clReleaseProgram(program);
  clReleaseKernel(kernel);
  clReleaseCommandQueue(command_queue);
  clReleaseContext(context);
  
  return 0;
  </code></pre>
  
  <p>}</p>