Hey,
I'm creating a matrix-matrix multiplier in C that will use the same format as the GOTO BLAS and ATLAS implementations. I need to allocate memory and store the matrices in COL MAJOR format not in row major as is the standard C representation.
Can you tell me if I am on the right track here:
Code:
//global vars
double **matrixA, **matrixB, **matrixC;
int main(int argc, char *argv[])
{
int i, c, row, col, j;
int n_rows = 10; //ASSUME SQUARE FOR NOW!
int m_cols = 10;
int mbyn = m_cols * n_rows;
int i, j;
double n = 0;
//allocate the number of cols
matrixA = (double**)malloc( sizeof( double* ) * m_cols);
//allocate the overall size??
matrixA[0] = (double *) malloc( sizeof( double*) * mbyn);
for (i=1; i<m_cols; i++)
{ //for each col allocate the rows
matrixA[i] = *matrixA + i * n_rows;
}
I then have a function fill matrix so:
Code:
for (i=0; i<SIZE; i++) //
for (j=0; j<SIZE; j++)
matrix[j][i] = n++; //or a[i][j]; //fill it col,row - like a graphics point
I think the malloc is correct but i'm not so sure about the filling of the matrix. Is this right??
I want it to work like this:
Image Attachment
(sorry don't know how to display the image in here.)
So that I have one long linear array, that stores one row, then the next row etc. This means that I can skip to the next element one by one the whole way throught the matrix. To get to the next row of a matrix with n cols I would simply move n elements from the start pointer.
thanks for your help,
Colm Mitchell