ug4
serialization.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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 SERIALIZATION_H_
34 #define SERIALIZATION_H_
35 
36 namespace ug{
37 
38 template<class TOStream>
39 void Serialize(TOStream &buf, const IndexLayout::Interface &interface)
40 {
41  Serialize(buf, (size_t)interface.size());
42  for(IndexLayout::Interface::const_iterator iter = interface.begin(); iter != interface.end(); ++iter)
43  Serialize(buf, interface.get_element(iter));
44 }
45 
46 template<class TIStream>
47 void Deserialize(TIStream &buf, IndexLayout::Interface &interface)
48 {
49  size_t s = Deserialize<size_t> (buf);
51  for(size_t i=0; i<s; i++)
52  {
53  Deserialize(buf, el);
54  interface.push_back(el);
55  }
56 }
57 
58 
59 template<class TOStream>
60 void Serialize(TOStream &buf, const IndexLayout &layout)
61 {
62  Serialize(buf, (size_t)layout.num_interfaces());
63  for(IndexLayout::const_iterator iter = layout.begin(); iter != layout.end(); ++iter)
64  {
65  Serialize(buf, (int) layout.proc_id(iter));
66  Serialize(buf, layout.interface(iter));
67  }
68 }
69 
70 
71 template<class TIStream>
72 void Deserialize(TIStream &buf, IndexLayout &layout)
73 {
74  size_t num_interfaces = Deserialize<size_t>(buf);
75  for(size_t i=0; i<num_interfaces; i++)
76  {
77  int pid = Deserialize<int>(buf);
78  Deserialize(buf, layout.interface(pid));
79  }
80 }
81 
82 template<typename T>
83 void SetParallelData(T &t,
84  IndexLayout &masterLayout, IndexLayout &slaveLayout,
87 {
88  t.set_master_layout(masterLayout);
89  t.set_slave_layout(slaveLayout);
90 
91  t.set_communicator(ic);
92  t.set_process_communicator(pc);
93 }
94 
95 template<typename T, class TOStream>
96 void SerializeParallelData(TOStream &buf, T &t)
97 {
98  Serialize(buf, t.layouts()->master());
99  Serialize(buf, t.layouts()->slave());
100 
101  Serialize(buf, t.layouts()->comm());
102 
103  Serialize(buf, t.layouts()->proc_comm());
104 }
105 
106 template<typename T, class TIStream>
107 void DeserializeParallelData(TIStream &buf, T &t,
108  IndexLayout &masterLayout, IndexLayout &slaveLayout,
111 {
112  Deserialize(buf, masterLayout);
113  Deserialize(buf, slaveLayout);
114 
115  Deserialize(buf, ic);
116  Deserialize(buf, pc);
117 }
118 
120 
121 template<typename T, class TOStream>
122 void SerializeUniquePart(TOStream &buf, const ParallelMatrix<T> &A)
123 {
124  Serialize(buf, A.get_storage_mask());
125 }
126 
127 template<typename T, class TIStream>
129 {
130  A.set_storage_type( Deserialize<uint>(buf) );
131 }
132 
133 /*template<typename T, class TOStream>
134 void Serialize(TOStream &buf, const ParallelMatrix<T> &A)
135 {
136  UG_ASSERT(0, "use SerializeUniquePart");
137 }
138 
139 template<typename T, class TIStream>
140 void Deserialize(TIStream &buf, ParallelMatrix<T> &A)
141 {
142  UG_ASSERT(0, "use DeserializeUniquePart");
143 }*/
144 
146 template<typename TValueType, class TOStream>
147 void SerializeUniquePart(TOStream &buf, const ParallelVector<TValueType> &v)
148 {
149  Serialize(buf, v.get_storage_mask());
150 }
151 
152 template<typename TValueType, class TIStream>
154 {
155  v.set_storage_type( Deserialize<uint>(buf) );
156 }
157 
158 /*template<typename TValueType, class TOStream>
159 void Serialize(TOStream &buf, const ParallelVector<TValueType> &v)
160 {
161  UG_ASSERT(0, "use SerializeUniquePart and SerializeParallelData");
162 }
163 
164 template<typename TValueType, class TIStream>
165 void Deserialize(TIStream &buf, ParallelVector<TValueType> &v)
166 {
167  UG_ASSERT(0, "use DeserializeUniquePart and DeserializeParallelData");
168 }*/
170 
171 template<class TOStream>
173 {
174  //Serialize<bool>(buf, ic.communication_debugging_enabled());
175 }
176 
177 template<class TIStream>
179 {
180  //
181 }
182 
183 template<class TOStream>
184 void Serialize(TOStream &buf, const pcl::ProcessCommunicator &ic)
185 {
186  int s;
187  if(ic.is_world())
188  s = -1;
189  else
190  s = ic.size();
191  Serialize(buf, s);
192 
193  if(s > 0)
194  {
195  for(int i=0; i<s; i++)
196  Serialize(buf, ic.get_proc_id(i));
197  }
198 }
199 
200 
201 template<class TIStream>
202 void Deserialize(TIStream &buf, pcl::ProcessCommunicator &ic)
203 {
204  int s = Deserialize<int>(buf);
205 
206  if(s == -1)
207  {
208  if(ic.is_world()) return;
210  }
211  else if (s == 0)
212  {
213  if(ic.empty()) return;
215  }
216  else
217  {
218  std::vector<int> procs;
219  for(int i=0; i<s; i++)
220  procs.push_back(Deserialize<int>(buf));
222  }
223 }
224 
225 }
226 #endif /* SERIALIZATION_H_ */
parameterString s
Performs communication between interfaces on different processes.
Definition: pcl_interface_communicator.h:68
Definition: pcl_process_communicator.h:70
static ProcessCommunicator create_communicator(std::vector< int > &newGlobalProcs)
Definition: pcl_process_communicator.cpp:234
int get_proc_id(size_t index) const
returns the i-th process in the communicator
Definition: pcl_process_communicator.cpp:86
bool empty() const
returns true if the communicator is empty, false if not.
Definition: pcl_process_communicator.h:77
bool is_world() const
return true if the communicator is PCD_WORLD
Definition: pcl_process_communicator.h:80
size_t size() const
returns the size of the communicator
Definition: pcl_process_communicator.cpp:71
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
size_t num_interfaces(size_t level=0) const
returns the number of interfaces in the layout
Definition: pcl_communication_structs.h:567
int proc_id(iterator iter) const
returns the target process of the interface given in iterator
Definition: pcl_communication_structs.h:509
Interface & interface(iterator iter)
returns the interface to the given iterator.
Definition: pcl_communication_structs.h:505
InterfaceMap::const_iterator const_iterator
Definition: pcl_communication_structs.h:477
Interface::Element Element
Element type.
Definition: pcl_communication_structs.h:473
TInterface Interface
Interface type.
Definition: pcl_communication_structs.h:467
Wrapper for sequential matrices to handle them in parallel.
Definition: parallel_matrix.h:65
void set_storage_type(uint type)
sets the storage type
Definition: parallel_matrix.h:101
uint get_storage_mask() const
returns storage type mask
Definition: parallel_matrix.h:120
Definition: parallel_vector.h:60
uint get_storage_mask() const
returns storage type mask
Definition: parallel_vector.h:123
void set_storage_type(uint type)
sets the storage type
Definition: parallel_vector.h:104
@ PCD_EMPTY
Definition: pcl_process_communicator.h:54
@ PCD_WORLD
Definition: pcl_process_communicator.h:55
the ug namespace
void DeserializeUniquePart(TIStream &buf, ParallelMatrix< T > &A)
Definition: serialization.h:128
void SerializeUniquePart(TOStream &buf, const ParallelMatrix< T > &A)
Definition: serialization.h:122
void DeserializeParallelData(TIStream &buf, T &t, IndexLayout &masterLayout, IndexLayout &slaveLayout, pcl::InterfaceCommunicator< IndexLayout > &ic, pcl::ProcessCommunicator &pc)
Definition: serialization.h:107
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
void SerializeParallelData(TOStream &buf, T &t)
Definition: serialization.h:96
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition: restart_bridge.cpp:103
void SetParallelData(T &t, IndexLayout &masterLayout, IndexLayout &slaveLayout, pcl::InterfaceCommunicator< IndexLayout > &ic, pcl::ProcessCommunicator &pc)
Definition: serialization.h:83