title: Too much memory allocated with malloc
body: <p>Hello i got some problem with allocating memory for 2d matrix. I do something like that </p>
  
  <pre><code>float *tempMatrix=(float *)malloc(size * size * sizeof (float));
  </code></pre>
  
  <p>using this code i make 2 matrices with i later try to multiply with this code:</p>
  
  <pre><code>for (xDim=0;xDim&lt;matrixSize;xDim++){
          for(yDim=0;yDim&lt;matrixSize;yDim++){
              for (i=0;i&lt;matrixSize;i++){
                  result+=matrixA[xDim*matrixSize +i]*matrixB[(i)*matrixSize+yDim];
              }   
              resultMatrix[xDim*matrixSize+yDim]=result;
              result=0;
          }
      }
  </code></pre>
  
  <p>And i want to do it on many Threads using OpenMP but the problem is when i set matrix size to be greater than 1000 the program is hanging and not execute at all. My guess it is because there is problem with memo allocation but i am not 100% sure. Can anyone clarify what is wrong here or how to improve the code?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>Edit#1</strong></p>
  
  <p>here is my code with OpenMP directives:</p>
  
  <pre><code>            #pragma omp parallel shared(matrixA,matrixB,resultMatrix,matrixSize) private(i,result,xDim,yDim) \
              num_threads(threadNo)
              {
  
              #pragma omp single
      {
          printf("Number of threads %d.\n",omp_get_num_threads());
      }
              #pragma omp for schedule(guided,1)
              for (xDim=0;xDim&lt;matrixSize;xDim++){
                      for(yDim=0;yDim&lt;matrixSize;yDim++){
                              for (i=0;i&lt;matrixSize;i++){
                                      result+=matrixA[xDim][i]*matrixB[i]yDim];
                              }
                              resultMatrix[xDim][yDim]=result;
                              result=0;
                      }
              }
      }
  </code></pre>
  
  <p><strong>Edit#2</strong>
  I change the initialization of matrices to be in single block as suggested</p>