help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] Matrix memory deallocation problem


From: Wei Cheng
Subject: [Help-gsl] Matrix memory deallocation problem
Date: Thu, 6 Jul 2006 15:05:23 +0100

I have a matrix-matrix multiplication function based on BLAS matrix-matrix
mutiplication function,just for the ease of my own use as follow:

//******************************************************************************
   gsl_matrix* matrix_matrix_mul(CBLAS_TRANSPOSE_t TransA,CBLAS_TRANSPOSE_t
TransB,const gsl_matrix* X1,const gsl_matrix* X2)
  //matrix matrix multiplication, return the result
  {
     int N1=(*X1).size1;
     int N2=(*X2).size1;
     int D1=(*X1).size2;
     int D2=(*X2).size2;
     gsl_matrix* Y;// to store the product in Y

//determine the dimension of product matrix Y
     if(TransB==CblasTrans)
     //X2 is transposed
        Y=gsl_matrix_alloc (N1,N2);
     else if(TransA==CblasTrans)
     //X1 is transposed
        Y=gsl_matrix_alloc (D1,D2);
     else
     //No transpose
        Y=gsl_matrix_alloc (N1,D2);

//calling BLAS general matrix multiplication function , product is stored in
Y
     gsl_blas_dgemm (TransA, TransB, 1.0, X1, X2, 0.0, Y);

     return Y;

  }
//*****************************************************************************
The function returns the matrix product  of X1 and X2. I notice that
whenever we create matrix we have to free the memory with gsl_matrix_free.
However in  the above function I can't free Y before I return it and i am
not able to free Y after return statement.
Memory leak problem occurs when I call the above function 5000000 times in a
loop like this:

//************************************************************************************
void testing()
{
gsl_matrix* A=rand(50,100);//create random 50 by 100 matrix
gsl_matrix* B=rand(100,50);//create random 100 by 50 matrix

for(int i=0;i<5000000;i++)
matrix_matrix_mul(CblasNoTrans ,CblasNoTrans ,A ,B );//calculate the project
of matrix A and B}
//*************************************************************************************

The problem I am having is that during the loop, my RAM usage shoot up and
eventually run out. I am certain the problem is with the the deallocation of
Y in mutiplication function.

Can anybody help me with this matrix deallocation problem. This is just a
test, in my application the matrices are thousands by thousands.

Wei

Thanks


reply via email to

[Prev in Thread] Current Thread [Next in Thread]