[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 |
Hi,
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 */
#define GSL_RANGE_CHECK 0
#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) ;
t.start();
for(k=0;k<N ; k++){
for(i=0;i<sz;i++){
#ifndef MANUAL
gsl_vector_set(v,i,i) ;
#else
myset(v,i,i);
//v->data[i*v->stride]=i;
#endif
}
}
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`
-DHAVE_INLNE -DMANUAL
the computation takes about 6s on my computer.
Using directly the gsl function:
g++ -O3 main.cpp -lgsl -lgslcblas `pkg-config --cflags --libs mirage`
-DHAVE_INLNE
the computation takes about 14s on my computer.
The same thing seems to hold for the gsl_vector_set function.
Best,
Matthieu
- [Bug-gsl] gsl_vector_get / set,
geist_mat <=