Hello i got some problem with allocating memory for 2d matrix. I do something like that
float *tempMatrix=(float *)malloc(size * size * sizeof (float));
using this code i make 2 matrices with i later try to multiply with this code:
for (xDim=0;xDim<matrixSize;xDim++){
for(yDim=0;yDim<matrixSize;yDim++){
for (i=0;i<matrixSize;i++){
result+=matrixA[xDim*matrixSize +i]*matrixB[(i)*matrixSize+yDim];
}
resultMatrix[xDim*matrixSize+yDim]=result;
result=0;
}
}
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?
Thanks in advance
Edit#1
here is my code with OpenMP directives:
#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<matrixSize;xDim++){
for(yDim=0;yDim<matrixSize;yDim++){
for (i=0;i<matrixSize;i++){
result+=matrixA[xDim][i]*matrixB[i]yDim];
}
resultMatrix[xDim][yDim]=result;
result=0;
}
}
}
Edit#2 I change the initialization of matrices to be in single block as suggested