33#ifndef __H__LIB_ALGEBRA__PARALLELIZATION__PARALLEL_MATRIX_IMPL__
34#define __H__LIB_ALGEBRA__PARALLELIZATION__PARALLEL_MATRIX_IMPL__
41template <
typename TMatrix>
46 TMatrix::operator= (*
dynamic_cast<const TMatrix*
>(&M));
56template <
typename TMatrix>
64 UG_LOG(
"Current Storage Type is undefined. "
65 "Cannot change storage type.\n");
70 if(has_storage_type(type))
74 UG_THROW(
"ParallelMatrix::change_storage_type:"
75 " Currently no storage conversion supported.");
79template <
typename TMatrix>
80template<
typename TPVector>
83apply(TPVector &res,
const TPVector &x)
const
98 UG_THROW(
"ParallelMatrix::apply (b = A*x): "
99 "Wrong storage type of Matrix/Vector: Possibilities are:\n"
100 " - A is PST_ADDITIVE and x is PST_CONSISTENT\n"
101 " - A is PST_CONSISTENT and x is PST_ADDITIVE\n"
102 " (storage type of A = " << get_storage_type() <<
", x = " << x.get_storage_type() <<
")");
106 TMatrix::axpy(res, 0.0, res, 1.0, x);
121template <
typename TMatrix>
122template<
typename TPVector>
140 UG_THROW(
"ParallelMatrix::apply_transposed (b = A^T*x): "
141 "Wrong storage type of Matrix/Vector: Possibilities are:\n"
142 " - A is PST_ADDITIVE and x is PST_CONSISTENT\n"
143 " - A is PST_CONSISTENT and x is PST_ADDITIVE\n"
144 " (storage type of A = " << get_storage_type() <<
", x = " << x.get_storage_type() <<
")");
148 TMatrix::axpy_transposed(res, 0.0, res, 1.0, x);
163template <
typename TMatrix>
164template<
typename TPVector>
179 UG_THROW(
"ParallelMatrix::matmul_minus (b -= A*x):"
180 " Wrong storage type of Matrix/Vector: Possibilities are:\n"
181 " - A is PST_ADDITIVE and x is PST_CONSISTENT and b is PST_ADDITIVE\n"
182 " (storage type of A = " << this->get_storage_type() <<
", x = " << x.get_storage_type() <<
", b = " << res.get_storage_type() <<
")");
186 TMatrix::axpy(res, 1.0, res, -1.0, x);
200template<
typename matrix_type,
typename vector_type>
214 UG_THROW(
"ParallelMatrix::apply (b = A*x): "
215 "Wrong storage type of Matrix/Vector: Possibilities are:\n"
216 " - A is PST_ADDITIVE and x is PST_CONSISTENT\n"
217 " - A is PST_CONSISTENT and x is PST_ADDITIVE\n"
223template<
typename matrix_type,
typename vector_type>
232 MatMult(
dynamic_cast<vector_type&
>(dest), beta1,
dynamic_cast<const matrix_type&
>(A1),
dynamic_cast<const vector_type&
>(w1));
241template<
typename matrix_type,
typename vector_type>
253 UG_THROW(
"MatMultAdd(dest, alpha1, v1, beta1, A1, w1): Storage type of A1*w1 = " << type <<
", storage type of v1 = " << v1.
get_storage_type() <<
".");
256 MatMultAdd(
dynamic_cast<vector_type&
>(dest), alpha1,
dynamic_cast<const vector_type&
>(v1),
257 beta1,
dynamic_cast<const matrix_type&
>(A1),
dynamic_cast<const vector_type&
>(w1));
266template<
typename matrix_type,
typename vector_type>
279 UG_THROW(
"MatMultAdd(dest, alpha1, v1, alpha2, v2, beta1, A1, w1):"
280 " Storage type of A1*w1 doesnt match storage type of v1 or v2.\n"
284 MatMultAdd(
dynamic_cast<vector_type&
>(dest), alpha1,
dynamic_cast<const vector_type&
>(v1), alpha2,
dynamic_cast<const vector_type&
>(v2),
285 beta1,
dynamic_cast<const matrix_type&
>(A1),
dynamic_cast<const vector_type&
>(w1));
294template<
typename matrix_type,
typename vector_type>
303 MatMultTransposed(
dynamic_cast<vector_type&
>(dest), beta1,
dynamic_cast<const matrix_type&
>(A1),
dynamic_cast<const vector_type&
>(w1));
Wrapper for sequential matrices to handle them in parallel.
Definition parallel_matrix.h:65
bool has_storage_type(uint type) const
returns if the current storage type has a given representation
Definition parallel_matrix.h:116
bool apply_transposed(TPVector &res, const TPVector &x) const
calculate res = A.T x
Definition parallel_matrix_impl.h:125
bool matmul_minus(TPVector &res, const TPVector &x) const
calculate res -= A x
Definition parallel_matrix_impl.h:167
ParallelStorageType get_storage_type() const
Definition parallel_matrix.h:121
ConstSmartPtr< AlgebraLayouts > layouts() const
returns the algebra layouts
Definition parallel_matrix.h:94
bool apply(TPVector &res, const TPVector &x) const
calculate res = A x
Definition parallel_matrix_impl.h:83
uint get_storage_mask() const
returns storage type mask
Definition parallel_matrix.h:120
bool change_storage_type(ParallelStorageType type)
changes to the requested storage type if possible
Definition parallel_matrix_impl.h:59
ParallelMatrix< TMatrix > this_type
own type
Definition parallel_matrix.h:76
this_type & operator=(const this_type &M)
assignment
Definition parallel_matrix_impl.h:43
Definition parallel_vector.h:60
bool has_storage_type(uint type) const
returns if the current storage type has a given representation
Definition parallel_vector.h:119
ParallelStorageType get_storage_type() const
Definition parallel_vector.h:124
void set_storage_type(uint type)
sets the storage type
Definition parallel_vector.h:104
ParallelStorageType
Definition parallel_storage_type.h:66
@ PST_UNDEFINED
Definition parallel_storage_type.h:67
@ PST_CONSISTENT
Definition parallel_storage_type.h:68
@ PST_ADDITIVE
Definition parallel_storage_type.h:69
#define UG_THROW(msg)
Definition error.h:57
#define UG_LOG(msg)
Definition log.h:367
double number
Definition types.h:124
void MatMultTransposedDirect(ParallelVector< vector_type > &dest, const number &beta1, const ParallelMatrix< matrix_type > &A1, const ParallelVector< vector_type > &w1)
Definition parallel_matrix_impl.h:295
bool MatMultAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition operations_mat.h:68
bool MatMultDirect(ParallelVector< vector_type > &dest, const number &beta1, const ParallelMatrix< matrix_type > &A1, const ParallelVector< vector_type > &w1)
Definition parallel_matrix_impl.h:224
bool MatMultAddDirect(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1, const number &alpha1, const vector_t &v1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition matrix_use_global_functions.h:43
bool MatMult(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = beta1 * A1;
Definition operations_mat.h:59
ug::ParallelStorageType GetMultType(const ParallelMatrix< matrix_type > &A1, const ParallelVector< vector_type > &x)
Definition parallel_matrix_impl.h:201
bool MatMultTransposed(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition operations_mat.h:111
#define PROFILE_FUNC_GROUP(groups)
Definition profiler.h:258