title: High number causes seg fault
body: <p>This bit of code is from a program I am writing to take in x col and x rows to run a matrix multiplication on CUDA, parallel processing. The larger the sample size, the better.    </p>
  
  <p>I have a function that auto generates x amount of random numbers.</p>
  
  <p>I know the answer is simple but I just wanted to know exactly why. But when I run it with say 625000000 elements in the array, it seg faults. I think it is because I have gone over the size allowed in memory for an int. </p>
  
  <p>What data type should I use in place of int for a larger number?
  This is how the data is being allocated, then passed into the function. </p>
  
  <pre><code>a.elements = (float*) malloc(mem_size_A);
  </code></pre>
  
  <p>where</p>
  
  <pre><code>int mem_size_A = sizeof(float) * size_A; //for the example let size_A be 625,000,000
  </code></pre>
  
  <p>Passed: </p>
  
  <pre><code>randomInit(a.elements, a.rowSize,a.colSize, oRowA, oColA);
  </code></pre>
  
  <p>What the randomInit is doing is say I enter a 2x2 but I am padding it up to a multiple of 16. So it takes the 2x2 and pads the matrix to a 16x16 of zeros and the 2x2 is still there. </p>
  
  <pre><code>void randomInit(float* data, int newRowSize,int newColSize,  int oldRowSize, int oldColSize)
  {
      printf("Initializing random function. The new sized row is %d\n", newRowSize);
      for (int i = 0; i &lt; newRowSize; i++)//go per row of new sized row.
      {
          for(int j=0;j&lt;newColSize;j++)
          {
              printf("This loop\n");
              if(i&lt;oldRowSize&amp;&amp;j&lt;oldColSize)
              {
                  data[newRowSize*i+j]=rand() / (float)RAND_MAX;//brandom();
              }
              else
                  data[newRowSize*i+j]=0;
          }
      }
  }
  </code></pre>
  
  <p>I've even ran it with the printf in the loop. This is the result I get:</p>
  
  <pre><code>Creating the random numbers now
  Initializing random function. The new sized row is 25000
  This loop
  Segmentation fault
  </code></pre>