[Top][All Lists]

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

[Bug-gsl] gsl_vector_get / set

From: geist_mat
Subject: [Bug-gsl] gsl_vector_get / set
Date: Fri, 28 Nov 2008 11:26:49 +0100


Trying to optimize some code, i remarked that calling the gsl_vector_get
function was much more slower than just accessing the structure with
something like v->data[i*v->stride], and the same seems to hold for
gsl_vector_set. On my program, it is about 15 time faster, however here
is a simpler example.

/* vector_get vs direct access */


#include <gsl/gsl_vector.h>
#include <gsl/gsl_rng.h>
#include <ctime>
#include <iostream>
#include <mirage.h>

inline void myset(gsl_vector *v,int i, double x) {
  if (i >= v->size)
      GSL_ERROR_VOID ("index out of range", GSL_EINVAL);
  v->data[i * v->stride] = x;

int main(int argc, char *argv[]) {
        mirage::Time t ;
        std::cout<<GSL_RANGE_CHECK<<std::endl ;
        int i, k, sz = 100 ;
        int N = 10000000 ;
        gsl_vector *v = gsl_vector_alloc(sz) ;
        for(k=0;k<N ; k++){
#ifndef MANUAL
                        gsl_vector_set(v,i,i) ;
        t.stop() ;
        std::cout << "Duration : " << t.getTime()        << std::endl;

/* end */

As i understand the gsl source code, calling the custom function myset
or the gsl function should do the same (the flag GSL_RANGE_CHECK being
set to 0). However it is not the case...

Compiling the custom function:
g++ -O3 main.cpp -lgsl -lgslcblas `pkg-config --cflags --libs mirage`
the computation takes about 6s on my computer.

Using directly the gsl function:
g++ -O3 main.cpp -lgsl -lgslcblas `pkg-config --cflags --libs mirage`
the computation takes about 14s on my computer.

The same thing seems to hold for the gsl_vector_set function.



reply via email to

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