ug4
pcl_interface_communicator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__PCL__PCL_INTERFACE_COMMUNICATOR__
34 #define __H__PCL__PCL_INTERFACE_COMMUNICATOR__
35 
36 #include <map>
37 #include <set>
38 #include <cassert>
42 
43 namespace pcl
44 {
45 
48 
50 // There are two types of communicators:
51 // - InterfaceCommunicator: Data is exchanged between elements of
52 // interfaces / layouts. CommunicationPolicies are used to
53 // collect and to extract interface-data.
54 // Benefits are low communication overhead and ease of use.
55 //
56 // - ProcessCommunicator: Arbitrary data is exchanged between all processes
57 // that are linked by layouts.
58 // Benefits are high flexibility and independency of
59 // interface element order.
61 
62 
64 // InterfaceCommunicator
66 template <class TLayout>
68 {
69  public:
70  // typedefs
71  typedef TLayout Layout;
72  typedef typename Layout::Interface Interface;
73  typedef typename Layout::Type Type;
74 
75  protected:
77 
78  public:
80 
82  // SEND
83 
85 
97  void send_raw(int targetProc, const void* pBuff, int bufferSize,
98  bool bSizeKnownAtTarget = false);
99 
101 
106  void send_data(int targetProc,
107  const Interface& interface,
109 
111 
116  void send_data(const Layout& layout,
118 
120  // RECEIVE
121 
123 
137  void receive_raw(int srcProc, ug::BinaryBuffer& bufOut,
138  int bufSize = -1);
139 
141 
155  void receive_raw(int srcProc, void* bufOut, int bufSize);
156 
158 
161  void receive_data(int srcProc,
162  const Interface& interface,
164 
166 
169  void receive_data(const Layout& layout,
171 
173  // EXCHANGE
175 
197  template <class TLayoutMap>
198  void exchange_data(const TLayoutMap& layoutMap,
199  const typename TLayoutMap::Key& keyFrom,
200  const typename TLayoutMap::Key& keyTo,
202 
204 
216  bool communicate(int tag = 749345);
217 
218 
220 
235  bool communicate_and_resume(int tag = 749345);
236 
238 
243  void wait();
244 
245 
247 
262  void enable_communication_debugging(const ProcessCommunicator& involvedProcs =
264 
267 
270 
271  protected:
272  typedef std::map<int, ug::BinaryBuffer> BufferMap;
273 
274  protected:
276  void send_data(const Layout& layout,
279 
281  void send_data(const Layout& layout,
284 
287  std::set<int>& curProcs,
288  const TLayout& layout);
290  void prepare_receiver_buffer_map(BufferMap& streamPack,
291  std::set<int>& curProcs,
292  const TLayout& layout,
295  void prepare_receiver_buffer_map(BufferMap& streamPack,
296  std::set<int>& curProcs,
297  const TLayout& layout,
299 
301 
305  bool collect_layout_buffer_sizes(const TLayout& layout,
307  std::map<int, int>* pMapBuffSizesOut,
309 
311 
315  bool collect_layout_buffer_sizes(const TLayout& layout,
317  std::map<int, int>* pMapBuffSizesOut,
319 
321  void extract_data(const TLayout& layout, BufferMap& bufMap,
322  CommPol& extractor);
323 
324  void extract_data(const TLayout& layout, BufferMap& bufMap,
325  CommPol& extractor,
327 
328  void extract_data(const TLayout& layout, BufferMap& bufMap,
329  CommPol& extractor,
331 
332  protected:
334 
340  {
342  ExtractorInfo(int srcProc, CommPol* pExtractor,
343  const Interface* pInterface, const Layout* pLayout,
344  void* buffer, ug::BinaryBuffer* binBuffer, int rawSize) :
345  m_srcProc(srcProc), m_extractor(pExtractor),
346  m_interface(pInterface), m_layout(pLayout),
347  m_buffer(buffer), m_binBuffer(binBuffer), m_rawSize(rawSize)
348  {
349  assert((srcProc == -1) || ((srcProc >= 0) && (srcProc < pcl::NumProcs())));
350  }
351 
355  const Layout* m_layout;
356  void* m_buffer;
359  };
360 
362  typedef std::list<ExtractorInfo> ExtractorInfoList;
363 
364  protected:
368  std::set<int> m_curOutProcs;
369 
373  std::set<int> m_curInProcs;
374 
377 
379  std::vector<MPI_Request> m_vSendRequests;
380  std::vector<MPI_Request> m_vReceiveRequests;
381 
384 
386 
388 
391 
393 
395 };
396 
397 // end group pcl
399 
400 }// end of namespace pcl
401 
403 // include implementation
405 
406 #endif
specializations are responsible to pack and unpack interface data during communication.
Definition: pcl_communication_structs.h:790
Performs communication between interfaces on different processes.
Definition: pcl_interface_communicator.h:68
BufferMap m_bufMapIn
holds the buffers that are used to receive data
Definition: pcl_interface_communicator.h:371
std::vector< MPI_Request > m_vReceiveRequests
Definition: pcl_interface_communicator.h:380
ICommunicationPolicy< Layout > CommPol
Definition: pcl_interface_communicator.h:76
bool communicate_and_resume(int tag=749345)
collects data and communicates it with other processes without waiting for receive
Definition: pcl_interface_communicator_impl.hpp:420
void prepare_receiver_buffer_map(BufferMap &bufMap, std::set< int > &curProcs, const TLayout &layout)
prepare stream-pack-in
Definition: pcl_interface_communicator_impl.hpp:230
void wait()
waits for the data communicated by communicate_and_resume() and extracts it
Definition: pcl_interface_communicator_impl.hpp:674
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
TLayout Layout
Definition: pcl_interface_communicator.h:71
Layout::Type Type
Definition: pcl_interface_communicator.h:73
bool m_bDebugCommunication
true if the communication shall be debugged.
Definition: pcl_interface_communicator.h:390
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 m_bSendBuffersFixed
holds info whether all send-buffers are of predetermined fixed size.
Definition: pcl_interface_communicator.h:394
ExtractorInfoList m_extractorInfos
holds information about the extractors that are awaiting data.
Definition: pcl_interface_communicator.h:376
std::set< int > m_curOutProcs
stores out-procs for the next communication step
Definition: pcl_interface_communicator.h:368
Layout::Interface Interface
Definition: pcl_interface_communicator.h:72
BufferMap m_bufMapOut
holds the buffers that are used to send data
Definition: pcl_interface_communicator.h:366
void extract_data(const TLayout &layout, BufferMap &bufMap, CommPol &extractor)
extract data from stream-pack
Definition: pcl_interface_communicator_impl.hpp:350
ProcessCommunicator m_debugProcComm
This procComm holds the processes that shall participate during communication-debugging.
Definition: pcl_interface_communicator.h:383
InterfaceCommunicator()
Definition: pcl_interface_communicator_impl.hpp:50
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 exchange_data(const TLayoutMap &layoutMap, const typename TLayoutMap::Key &keyFrom, const typename TLayoutMap::Key &keyTo, ICommunicationPolicy< TLayout > &commPol)
internally calls send_data and receive_data with the specified layouts.
Definition: pcl_interface_communicator_impl.hpp:213
bool communication_debugging_enabled()
returns true if communication debugging is enabled
Definition: pcl_interface_communicator_impl.hpp:767
std::set< int > m_curInProcs
stores in-procs for the next communication step
Definition: pcl_interface_communicator.h:373
void disable_communication_debugging()
disables debugging of communication
Definition: pcl_interface_communicator_impl.hpp:760
std::vector< MPI_Request > m_vSendRequests
used by communicate, communicate_and_resume and wait, to check whether communication is done.
Definition: pcl_interface_communicator.h:379
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
void enable_communication_debugging(const ProcessCommunicator &involvedProcs=ProcessCommunicator(PCD_WORLD))
enables debugging of communication. This has a severe effect on performance!
Definition: pcl_interface_communicator_impl.hpp:745
int m_curComTag
This is the tag for the currently performed communication.
Definition: pcl_interface_communicator.h:387
std::list< ExtractorInfo > ExtractorInfoList
A list that holds information about extractors.
Definition: pcl_interface_communicator.h:362
bool collect_layout_buffer_sizes(const TLayout &layout, ICommunicationPolicy< TLayout > &commPol, std::map< int, int > *pMapBuffSizesOut, const layout_tags::single_level_layout_tag &)
collects buffer sizes for a given layout and stores them in a map
Definition: pcl_interface_communicator_impl.hpp:282
std::map< int, ug::BinaryBuffer > BufferMap
Definition: pcl_interface_communicator.h:272
Definition: pcl_process_communicator.h:70
marks a layout as a multi-level layout
Definition: pcl_communication_structs.h:426
marks a layout as a single-level layout
Definition: pcl_communication_structs.h:407
A Buffer for binary data.
Definition: binary_buffer.h:56
int NumProcs()
returns the number of processes
Definition: pcl_base.cpp:91
@ PCD_WORLD
Definition: pcl_process_communicator.h:55
Definition: parallel_grid_layout.h:46
holds information that will be passed to the extract routines.
Definition: pcl_interface_communicator.h:340
void * m_buffer
Definition: pcl_interface_communicator.h:356
ExtractorInfo()
Definition: pcl_interface_communicator.h:341
CommPol * m_extractor
Definition: pcl_interface_communicator.h:353
int m_rawSize
Definition: pcl_interface_communicator.h:358
int m_srcProc
Definition: pcl_interface_communicator.h:352
ExtractorInfo(int srcProc, CommPol *pExtractor, const Interface *pInterface, const Layout *pLayout, void *buffer, ug::BinaryBuffer *binBuffer, int rawSize)
Definition: pcl_interface_communicator.h:342
const Interface * m_interface
Definition: pcl_interface_communicator.h:354
const Layout * m_layout
Definition: pcl_interface_communicator.h:355
ug::BinaryBuffer * m_binBuffer
Definition: pcl_interface_communicator.h:357