24#ifndef _GEMA_THREAD_LOCAL_BUFFER_H_
25#define _GEMA_THREAD_LOCAL_BUFFER_H_
44 T* buffer =
new T[n * nt];
45 for(
int i = 0; i < nt; i++, buffer += n)
68 for(
int i = 0; i < nt; i++)
70 T* ptr = (T*)(rawbuffer + i*tsize);
84 for(
int i = 0; i<nt; i++)
157 for(
int j = 0; j <
_n; j++)
A class similar to GmTLS that creates a buffer for each possible thread in the GmThreadManager,...
Definition gmThreadLocalBuffer.h:106
void init(const T &defVal)
Initializes each buffer entry to defVal.
Definition gmThreadLocalBuffer.h:152
int _n
The size of each buffer.
Definition gmThreadLocalBuffer.h:171
const T * localBuffer(int tid) const
Returns a const pointer to the given thread local buffer.
Definition gmThreadLocalBuffer.h:143
int size() const
Returns the buffer size.
Definition gmThreadLocalBuffer.h:128
void setSize(int n)
Set buffer size for a default constructed buffer.
Definition gmThreadLocalBuffer.h:131
GmTLBuffer()
Default constructor. Buffer sizes MUST be initialized by a call to setSize()
Definition gmThreadLocalBuffer.h:113
T * localBuffer(int tid)
Returns a pointer to the given thread local buffer.
Definition gmThreadLocalBuffer.h:140
void resize(int n)
Change buffer size.
Definition gmThreadLocalBuffer.h:137
GmTLBuffer(int n, const T &defVal)
Constructor. Each thread buffer will store n entries of type T, initialized to defVal.
Definition gmThreadLocalBuffer.h:119
void setSize(int n, const T &defVal)
Set buffer size for a default constructed buffer and initializes the contents to defVal.
Definition gmThreadLocalBuffer.h:134
~GmTLBuffer()
Destructor.
Definition gmThreadLocalBuffer.h:122
const T * localBuffer() const
Returns a const pointer to the current thread local buffer.
Definition gmThreadLocalBuffer.h:149
T * localBuffer()
Returns a pointer to the current thread local buffer.
Definition gmThreadLocalBuffer.h:146
GmTLS< T * > _data
The local storage with pointers to each thread buffer. No need to align _data since worker threads wi...
Definition gmThreadLocalBuffer.h:169
GmTLBuffer(int n)
Constructor. Each thread buffer will store n entries of type T.
Definition gmThreadLocalBuffer.h:116
void clear()
Clears the allocated buffers returning the object to a default constructed state.
Definition gmThreadLocalBuffer.h:125
A class that works together with GmThreadManager to provide thread local storage.
Definition gmThreadLocalStorage.h:132
T & localData(int tid)
Returns the given thread local data as a modifiable reference.
Definition gmThreadLocalStorage.h:163
void setLocalData(int tid, const T &data)
Updates the given thread local data.
Definition gmThreadLocalStorage.h:183
void init(const T &val)
Initializes the value for ALL threads with the given value.
Definition gmThreadLocalStorage.h:153
static int currentId()
Returns the id of the current thread, which MUST be either the main thread or a thread created by the...
Definition gmThreadManager.h:171
static int maxWorkerThreads()
Returns the maximum number of allowed working threads.
Definition gmThreadManager.h:158
Implementation of the custom allocator used by Armadillo when memory is needed for matrices and vecto...
#define GM_CACHE_LINE_SIZE
Cache line size. TODO: Get this from a configuration parameter.
Definition gmMemory.h:35
bool GmIsCacheAligned(void *ptr)
Checks if a pointer is cache aligned or not.
Definition gmMemory.h:81
void * GmAlignedMallocThrow(size_t size, size_t align)
A version of GmAlignedMalloc that throws a bad_alloc exception on failure.
Definition gmMemory.h:65
void GmConstructObjectsInMemory(T *ptr, int n=1)
Calls the default T constructor for creating 'n' consecutive objects in the memory area pointed by pt...
Definition gmMemory.h:90
void GmDestroyObjectsInMemory(T *ptr, int n=1)
Calls T destructor for 'n' consecutive objects in the memory area pointed by ptr.
Definition gmMemory.h:109
Declaration of the GmTLS class.
static void alloc(int n, GmTLS< T * > &tls)
Alloc one buffer with size n for each thread, storing pointers in tls.
Definition gmThreadLocalBuffer.h:38
static void free(int n, GmTLS< T * > &tls)
Releases the memory allocated by alloc.
Definition gmThreadLocalBuffer.h:50
static void alloc(int n, GmTLS< T * > &tls)
Alloc one cache aligned buffer with size n for each thread, storing pointers in tls.
Definition gmThreadLocalBuffer.h:57
static void free(int n, GmTLS< T * > &tls)
Releases the memory allocated by alloc.
Definition gmThreadLocalBuffer.h:79
Aux structure to define the allocation strategy for GmTLBuffer.
Definition gmThreadLocalBuffer.h:32