Boost logo

Ublas :

From: Brian Budge (brian.budge_at_[hidden])
Date: 2006-08-16 15:55:55


I would venture a couple of guesses:

200 iterations isn't very many, you could try more iterations, and the
timings should be more consistent.

The timer may not be very high resolution. This depends on your
platform, I believe.

  Brian

On 8/16/06, Fred <hakonbh_at_[hidden]> wrote:
> Hi,
>
> Could you help to decrease time of prod when I use the typedef defined in
> the code below?
>
> #include <boost/timer.hpp>
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/matrix_sparse.hpp>
> #include <boost/numeric/ublas/matrix_proxy.hpp>
> #include <boost/numeric/ublas/vector_sparse.hpp>
> #include <boost/numeric/ublas/vector_proxy.hpp>
> #include <boost/numeric/ublas/vector_of_vector.hpp>
> #include <boost/numeric/ublas/operation.hpp>
> #include <boost/numeric/ublas/io.hpp>
>
> int main () {
> using namespace boost::numeric::ublas;
>
> typedef generalized_vector_of_vector< double, row_major,
> boost::numeric::ublas::vector< compressed_vector<double> > > matrix;
> typedef compressed_vector<double> vec_d;
>
> // typedef matrix<double> matrix;
> // typedef vector<double> vec_d;
>
> boost::timer t1;
> double t_final;
>
> matrix m(3,3);
> vec_d v(3);
> vec_d result;
> for (unsigned i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
> for (unsigned j = 0; j < m.size2 (); ++ j)
> m (i, j) = 3 * i + j;
> v (i) = i;
> }
>
> std::cout << m << std::endl;
> std::cout << v << std::endl;
>
> int counter = 0;
> for(int n=0; n<20 ; ++n)
> {
> for(int i=0; i<200 ; ++i)
> {
> t1.restart();
> result = prod(m, v);
> t_final = t1.elapsed();
>
> if (t_final > 0.01)
> {
> std::cout << "time = " << t_final << std::endl;
> counter++;
> }
> }
> }
> std::cout << "counter = " << counter << std::endl;
> }
> I don't understand why prod spends "0 sec" in some iterations and " 0.016
> sec" (in my computer) if variables are always the same...
>
> Thank you for your time!
>
> Frederico B. Teixeira
> ---
> UFMG, Brazil
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>
>
>