Main Page | Class List | File List | Class Members

CS_TS.hpp

00001 
00002 #include <vector>
00003 #include <assert.h>
00004 #include "CACHE.hpp"
00005 #include "Triplet.hpp"
00006 #include "CS_ARRAY.hpp"
00007 
00009 template< typename T >
00010 class CS_TS {
00011 
00012    private:
00013         
00015         typedef unsigned long int ULI;
00016 
00017    protected:
00018 
00020         ULI nnz;
00021 
00023         ULI nor;
00024 
00026         ULI noc;
00027 
00029         CS_ARRAY< T >* nzs;
00030 
00032         CS_ARRAY< ULI >* row;
00033 
00035         CS_ARRAY< ULI >* col;
00036 
00038         T zero_element;
00039 
00041         unsigned long int FAC;
00042 
00043    public:
00044 
00046         CS_TS( std::vector< Triplet< T > > input, ULI m, ULI n, T zero ) {
00047                 ULI offset = 0;
00048 
00049                 zero_element = zero;
00050                 nor = m;
00051                 noc = n;
00052                 nnz = input.size();
00053         //      nzs = new Triplet< T >[ nnz ];
00054                 nzs = new CS_ARRAY< T >( nnz, "Non-zero array in CS_TS" );
00055                 row = new CS_ARRAY< ULI >( nnz, "Row-index array in CS_TS" );
00056                 col = new CS_ARRAY< ULI >( nnz, "Column-index array in CS_TS" );
00057                 for( ULI i=0; i<nnz; i++ )
00058                         if( input[ i ].value != zero_element ) {
00059                                 nzs->access( i - offset ) = input[ i ].value;
00060                                 row->access( i - offset ) = input[ i ].i();
00061                                 col->access( i - offset ) = input[ i ].j();
00062                         } else
00063                                 offset++;
00064                 nnz -= offset;
00065                 FAC  = 0;
00066         }
00067 
00069         T* MV( T* x ) {
00070                 T* ret = new T[ nor ]; CACHE::getInstance()->access( ret, sizeof( void* ), FAC );
00071                 for( ULI i=0; i<nor; i++ ) {
00072                         CACHE::getInstance()->access( &( ret[ i ] ), sizeof( T ), FAC );
00073                         ret[ i ] = zero_element;
00074                 }
00075                 for( ULI i=0; i<nnz; i++ ) {
00076                         /*CACHE::getInstance()->access( &( nzs[i].column ), sizeof( unsigned long int ) );
00077                         CACHE::getInstance()->access( &( x[ nzs[i].j() ] ), sizeof( T ) );
00078                         CACHE::getInstance()->access( &( nzs[i].value ), sizeof( T ) );
00079                         CACHE::getInstance()->access( &( nzs[i].row ), sizeof( unsigned long int ) );
00080                         CACHE::getInstance()->access( &( ret[nzs[i].i()] ), sizeof( T ) );*/
00081                         
00082                         assert( row->unrecorded_access( i ) >= 0 );
00083                         assert( row->unrecorded_access( i ) <  nor );
00084                         assert( col->unrecorded_access( i ) >= 0 );
00085                         assert( col->unrecorded_access( i ) <  noc );
00086                         ret[ row->const_access( i ) ] += nzs->const_access( i ) * x[ col->const_access( i ) ];
00087                         CACHE::getInstance()->access( &( x[ col->unrecorded_const_access( i ) ] ), sizeof( unsigned long int ), FAC );
00088                         CACHE::getInstance()->access( &( ret[ row->unrecorded_const_access( i ) ] ), sizeof( T ), FAC );
00089                 }
00090                 return ret;
00091         }
00092 
00094         ~CS_TS() {
00095                 delete nzs;
00096                 delete row;
00097                 delete col;
00098         }
00099 
00100 };
00101 
00102 

Generated on Fri Aug 15 18:12:22 2008 for Run-timeCacheSimulator by  doxygen 1.3.9.1