Boost logo

Ublas :

Subject: Re: [ublas] question about the atlas and
From: Kaveh Kohan (kaveh.kohan_at_[hidden])
Date: 2009-04-01 12:13:10


Hi Jesse,

Thank you for your help. I downloaded the binding and linked it with blas and I saw very significant improvement. I realized that last time my program did not link with blas. Anyway, here is a copy of my test:

>> g++ test1.cpp -o test1 -Wall -O3 -DNDEBUG -lblas

>> ./test1 1000000 10 20
ublas default implementation in blas
Time : 0.44897
default implementation in atlas
Time : 0.343825

----------------------------------------------
#include <iostream>
//#include <valarray>

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/timer.hpp>

#include <boost/numeric/bindings/atlas/cblas3.hpp>
#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
namespace atlas = boost::numeric::bindings::atlas;

# include <sys/time.h>

namespace ublas = boost::numeric::ublas;
using namespace std;

double gettime() {
    struct timeval t;
    gettimeofday(&t, NULL);
    return (double)t.tv_sec+t.tv_usec*0.000001;
}

void initmatrix(ublas::matrix<double>& A) {
 for(size_t i = 0; i<A.size1(); i++)
  for(size_t j = 0; j<A.size2(); j++)
   A(i,j) = 1.0*rand();
}
void initmatrix(ublas::matrix<double,ublas::column_major>& A) {
 for(size_t i = 0; i<A.size1(); i++)
  for(size_t j = 0; j<A.size2(); j++)
   A(i,j) = 1.0*rand();
}

int main(int argc, char *argv[])
{
    long int D,r,n ;

    //std::clock_t start;
    //double diff;
    double t1,t2 ;

    //D = 1000 ;
    D = atoi(argv[1]) ;
    //r = 1000 ;
    r = atoi(argv[2]) ;
    //n = 1000 ;
    n = atoi(argv[3]) ;

   {
   cout << "ublas ";

   ublas::matrix<double> A(D,r);
   ublas::matrix<double,ublas::column_major> B(r,n);
   ublas::matrix<double> X(D,n);
   initmatrix(A);
   initmatrix(B);

   cout << "default implementation in blas" << endl ;
   t1 = gettime() ;
   //X = ublas::prod< ublas::matrix<double> >(A,B);
   noalias(X) = ublas::prod(A,B) ;
   t2 = gettime() ;
   cout << "Time : " << t2 - t1 << endl;

   
   }

   {
        ublas::matrix<double, ublas::column_major> A(D,r),B(r,n),C(D,n);
     initmatrix(A);
        initmatrix(B);

    cout << "default implementation in atlas" << endl ;
    t1 = gettime() ;
       atlas::gemm(A,B,C);
    t2 = gettime() ;
    cout << "Time : " << t2 - t1 << endl;

    
        
   }

}

________________________________
From: Jesse Perla <jesseperla_at_[hidden]>
To: Kaveh Kohan <kaveh.kohan_at_[hidden]>
Cc: ublas mailing list <ublas_at_[hidden]>
Sent: Tuesday, March 31, 2009 7:01:17 PM
Subject: Re: [ublas] question about the atlas and

On Tue, Mar 31, 2009 at 6:46 PM, Kaveh Kohan <kaveh.kohan_at_[hidden]> wrote:

libraries folder. My question is that the boost library installed in my machine does not have binding folder. How can I get it? should I do something like this: svn checkout https://svn.boost.org/svn/boost/sandbox/numeric_bindings-v1/libs/numeric/bindings/
but after this, do I need to compile it to make libraries or it is not necessary?

The library is header only, so you should make sure to get the headers as well. Do an svn checkout on: https://svn.boost.org/svn/boost/sandbox/numeric_bindings-v1/

You shouldn't need to worry about the libs folder. You will want to merge the "boost" subdirectory of this with the location of your boost headers so that it matches up with numeric, etc. and the includes of where the headers are in the sample code. After that, you should be in business and don't need to do any building of the libs directory. Or at least that is what I did for the LAPACK setup using Intel MKL.

Also, a newer version of the boost bindings is in progress which is looking great. I am not sure of the exact plans for atlas, but there seems to be BLAS binding support in progress and may actually work. So depending on the time horizon of your project, you may want to consider testing out some of the newer BLAS bindings (if this is bad advice, I apologize to the developers of the bindings).

As for noalias... I don't know the answer of why it wouldn't help, or how much it possibly could help. Just to verify though... you are setting NDEBUG as a preprocessor instruction? That could make an enormous difference.