33 #ifndef __H__PCL_TEST_LAYOUTS__
34 #define __H__PCL_TEST_LAYOUTS__
52 #include <boost/function.hpp>
62 template <
class TElem>
69 UG_LOG(processCommunicator.
size() <<
" involved procs: ");
70 for(
size_t i=0; i<processCommunicator.
size(); i++)
76 #define PRINTPC(com) UG_LOG(__FUNCTION__ << " : " << __LINE__ << "\n"); PrintPC(com)
83 template<
typename TLayout>
86 const TLayout &masterLayout,
const TLayout &slaveLayout)
91 std::vector<char> bMasterToProcess; bMasterToProcess.resize(processCommunicator.
size(), 0x00);
92 std::vector<char> bSlaveToProcess; bSlaveToProcess.resize(processCommunicator.
size(), 0x00);
94 for(
typename TLayout::const_iterator iter = masterLayout.begin(); iter != masterLayout.end(); ++iter)
98 UG_LOG(
"Processor " << masterLayout.proc_id(iter) <<
" not in processCommunicator, but in MasterLayout\n")
99 else bMasterToProcess[id] =
true;
101 for(
typename TLayout::const_iterator iter = slaveLayout.begin(); iter != slaveLayout.end(); ++iter)
105 UG_LOG(
"Processor " << slaveLayout.proc_id(iter) <<
" not in processCommunicator, but in SlaveLayout\n")
106 else bSlaveToProcess[id] =
true;
109 for(
size_t i=0; i<processCommunicator.
size(); i++)
115 std::vector<ug::BinaryBuffer> masterToThisProcessMap(processCommunicator.
size());
116 std::vector<ug::BinaryBuffer> slaveToThisProcessMap(processCommunicator.
size());
117 for(
size_t i=0; i < processCommunicator.
size(); i++)
125 for(
size_t i=0; i<processCommunicator.
size(); i++)
127 char bMasterToThisProcess, bSlaveToThisProcess;
132 if(bMasterToThisProcess != bSlaveToProcess[i])
134 UG_LOG(
"Process " << std::setw(4) << pid <<
" has " << (bMasterToThisProcess ?
"a" :
"no") <<
" master connection to this process (" << std::setw(4) <<
pcl::ProcRank()
135 <<
"), but we have " << (bSlaveToProcess[i] ?
"a" :
"no") <<
" slave connection to " << std::setw(4) << pid << std::endl);
138 if(bSlaveToThisProcess != bMasterToProcess[i]){
139 UG_LOG(
"Process " << std::setw(4) << pid <<
" has " << (bSlaveToThisProcess ?
"a" :
"no") <<
" slave connection to this process (" <<
pcl::ProcRank()
140 <<
"), but we have " << (bMasterToProcess[i] ?
"a" :
"no") <<
" master connection to " << std::setw(4) << pid << std::endl);
159 template<
typename TLayout,
typename TValue>
161 const TLayout &masterLayout,
162 const TLayout &slaveLayout,
bool bPrint=
false,
163 boost::function<TValue (
typename TLayout::Element)> cbToValue
164 = TrivialToValue<typename TLayout::Element>,
165 bool compareValues =
false)
168 typedef std::map<int, ug::BinaryBuffer> BufferMap;
169 typedef typename TLayout::Interface Interface;
171 BufferMap sendMap, receiveMap;
173 for(
typename TLayout::const_iterator iter = slaveLayout.begin(); iter != slaveLayout.end(); ++iter)
175 const Interface &
interface = slaveLayout.interface(iter);
176 int pid = slaveLayout.proc_id(iter);
179 for(
typename TLayout::Interface::const_iterator iter2 = interface.begin(); iter2 != interface.end(); ++iter2)
181 const typename Interface::Element &element = interface.get_element(iter2);
188 for(
typename TLayout::const_iterator iter = masterLayout.begin(); iter != masterLayout.end(); ++iter)
190 int pid = masterLayout.proc_id(iter);
196 bool layoutBroken=
false;
197 bool valueMismatch =
false;
199 for(
typename TLayout::const_iterator iter = masterLayout.begin(); iter != masterLayout.end(); ++iter)
201 int pid = masterLayout.proc_id(iter);
204 if(bPrint) {
UG_LOG(
" Interface processor " <<
pcl::ProcRank() <<
" <-> processor " << pid <<
" (Master <-> Slave):\n"); }
205 const typename TLayout::Interface &
interface = masterLayout.interface(iter);
206 std::stringstream brokenInformation;
207 size_t onMaster=0, onSlave=0;
208 for(
typename TLayout::Interface::const_iterator iter2 = interface.begin(); iter2 != interface.end(); ++iter2)
210 TValue val1 = cbToValue(interface.get_element(iter2));
216 UG_LOG(
" " << onMaster <<
": " << std::setw(9) << val1 <<
" <-> " <<
"-?-" <<
"\n");
225 bool mismatch =
false;
227 mismatch = (val1 != val2);
231 UG_LOG(
" " << std::setw(9) << val1 <<
" <-> " << val2 <<
" --- MISMATCH! ---"
232 <<
" (interface to proc " << pid <<
")" << std::endl);
234 valueMismatch |= mismatch;
237 UG_LOG(
" " << onMaster <<
": " << std::setw(9) << val1 <<
" <-> " << val2 <<
"\n");
250 {
UG_LOG(
" " << onSlave <<
": " << std::setw(9) <<
"-?-" <<
" <-> " << val2 <<
"\n");}
256 if(onMaster!=onSlave)
258 UG_LOG(
" Interface sizes do not match:\n");
259 UG_LOG(
" - Slave Interface " << pid <<
" -> " <<
pcl::ProcRank() <<
", size = " << onSlave <<
"\n");
260 UG_LOG(
" - Master Interface " <<
pcl::ProcRank() <<
" -> " << pid <<
", size = " << onMaster <<
"\n");
263 {
UG_LOG(
" In total " << std::setw(9) << onMaster <<
" entries in this interface." << std::endl); }
268 UG_LOG(
" Interface from processor " << std::setw(4) <<
pcl::ProcRank() <<
" to processor " << std::setw(4) << pid <<
" is BROKEN!\n");
274 if(layoutBroken ==
true)
276 UG_LOG(
"One or more interfaces are broken\n");
281 UG_LOG(
"MISMATCH! Not all values at connected interface elements did match!\n");
299 template<
typename TLayout,
typename TValue>
302 const TLayout &masterLayout,
303 const TLayout &slaveLayout,
bool bPrint=
false,
304 boost::function<TValue (
typename TLayout::Element)> cbToValue
305 = TrivialToValue<typename TLayout::Element>,
306 bool compareValues =
false)
312 UG_LOG(
" MasterLayout is to processes ");
313 for(
typename TLayout::const_iterator iter = masterLayout.begin(); iter != masterLayout.end(); ++iter) {
314 UG_LOG(
" " << std::setw(4) << masterLayout.proc_id(iter) <<
" ");
316 UG_LOG(
"\n Slave Layout is to processes ");
317 for(
typename TLayout::const_iterator iter = slaveLayout.begin(); iter != slaveLayout.end(); ++iter) {
318 UG_LOG(
" " << std::setw(4) << slaveLayout.proc_id(iter) <<
" ");
323 com, masterLayout, slaveLayout);
327 bool bSuccess = TestSizeOfInterfacesInLayoutsMatch<TLayout, TValue>(com, masterLayout,
328 slaveLayout, bPrint, cbToValue, compareValues);
332 template<
typename TLayout>
335 const TLayout &slaveLayout,
bool bPrint=
false,
336 bool compareValues =
false)
338 return TestLayout<TLayout, typename TLayout::Element>(processCommunicator, com,
339 masterLayout, slaveLayout, bPrint,
340 TrivialToValue<typename TLayout::Element>, compareValues);
343 template<
typename TLayout,
typename TValue>
346 const TLayout &slaveLayout,
347 boost::function<TValue (
typename TLayout::Element)> cbToValue
348 = TrivialToValue<typename TLayout::Element>)
350 return TestLayout(processCommunicator, com, masterLayout, slaveLayout,
true, cbToValue);
354 template<
typename TLayout>
357 const TLayout &masterLayout,
358 const TLayout &slaveLayout)
360 return TestLayout(processCommunicator, com, masterLayout, slaveLayout,
true);
365 template<
typename TLayout>
368 for(
typename TLayout::const_iterator iter = layout.begin(); iter != layout.end(); ++iter)
370 size_t pid = layout.proc_id(iter);
371 UG_LOG(
"to processor " << pid <<
": ");
372 const typename TLayout::Interface &
interface = layout.interface(iter);
373 for(
typename TLayout::Interface::const_iterator iter2 = interface.begin(); iter2 != interface.end(); ++iter2)
374 UG_LOG(interface.get_element(iter2) <<
" ");
379 #define TESTLAYOUT(processCommunicator, com, master, slave) { if(TestLayout(processCommunicator,\
380 com, master, slave) == false) { PrintLayout(processCommunicator, com, master, slave); UG_COND_THROW(true, "layout broken"); } }
383 #define DEBUG_TESTLAYOUT(processCommunicator, com, master, slave) TESTLAYOUT(processCommunicator, com, master, slave)
385 #define DEBUG_TESTLAYOUT(processCommunicator, com, master, slave)
388 #define DEBUG_TESTLAYOUTS(layout) DEBUG_TESTLAYOUT(layout->proc_comm(), layout->comm(), layout->master(), layout->slave())
389 #define TESTLAYOUTS(layout) TESTLAYOUT(layout->proc_comm(), layout->comm(), layout->master(), layout->slave())
Performs communication between interfaces on different processes.
Definition: pcl_interface_communicator.h:68
void send_raw(int targetProc, const void *pBuff, int bufferSize, bool bSizeKnownAtTarget=false)
sends raw data to a target-proc.
Definition: pcl_interface_communicator_impl.hpp:61
void receive_raw(int srcProc, ug::BinaryBuffer &bufOut, int bufSize=-1)
registers a binary-stream to receive data from a source-proc.
Definition: pcl_interface_communicator_impl.hpp:166
bool communicate(int tag=749345)
sends and receives the collected data.
Definition: pcl_interface_communicator_impl.hpp:409
Definition: pcl_process_communicator.h:70
int get_proc_id(size_t index) const
returns the i-th process in the communicator
Definition: pcl_process_communicator.cpp:86
size_t size() const
returns the size of the communicator
Definition: pcl_process_communicator.cpp:71
int get_local_proc_id(int globalProcID=pcl::ProcRank()) const
returns the proc-id relative to this communicator
Definition: pcl_process_communicator.cpp:95
A Buffer for binary data.
Definition: binary_buffer.h:56
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
bool eof()
returns true if the read-position reached the write-position
Definition: binary_buffer_impl.h:99
bool TestLayoutIsDoubleEnded(const pcl::ProcessCommunicator processCommunicator, pcl::InterfaceCommunicator< TLayout > &com, const TLayout &masterLayout, const TLayout &slaveLayout)
tests if masterLayouts proc id's find a match in corresponding slaveLayouts proc ids.
Definition: pcl_layout_tests.h:84
int ProcRank()
returns the rank of the process
Definition: pcl_base.cpp:83
TElem TrivialToValue(TElem e)
Trivial implementation of a to-value callback.
Definition: pcl_layout_tests.h:63
bool TestLayout(const pcl::ProcessCommunicator &processCommunicator, pcl::InterfaceCommunicator< TLayout > &com, const TLayout &masterLayout, const TLayout &slaveLayout, bool bPrint=false, boost::function< TValue(typename TLayout::Element)> cbToValue=TrivialToValue< typename TLayout::Element >, bool compareValues=false)
Checks whether the given layouts are consistent.
Definition: pcl_layout_tests.h:300
bool AllProcsTrue(bool bFlag, ProcessCommunicator comm)
Definition: pcl_util.cpp:54
bool PrintLayout(const pcl::ProcessCommunicator &processCommunicator, pcl::InterfaceCommunicator< TLayout > &com, const TLayout &masterLayout, const TLayout &slaveLayout, boost::function< TValue(typename TLayout::Element)> cbToValue=TrivialToValue< typename TLayout::Element >)
Definition: pcl_layout_tests.h:344
bool TestSizeOfInterfacesInLayoutsMatch(pcl::InterfaceCommunicator< TLayout > &com, const TLayout &masterLayout, const TLayout &slaveLayout, bool bPrint=false, boost::function< TValue(typename TLayout::Element)> cbToValue=TrivialToValue< typename TLayout::Element >, bool compareValues=false)
if processor P1 has a interface to P2, then the size of the interface P1->P2 has to be the same as th...
Definition: pcl_layout_tests.h:160
void PrintPC(const pcl::ProcessCommunicator &processCommunicator)
Definition: pcl_layout_tests.h:67
#define UG_LOG(msg)
Definition: log.h:367
Definition: parallel_grid_layout.h:46
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
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