SparseLibrary  Version 1.6.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
BetaHilbert< T > Class Template Reference

The Beta Hilbert triplet scheme. More...

#include <BetaHilbert.hpp>

Inheritance diagram for BetaHilbert< T >:
Inheritance graph
[legend]
Collaboration diagram for BetaHilbert< T >:
Collaboration graph
[legend]

Public Member Functions

 BetaHilbert (const std::string file, T zero=0, std::vector< unsigned short int > *_p_translate=NULL)
 File-based constructor. More...
 
 BetaHilbert (std::vector< Triplet< T > > &input, ULI m, ULI n, T zero=0, std::vector< unsigned short int > *_p_translate=NULL)
 COO-based constructor. More...
 
virtual ~BetaHilbert ()
 Base deconstructor. More...
 
void wait ()
 Callee will Wait for end of SpMV. More...
 
virtual void load (std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero)
 Loads from input COO matrix. More...
 
virtual void zxa (const T *x, T *z)
 Computes z=xA in place. More...
 
virtual void zxa (const T *x, T *z, const size_t repeat)
 Computes z=xA in place, a given number of times successively. More...
 
void reset ()
 Reset all local output vectors to zero.
 
virtual T * mv (const T *x)
 Overloaded mv call; allocates output vector using numa_interleaved. More...
 
virtual void zax (const T *x, T *z)
 Computes z=Ax in place. More...
 
virtual void zax (const T *x, T *z, const size_t repeat, const clockid_t clock_id, double *elapsed_time)
 Computes z=Ax in place, a given number of times in succession, and measures the time taken. More...
 
virtual void getFirstIndexPair (ULI &i, ULI &j)
 
virtual size_t bytesUsed ()
 
- Public Member Functions inherited from SparseMatrix< T, ULI >
 SparseMatrix ()
 Base constructor. More...
 
 SparseMatrix (const ULInzs, const ULInr, const ULInc, const T zero)
 Base constructor. More...
 
virtual ~SparseMatrix ()
 Base deconstructor. More...
 
void loadFromFile (const std::string file, const T zero=0)
 Function which loads a matrix from a matrix market file. More...
 
virtual unsigned long int m ()
 Queries the number of rows this matrix contains. More...
 
virtual unsigned long int n ()
 Queries the number of columns this matrix contains. More...
 
virtual unsigned long int nzs ()
 Queries the number of nonzeroes stored in this matrix. More...
 
virtual void zax (const T *__restrict__ x, T *__restrict__ z)=0
 In-place z=Ax function. More...
 
virtual void zxa (const T *__restrict__ x, T *__restrict__ z)=0
 In-place z=xA function. More...
 
- Public Member Functions inherited from Matrix< T >
 Matrix ()
 Base constructor. More...
 
virtual ~Matrix ()
 Base deconstructor. More...
 
virtual void zax (const T *__restrict__ x, T *__restrict__ z, const size_t k, const clockid_t clock_id=0, double *elapsed_time=NULL)
 Wrapper function to call the zax kernel multiple times successively, while timing the duration of the operation. More...
 
template<size_t k>
void ZaX (const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z)
 In-place Z=AX function, where A is m x n, Z = m x k, and X is n x k. More...
 
template<size_t k>
void ZXa (const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z)
 In-place Z=XA function, where A is m x n, Z = k x n, and X is k x m. More...
 
virtual void zxa (const T *__restrict__ x, T *__restrict__ z, const unsigned long int repeat, const clockid_t clock_id=0, double *elapsed_time=NULL)
 Wrapper function to call the zxa kernel multiple times successively, while timing the operation duration. More...
 

Static Public Member Functions

static void end (pthread_mutex_t *mutex, pthread_cond_t *cond, size_t *sync, const size_t P)
 End synchronisation function. More...
 
static void synchronise (pthread_mutex_t *mutex, pthread_cond_t *cond, size_t *sync, const size_t P)
 Thread synchronisation function. More...
 
static void * thread (void *data)
 SPMD code for each thread doing an SpMV. More...
 
