title: How do you create a 2d array in cuda
body: <p>For practice, I'm working on making a simple matrix initialization program in cuda.  I made a little sequential version for reference as a starting point.  It just creates an n by m array and fills it with doubles.  I've been reading through other posts and documentation, but I'm pretty confused and I was hoping someone could explain to me how to initialize a 2d array in cuda in a similar manner of n by m size as I did below.  I would also appreciate insight on how to fill that cuda matrix if anyone would be willing to explain.</p>
  
  <p>Hi again, in regards to it being a possible duplicate, I should elaborate. The linked post doesn't really explain anything, it's just sample code and it's one of the posts that I previously viewed but don't understand because it isn't explained.  Thank you. </p>
  
  <p>Sequential version:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;assert.h&gt;
  
  int n,m, i, j;
  double count;
  
  void update(int n, int m, double arr[][m]){
    for(i=0; i&lt;n; i++){
      for(j=0; j&lt;m; j++){
        count++;
        arr[i][j] = count;
      }
    }
  }
  
  
  int main(int argc, char * argv[]) {
    assert(argc==3);
    n = atoi(argv[2]);
    m = atoi(argv[1]);
  
    double (*arr)[n][m] = malloc(sizeof *arr);
    update(n,m,arr);
    return 0;
  }
  </code></pre>