ug4
compol_interface_status.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-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__UG__compol_interface_status__
34 #define __H__UG__compol_interface_status__
35 
36 #include <map>
37 #include <vector>
38 #include "common/assert.h"
39 #include "../distributed_grid.h"
41 
42 namespace ug
43 {
44 
46 
53 template <class TLayout>
55 {
56  public:
57  typedef TLayout Layout;
58  typedef typename Layout::Type GeomObj;
59  typedef typename Layout::Element Element;
60  typedef typename Layout::Interface Interface;
61  typedef typename Interface::const_iterator InterfaceIter;
62 
63  public:
69  m_pLayout(NULL),
70  m_distGridMgr(NULL),
71  m_status(status),
72  m_curLevel(0) {}
73 
75  uint status = INT_NONE) :
76  m_pLayout(NULL),
77  m_distGridMgr(distGridMgr),
78  m_status(status),
79  m_curLevel(0) {}
80 
81  void set_status(uint status) {m_status = status;}
85  uint get_status() {return m_status;}
86 
89  {m_distGridMgr = distGridMgr;}
90 
91 
93 
96  const std::vector<bool>& get_result_vec(int procRank, int level = 0)
97  {
98  UG_ASSERT(m_pLayout, "communication has to be performed"
99  " before results are checked.");
100 
101  UG_ASSERT(m_pLayout->interface_exists(procRank, level),
102  "interface to proc " << procRank << " on level "
103  << level << " does not exist.");
104 
105  if(level >= m_vecMaps.size())
106  m_vecMaps.resize(level + 1);
107 
108  std::vector<bool>& result = m_vecMaps[level][procRank];
109 
110  UG_ASSERT(result.size() == m_pLayout->interface(procRank, level).size(),
111  "result size and interface size do not match."
112  " perform communication directly before querying the results.");
113 
114  return result;
115  }
116 
117  const std::map<int, std::vector<bool> >& get_result_map(int level = 0)
118  {
119  UG_ASSERT(m_pLayout, "communication has to be performed"
120  " before results are checked.");
121 
122  if(level >= (int)m_vecMaps.size())
123  m_vecMaps.resize(level + 1);
124 
125  return m_vecMaps[level];
126  }
127 
129  // COMMUNICATION STUFF
130  virtual int
132  {
133  return interface.size() * sizeof(char);
134  }
135 
136  virtual bool
138  {
139  // clear and prepare the maps and set the layout
140  m_pLayout = pLayout;
141 
142  m_vecMaps.clear();
143  m_vecMaps.resize(m_pLayout->num_levels());
144 
145  return true;
146  }
147 
148  virtual bool
149  collect(ug::BinaryBuffer& buff, const Interface& interface)
150  {
151  // iterate over all elements in the interface and write
152  // whether they contain the status or not.
153  UG_ASSERT(m_distGridMgr, "Please set the distributed grid manager"
154  " before performing communication.");
155 
156  for(InterfaceIter iter = interface.begin();
157  iter != interface.end(); ++iter)
158  {
159  Element elem = interface.get_element(iter);
160  char val = (char)m_distGridMgr->contains_status(elem, m_status);
161  buff.write(&val, sizeof(char));
162  }
163 
164  return true;
165  }
166 
167  virtual void begin_level_extraction(int level)
168  {
169  UG_ASSERT(level < (int)m_vecMaps.size(), "Internal pcl error.");
170  m_curLevel = level;
171  }
172 
173  virtual bool
174  extract(ug::BinaryBuffer& buff, const Interface& interface)
175  {
176  // read the info from the buff and push bools to the
177  // vector associated with the interface.
178 
179  std::vector<bool>&
180  vec = m_vecMaps[m_curLevel][interface.get_target_proc()];
181  vec.clear();
182  vec.reserve(interface.size());
183 
184  for(InterfaceIter iter = interface.begin();
185  iter != interface.end(); ++iter)
186  {
187  Element elem = interface.get_element(iter);
188  char val;
189  buff.read(&val, sizeof(char));
190 
191  vec.push_back(((bool)val) ||
193  }
194 
195  return true;
196  }
197 
198  private:
199  typedef std::map<int, std::vector<bool> > VecMap;
200 
201  std::vector<VecMap> m_vecMaps;
202  const TLayout* m_pLayout;
206 };
207 
208 }// end of namespace
209 
210 #endif
specializations are responsible to pack and unpack interface data during communication.
Definition: pcl_communication_structs.h:790
A Buffer for binary data.
Definition: binary_buffer.h:56
void read(char *buf, size_t size)
reads data of the given size (in bytes)
Definition: binary_buffer_impl.h:58
void write(const char *buf, size_t size)
writes data of the given size (in bytes)
Definition: binary_buffer_impl.h:71
Exchanges information on the interface-status of connected elements.
Definition: compol_interface_status.h:55
std::map< int, std::vector< bool > > VecMap
Definition: compol_interface_status.h:199
void set_status(uint status)
Definition: compol_interface_status.h:81
TLayout Layout
Definition: compol_interface_status.h:57
ComPol_InterfaceStatus(DistributedGridManager *distGridMgr, uint status=INT_NONE)
Definition: compol_interface_status.h:74
Layout::Interface Interface
Definition: compol_interface_status.h:60
Layout::Element Element
Definition: compol_interface_status.h:59
uint m_status
Definition: compol_interface_status.h:204
const TLayout * m_pLayout
Definition: compol_interface_status.h:202
Layout::Type GeomObj
Definition: compol_interface_status.h:58
virtual int get_required_buffer_size(const Interface &interface)
returns the size of the buffer in bytes, that will be required for interface-communication.
Definition: compol_interface_status.h:131
void set_distributed_grid_manager(DistributedGridManager *distGridMgr)
set the distributed grid manager
Definition: compol_interface_status.h:88
virtual void begin_level_extraction(int level)
signals that a new layout-level will now be processed.
Definition: compol_interface_status.h:167
const std::map< int, std::vector< bool > > & get_result_map(int level=0)
Definition: compol_interface_status.h:117
std::vector< VecMap > m_vecMaps
Definition: compol_interface_status.h:201
int m_curLevel
Definition: compol_interface_status.h:205
const std::vector< bool > & get_result_vec(int procRank, int level=0)
returns the vector which holds the results for the interface to the given process
Definition: compol_interface_status.h:96
DistributedGridManager * m_distGridMgr
Definition: compol_interface_status.h:203
ComPol_InterfaceStatus(uint status=INT_NONE)
Definition: compol_interface_status.h:68
virtual bool begin_layout_extraction(const Layout *pLayout)
signals the beginning of a layout extraction.
Definition: compol_interface_status.h:137
uint get_status()
returns the current status
Definition: compol_interface_status.h:85
Interface::const_iterator InterfaceIter
Definition: compol_interface_status.h:61
virtual bool collect(ug::BinaryBuffer &buff, const Interface &interface)
should write data which is associated with the interface elements to the buffer.
Definition: compol_interface_status.h:149
virtual bool extract(ug::BinaryBuffer &buff, const Interface &interface)
extract data from the buffer and assigns it to the interface-elements.
Definition: compol_interface_status.h:174
manages the layouts and interfaces which are associated with a distributed grid.
Definition: distributed_grid.h:88
bool contains_status(TGeomObj *o, byte status) const
returns true if the status of the given object contains the given status.
Definition: distributed_grid.h:135
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
unsigned int uint
Definition: types.h:114
the ug namespace
@ INT_NONE
Definition: parallel_grid_layout.h:103