33 #ifndef __H__UG_matrix_overlap_impl
34 #define __H__UG_matrix_overlap_impl
42 template <
class TLayout>
46 typedef typename TLayout::const_iterator const_iter_t;
47 for(const_iter_t iter = layout.begin(); iter != layout.end(); ++iter)
49 procsOut.push_back(layout.interface(iter).get_target_proc());
54 template <
class TMatrix>
73 iter != interface.
end(); ++iter)
86 iter != interface.
end(); ++iter)
111 template <
class TMatrix>
133 typedef typename TMatrix::row_iterator row_iterator;
137 iter != interface.
end(); ++iter)
143 const row_iterator rowEnd =
m_mat.end_row(index);
144 size_t numRowEntry = 0;
145 for(row_iterator it_k =
m_mat.begin_row(index); it_k != rowEnd; ++it_k)
152 for(row_iterator it_k =
m_mat.begin_row(index); it_k != rowEnd; ++it_k)
154 const size_t k = it_k.index();
185 iter != interface.
end(); ++iter)
191 size_t numConnections = 0;
195 for(
size_t i_conn = 0; i_conn < numConnections; ++i_conn){
203 m_mat(index, conInd) += block;
228 *newLayout = *
m_mat.layouts();
229 newLayout->enable_overlap(
true);
230 m_mat.set_layouts (newLayout);
232 const size_t oldSize =
m_mat.num_rows();
234 const size_t newSize = oldSize + numNewInds;
240 for(set<AlgebraID>::iterator iter =
m_recvNewIDs.begin();
248 if(newSize != oldSize) {
250 m_mat.resize_and_keep_values (newSize, newSize);
251 for(
size_t i = oldSize; i < newSize; ++i){
257 vector<int> slaveProcs;
265 vector<int> msgSizeForSlaveProcs(slaveProcs.size(), 0);
273 for (
typename map<ExtCon, block_t>::iterator iter =
m_recvNewCons.begin();
276 const ExtCon& curExtCon = iter->first;
277 const int targetProc = curExtCon.
conProc;
279 itfc = &newLayout->master_overlap().interface(targetProc);
281 added.resize(numNewInds,
false);
285 for(
size_t islave = 0; islave < slaveProcs.size(); ++islave){
286 if(slaveProcs[islave] == targetProc){
287 slaveInd = int(islave);
291 UG_COND_THROW(slaveInd == -1,
"slaveProcs doas not contain referenced slave rank");
296 "Expected AlgebraID not found in Hash");
298 if(!added[toInd - oldSize]){
300 const size_t oldWritePos = sendBuf.
write_pos();
302 msgSizeForSlaveProcs[slaveInd] += int(sendBuf.
write_pos() - oldWritePos);
304 added[toInd - oldSize] =
true;
312 vector<int> masterProcs;
315 vector<int> recvSizes (masterProcs.size());
318 newLayout->proc_comm().distribute_data(
319 recvBuf, &recvSizes.front(), &masterProcs.front(),
320 (
int)masterProcs.size(),
321 sendBuf.
buffer(), &msgSizeForSlaveProcs.front(),
322 &slaveProcs.front(), (
int)slaveProcs.size());
325 for(
size_t i = 0; i < masterProcs.size(); ++i)
328 .interface(masterProcs[i]);
330 size_t oldReadPos = recvBuf.
read_pos();
331 while(recvBuf.
read_pos() < oldReadPos + recvSizes[i]){
339 UG_THROW(
"GlobalID " << globID <<
" expected on this process "
348 newLayout->comm().send_data(newLayout->master(), comPolMatCopy);
349 newLayout->comm().receive_data(newLayout->slave(), comPolMatCopy);
350 newLayout->comm().communicate();
386 newLayout->comm().send_data(newLayout->slave_overlap(), comPolMatCopyDiag);
387 newLayout->comm().receive_data(newLayout->master_overlap(), comPolMatCopyDiag);
388 newLayout->comm().communicate();
420 else if(
toID > ec.
toID)
return false;
433 template <
class TMatrix>
439 vector<AlgebraID> globalIDs;
444 mat.layouts()->master(),
445 mat.layouts()->slave());
448 mat.layouts()->comm().send_data(mat.layouts()->slave(), comPolOverlap);
449 mat.layouts()->comm().receive_data(mat.layouts()->master(), comPolOverlap);
450 mat.layouts()->comm().communicate();
Definition: smart_pointer.h:108
specializations are responsible to pack and unpack interface data during communication.
Definition: pcl_communication_structs.h:790
You may add elements to this interface and iterate over them.
Definition: pcl_communication_structs.h:207
iterator push_back(const Element &elem)
Definition: pcl_communication_structs.h:245
ElemContainer::const_iterator const_iterator
Definition: pcl_communication_structs.h:237
iterator end()
Definition: pcl_communication_structs.h:293
iterator begin()
Definition: pcl_communication_structs.h:292
Element & get_element(iterator iter)
Definition: pcl_communication_structs.h:298
int get_target_proc() const
Definition: pcl_communication_structs.h:309
size_t size() const
returns the number of elements that are stored in the interface.
Definition: pcl_communication_structs.h:306
Extends the HorizontalAlgebraLayouts by vertical layouts.
Definition: algebra_layouts.h:121
A Buffer for binary data.
Definition: binary_buffer.h:56
size_t read_pos() const
returns the current read-pos (in bytes)
Definition: binary_buffer_impl.h:48
char * buffer()
returns the raw buffer pointer or NULL if the buffer is empty (capacity() == 0)
Definition: binary_buffer_impl.h:94
size_t write_pos() const
returns the current write-pos (in bytes)
Definition: binary_buffer_impl.h:53
Definition: matrix_overlap_impl.h:56
int get_required_buffer_size(const Interface &interface)
returns the size of the buffer in bytes, that will be required for interface-communication.
Definition: matrix_overlap_impl.h:60
ComPol_MatCopyDiag(TMatrix &mat)
Definition: matrix_overlap_impl.h:58
TMatrix & m_mat
Definition: matrix_overlap_impl.h:95
bool collect(ug::BinaryBuffer &buff, const Interface &interface)
should write data which is associated with the interface elements to the buffer.
Definition: matrix_overlap_impl.h:68
bool extract(ug::BinaryBuffer &buff, const Interface &interface)
extract data from the buffer and assigns it to the interface-elements.
Definition: matrix_overlap_impl.h:81
Communication Policy to copy couplings between interfaces.
Definition: communication_policies.h:1273
Highly specialized communication policy for matrix overlap creation.
Definition: matrix_overlap_impl.h:114
TMatrix & m_mat
Definition: matrix_overlap_impl.h:393
virtual void post_process()
After communication is done, this method should be called to create the overlap.
Definition: matrix_overlap_impl.h:219
TMatrix::value_type block_t
Definition: matrix_overlap_impl.h:116
AlgebraIDVec & m_globalIDs
map localID->globalID
Definition: matrix_overlap_impl.h:396
std::set< AlgebraID > m_recvNewIDs
Here we just collect the new IDs which are added to the local matrix.
Definition: matrix_overlap_impl.h:428
AlgebraIDHashList m_algIDHash
map globalID->localID
Definition: matrix_overlap_impl.h:399
std::map< ExtCon, block_t > m_recvNewCons
New connections received from other processes.
Definition: matrix_overlap_impl.h:426
ComPol_MatCreateOverlap(TMatrix &rMat, AlgebraIDVec &vGlobalID)
Constructor setting the vector.
Definition: matrix_overlap_impl.h:121
virtual bool collect(ug::BinaryBuffer &buff, const Interface &interface)
writes the interface values into a buffer that will be sent
Definition: matrix_overlap_impl.h:130
virtual bool extract(ug::BinaryBuffer &buff, const Interface &interface)
writes values from a buffer into the interface
Definition: matrix_overlap_impl.h:171
void insert(const key_t &key, const value_t &val)
Definition: hash_impl.hpp:199
value_t & get_entry(const key_t &key)
Definition: hash_impl.hpp:158
void GenerateGlobalAlgebraIDs(pcl::InterfaceCommunicator< TLayout > &communicator, std::vector< AlgebraID > &idsOut, size_t numIDs, const TLayout &masterLayout, const TLayout &slaveLayout)
Generates a set of unique global algebra ids.
Definition: parallelization_util.h:81
void SetDirichletRow(TSparseMatrix &A, size_t i, size_t alpha)
Definition: sparsematrix_util.h:796
#define UG_THROW(msg)
Definition: error.h:57
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
Definition: smart_pointer.h:814
void GetLayoutTargetProcs(std::vector< int > &procsOut, const TLayout &layout)
Definition: matrix_overlap_impl.h:43
void CreateOverlap(TMatrix &matInOut)
Adds coefficients and connections to create an overlapping matrix.
Definition: matrix_overlap_impl.h:434
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
std::vector< AlgebraID > AlgebraIDVec
Definition: algebra_id.h:63
void GenerateAlgebraIDHashList(AlgebraIDHashList &hash, AlgebraIDVec &algebraIDs)
Creates a hash which allows a algebraID->localIndex mapping.
Definition: algebra_id.h:70
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition: restart_bridge.cpp:103
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258
#define PROFILE_BEGIN_GROUP(name, groups)
Definition: profiler.h:255
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
T value_type
Definition: sparsematrix_interface.h:2
this type is used to identify distributed objects.
Definition: algebra_id.h:46
Definition: matrix_overlap_impl.h:401
AlgebraID fromID
Definition: matrix_overlap_impl.h:411
int conProc
Definition: matrix_overlap_impl.h:413
size_t fromInd
Definition: matrix_overlap_impl.h:410
ExtCon(size_t _fromInd, const AlgebraID &_fromID, const AlgebraID &_toID, int _conProc)
Definition: matrix_overlap_impl.h:402
bool operator<(const ExtCon &ec) const
Definition: matrix_overlap_impl.h:415
AlgebraID toID
Definition: matrix_overlap_impl.h:412
Definition: communication_policies.h:58