help-gsl
[Top][All Lists]
Advanced

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

Re: [Help-gsl] How to use 'gsl_blas_dnrm2'?


From: Martin Jansche
Subject: Re: [Help-gsl] How to use 'gsl_blas_dnrm2'?
Date: Sat, 8 Jul 2017 07:15:23 +0100

#include <gsl/gsl_blas.h>

On Sat, Jul 8, 2017 at 3:35 AM, Lukas Gradl <address@hidden> wrote:

> Hello,
>
> I am new to the GSL and C and I am having some trouble using the
> function gsl_blas_dnrm2.  I have the following example program:
>
>
> ---8<--- cut here -------------------- start --->8---
> #include <stdio.h>
> #include <gsl/gsl_vector.h>
> #include <gsl/gsl_cblas.h>
>
> int main ()
> {
>   gsl_vector *a = gsl_vector_alloc(3);
>   gsl_vector_set_all(a, 0.50);
>
>   double nrm;
>   nrm = gsl_blas_dnrm2(a);
>
>   fprintf(stdout, "%f\n", nrm);
>
>   gsl_vector_free(a);
>   return 0;
> }
> ---8<--- cut here -------------------- end ----->8---
>
>
> The output that I expect from this program is 0.8660254.
> However, if I compile and run the program I get the following:
>
>
> ---8<--- cut here -------------------- start --->8---
> address@hidden gcc -lgsl -lcblas -latlas -lm test.c
> test.c: In function ‘main’:
> test.c:11:9: warning: implicit declaration of function ‘gsl_blas_dnrm2’
> [-Wimplicit-function-declaration]
>    nrm = gsl_blas_dnrm2(a);
>          ^~~~~~~~~~~~~~
> address@hidden ./a.out
> 24666208.000000
> address@hidden ./a.out
> 45424736.000000
> ---8<--- cut here -------------------- end ----->8---
>
>
> The output is actually different every time I run the program without
> recompiling.
>
> I tried to do the same using the CBLAS library that comes with GSL
> instead of Atlas.  In that case the output is always the number 3.0:
>
>
> ---8<--- cut here -------------------- start --->8---
> address@hidden gcc -lgsl -lgslcblas -lm test.c
> test.c: In function ‘main’:
> test.c:11:9: warning: implicit declaration of function ‘gsl_blas_dnrm2’
> [-Wimplicit-function-declaration]
>    nrm = gsl_blas_dnrm2(a);
>          ^~~~~~~~~~~~~~
> address@hidden ./a.out
> 3.000000
> address@hidden ./a.out
> 3.000000
> ---8<--- cut here -------------------- end ----->8---
>
>
> How would I use this function so that it gives the correct result?  My
> guess is that I am making a trivial mistake somewhere but I can't find
> it.
>
> Thank you for your help!
>
> Best,
> Lukas
>


reply via email to

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