Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pcl_layout_util.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-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_layout_util__
34#define __H__PCL__pcl_layout_util__
35
36#include <vector>
37#include "common/util/hash.h"
39
40
41namespace pcl{
42
45
47template <class TLayout>
48void RemoveEmptyInterfaces(TLayout& layout)
49{
50 typedef typename TLayout::iterator TInterfaceIter;
51 typedef typename TLayout::Interface TInterface;
52
53 for(size_t lvl = 0; lvl < layout.num_levels(); ++lvl){
54 for(TInterfaceIter iter = layout.begin(lvl); iter != layout.end(lvl);)
55 {
56 TInterface& intfc = layout.interface(iter);
57 if(intfc.empty())
58 iter = layout.erase(iter, lvl);
59 else
60 ++iter;
61 }
62 }
63}
64
67
75template <class TLayout>
76size_t CollectAssociatedProcesses(std::vector<int>& procIDsOut,
77 TLayout& layout)
78{
79 procIDsOut.clear();
80
81// iterate through the levels of the layout
82 for(size_t i = 0; i < layout.num_levels(); ++i){
83 // iterate through the interfaces on that level
84 for(typename TLayout::iterator iIter = layout.begin(i);
85 iIter != layout.end(i); ++iIter)
86 {
87 int procID = layout.proc_id(iIter);
88 // check whether the process is already contained in procIDsOut
89 if(i > 0){
90 if(find(procIDsOut.begin(), procIDsOut.end(), procID)
91 == procIDsOut.end())
92 {
93 // the entry has not yet been added
94 procIDsOut.push_back(procID);
95 }
96 }
97 else{
98 // on level 0 each process exists only once
99 procIDsOut.push_back(procID);
100 }
101 }
102 }
103
104 return procIDsOut.size();
105}
106
108
113template <class TLayout>
114void CollectElements(std::vector<typename TLayout::Element>& elemsOut,
115 TLayout& layout,
116 bool clearContainer = true)
117{
118 typedef typename TLayout::Interface Interface;
119
120// clear the return value
121 if(clearContainer) elemsOut.clear();
122
123// iterate over all interfaces
124 for(size_t lvl = 0; lvl < layout.num_levels(); ++lvl){
125 for(typename TLayout::const_iterator interfaceIter = layout.begin(lvl);
126 interfaceIter != layout.end(lvl); ++interfaceIter)
127 {
128 // iterate over the entries of the interface
129 const Interface& interface = layout.interface(interfaceIter);
130 for(typename Interface::const_iterator iter = interface.begin();
131 iter != interface.end(); ++iter)
132 {
133 // add elem to vector
134 elemsOut.push_back(interface.get_element(iter));
135 }
136 }
137 }
138}
139
141template <class TLayout>
142void CollectUniqueElements(std::vector<typename TLayout::Element>& elemsOut,
143 const TLayout& layout)
144{
145 typedef typename TLayout::Interface Interface;
146 typedef typename TLayout::Element TElem;
147
148// clear the return value
149 elemsOut.clear();
150
151// we'll use a hash to make sure that each element only exists once
152 ug::Hash<TElem, int> hash(layout.num_interface_elements());
153 hash.reserve(layout.num_interface_elements());
154
155// iterate over all interfaces
156 for(size_t lvl = 0; lvl < layout.num_levels(); ++lvl){
157 for(typename TLayout::const_iterator interfaceIter = layout.begin(lvl);
158 interfaceIter != layout.end(lvl); ++interfaceIter)
159 {
160 // iterate over the entries of the interface
161 const Interface& interface = layout.interface(interfaceIter);
162 for(typename Interface::const_iterator iter = interface.begin();
163 iter != interface.end(); ++iter)
164 {
165 // check whether the entry already exists in the hash
166 if(!hash.has_entry(interface.get_element(iter))){
167 // we don't care about the value
168 hash.insert(interface.get_element(iter), 0);
169 elemsOut.push_back(interface.get_element(iter));
170 }
171 }
172 }
173 }
174}
175
176// end group pcl
178
179}// end of namespace
180
181#endif
Definition hash.h:48
void insert(const key_t &key, const value_t &val)
Definition hash_impl.hpp:199
bool has_entry(const key_t &key) const
Definition hash_impl.hpp:150
void reserve(size_t size)
Reserves memory for key-value-pair storage.
Definition hash_impl.hpp:113
void CollectElements(std::vector< typename TLayout::Element > &elemsOut, TLayout &layout, bool clearContainer=true)
writes all elements in the interfaces into the vector.
Definition pcl_layout_util.h:114
size_t CollectAssociatedProcesses(std::vector< int > &procIDsOut, TLayout &layout)
collects the ids of all processes to which interfaces exist.
Definition pcl_layout_util.h:76
void CollectUniqueElements(std::vector< typename TLayout::Element > &elemsOut, const TLayout &layout)
writes all elements in the interfaces into the resulting vector. avoids doubles.
Definition pcl_layout_util.h:142
Definition parallel_grid_layout.h:46
IndexLayout::Interface::iterator find(IndexLayout::Interface &interface, size_t i)
Definition parallel_index_layout.h:77
static void RemoveEmptyInterfaces(typename GridLayoutMap::Types< TGeomObj >::Map &map)
A helper method for GridLayoutMap::remove_empty_interfaces()
Definition parallel_grid_layout.cpp:64