title: How to allocate a large 3-dimensional array dynamically?
body: <p>My computer RAM has 32GB of memory available. I want to define a 1500*1500*500 size array. How should I define a dynamic array?</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;openacc.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string.h&gt;
  #include &lt;cuda_runtime_api.h&gt;
  
  void main(void) {
      #define NX 1501
      #define NY 1501
      #define NZ 501
      int  i, j, k, l, m, dt, nstop;
      double  comp;
      dt = 5;
      nstop = 5
      static double ex[NX][NY][NZ] = { 0. }, ey[NX][NY][NZ] = { 0. }, ez[NX][NY][NZ] = { 0. };
      static double hx[NX][NY][NZ] = { 1. }, hy[NX][NY][NZ] = { 0. }, hz[NX][NY][NZ] = { 1. };
      static double t, comp;
      FILE *file;
  
      file = fopen("point A hm=0.csv", "w"); /* Output data file name */
  
      t = 0.;
  
      for (l = 0; l &lt; nstop; l++) {
          for (i = 0; i &lt; NX - 1; i++) {
              for (j = 1; j &lt; NY - 1; j++) {
                  for (k = 1; k &lt; NZ - 1; k++) {
                      ex[i][j][k] =  2 * ey[i][j][k]
                                   + 3 * (hz[i][j][k] - hx[i][j - 1][k])
                                   - 5 * (hy[i][j][k] - 2 * hz[i][j][k - 1]);
                  }
              }
          }
          comp = ((double)(l + 1) / nstop) * 100.;
          printf("Computation: %4.3f %% completed \r", comp);
          fprintf(file, "%e, %e \n", t * 1e6, -ex[1200][950][20] + ex[1170][950][20]) / 2.);
          t = t + dt;
      }
  
      fclose(file);
  } 
  </code></pre>