33 #ifndef __H__LIB_ALGEBRA__PARALLELIZATION__PARALLEL_VECTOR_IMPL__
34 #define __H__LIB_ALGEBRA__PARALLELIZATION__PARALLEL_VECTOR_IMPL__
41 #define PROFILE_PARALLEL_VECTOR
42 #ifdef PROFILE_PARALLEL_VECTOR
43 #define PARVEC_PROFILE_FUNC() PROFILE_FUNC()
44 #define PARVEC_PROFILE_BEGIN(name) PROFILE_BEGIN(name)
45 #define PARVEC_PROFILE_END() PROFILE_END()
47 #define PARVEC_PROFILE_FUNC()
48 #define PARVEC_PROFILE_BEGIN(name)
49 #define PARVEC_PROFILE_END()
56 template <
typename TVector>
61 TVector::operator=(*
dynamic_cast<const TVector*
>(&v));
71 template <
typename TVector>
80 UG_THROW(
"ParallelVector::operator-=: Incompatible storage type: "<<
87 TVector::operator-=(*
dynamic_cast<const TVector*
>(&v));
93 template <
typename TVector>
102 UG_THROW(
"ParallelVector::operator+=: Incompatible storage type: "<<
109 TVector::operator+=(*
dynamic_cast<const TVector*
>(&v));
115 template <
typename TVector>
124 UG_THROW(
"ParallelVector::change_storage_type: Trying to change"
125 " storage type of a vector that has type PST_UNDEFINED.");
128 if(has_storage_type(type))
return true;
131 if(layouts().invalid())
132 UG_THROW(
"ParallelVector::change_storage_type: No "
133 "layouts given but trying to change type.")
155 if(layouts()->overlap_enabled()){
158 layouts()->master_overlap(), &layouts()->comm());
172 if(layouts()->overlap_enabled())
184 if(layouts()->overlap_enabled()){
188 layouts()->master_overlap(), &layouts()->comm());
200 if(layouts()->overlap_enabled()){
202 layouts()->master_overlap(), &layouts()->comm());
211 if(layouts()->overlap_enabled()){
215 default:
return false;
220 template <
typename TVector>
246 template <
typename TVector>
255 template <
typename TVector>
262 TVector::set_random(from, to);
266 change_storage_type(type);
269 template <
typename TVector>
276 UG_THROW(
"ParallelVector::norm(): Cannot change"
277 " ParallelStorageType to unique.");
280 double tNormLocal = (double)TVector::norm();
281 tNormLocal *= tNormLocal;
286 if(layouts()->proc_comm().empty())
287 tNormGlobal = tNormLocal;
289 tNormGlobal = layouts()->proc_comm().allreduce(tNormLocal,
PCL_RO_SUM);
293 return sqrt((
number)tNormGlobal);
296 template <
typename TVector>
304 UG_THROW(
"ParallelVector::norm(): Cannot change"
305 " ParallelStorageType to unique.");
308 double tNormLocal = (double)TVector::maxnorm();
313 if(layouts()->proc_comm().empty())
314 tNormGlobal = tNormLocal;
316 tNormGlobal = layouts()->proc_comm().allreduce(tNormLocal,
PCL_RO_MAX);
320 return (
number)tNormGlobal;
323 template <
typename TVector>
331 UG_LOG(
"ERROR in 'ParallelVector::dotprod': "
332 "Parallel storage type of vector not given.\n");
333 UG_THROW(
"ERROR in ParallelVector::dotprod(): No parallel "
334 "Storage type given.");
367 double tSumLocal = (double)TVector::dotprod(v);
371 if(layouts()->proc_comm().empty())
372 tSumGlobal = tSumLocal;
374 layouts()->proc_comm().allreduce(&tSumLocal, &tSumGlobal, 1,
381 template <
typename TVector>
395 for(; iter != end; ++iter)
402 iter != interface.end(); ++iter)
410 " has block norm: "<<
BlockNorm2((*
this)[index])<<
"\n");
426 com.
send_data(layouts()->slave(), cpVecCheckConsistency);
427 com.
receive_data(layouts()->master(), cpVecCheckConsistency);
432 template <
typename TVector>
459 VecScaleAssign(*
dynamic_cast<T*
>(&dest), alpha1, *
dynamic_cast<const T*
>(&v1));
470 VecAssign(*
dynamic_cast<T*
>(&dest), *
dynamic_cast<const T*
>(&v1));
482 UG_COND_THROW(mask == 0,
"VecScaleAdd: cannot add vectors v1 and v2 because their storage masks are incompatible");
485 VecScaleAdd(*
dynamic_cast<T*
>(&dest), alpha1, *
dynamic_cast<const T*
>(&v1),
486 alpha2, *
dynamic_cast<const T*
>(&v2));
500 UG_COND_THROW(mask == 0,
"VecScaleAdd: cannot add vectors v1 and v2 because their storage masks are incompatible");
503 VecScaleAdd((T&)dest, alpha1, (
const T&)v1, alpha2, (
const T&)v2, alpha3, (
const T&)v3);
518 UG_COND_THROW(mask == 0,
"VecHadamardProd: cannot multiply vectors v1 and v2 because their storage masks are incompatible");
521 VecHadamardProd(*
dynamic_cast<T*
>(&dest), *
dynamic_cast<const T*
>(&v1), *
dynamic_cast<const T*
>(&v2));
528 VecExp(*
dynamic_cast<T*
>(&dest), *
dynamic_cast<const T*
>(&v));
535 VecLog(*
dynamic_cast<T*
>(&dest), *
dynamic_cast<const T*
>(&v));
540 template<
typename TVector>
549 template<
typename TVector>
557 template<
typename TVector>
563 template<
typename TVector>
572 template<
typename TVector>
Definition: smart_pointer.h:108
Performs communication between interfaces on different processes.
Definition: pcl_interface_communicator.h:68
bool communicate(int tag=749345)
sends and receives the collected data.
Definition: pcl_interface_communicator_impl.hpp:409
void send_data(int targetProc, const Interface &interface, ICommunicationPolicy< TLayout > &commPol)
collects data that will be send during communicate.
Definition: pcl_interface_communicator_impl.hpp:80
void receive_data(int srcProc, const Interface &interface, ICommunicationPolicy< TLayout > &commPol)
registers a communication-policy to receive data on communicate.
Definition: pcl_interface_communicator_impl.hpp:188
You may add elements to this interface and iterate over them.
Definition: pcl_communication_structs.h:207
Element & get_element(iterator iter)
Definition: pcl_communication_structs.h:298
iterator end(size_t level=0)
returns the iterator to the last interface of the layout.
Definition: pcl_communication_structs.h:492
iterator begin(size_t level=0)
returns the iterator to the first interface of the layout.
Definition: pcl_communication_structs.h:486
InterfaceMap::const_iterator const_iterator
Definition: pcl_communication_structs.h:477
Communication Policy to check consistency of a vector.
Definition: communication_policies.h:783
Definition: parallel_vector.h:60
number dotprod(const this_type &v)
dotprod (overwrites TVector::dotprod())
Definition: parallel_vector_impl.h:325
virtual this_type * virtual_clone() const
virtual clone using covariant return type
Definition: parallel_vector_impl.h:550
void check_storage_type() const
checks correctness of storage type
Definition: parallel_vector_impl.h:382
void set_random(number from, number to, ParallelStorageType type)
set all entries to a random number (overwrites TVector::set_random(number from, number to))
Definition: parallel_vector_impl.h:258
bool has_storage_type(uint type) const
returns if the current storage type has a given representation
Definition: parallel_vector.h:119
this_type & operator=(T t)
catch all other assignments so we don't use copy constructor here
ConstSmartPtr< AlgebraLayouts > layouts() const
returns the algebra layouts
Definition: parallel_vector.h:97
virtual this_type * virtual_clone_without_values() const
virtual clone using covariant return type excluding values
Definition: parallel_vector_impl.h:564
uint get_storage_mask() const
returns storage type mask
Definition: parallel_vector.h:123
void set(number w, ParallelStorageType type)
set all entries to value and the storage type
Definition: parallel_vector_impl.h:223
this_type & operator-=(const this_type &v)
subtract a vector
Definition: parallel_vector_impl.h:73
SmartPtr< this_type > clone() const
clones the vector (deep-copy) including values
Definition: parallel_vector_impl.h:558
bool change_storage_type(ParallelStorageType type)
changes to the requested storage type if possible
Definition: parallel_vector_impl.h:118
void set_storage_type(uint type)
sets the storage type
Definition: parallel_vector.h:104
number maxnorm() const
max norm (overwrites TVector::maxnorm())
Definition: parallel_vector_impl.h:298
number norm() const
two norm (overwrites TVector::norm())
Definition: parallel_vector_impl.h:271
ParallelVector< TVector > this_type
own type
Definition: parallel_vector.h:66
this_type & operator+=(const this_type &v)
add a vector
Definition: parallel_vector_impl.h:95
void set_layouts(ConstSmartPtr< AlgebraLayouts > layouts)
sets the algebra layouts
Definition: parallel_vector.h:100
SmartPtr< this_type > clone_without_values() const
clones the vector (deep-copy) excluding values
Definition: parallel_vector_impl.h:573
void enforce_consistent_type()
sets storage type to consistent
Definition: parallel_vector_impl.h:433
void ConsistentToUnique(TVector *pVec, const IndexLayout &slaveLayout)
changes parallel storage type from consistent to unique
Definition: parallelization_util.h:388
void SetLayoutValues(TVector *pVec, const IndexLayout &layout, typename TVector::value_type val)
sets the values of a vector to a given number only on the layout indices
Definition: parallelization_util.h:315
void UniqueToConsistent(TVector *pVec, const IndexLayout &masterLayout, const IndexLayout &slaveLayout, pcl::InterfaceCommunicator< IndexLayout > *pCom=NULL)
changes parallel storage type from unique to consistent
Definition: parallelization_util.h:204
void AdditiveToUnique(TVector *pVec, const IndexLayout &masterLayout, const IndexLayout &slaveLayout, pcl::InterfaceCommunicator< IndexLayout > *pCom=NULL)
changes parallel storage type from additive to unique
Definition: parallelization_util.h:261
void CopyValues(TVector *pVec, const IndexLayout &sourceLayout, const IndexLayout &targetLayout, pcl::InterfaceCommunicator< IndexLayout > *pCom=NULL)
Copies values from the source to the target layout.
Definition: parallelization_util.h:228
void AdditiveToConsistent(TVector *pVec, const IndexLayout &masterLayout, const IndexLayout &slaveLayout, pcl::InterfaceCommunicator< IndexLayout > *pCom=NULL)
changes parallel storage type from additive to consistent
Definition: parallelization_util.h:160
ParallelStorageType
Definition: parallel_storage_type.h:66
@ PST_UNDEFINED
Definition: parallel_storage_type.h:67
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
@ PST_UNIQUE
Definition: parallel_storage_type.h:70
@ PST_ADDITIVE
Definition: parallel_storage_type.h:69
#define PCL_RO_SUM
Definition: pcl_methods.h:63
#define PCL_DT_DOUBLE
Definition: pcl_datatype.h:57
#define PCL_RO_MAX
Definition: pcl_methods.h:61
#define UG_LOG_ALL_PROCS(msg)
Definition: log.h:371
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
unsigned int uint
Definition: types.h:114
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition: math_vector_functions_common_impl.hpp:265
void VecAssign(vector_t &dest, const vector_t &v1)
sets dest = v1 entrywise
Definition: operations_vec.h:154
void VecExp(double &dest, const double &v)
calculates elementwise exp
Definition: operations_vec.h:122
void CloneVector(Vector< TValueType > &dest, const Vector< TValueType > &src)
Definition: vector_impl.h:341
double VecProd(const double &a, const double &b)
returns scal<a, b>
Definition: operations_vec.h:84
void VecLog(double &dest, const double &v)
calculates elementwise log (natural logarithm)
Definition: operations_vec.h:128
double BlockNorm2(const TYPE &v)
Definition: blocks.h:51
void VecHadamardProd(double &dest, const double &v1, const double &v2)
calculates s = a * b (the Hadamard product)
Definition: operations_vec.h:114
void VecScaleAssign(double &dest, double alpha1, const double &v1)
calculates dest = alpha1*v1. for doubles
Definition: operations_vec.h:49
#define PARVEC_PROFILE_END()
Definition: parallel_vector_impl.h:45
#define PARVEC_PROFILE_BEGIN(name)
Definition: parallel_vector_impl.h:44
switch(yytype)
Definition: parser.cpp:1299
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258