ug4
domain_load_balancer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-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__domain_load_balancer__
34 #define __H__UG__domain_load_balancer__
35 
36 #include "lib_disc/domain.h" // for DomainInfo
40 
41 namespace ug{
42 
44 template <class TDomain>
46 CreateProcessHierarchy(TDomain& dom, size_t minNumElemsPerProcPerLvl,
47  size_t maxNumRedistProcs, size_t maxNumProcs,
48  int minDistLvl, int maxLevelsWithoutRedist)
49 {
50  return CreateProcessHierarchy(dom, minNumElemsPerProcPerLvl,
51  maxNumRedistProcs, maxNumProcs, minDistLvl,
52  maxLevelsWithoutRedist, NULL);
53 }
54 
55 template <class TDomain>
57 CreateProcessHierarchy(TDomain& dom, size_t minNumElemsPerProcPerLvl,
58  size_t maxNumRedistProcs, size_t maxNumProcs,
59  int minDistLvl, int maxLevelsWithoutRedist,
60  IRefiner* refiner)
61 {
62  const DomainInfo& domInf = dom.domain_info();
63  std::vector<size_t> numElemsOnLvl;
64  numElemsOnLvl.reserve(domInf.num_levels());
65  for(size_t i = 0; i < domInf.num_levels(); ++i)
66  numElemsOnLvl.push_back(domInf.num_elements_on_level(i));
67 
68  if(numElemsOnLvl.empty()){
69  return ProcessHierarchy::create();
70  }
71 
72  if(refiner){
73  std::vector<int> numMarked;
74  int elemFactor = 1;
75  if(dom.get_dim() == 1){
76  refiner->num_marked_edges(numMarked);
77  elemFactor = 2;
78  }
79  else if(dom.get_dim() == 2){
80  refiner->num_marked_faces(numMarked);
81  elemFactor = 4;
82  }
83  else if(dom.get_dim() == 3){
84  refiner->num_marked_volumes(numMarked);
85  elemFactor = 8;
86  }
87 
88  if(numMarked.size() < numElemsOnLvl.size())
89  numMarked.resize(numElemsOnLvl.size(), 0);
90 
91  if(numMarked[numElemsOnLvl.size() - 1] > 0)
92  numElemsOnLvl.resize(numElemsOnLvl.size() + 1, 0);
93 
94  for(size_t i = 0; i < numElemsOnLvl.size(); ++i){
95  if(numMarked[i] > 0){
96  numElemsOnLvl[i+1] += numMarked[i] * elemFactor;
97  }
98  }
99  }
100 
101  return CreateProcessHierarchy(&numElemsOnLvl.front(), numElemsOnLvl.size(),
102  minNumElemsPerProcPerLvl, maxNumRedistProcs,
103  maxNumProcs, minDistLvl, maxLevelsWithoutRedist);
104 }
105 
107 template <class TDomain>
109 {
111 
112  public:
114 
117  {
118  base_class::set_grid(dom->grid().get());
119 
122  create(*dom->grid(), dom->position_attachment()));
123 
125  SubsetHandlerSerializer::create(*dom->subset_handler()));
126 
127  std::vector<std::string> additionalSHNames = dom->additional_subset_handler_names();
128  for(size_t i = 0; i < additionalSHNames.size(); ++i){
129  SmartPtr<ISubsetHandler> sh = dom->additional_subset_handler(additionalSHNames[i]);
130  if(sh.valid()){
132  }
133  }
134  }
135 
136  private:
138 };
139 
140 
141 template <class TDomain, class TPartitioner>
142 class DomainPartitioner : public TPartitioner{
143  public:
144  DomainPartitioner(TDomain& dom){
145  TPartitioner::set_grid(dom.grid().get(), dom.position_attachment());
146  }
147 };
148 
149 template <class TDomain, class TBalanceWeights>
150 class DomainBalanceWeights : public TBalanceWeights{
151  public:
152  DomainBalanceWeights(TDomain& dom){
153  TBalanceWeights::set_grid(dom.grid().get(), dom.position_attachment());
154  }
155 };
156 
157 template <class TDomain, class TCommunicationCostWeights>
158 class DomainCommunicationCostWeights : public TCommunicationCostWeights{
159  public:
161  TCommunicationCostWeights::set_grid(dom.grid().get(), dom.position_attachment());
162  }
163 };
164 
165 }// end of namespace
166 
167 #endif
T * get()
returns encapsulated pointer
Definition: smart_pointer.h:197
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:206
Definition: domain_load_balancer.h:150
DomainBalanceWeights(TDomain &dom)
Definition: domain_load_balancer.h:152
Definition: domain_load_balancer.h:158
DomainCommunicationCostWeights(TDomain &dom)
Definition: domain_load_balancer.h:160
Describes the contents of a domain.
Definition: domain.h:59
A small wrapper for LoadBalancer which adds comfort methods to balance and distribute domains.
Definition: domain_load_balancer.h:109
LoadBalancer base_class
Definition: domain_load_balancer.h:110
DomainLoadBalancer(SmartPtr< TDomain > dom)
Definition: domain_load_balancer.h:116
SmartPtr< TDomain > m_dom
Definition: domain_load_balancer.h:137
Definition: domain_load_balancer.h:142
DomainPartitioner(TDomain &dom)
Definition: domain_load_balancer.h:144
Serialization callback for grid attachments.
Definition: serialization.h:290
The refiner interface allows to mark elements for refinement and to call refine.
Definition: refiner_interface.h:67
size_t num_marked_edges(std::vector< int > &numMarkedEdgesOut)
returns the number of (globally) marked edges on all levels of the hierarchy
Definition: refiner_interface.cpp:314
size_t num_marked_faces(std::vector< int > &numMarkedFacesOut)
returns the number of (globally) marked faces on all levels of the hierarchy
Definition: refiner_interface.cpp:332
size_t num_marked_volumes(std::vector< int > &numMarkedVolsOut)
returns the number of (globally) marked volumes on all levels of the hierarchy
Definition: refiner_interface.cpp:350
A load-balancer redistributes grids using the specified partitioner and process-hierarchy.
Definition: load_balancer.h:51
virtual void set_grid(MultiGrid *mg)
Definition: load_balancer.cpp:269
virtual void add_serializer(SPVertexDataSerializer cb)
add serialization callbacks.
Definition: load_balancer.h:135
static SPProcessHierarchy create()
Definition: process_hierarchy.h:57
static SPGridDataSerializer create(ISubsetHandler &sh)
Definition: serialization.h:314
size_t num_elements_on_level(size_t lvl) const
returns the global number of elements on the given level (excluding ghosts...)
Definition: domain.h:66
size_t num_levels() const
Definition: domain.h:64
function util LuaCallbackHelper create(func)
the ug namespace
SmartPtr< ProcessHierarchy > SPProcessHierarchy
Definition: process_hierarchy.h:46
SPProcessHierarchy CreateProcessHierarchy(TDomain &dom, size_t minNumElemsPerProcPerLvl, size_t maxNumRedistProcs, size_t maxNumProcs, int minDistLvl, int maxLevelsWithoutRedist)
Creates a process-hierarchy that fullfills the given conditions.
Definition: domain_load_balancer.h:46