bug-gsl
[Top][All Lists]
Advanced

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

[Bug-gsl] memory problem


From: buc-family
Subject: [Bug-gsl] memory problem
Date: Sun, 17 Dec 2006 22:48:59 +0100
User-agent: Thunderbird 1.5.0.8 (X11/20060911)

When I place the command 

 gsl_rng_free (r);  in line 43 , then comes out the memory segmantation
problem.

Bug, or my mistake?

Regards

Andrzej Buczynski

Moosburg, Germany
#include <stdio.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_complex.h>
#include <gsl/gsl_complex_math.h>
#include <gsl/gsl_mode.h>
#include <gsl/gsl_permutation.h>
#include<gsl/gsl_permute_complex_double.h>
#include <gsl/gsl_types.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_check_range.h>
#include <gsl/gsl_vector_double.h>
#include <gsl/gsl_vector_complex.h>
#include <gsl/gsl_block_complex_double.h>
#include <gsl/gsl_rng.h>
/*     produce uniform random numbers 
        in the range [0.0, 1.0)   */
int main (void)
{
   int N =3  ; // matrix N x N
   int i, j ; // current variable
   gsl_complex temp , temp2 ; // temporary variable
   gsl_matrix_complex  *A =  gsl_matrix_complex_alloc(N, N );
   gsl_matrix_complex  *inverseA =  gsl_matrix_complex_alloc(N, N );
   gsl_matrix_complex  *inverseinverseA =  gsl_matrix_complex_alloc(N, N );

// setting of  random matrix A

   const gsl_rng_type * T;
   gsl_rng * r;
   gsl_rng_env_setup();
   T = gsl_rng_default;
   r = gsl_rng_alloc (T);
   double u1, u2 ;  // temporary variable
   for(i = 0; i <N ; i++) 
     for(j = 0; j <N ; j++) 
           { u1= gsl_rng_uniform (r) ; 
         u2= gsl_rng_uniform (r) ; 
         gsl_matrix_complex_set(A,i,j,gsl_complex_rect(u1,u2));
           }; 
// free memory   
gsl_rng_free (r);
// determinant 
    
gsl_complex det ;
int signum;
gsl_linalg_complex_LU_det ( A,  signum ) ;

printf("\n  det A = %g +i * %g \n", GSL_REAL(det) , GSL_IMAG(det) ) ;


// inversion of matrix A = inverseA
  
   {
   gsl_permutation * p = gsl_permutation_alloc (N); 
   gsl_linalg_complex_LU_invert ( A ,  p,  inverseA ) ;
   //free memory
   gsl_permutation_free (p);
   }
  
// inversion of inversion of A = inverseinverseA
 
    {
     gsl_permutation * p = gsl_permutation_alloc (N); 
     gsl_linalg_complex_LU_invert ( inverseA ,  p,  inverseinverseA ) ;
    //free memory
     gsl_permutation_free (p);
    } 
  
printf("\n\n   A=A-(inverse_inverseA)  should be  ZERO   \n");
    for(i=0; i<N ;i++)  
          { printf("\n");
        for(j=0; j<N ;j++)
                  { temp  =  gsl_matrix_complex_get ( inverseinverseA, i, j);
            temp2 = gsl_matrix_complex_get ( A, i, j);
printf("A(%d,%d)=%f+i*%f \n", i, j, GSL_REAL(gsl_complex_sub(temp2, temp)),
                                     GSL_IMAG(gsl_complex_sub(temp2, temp) ) ); 
                  }; 
          };
printf("\n");
// free memory

gsl_matrix_complex_free (A) ;
gsl_matrix_complex_free (inverseA) ;
gsl_matrix_complex_free (inverseinverseA) ;

return 0;
};






reply via email to

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