static void collectY (shared_data< T > *shared)
 Code that collects a distributed output vector. More...
 

Protected Member Functions

void set_p_translate (std::vector< unsigned short int > *_p_translate)
 Sets p_translate to 0..P-1 by default, or equal to the optionally supplied vector. More...
 

Protected Attributes

std::vector< unsigned short int > p_translate
 Which processors to pin threads to.
 
const T * input
 Input vector.
 
T * output
 Output vector.
 
pthread_t * threads
 p_threads associated to this data strcuture
 
shared_data< T > * thread_data
 array of initial thread data
 
pthread_mutex_t mutex
 Stop/continue mechanism: mutex.
 
pthread_cond_t cond
 Stop/continue mechanism: condition.
 
pthread_mutex_t end_mutex
 Wait for end mechanism: mutex.
 
pthread_cond_t end_cond
 Wait for end mechanism: condition.
 
size_t sync
 Used for synchronising threads.
 
size_t end_sync
 Used for construction end signal.
 
- Protected Attributes inherited from SparseMatrix< T, ULI >
ULI nor
 Number of rows. More...
 
ULI noc
 Number of columns.
 
ULI nnz
 Number of non-zeros. More...
 

Static Protected Attributes

static size_t P = 0
 Number of threads to fire up.
 
static clockid_t global_clock_id = 0
 Clock type used for thread-local timing.
 
static const ULI max_n = FBICRS< T >::beta_n
 Given FBICRS, the maximum value for columnwise matrix size.
 
static const ULI max_m = FBICRS< T >::beta_m
 Given FBICRS, the maximum value for the rowwise matrix size, assuming short ints on ICRS at the lower level.
 

Additional Inherited Members

- Public Attributes inherited from SparseMatrix< T, ULI >
zero_element
 The element considered to be zero. More...
 

Detailed Description

template<typename T>
class BetaHilbert< T >

The Beta Hilbert triplet scheme.

Full parallel SpMV, based on Blocked Hilbert and PThreads. Inspired by Aydin & Gilbert's CSB, and comments by Patrick Amestoy on the BICRS Hilbert scheme.

Constructor & Destructor Documentation

template<typename T>
BetaHilbert< T >::BetaHilbert ( const std::string  file,
zero = 0,
std::vector< unsigned short int > *  _p_translate = NULL 
)
inline

File-based constructor.

Parameters
fileFilename to read from.
zeroZero element of the sparse matrix.
_p_translateThread pinning array.

References SparseMatrix< T, ULI >::loadFromFile(), and BetaHilbert< T >::set_p_translate().

template<typename T>
BetaHilbert< T >::BetaHilbert ( std::vector< Triplet< T > > &  input,
ULI  m,
ULI  n,
zero = 0,
std::vector< unsigned short int > *  _p_translate = NULL 
)
inline

COO-based constructor.

Parameters
inputCOO matrix.
mThe number of rows in the input matrix.
nThe number of columns in the input matrix.
zeroZero element of the sparse matrix.
_p_translateThread pinning array.

References BetaHilbert< T >::input, BetaHilbert< T >::load(), and BetaHilbert< T >::set_p_translate().

template<typename T>
virtual BetaHilbert< T >::~BetaHilbert ( )
inlinevirtual

Member Function Documentation

template<typename T>
virtual size_t BetaHilbert< T >::bytesUsed ( )
inlinevirtual
Returns
The number of bytes used by all threads corresponding to this scheme.

Implements Matrix< T >.

References BetaHilbert< T >::P, and BetaHilbert< T >::thread_data.

template<typename T>
static void BetaHilbert< T >::collectY ( shared_data< T > *  shared)
inlinestatic
template<typename T>
static void BetaHilbert< T >::end ( pthread_mutex_t *  mutex,
pthread_cond_t *  cond,
size_t *  sync,
const size_t  P 
)
inlinestatic

End synchronisation function.

Parameters
mutexWhich mutex to sync with.
condWhich condition to sync with.
syncSync counter to be used.
PHow many SPMD processes are running.

