title: How do you read a multidimensional array out of clEnqueueReadBuffer?
body: <p>I have 2D array C which I instantiate like this:</p>
  
  <pre><code>const int wA = 16;
  float * C[wA];
  for(int i = 0; i &lt; hA; i++)
  {
  C[i] = new float[hA];
  for(int i2 = 0; i2 &lt; hA; i2++)
      C[i][i2] = 0;
  }
  
  /* looks like this:
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  */
  </code></pre>
  
  <p>I create a kernel which operates on C:</p>
  
  <pre><code>__kernel void simpleMultiply(__global float* outputC, 
                              int widthA, 
                              int heightA, 
                              int widthB, 
                              int heightB, 
                              __global float * inputA, 
                              __global float * inputB)
  {
      int row = get_global_id(1);
      int col = get_global_id(0);
      float sum = 0.0f;
      for(int i = 0; i &lt; widthA; i++)
      {
          sum += inputA[row*widthA+i] * inputB[i*widthB+col];
      }
      outputC[row*widthB+col] = sum;
  }
  </code></pre>
  
  <p>and everything goes fine. I get CL_SUCCESS for status all the way through from setting up the context to creating the buffers, creating the kernel, program, clEnqueueNDRangeKernel,  clEnqueueReadBuffer, etc.</p>
  
  <p>But when I go to read the output it crashes. </p>
  
  <pre><code>status = clEnqueueNDRangeKernel(cmdQueue, kernel, 2, NULL, globalws, localws, 0, NULL, NULL);
  cout &lt;&lt; "\nclEnqueueNDRangeKernel: " &lt;&lt; (status == CL_SUCCESS ? "SUCCESS" : "FAIL"); // prints SUCCESS
  status = clEnqueueReadBuffer(cmdQueue, bufferC, CL_TRUE, 0, wC*hC*sizeof(float), (void*)C, 0, NULL, NULL);
  cout &lt;&lt; "\nclEnqueueReadBuffer: " &lt;&lt; (status == CL_SUCCESS ? "SUCCESS" : "FAIL"); // prints SUCCESS
  cout &lt;&lt; "\nC[0][0]: " &lt;&lt; C[0][0]; // &lt;--crash
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Mkcmd.png" alt="enter image description here"></p>
  
  <p>I am just as new to C++ as I am OpenCL so this could be due to a weak understanding of arrays and pointers in c++.</p>
  
  <p>The whole code is <a href="http://pastebin.com/NkiCam7Z" rel="nofollow noreferrer">here</a></p>