24 #include <tbb/scalable_allocator.h> 25 #include <tbb/spin_mutex.h> 37 template<
typename scalar>
88 reference_mutex =
new tbb::spin_mutex();
89 references =
new int64_t;
118 reference_mutex =
new tbb::spin_mutex();
119 references =
new int64_t;
150 reference_mutex =
new tbb::spin_mutex();
151 references =
new int64_t;
181 reference_mutex =
new tbb::spin_mutex();
182 references =
new int64_t;
207 if (rows > 0 && cols>0) assert(data);
216 reference_mutex =
new tbb::spin_mutex();
217 references =
new int64_t;
243 tbb::spin_mutex::scoped_lock my_lock{*reference_mutex};
323 reference_mutex =
new tbb::spin_mutex();
324 references =
new int64_t;
335 if (references==NULL)
return;
336 bool call_delete =
false;
340 tbb::spin_mutex::scoped_lock my_lock{*reference_mutex};
342 if (references==NULL)
return;
343 call_delete = ((*references)==1);
349 scalable_aligned_free(data);
362 if ( call_delete && reference_mutex !=NULL) {
363 reference_mutex->~spin_mutex();
365 reference_mutex=NULL;
411 tbb::spin_mutex::scoped_lock my_lock{*reference_mutex};
426 if ( idx >= rows*stride || idx < 0) {
427 std::cout <<
"Accessing element out of bonds. Exiting" << std::endl;
451 memcpy( ret.
data, data, rows*stride*
sizeof(
scalar));
458 if (((uintptr_t)(
void*)data & (
CACHELINE-1)) == 0)
return;
460 memcpy( newdata, data, rows*stride*
sizeof(
scalar));
481 std::cout << std::endl <<
"The stored matrix:" << std::endl;
482 for (
int row_idx=0; row_idx <
rows; row_idx++ ) {
483 for (
int col_idx=0; col_idx <
cols; col_idx++ ) {
484 int element_idx = row_idx*stride + col_idx;
485 std::cout <<
" " << data[element_idx];
487 std::cout << std::endl;
489 std::cout << std::endl << std::endl << std::endl;
bool owner
logical value indicating whether the class instance is the owner of the stored data or not...
int stride
The column stride of the array. (The array elements in one row are a_0, a_1, ... a_{cols-1}, 0, 0, 0, 0. The number of zeros is stride-cols)
matrix_base< scalar > copy() const
Call to create a copy of the matrix.
scalar * data
pointer to the stored data
matrix_base(scalar *data_in, int rows_in, int cols_in)
Constructor of the class.
void release_data()
Call to release the data stored by the matrix.
matrix_base(scalar *data_in, int rows_in, int cols_in, int stride_in)
Constructor of the class.
bool transposed
logical variable indicating whether the matrix needs to be transposed in CBLAS operations ...
bool conjugated
logical variable indicating whether the matrix needs to be conjugated in CBLAS operations ...
scalar * get_data() const
Call to get the pointer to the stored data.
~matrix_base()
Destructor of the class.
bool is_conjugated()
Call to get whether the matrix should be conjugated in CBLAS functions or not.
Base Class to store data of arrays and its properties.
void operator=(const matrix_base &mtx)
Assignment operator.
scalar & operator[](int idx) const
Operator [] to access elements in array style (does not check the boundaries of the stored array) ...
int rows
The number of rows.
int cols
The number of columns.
void replace_data(scalar *data_in, bool owner_in)
Call to replace the stored data by an another data array.
matrix_base(int rows_in, int cols_in, int stride_in)
Constructor of the class.
Custom types for the SQUANDER package.
void print_matrix() const
Call to prints the stored matrix on the standard output.
void set_owner(bool owner_in)
Call to set the current class instance to be (or not to be) the owner of the stored data array...
int size() const
Call to get the number of the allocated elements.
void transpose()
Call to transpose (or un-transpose) the matrix for CBLAS functions.
matrix_base()
Default constructor of the class.
matrix_base(int rows_in, int cols_in)
Constructor of the class.
void conjugate()
Call to conjugate (or un-conjugate) the matrix for CBLAS functions.
matrix_base(const matrix_base< scalar > &in)
Copy constructor of the class.
int64_t * references
the number of the current references of the present object
tbb::spin_mutex * reference_mutex
mutual exclusion to count the references for class instances referring to the same data...
bool is_transposed()
Call to get whether the matrix should be conjugated in CBLAS functions or not.