Referenced by BetaHilbert< T >::thread().

template<typename T>
virtual void BetaHilbert< T >::getFirstIndexPair ( ULI &  i,
ULI &  j 
)
inlinevirtual
template<typename T>
virtual void BetaHilbert< T >::load ( std::vector< Triplet< T > > &  input,
const ULI  m,
const ULI  n,
const T  zero 
)
inlinevirtual
template<typename T>
virtual T* BetaHilbert< T >::mv ( const T *  x)
inlinevirtual

Overloaded mv call; allocates output vector using numa_interleaved.

Parameters
xThe input vector of length n.
Returns
Newly allocated output vector of length m.

Reimplemented from SparseMatrix< T, ULI >.

References SparseMatrix< T, ULI >::nor, BetaHilbert< T >::reset(), BetaHilbert< T >::zax(), and SparseMatrix< T, ULI >::zero_element.

template<typename T>
void BetaHilbert< T >::set_p_translate ( std::vector< unsigned short int > *  _p_translate)
inlineprotected

Sets p_translate to 0..P-1 by default, or equal to the optionally supplied vector.

References MachineInfo::cores(), MachineInfo::getInstance(), BetaHilbert< T >::P, and BetaHilbert< T >::p_translate.

Referenced by BetaHilbert< T >::BetaHilbert().

template<typename T>
static void BetaHilbert< T >::synchronise ( pthread_mutex_t *  mutex,
pthread_cond_t *  cond,
size_t *  sync,
const size_t  P 
)
inlinestatic

Thread synchronisation function.

Parameters
mutexMutex used for synchronisation.
condCondition used for synchronisation.
syncSynchronisation counter.
PThe number of SPMD processes running.

Referenced by BetaHilbert< T >::collectY(), and BetaHilbert< T >::thread().

template<typename T>
static void* BetaHilbert< T >::thread ( void *  data)
inlinestatic
template<typename T>
void BetaHilbert< T >::wait ( )
inline
template<typename T>
virtual void BetaHilbert< T >::zax ( const T *  x,
T *  z 
)
inlinevirtual

Computes z=Ax in place.

Parameters
xThe input vector of length n.
zThe output vector of length m.

Referenced by BetaHilbert< T >::mv().

template<typename T>
virtual void BetaHilbert< T >::zax ( const T *  x,
T *  z,
const size_t  repeat,
const clockid_t  clock_id,
double *  elapsed_time 
)
inlinevirtual

Computes z=Ax in place, a given number of times in succession, and measures the time taken.

Parameters
xThe input vector of length n.
zThe output vector of length m.
repeatThe number of times this SpMV will be repeated.
clock_idWhich system clock to use for timing.
elapsed_timeWhere to add the elapsed time to.

References BetaHilbert< T >::cond, BetaHilbert< T >::end_mutex, BetaHilbert< T >::global_clock_id, BetaHilbert< T >::input, BetaHilbert< T >::mutex, SparseMatrix< T, ULI >::nor, BetaHilbert< T >::output, BetaHilbert< T >::P, BetaHilbert< T >::thread_data, and BetaHilbert< T >::wait().

template<typename T>
virtual void BetaHilbert< T >::zxa ( const T *  x,
T *  z 
)
inlinevirtual

Computes z=xA in place.

Parameters
xThe input vector of length m.
zThe output vector of length n.
template<typename T>
virtual void BetaHilbert< T >::zxa ( const T *  x,
T *  z,
const size_t  repeat 
)
inlinevirtual

Computes z=xA in place, a given number of times successively.

Parameters
xThe input vector of length m.
zThe output vector of length n.
repeatThe number of times to repeat the in-place SpMV.

References BetaHilbert< T >::cond, BetaHilbert< T >::end_mutex, BetaHilbert< T >::input, BetaHilbert< T >::mutex, SparseMatrix< T, ULI >::nor, BetaHilbert< T >::output, BetaHilbert< T >::P, BetaHilbert< T >::thread_data, and BetaHilbert< T >::wait().


The documentation for this class was generated from the following file: