42 size_t submatrices_num = 4;
44 size_t submatrices_num_row = 2;
48 std::vector<Matrix, tbb::cache_aligned_allocator<Matrix>> submatrices(submatrices_num);
57 size_t prod_num = submatrices_num*submatrices_num_row;
58 tbb::combinable<double> priv_prod_cost_functions{[](){
return 0;}};
60 tbb::parallel_for(0, (
int) prod_num, 1,
functor_submtx_cost_fnc( &submatrices, &priv_prod_cost_functions, prod_num ));
67 double cost_function = 0;
68 priv_prod_cost_functions.combine_each([&cost_function](
double a) {
69 cost_function = cost_function + a;
99 for (
size_t submtx_idx = r.begin(); submtx_idx != r.end(); submtx_idx++) {
102 Matrix& submatrix = (*submatrices)[ submtx_idx ];
105 size_t submatrices_num_row = 2;
114 submatrix =
Matrix(submatrix_size, submatrix_size);
118 size_t jdx = submtx_idx % submatrices_num_row;
119 size_t idx = (
size_t) (submtx_idx-jdx)/submatrices_num_row;
122 for (
size_t row_idx=0; row_idx<submatrix_size; row_idx++ ) {
125 size_t submatrix_offset = row_idx*submatrix_size;
160 size_t submatrices_num_row = 2;
163 size_t jdx = product_idx % submatrices_num_row;
164 size_t idx = (
size_t) ( product_idx - jdx )/submatrices_num_row;
167 Matrix tmp = (*submatrices)[jdx];
175 size_t submatrix_size = submatrix_prod.
rows;
176 size_t element_num = submatrix_size*submatrix_size;
180 tbb::parallel_for( tbb::blocked_range<size_t>(0, submatrix_size, 1), [&](tbb::blocked_range<size_t> r){
181 for (
size_t row_idx=r.begin(); row_idx != r.end(); row_idx++) {
182 size_t element_idx = row_idx*submatrix_size+row_idx;
183 submatrix_prod[element_idx].real = submatrix_prod[element_idx].real - corner_element.
real;
184 submatrix_prod[element_idx].imag = submatrix_prod[element_idx].imag - corner_element.
imag;
190 tbb::parallel_for( tbb::blocked_range<size_t>(0, element_num, 1), [&](tbb::blocked_range<size_t> r){
191 for (
size_t idx = r.begin(); idx != r.end(); idx ++) {
195 prod_cost_function_priv = prod_cost_function_priv + submatrix_prod[idx].real*submatrix_prod[idx].real + submatrix_prod[idx].imag*submatrix_prod[idx].imag;
201 printf(
"cost function NaN on thread %d: exiting\n", product_idx);
Matrix dot(Matrix &A, Matrix &B)
Call to calculate the product of two complex matrices by calling method zgemm3m from the CBLAS librar...
Function operator class to calculate the partial cost function derived from the individual products o...
std::vector< Matrix, tbb::cache_aligned_allocator< Matrix > > * submatrices
container storing the submatrices
size_t rows
The number of rows.
void operator()(int product_idx) const
Operator to calculate the partial cost function labeled by product_idx.
scalar * get_data()
Call to get the pointer to the stored data.
double get_submatrix_cost_function(Matrix &matrix)
Call to calculate the cost function of a given matrix during the submatrix decomposition process.
functor_submtx_cost_fnc(std::vector< Matrix, tbb::cache_aligned_allocator< Matrix >> *submatrices_in, tbb::combinable< double > *prod_cost_functions_in, size_t prod_num_in)
Constructor of the class.
Structure type representing complex numbers in the QGD package.
Class to store data of complex arrays and its properties.
void transpose()
Call to transpose (or un-transpose) the matrix for CBLAS functions.
double real
the real part of a complex number
void conjugate()
Call to conjugate (or un-conjugate) the matrix for CBLAS functions.
int prod_num
number of distinct submatix products
tbb::combinable< double > * prod_cost_functions
Header file for the paralleized calculation of the cost function of the subdecomposition (supporting ...
double imag
the imaginary part of a complex number