F
Frederic Soustra
Hi,
I am trying to speed up some work I have to do with a 3D Matrix.
If I am not mistaken, C is row major,
hence the matrix
A of size 2 x 2 x 2
would be stored like this in memory:
A[1][1][1],A[1][2][1],A[2][1][1],A[2][2][2],A[1][1][2],A[1][2][2],A[2][1][2],A[2][2][2]
?
Am I correct, I need to work on Big 3D matrices, and I know that the way
I traverse the matrices counts, which way is fastest? will gcc optimize
this as to minimize the page jumps in memory?
The matrix is declared using malloc so if A is n x n x d then i setup
the matrix this way:
A = (int***) malloc(n*sizeof(int));
for(i = 0;i < n;i++){
A = (int**) malloc(n*sizeof(int));
for(j = 0;j < n;j++)
A[j] = (int*) malloc(d*sizeof(int));
}
Is this a good way to declare the 3d Matrix? and am I traversing it
correctly?
Thank You for the help.
Fred
I am trying to speed up some work I have to do with a 3D Matrix.
If I am not mistaken, C is row major,
hence the matrix
A of size 2 x 2 x 2
would be stored like this in memory:
A[1][1][1],A[1][2][1],A[2][1][1],A[2][2][2],A[1][1][2],A[1][2][2],A[2][1][2],A[2][2][2]
?
Am I correct, I need to work on Big 3D matrices, and I know that the way
I traverse the matrices counts, which way is fastest? will gcc optimize
this as to minimize the page jumps in memory?
The matrix is declared using malloc so if A is n x n x d then i setup
the matrix this way:
A = (int***) malloc(n*sizeof(int));
for(i = 0;i < n;i++){
A = (int**) malloc(n*sizeof(int));
for(j = 0;j < n;j++)
A[j] = (int*) malloc(d*sizeof(int));
}
Is this a good way to declare the 3d Matrix? and am I traversing it
correctly?
Thank You for the help.
Fred