Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
global_layout.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 * Author: Martin Rupp
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 GLOBAL_LAYOUT_H_
34#define GLOBAL_LAYOUT_H_
35
36#ifdef UG_PARALLEL
37
38#include <vector>
39#include <map>
40#include "pcl/pcl.h"
41#include "parallelization.h"
43
44namespace ug
45{
46
47typedef std::map<int, std::vector<AlgebraID> > GlobalLayout;
48
49void ReceiveGlobalLayout(pcl::InterfaceCommunicator<IndexLayout> &comm, const std::vector<int> &srcprocs,
50 GlobalLayout &globalMasterLayout, GlobalLayout &globalSlaveLayout);
52 const GlobalLayout &globalMasterLayout, const GlobalLayout &globalSlaveLayout, int pid);
53void MergeGlobalLayout(GlobalLayout &globalLayout, const std::map<int, int> &merge);
54
55
56template<typename TGlobalToLocal>
57void AddLayoutFromGlobalLayout(IndexLayout &layout, GlobalLayout &globalLayout, TGlobalToLocal &globalToLocal, bool bRemoveDoubles=true)
58{
60 for(GlobalLayout::iterator it = globalLayout.begin(); it != globalLayout.end(); ++it)
61 {
62 int pid = it->first;
63 std::vector<AlgebraID> &v = it->second;
64 if(v.size() == 0) continue;
65 sort(v.begin(), v.end());
66
67 IndexLayout::Interface &interface = layout.interface(pid);
68
69 if(bRemoveDoubles)
70 {
71 interface.push_back(globalToLocal[v[0]]);
72 for(size_t i=1; i<v.size(); i++)
73 if(v[i-1] != v[i])
74 interface.push_back(globalToLocal[v[i]]);
75 }
76 else
77 {
78 for(size_t i=0; i<v.size(); i++)
79 interface.push_back(globalToLocal[v[i]]);
80 }
81 }
82}
83
84template<typename TGlobalToLocal>
85inline void CreateLayoutFromGlobalLayout(IndexLayout &layout, GlobalLayout &globalLayout, TGlobalToLocal &globalToLocal, bool bRemoveDoubles=true)
86{
87 layout.clear();
88 AddLayoutFromGlobalLayout(layout, globalLayout, globalToLocal, bRemoveDoubles);
89}
90
91
92template<typename TLocalToGlobal>
94 const IndexLayout &layout, const TLocalToGlobal &localToGlobal)
95{
97 for(IndexLayout::const_iterator iter = layout.begin(); iter != layout.end(); ++iter)
98 {
99 const IndexLayout::Interface &interface = layout.interface(iter);
100 int pid = layout.proc_id(iter);
101
102 std::vector<AlgebraID> &v = globalLayout[pid];
103 for(IndexLayout::Interface::const_iterator iter2 = interface.begin(); iter2 != interface.end(); ++iter2)
104 {
105 size_t localIndex = interface.get_element(iter2);
106 v.push_back(localToGlobal[localIndex]);
107 }
108 }
109}
110
111void PrintGlobalLayout(const GlobalLayout &globalLayout, const char *name=NULL);
112} // namespace ug
113
114#endif
115
116#endif /* GLOBAL_LAYOUT_H_ */
location name
Definition checkpoint_util.lua:128
Performs communication between interfaces on different processes.
Definition pcl_interface_communicator.h:68
You may add elements to this interface and iterate over them.
Definition pcl_communication_structs.h:207
iterator push_back(const Element &elem)
Definition pcl_communication_structs.h:245
iterator end(size_t level=0)
returns the iterator to the last interface of the layout.
Definition pcl_communication_structs.h:492
iterator begin(size_t level=0)
returns the iterator to the first interface of the layout.
Definition pcl_communication_structs.h:486
int proc_id(iterator iter) const
returns the target process of the interface given in iterator
Definition pcl_communication_structs.h:509
InterfaceMap::const_iterator const_iterator
Definition pcl_communication_structs.h:477
void clear()
clears the layout
Definition pcl_communication_structs.h:522
function table merge(t1, t2)
the ug namespace
void CreateGlobalLayout(GlobalLayout &globalLayout, const IndexLayout &layout, const TLocalToGlobal &localToGlobal)
Definition global_layout.h:93
void AddLayoutFromGlobalLayout(IndexLayout &layout, GlobalLayout &globalLayout, TGlobalToLocal &globalToLocal, bool bRemoveDoubles=true)
Definition global_layout.h:57
void SendGlobalLayout(pcl::InterfaceCommunicator< IndexLayout > &comm, const GlobalLayout &globalMasterLayout, const GlobalLayout &globalSlaveLayout, int pid)
Definition global_layout.cpp:118
void PrintGlobalLayout(const GlobalLayout &globalLayout, const char *name)
Definition global_layout.cpp:62
std::map< int, std::vector< AlgebraID > > GlobalLayout
Definition global_layout.h:47
void CreateLayoutFromGlobalLayout(IndexLayout &layout, GlobalLayout &globalLayout, TGlobalToLocal &globalToLocal, bool bRemoveDoubles=true)
Definition global_layout.h:85
void ReceiveGlobalLayout(pcl::InterfaceCommunicator< IndexLayout > &comm, const std::vector< int > &srcprocs, GlobalLayout &globalMasterLayout, GlobalLayout &globalSlaveLayout)
Definition global_layout.cpp:81
void MergeGlobalLayout(GlobalLayout &globalLayout, const std::map< int, int > &merge)
Definition global_layout.cpp:135
#define PROFILE_FUNC()
Definition profiler.h:257