possible gsl gsl_blas_dnrm2 bug

Carl Glen Henshaw ghenshaw at space.nrl.navy.mil
Wed Mar 17 07:51:13 PST 2004


Hi,

I'm using gsl1.4 and gcc 3.3,  and I think I've encountered a bug. I'm trying 
to calculate the Euclidean norm of a vector and I'm getting garbage from 
gsl_blas_dnrm2.


Here is the code:

#include <gsl/gsl_vector.h>
#include <gsl/gsl_cblas.h>
#include <stdio.h>
#include <math.h>

#define INT(X) ((int)(X))


int main() {

	double norm;
	gsl_vector * temp1 = gsl_vector_calloc(3);

	gsl_vector_set(temp1, 0, 1.0);
	gsl_vector_set(temp1, 1, 1.0);
	gsl_vector_set(temp1, 2, 1.0);
	
	printf("Vector is:\n");
	gsl_vector_fprintf(stdout, temp1, "%f");
	printf("\n");
	
	norm = gsl_blas_dnrm2((const gsl_vector *) temp1);
	printf("Norm as reported by gsl_blas_dnrm2 is %f\n", norm);
	
	gsl_blas_ddot(temp1, temp1, &norm);
	norm = sqrt(norm);
	printf("Norm as reported by sqrt(gsl_blas_ddot) is %f\n", norm);
	
	norm = cblas_dnrm2(INT(temp1->size), temp1->data, INT(temp1->stride));
	printf("Norm as reported by cblas_dnrm2 is %f\n", norm);
	
	gsl_vector_free(temp1);
	}



I compile it thusly:

gcc33 -I/usr/local/include -L/usr/local/lib -lgsl -lm -lc -lcblas -latlas 
dnrm2bug.c

and I get the following output:

> ./a.out
Vector is:
1.000000
1.000000
1.000000

Norm as reported by gsl_blas_dnrm2 is 672934396.000000
Norm as reported by sqrt(gsl_blas_ddot) is 1.732051
Norm as reported by cblas_dnrm2 is 1.732051


The output line for dnrm2 is, of course, in error. If I compile with gcc 
2.95.4 I get the same output, so it doesn't appear to be a compiler 
problem...

Thanks,
Glen

____________________________________________________________

Dr. Glen Henshaw
Naval Center for Space Technology
U.S. Naval Research Laboratory
(202) 767-1196


More information about the freebsd-ports mailing list